This commit is contained in:
walterhiggins 2013-12-24 00:18:43 +00:00
parent d0da034fb7
commit b2761d29e3
27 changed files with 516 additions and 536 deletions

View file

@ -1,4 +1,7 @@
plugin("alias", {
var _store = {players: {}};
var alias = plugin("alias", {
help: function(){ help: function(){
return [ return [
"/jsp alias set <alias> <commands> : Set a shortcut/alias for one or more commands (separated by ';')\n" + "/jsp alias set <alias> <commands> : Set a shortcut/alias for one or more commands (separated by ';')\n" +
@ -10,30 +13,30 @@ plugin("alias", {
]; ];
}, },
set: function(player, alias, commands){ set: function(player, alias, commands){
var aliases = this.store.players; var aliases = _store.players;
var name = player.name; var name = player.name;
if (typeof aliases[name] == "undefined") if (typeof aliases[name] == "undefined")
aliases[name] = {}; aliases[name] = {};
aliases[name][alias] = commands; aliases[name][alias] = commands;
}, },
remove: function(player, alias){ remove: function(player, alias){
var aliases = this.store.players; var aliases = _store.players;
if (aliases[player.name]) if (aliases[player.name])
delete aliases[player.name][alias]; delete aliases[player.name][alias];
}, },
list: function(player){ list: function(player){
var result = []; var result = [];
var aliases = this.store.players[player.name]; var aliases = _store.players[player.name];
for (var a in aliases) for (var a in aliases)
result.push(a + " = " + aliases[a].join(";")); result.push(a + " = " + aliases[a].join(";"));
return result; return result;
} },
store: _store
},true); },true);
if (typeof alias.store.players == "undefined") exports.alias = alias;
alias.store.players = {};
command("alias",function(params){ command("alias", function ( params ) {
/* /*
this function also intercepts command options for /jsp this function also intercepts command options for /jsp
*/ */
@ -59,7 +62,7 @@ command("alias",function(params){
if (params.length == 0) if (params.length == 0)
return self.sendMessage(alias.help()); return self.sendMessage(alias.help());
var playerHasAliases = alias.store.players[self.name]; var playerHasAliases = _store.players[self.name];
if (!playerHasAliases) if (!playerHasAliases)
return false; return false;
// is it an alias? // is it an alias?

View file

@ -1,25 +1,33 @@
/* /*************************************************************************
The arrows mod adds fancy arrows to the game. ## The arrows mod adds fancy arrows to the game.
Usage: ### Usage:
/js arrows.sign() turns a targeted sign into a Arrows menu /js var arrows = require('./arrows/arrows')
/js arrows.normal() sets arrow type to normal.
/js arrows.explosive() - makes arrows explode. * `/js arrows.sign()` turns a targeted sign into a Arrows menu
/js arrows.teleport() - makes player teleport to where arrow has landed. * `/js arrows.normal()` sets arrow type to normal.
/js arrows.flourish() - makes a tree grow where the arrow lands. * `/js arrows.explosive()` - makes arrows explode.
/js arrows.lightning() - lightning strikes where the arrow lands. * `/js arrows.teleport()` - makes player teleport to where arrow has landed.
/js arrows.firework() - A firework launches where the the arrow lands. * `/js arrows.flourish()` - makes a tree grow where the arrow lands.
* `/js arrows.lightning()` - lightning strikes where the arrow lands.
* `/js arrows.firework()` - A firework launches where the the arrow lands.
All of the above functions can take an optional player object or name as All of the above functions can take an optional player object or name as
a parameter. E.g. a parameter. E.g.
/js arrows.explosive('player23') makes player23's arrows explosive. `/js arrows.explosive('player23')` makes player23's arrows explosive.
*/ ***/
var arrows = arrows || plugin("arrows",{ var signs = require('signs');
var events = require('events');
var fireworks = require('fireworks');
var _store = {players: {}};
var arrows = plugin("arrows",{
/* /*
turn a sign into a menu of arrow choices turn a sign into a menu of arrow choices
*/ */
@ -48,91 +56,88 @@ var arrows = arrows || plugin("arrows",{
/* /*
launch a firework where the arrow lands launch a firework where the arrow lands
*/ */
explosiveYield: 2.5 explosiveYield: 2.5,
store: _store
},true); },true);
/*
initialize data
*/
arrows.store.players = arrows.store.players || {};
/* exports.arrows = arrows;
private implementation of normal, explosive, teleport, flourish and lightning functions
*/ //
(function(){ // setup functions for the arrow types
// //
// setup functions for the arrow types var _types = {normal: 0, explosive: 1, teleport: 2, flourish: 3, lightning: 4, firework: 5};
// for (var type in _types)
var _types = {normal: 0, explosive: 1, teleport: 2, flourish: 3, lightning: 4, firework: 5};
for (var type in _types)
{
arrows[type] = (function(n){
return function(player){
if (typeof player == "undefined")
player = self;
var playerName = null;
if (typeof player == "string")
playerName = player;
else
playerName = player.name;
arrows.store.players[playerName] = n;
};
})(_types[type]);
}
}());
/*
Arrows depends on 2 other modules: 'signs' and 'events' so the following code
can't execute until all modules have loaded (ready).
*/
ready(function()
{ {
/* arrows[type] = (function(n){
called when the player chooses an arrow option from a menu sign return function(player){
*/ if (typeof player == "undefined")
var _onMenuChoice = function(event){ player = self;
arrows.store.players[event.player.name] = event.number; var playerName = null;
}; if (typeof player == "string")
arrows.sign = signs.menu("Arrow", playerName = player;
["Normal","Explosive","Teleport","Flourish","Lightning","Firework"], else
_onMenuChoice ); playerName = player.name;
arrows.store.players[playerName] = n;
};
})(_types[type]);
}
/* /*
event handler called when a projectile hits something called when the player chooses an arrow option from a menu sign
*/ */
var _onArrowHit = function(listener,event) var _onMenuChoice = function(event){
arrows.store.players[event.player.name] = event.number;
};
arrows.sign = signs.menu("Arrow",
["Normal","Explosive","Teleport","Flourish","Lightning","Firework"],
_onMenuChoice );
/*
event handler called when a projectile hits something
*/
var _onArrowHit = function(listener,event)
{
var projectile = event.entity;
var world = projectile.world;
var shooter = projectile.shooter;
var fireworkCount = 5;
if (projectile instanceof org.bukkit.entity.Arrow &&
shooter instanceof org.bukkit.entity.Player)
{ {
var projectile = event.entity; var arrowType = arrows.store.players[shooter.name];
var world = projectile.world;
var shooter = projectile.shooter; switch (arrowType){
if (projectile instanceof org.bukkit.entity.Arrow && case 1:
shooter instanceof org.bukkit.entity.Player) projectile.remove();
{ world.createExplosion(projectile.location,arrows.explosiveYield);
var arrowType = arrows.store.players[shooter.name]; break;
switch (arrowType){ case 2:
case 1: projectile.remove();
projectile.remove(); var teleportCause =org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
world.createExplosion(projectile.location,arrows.explosiveYield); shooter.teleport(projectile.location,
break; teleportCause.PLUGIN);
case 2: break;
projectile.remove(); case 3:
var teleportCause =org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; projectile.remove();
shooter.teleport(projectile.location, world.generateTree(projectile.location, org.bukkit.TreeType.BIG_TREE);
teleportCause.PLUGIN); break;
break; case 4:
case 3: projectile.remove();
projectile.remove(); world.strikeLightning(projectile.location);
world.generateTree(projectile.location, org.bukkit.TreeType.BIG_TREE); break;
break; case 5:
case 4: projectile.remove();
projectile.remove(); var launch = function(){
world.strikeLightning(projectile.location);
break;
case 5:
projectile.remove();
fireworks.firework(projectile.location); fireworks.firework(projectile.location);
break; if (--fireworkCount)
} setTimeout(launch,2000);
};
launch();
break;
} }
}; }
events.on("entity.ProjectileHitEvent",_onArrowHit); };
}); events.on('entity.ProjectileHitEvent',_onArrowHit);

View file

@ -1,53 +1,56 @@
/*
TODO: Document this module
*/
var events = require('events');
var _store = {players: {}};
/* /*
declare a new javascript plugin for changing chat text color declare a new javascript plugin for changing chat text color
*/ */
var chat = chat || plugin("chat", { exports.chat = plugin("chat", {
/* /*
set the color of text for a given player set the color of text for a given player
*/ */
setColor: function(player, color){ setColor: function(player, color){
this.store.players[player.name] = color; this.store.players[player.name] = color;
} },
store: _store
},true); },true);
/*
initialize the store
*/
chat.store.players = chat.store.players || {};
ready(function() var colors = [
{ "black", "blue", "darkgreen", "darkaqua", "darkred",
var colors = [ "purple", "gold", "gray", "darkgray", "indigo",
"black", "blue", "darkgreen", "darkaqua", "darkred", "brightgreen", "aqua", "red", "pink", "yellow", "white"
"purple", "gold", "gray", "darkgray", "indigo", ];
"brightgreen", "aqua", "red", "pink", "yellow", "white" var colorCodes = {};
]; for (var i =0;i < colors.length;i++) {
var colorCodes = {}; var hexCode = i.toString(16);
for (var i =0;i < colors.length;i++) { colorCodes[colors[i]] = hexCode;
var hexCode = i.toString(16); }
colorCodes[colors[i]] = hexCode;
events.on("player.AsyncPlayerChatEvent",function(l,e){
var player = e.player;
var playerChatColor = chat.store.players[player.name];
if (playerChatColor){
e.message = "§" + colorCodes[playerChatColor] + e.message;
} }
events.on("player.AsyncPlayerChatEvent",function(l,e){
var player = e.player;
var playerChatColor = chat.store.players[player.name];
if (playerChatColor){
e.message = "§" + colorCodes[playerChatColor] + e.message;
}
});
var listColors = function(params){
var colorNamesInColor = [];
for (var i = 0;i < colors.length;i++)
colorNamesInColor[i] = "§"+colorCodes[colors[i]] + colors[i];
self.sendMessage("valid chat colors are " + colorNamesInColor.join(", "));
};
command("list_colors", listColors);
command("chat_color",function(params){
var color = params[0];
if (colorCodes[color]){
chat.setColor(self,color);
}else{
self.sendMessage(color + " is not a valid color");
listColors();
}
},colors);
}); });
var listColors = function(params){
var colorNamesInColor = [];
for (var i = 0;i < colors.length;i++)
colorNamesInColor[i] = "§"+colorCodes[colors[i]] + colors[i];
self.sendMessage("valid chat colors are " + colorNamesInColor.join(", "));
};
command("list_colors", listColors);
command("chat_color",function(params){
var color = params[0];
if (colorCodes[color]){
chat.setColor(self,color);
}else{
self.sendMessage(color + " is not a valid color");
listColors();
}
},colors);

View file

@ -1,3 +1,6 @@
var utils = require('utils');
var events = require('events');
/************************************************************************ /************************************************************************
Classroom Module Classroom Module
================ ================
@ -41,22 +44,19 @@ Only ops users can run the classroom.allowScripting() function - this is so that
don't try to bar themselves and each other from scripting. don't try to bar themselves and each other from scripting.
***/ ***/
var classroom = { var _canScript = false;
allowScripting: function(/* boolean: true or false */ canScript){}
};
ready(function(){ exports.classroom = {
classroom.allowScripting = function(canScript) allowScripting: function (/* boolean: true or false */ canScript) {
{
/* /*
only operators should be allowed run this function only operators should be allowed run this function
*/ */
if (!self.isOp()) if (!self.isOp())
return; return;
if (canScript){ if (canScript){
utils.foreach( server.onlinePlayers, function (player) { utils.foreach( server.onlinePlayers, function (player) {
player.addAttachment(__plugin, "scriptcraft.*", true); player.addAttachment(__plugin, "scriptcraft.*", true);
}); });
}else{ }else{
utils.foreach( server.onlinePlayers, function(player) { utils.foreach( server.onlinePlayers, function(player) {
utils.foreach(player.getEffectivePermissions(), function(perm) { utils.foreach(player.getEffectivePermissions(), function(perm) {
@ -67,12 +67,13 @@ ready(function(){
}); });
}); });
} }
classroom.canScript = canScript; _canScript = canScript;
}; }
events.on("player.PlayerLoginEvent", function(listener, event) { };
var player = event.player; events.on('player.PlayerLoginEvent', function(listener, event) {
if (classroom.canScript){ var player = event.player;
player.addAttachment(__plugin, "scriptcraft.*", true); if (classroom.canScript){
} player.addAttachment(__plugin, "scriptcraft.*", true);
}, "HIGHEST"); }
}); }, "HIGHEST");

View file

@ -272,4 +272,4 @@ blocks.rainbow = [blocks.wool.red,
blocks.wool.purple]; blocks.wool.purple];
module.exports = blocks; exports.blocks = blocks;

View file

@ -1,7 +1,6 @@
var Drone = require('./drone'); var Drone = require('./drone').Drone;
var blocks = require('./blocks'); var blocks = require('./blocks').blocks;
module.exports = Drone;
/************************************************************************ /************************************************************************
Drone.blocktype() method Drone.blocktype() method
======================== ========================

View file

@ -1,5 +1,5 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
module.exports = Drone;
// //
// a castle is just a big wide fort with 4 taller forts at each corner // a castle is just a big wide fort with 4 taller forts at each corner
// //

View file

@ -1,7 +1,6 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
var blocks = require('../blocks'); var blocks = require('../blocks').blocks;
module.exports = Drone;
/** /**
* Creates a tile pattern of given block types and size * Creates a tile pattern of given block types and size
* *

View file

@ -1,5 +1,5 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
module.exports = Drone;
// //
// usage: // usage:
// [1] to build a cottage at the player's current location or the cross-hairs location... // [1] to build a cottage at the player's current location or the cross-hairs location...

View file

@ -1,5 +1,5 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
module.exports = Drone;
// //
// Create a floor of colored tiles some of which emit light. // Create a floor of colored tiles some of which emit light.
// The tiles change color every second creating a strobe-lit dance-floor. // The tiles change color every second creating a strobe-lit dance-floor.

View file

@ -1,5 +1,5 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
module.exports = Drone;
// //
// constructs a medieval fort // constructs a medieval fort
// //

View file

@ -1,5 +1,5 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
module.exports = Drone;
// //
// Constructs the JS logo // Constructs the JS logo
// https://raw.github.com/voodootikigod/logo.js/master/js.png // https://raw.github.com/voodootikigod/logo.js/master/js.png

View file

@ -1,6 +1,6 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
var blocks = require('../blocks'); var blocks = require('../blocks').blocks;
module.exports = Drone;
/************************************************************************ /************************************************************************
Drone.rainbow() method Drone.rainbow() method
====================== ======================

View file

@ -1,5 +1,5 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
module.exports = Drone;
/** /**
* Iterates over each cube in a cubic region. For each cube has a chance to callback your * Iterates over each cube in a cubic region. For each cube has a chance to callback your
* function and provide a new drone to it. * function and provide a new drone to it.

View file

@ -1,6 +1,6 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
var blocks = require('../blocks'); var blocks = require('../blocks').blocks;
module.exports = Drone;
// //
// usage: // usage:
// [1] to place a new block with redstone wire on it (block on bottom, redstone on top) // [1] to place a new block with redstone wire on it (block on bottom, redstone on top)

View file

@ -1,7 +1,6 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
var blocks = require('../blocks'); var blocks = require('../blocks').blocks;
module.exports = Drone;
Drone.extend('skyscraper',function(floors){ Drone.extend('skyscraper',function(floors){
if (typeof floors == "undefined") if (typeof floors == "undefined")

View file

@ -1,7 +1,6 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
var blocks = require('../blocks'); var blocks = require('../blocks').blocks;
module.exports = Drone;
/************************************************************************ /************************************************************************
Drone.spiral_stairs() method Drone.spiral_stairs() method
============================ ============================

View file

@ -1,5 +1,4 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
module.exports = Drone;
/** /**
* Creates a stream of blocks in a given direction until it hits something other than air * Creates a stream of blocks in a given direction until it hits something other than air
* *

View file

@ -1,5 +1,4 @@
var Drone = require('../drone'); var Drone = require('../drone').Drone;
module.exports = Drone;
// //
// constructs a mayan temple // constructs a mayan temple
// //

View file

@ -1,25 +0,0 @@
var Drone = require('./drone');
var utils = require('../utils/utils');
var files = [];
var filter = function(file,name){
name = "" + name;
if (name.match(/drone\.js$/))
return false;
if (name.match(/drone\-exts\.js$/))
return false;
if (name.match(/\.js$/))
return true;
if (file.isDirectory())
return true;
return false;
};
var files = utils.find(__dirname, filter);
utils.foreach(files, function (file){
require(file);
});
module.exports = Drone;

View file

@ -1,5 +1,5 @@
var _utils = require('../utils/utils'); var _utils = require('utils');
var blocks = require('./blocks'); var blocks = require('./blocks').blocks;
/********************************************************************* /*********************************************************************
Drone Module Drone Module
@ -732,7 +732,7 @@ Drone = function(x,y,z,dir,world)
return this; return this;
}; };
module.exports = Drone; exports.Drone = Drone;
// //
// add custom methods to the Drone object using this function // add custom methods to the Drone object using this function

View file

@ -1,5 +1,4 @@
var Drone = require('./drone'); var Drone = require('./drone').Drone;
module.exports = Drone;
/************************************************************************ /************************************************************************
Drone.sphere() method Drone.sphere() method

View file

@ -1,4 +1,4 @@
var Drone = require('./drone'); var Drone = require('./drone').Drone;
Drone.prototype.testHorizontalStrokeWidth = function(){ Drone.prototype.testHorizontalStrokeWidth = function(){
this.arc({ this.arc({

View file

@ -1,8 +1,14 @@
var utils = require('utils');
var _store = {
houses: {},
openHouses: {},
invites: {}
};
/* /*
The homes plugin lets players set a location as home and return to the location, invite The homes plugin lets players set a location as home and return to the location, invite
other players to their home and also visit other player's homes. other players to their home and also visit other player's homes.
*/ */
plugin("homes", { var homes = plugin("homes", {
help: function(){ help: function(){
return [ return [
/* basic functions */ /* basic functions */
@ -33,7 +39,7 @@ plugin("homes", {
host = guest; host = guest;
guest = utils.getPlayerObject(guest); guest = utils.getPlayerObject(guest);
host = utils.getPlayerObject(host); host = utils.getPlayerObject(host);
var loc = this.store.houses[host.name]; var loc = _store.houses[host.name];
if (!loc){ if (!loc){
guest.sendMessage(host.name + " has no home"); guest.sendMessage(host.name + " has no home");
return; return;
@ -53,9 +59,9 @@ plugin("homes", {
_canVisit: function(guest, host){ _canVisit: function(guest, host){
if (guest == host) if (guest == host)
return true; return true;
if (this.store.openHouses[host.name]) if (_store.openHouses[host.name])
return true; return true;
var invitations = this.store.invites[host.name]; var invitations = _store.invites[host.name];
if (invitations) if (invitations)
for (var i = 0;i < invitations.length;i++) for (var i = 0;i < invitations.length;i++)
if (invitations[i] == guest.name) if (invitations[i] == guest.name)
@ -65,16 +71,16 @@ plugin("homes", {
set: function(player){ set: function(player){
player = utils.getPlayerObject(player); player = utils.getPlayerObject(player);
var loc = player.location; var loc = player.location;
this.store.houses[player.name] = [""+loc.world.name _store.houses[player.name] = [""+loc.world.name
,Math.floor(loc.x) ,Math.floor(loc.x)
,Math.floor(loc.y) ,Math.floor(loc.y)
,Math.floor(loc.z) ,Math.floor(loc.z)
,Math.floor(loc.yaw) ,Math.floor(loc.yaw)
,Math.floor(loc.pitch)]; ,Math.floor(loc.pitch)];
}, },
remove: function(player){ remove: function(player){
player = utils.getPlayerObject(player); player = utils.getPlayerObject(player);
delete this.store.houses[player.name]; delete _store.houses[player.name];
}, },
/* ======================================================================== /* ========================================================================
social functions social functions
@ -85,11 +91,11 @@ plugin("homes", {
*/ */
list: function(player){ list: function(player){
var result = []; var result = [];
for (var ohp in this.store.openHouses) for (var ohp in _store.openHouses)
result.push(ohp); result.push(ohp);
player = utils.getPlayerObject(player); player = utils.getPlayerObject(player);
for (var host in this.store.invites){ for (var host in _store.invites){
var guests = this.store.invites[host]; var guests = _store.invites[host];
for (var i = 0;i < guests.length; i++) for (var i = 0;i < guests.length; i++)
if (guests[i] == player.name) if (guests[i] == player.name)
result.push(host); result.push(host);
@ -103,14 +109,14 @@ plugin("homes", {
player = utils.getPlayerObject(player); player = utils.getPlayerObject(player);
var result = []; var result = [];
// if home is public - all players // if home is public - all players
if (this.store.openHouses[player.name]){ if (_store.openHouses[player.name]){
var online = org.bukkit.Bukkit.getOnlinePlayers(); var online = org.bukkit.Bukkit.getOnlinePlayers();
for (var i = 0;i < online.length; i++) for (var i = 0;i < online.length; i++)
if (online[i].name != player.name) if (online[i].name != player.name)
result.push(online[i].name); result.push(online[i].name);
}else{ }else{
if (this.store.invites[player.name]) if (_store.invites[player.name])
result = this.store.invites[player.name]; result = _store.invites[player.name];
else else
result = []; result = [];
} }
@ -123,10 +129,10 @@ plugin("homes", {
host = utils.getPlayerObject(host); host = utils.getPlayerObject(host);
guest = utils.getPlayerObject(guest); guest = utils.getPlayerObject(guest);
var invitations = []; var invitations = [];
if (this.store.invites[host.name]) if (_store.invites[host.name])
invitations = this.store.invites[host.name]; invitations = _store.invites[host.name];
invitations.push(guest.name); invitations.push(guest.name);
this.store.invites[host.name] = invitations; _store.invites[host.name] = invitations;
guest.sendMessage(host.name + " has invited you to their home."); guest.sendMessage(host.name + " has invited you to their home.");
guest.sendMessage("type '/jsp home " + host.name + "' to accept"); guest.sendMessage("type '/jsp home " + host.name + "' to accept");
}, },
@ -136,21 +142,21 @@ plugin("homes", {
uninvite: function(host, guest){ uninvite: function(host, guest){
host = utils.getPlayerObject(host); host = utils.getPlayerObject(host);
guest = utils.getPlayerObject(guest); guest = utils.getPlayerObject(guest);
var invitations = this.store.invites[host.name]; var invitations = _store.invites[host.name];
if (!invitations) if (!invitations)
return; return;
var revisedInvites = []; var revisedInvites = [];
for (var i =0;i < invitations.length; i++) for (var i =0;i < invitations.length; i++)
if (invitations[i] != guest.name) if (invitations[i] != guest.name)
revisedInvites.push(invitations[i]); revisedInvites.push(invitations[i]);
this.store.invites[host.name] = revisedInvites; _store.invites[host.name] = revisedInvites;
}, },
/* /*
make the player's house public make the player's house public
*/ */
open: function(player, optionalMsg){ open: function(player, optionalMsg){
player = utils.getPlayerObject(player); player = utils.getPlayerObject(player);
this.store.openHouses[player.name] = true; _store.openHouses[player.name] = true;
if (typeof optionalMsg != "undefined") if (typeof optionalMsg != "undefined")
__plugin.server.broadcastMessage(optionalMsg); __plugin.server.broadcastMessage(optionalMsg);
}, },
@ -159,132 +165,122 @@ plugin("homes", {
*/ */
close: function(player){ close: function(player){
player = utils.getPlayerObject(player); player = utils.getPlayerObject(player);
delete this.store.openHouses[player.name]; delete _store.openHouses[player.name];
}, },
/* ======================================================================== /* ========================================================================
admin functions admin functions
======================================================================== */ ======================================================================== */
listall: function(){ listall: function(){
var result = []; var result = [];
for (var home in this.store.houses) for (var home in _store.houses)
result.push(home); result.push(home);
return result; return result;
}, },
clear: function(player){ clear: function(player){
player = utils.getPlayerObject(player); player = utils.getPlayerObject(player);
delete this.store.houses[player.name]; delete _store.houses[player.name];
delete this.store.openHouses[player.name]; delete _store.openHouses[player.name];
} },
store: _store
}, true); }, true);
exports.homes = homes;
/* /*
private implementation define a set of command options that can be used by players
*/ */
(function(){ var options = {
/* 'set': function(){homes.set();},
define a set of command options that can be used by players 'delete': function(){ homes.remove();},
*/ 'help': function(){ self.sendMessage(homes.help());},
var options = { 'list': function(){
'set': function(){homes.set();}, var visitable = homes.list();
'delete': function(){ homes.remove();}, if (visitable.length == 0){
'help': function(){ self.sendMessage(homes.help());}, self.sendMessage("There are no homes to visit");
'list': function(){ return;
var visitable = homes.list(); }else{
if (visitable.length == 0){ self.sendMessage([
self.sendMessage("There are no homes to visit"); "You can visit any of these " + visitable.length + " homes"
return; ,visitable.join(", ")
}else{ ]);
self.sendMessage([
"You can visit any of these " + visitable.length + " homes"
,visitable.join(", ")
]);
}
},
'ilist': function(){
var potentialVisitors = homes.ilist();
if (potentialVisitors.length == 0)
self.sendMessage("No one can visit your home");
else
self.sendMessage([
"These " + potentialVisitors.length + "players can visit your home",
potentialVisitors.join(", ")]);
},
'invite': function(params){
if (params.length == 1){
self.sendMessage("You must provide a player's name");
return;
}
var playerName = params[1];
var guest = utils.getPlayerObject(playerName);
if (!guest)
self.sendMessage(playerName + " is not here");
else
homes.invite(self,guest);
},
'uninvite': function(params){
if (params.length == 1){
self.sendMessage("You must provide a player's name");
return;
}
var playerName = params[1];
var guest = utils.getPlayerObject(playerName);
if (!guest)
self.sendMessage(playerName + " is not here");
else
homes.uninvite(self,guest);
},
'public': function(params){
homes.open(self,params.slice(1).join(' '));
self.sendMessage("Your home is open to the public");
},
'private': function(){
homes.close();
self.sendMessage("Your home is closed to the public");
},
'listall': function(){
if (!self.isOp())
self.sendMessage("Only operators can do this");
else
self.sendMessage(homes.listall().join(", "));
},
'clear': function(params){
if (!self.isOp())
self.sendMessage("Only operators can do this");
else
homes.clear(params[1]);
} }
}; },
var optionList = []; 'ilist': function(){
for (var o in options) var potentialVisitors = homes.ilist();
optionList.push(o); if (potentialVisitors.length == 0)
/* self.sendMessage("No one can visit your home");
Expose a set of commands that players can use at the in-game command prompt else
*/ self.sendMessage([
command("home", function(params){ "These " + potentialVisitors.length + "players can visit your home",
if (params.length == 0){ potentialVisitors.join(", ")]);
homes.go(); },
'invite': function(params){
if (params.length == 1){
self.sendMessage("You must provide a player's name");
return; return;
} }
var option = options[params[0]]; var playerName = params[1];
if (option) var guest = utils.getPlayerObject(playerName);
option(params); if (!guest)
else{ self.sendMessage(playerName + " is not here");
var host = utils.getPlayerObject(params[0]); else
if (!host) homes.invite(self,guest);
self.sendMessage(params[0] + " is not here"); },
else 'uninvite': function(params){
homes.go(self,host); if (params.length == 1){
self.sendMessage("You must provide a player's name");
return;
} }
},optionList); var playerName = params[1];
var guest = utils.getPlayerObject(playerName);
if (!guest)
self.sendMessage(playerName + " is not here");
else
homes.uninvite(self,guest);
},
'public': function(params){
homes.open(self,params.slice(1).join(' '));
self.sendMessage("Your home is open to the public");
},
'private': function(){
homes.close();
self.sendMessage("Your home is closed to the public");
},
'listall': function(){
if (!self.isOp())
self.sendMessage("Only operators can do this");
else
self.sendMessage(homes.listall().join(", "));
},
'clear': function(params){
if (!self.isOp())
self.sendMessage("Only operators can do this");
else
homes.clear(params[1]);
}
};
var optionList = [];
for (var o in options)
optionList.push(o);
/*
Expose a set of commands that players can use at the in-game command prompt
*/
command("home", function ( params ) {
if (params.length == 0){
homes.go();
return;
}
var option = options[params[0]];
if (option)
option(params);
else{
var host = utils.getPlayerObject(params[0]);
if (!host)
self.sendMessage(params[0] + " is not here");
else
homes.go(self,host);
}
},optionList);
/*
initialize the store
*/
if (typeof homes.store.houses == "undefined")
homes.store.houses = {};
if (typeof homes.store.openHouses == "undefined")
homes.store.openHouses = {};
if (typeof homes.store.invites == "undefined")
homes.store.invites = {};
}());

View file

@ -1,10 +1,16 @@
/* /*************************************************************************
A basic number-guessing game that uses the Bukkit Conversation API. ## Minigame: Guess the number
*/
ready(function(){
global.GuessTheNumber = function() ### Example
{
/js Game_NumberGuess.start()
... Begins a number-guessing game where you must guess the number (between 1 and 10) chosen by the computer.
A basic number-guessing game that uses the Bukkit Conversation API.
***/
exports.Game_NumberGuess = {
start: function() {
importPackage(org.bukkit.conversations); importPackage(org.bukkit.conversations);
var number = Math.ceil(Math.random() * 10); var number = Math.ceil(Math.random() * 10);
@ -44,5 +50,5 @@ ready(function(){
.withPrefix(new ConversationPrefix(){ getPrefix: function(ctx){ return "[1-10] ";} }) .withPrefix(new ConversationPrefix(){ getPrefix: function(ctx){ return "[1-10] ";} })
.buildConversation(self); .buildConversation(self);
conv.begin(); conv.begin();
}; }
}); };

View file

@ -1,4 +1,5 @@
load(__folder + "../events/events.js"); var events = require('events');
/* /*
OK - this is a rough and ready prototype of a simple multi-player shoot-em-up. OK - this is a rough and ready prototype of a simple multi-player shoot-em-up.
Get a bunch of players in close proximity and issue the following commands... Get a bunch of players in close proximity and issue the following commands...
@ -6,7 +7,7 @@ load(__folder + "../events/events.js");
/js var redTeam = ['<player1>','<player2>',...etc] /js var redTeam = ['<player1>','<player2>',...etc]
/js var blueTeam = ['<player3>','<player4>,...etc] /js var blueTeam = ['<player3>','<player4>,...etc]
/js var greenTeam = ['<player5>','<player6>,...etc] /js var greenTeam = ['<player5>','<player6>,...etc]
/js new SnowBallFight({red: redTeam,blue: blueTeam,green: greenTeam},60).start(); /js new Game_SnowBallFight({red: redTeam,blue: blueTeam,green: greenTeam},60).start();
Alternatively you can just have all players play against each other... Alternatively you can just have all players play against each other...
@ -29,152 +30,147 @@ load(__folder + "../events/events.js");
*/ */
var SnowBallFight = function(teams, duration){}; /*
SnowBallFight.prototype.start = function(){}; setup game
*/
var _startGame = function(gameState){
// don't let game start if already in progress (wait for game to finish)
if (gameState.inProgress){
return;
}
gameState.inProgress = true;
// reset timer
gameState.duration = gameState.originalDuration;
// put all players in survival mode and give them each 200 snowballs
// 64 snowballs for every 30 seconds should be more than enough
for (var i = 10;i < gameState.duration;i+=10)
gameState.ammo.push(gameState.ammo[0]);
(function(){ for (var teamName in gameState.teams)
{
/* gameState.teamScores[teamName] = 0;
setup game var team = gameState.teams[teamName];
*/ for (var i = 0;i < team.length;i++) {
var _startGame = function(gameState){ var player = server.getPlayer(team[i]);
// don't let game start if already in progress (wait for game to finish) gameState.savedModes[player.name] = player.gameMode;
if (gameState.inProgress){ player.gameMode = org.bukkit.GameMode.SURVIVAL;
return; player.inventory.addItem(gameState.ammo);
} }
gameState.inProgress = true; }
// reset timer };
gameState.duration = gameState.originalDuration; /*
// put all players in survival mode and give them each 200 snowballs end the game
// 64 snowballs for every 30 seconds should be more than enough */
for (var i = 10;i < gameState.duration;i+=10) var _endGame = function(gameState){
gameState.ammo.push(gameState.ammo[0]); var scores = [];
for (var teamName in gameState.teams) var leaderBoard = [];
{ for (var tn in gameState.teamScores){
gameState.teamScores[teamName] = 0; leaderBoard.push([tn,gameState.teamScores[tn]]);
var team = gameState.teams[teamName]; }
for (var i = 0;i < team.length;i++) { leaderBoard.sort(function(a,b){ return b[1] - a[1];});
var player = server.getPlayer(team[i]);
gameState.savedModes[player.name] = player.gameMode; for (var i = 0;i < leaderBoard.length; i++){
player.gameMode = org.bukkit.GameMode.SURVIVAL; scores.push("Team " + leaderBoard[i][0] + " scored " + leaderBoard[i][1]);
player.inventory.addItem(gameState.ammo); }
}
for (var teamName in gameState.teams) {
var team = gameState.teams[teamName];
for (var i = 0;i < team.length;i++) {
// restore player's previous game mode and take back snowballs
var player = server.getPlayer(team[i]);
player.gameMode = gameState.savedModes[player.name];
player.inventory.removeItem(gameState.ammo);
player.sendMessage("GAME OVER.");
player.sendMessage(scores);
} }
}
var handlerList = org.bukkit.event.entity.EntityDamageByEntityEvent.getHandlerList();
handlerList.unregister(gameState.listener);
gameState.inProgress = false;
};
/*
get the team the player belongs to
*/
var _getTeam = function(player,pteams) {
for (var teamName in pteams) {
var team = pteams[teamName];
for (var i = 0;i < team.length; i++)
if (team[i] == player.name)
return teamName;
}
return null;
};
/*
construct a new game
*/
var _constructor = function(duration, teams) {
var _snowBalls = new org.bukkit.inventory.ItemStack(org.bukkit.Material.SNOW_BALL, 64);
var _gameState = {
teams: teams,
duration: duration,
originalDuration: duration,
inProgress: false,
teamScores: {},
listener: null,
savedModes: {},
ammo: [_snowBalls]
}; };
/* if (typeof duration == "undefined"){
end the game duration = 60;
*/ }
var _endGame = function(gameState){ if (typeof teams == "undefined"){
var scores = [];
var leaderBoard = [];
for (var tn in gameState.teamScores){
leaderBoard.push([tn,gameState.teamScores[tn]]);
}
leaderBoard.sort(function(a,b){ return b[1] - a[1];});
for (var i = 0;i < leaderBoard.length; i++){
scores.push("Team " + leaderBoard[i][0] + " scored " + leaderBoard[i][1]);
}
for (var teamName in gameState.teams) {
var team = gameState.teams[teamName];
for (var i = 0;i < team.length;i++) {
// restore player's previous game mode and take back snowballs
var player = server.getPlayer(team[i]);
player.gameMode = gameState.savedModes[player.name];
player.inventory.removeItem(gameState.ammo);
player.sendMessage("GAME OVER.");
player.sendMessage(scores);
}
}
var handlerList = org.bukkit.event.entity.EntityDamageByEntityEvent.getHandlerList();
handlerList.unregister(gameState.listener);
gameState.inProgress = false;
};
/*
get the team the player belongs to
*/
var _getTeam = function(player,pteams) {
for (var teamName in pteams) {
var team = pteams[teamName];
for (var i = 0;i < team.length; i++)
if (team[i] == player.name)
return teamName;
}
return null;
};
/*
construct a new game
*/
var _constructor = function(duration, teams) {
var _snowBalls = new org.bukkit.inventory.ItemStack(org.bukkit.Material.SNOW_BALL, 64);
var _gameState = {
teams: teams,
duration: duration,
originalDuration: duration,
inProgress: false,
teamScores: {},
listener: null,
savedModes: {},
ammo: [_snowBalls]
};
if (typeof duration == "undefined"){
duration = 60;
}
if (typeof teams == "undefined"){
/*
wph 20130511 use all players
*/
teams = [];
var players = server.onlinePlayers;
for (var i = 0;i < players.length; i++){
teams.push(players[i].name);
}
}
//
// allow for teams param to be either {red:['player1','player2'],blue:['player3']} or
// ['player1','player2','player3'] if all players are against each other (no teams)
//
if (teams instanceof Array){
_gameState.teams = {};
for (var i = 0;i < teams.length; i++)
_gameState.teams[teams[i]] = [teams[i]];
}
/* /*
this function is called every time a player is damaged by another entity/player wph 20130511 use all players
*/ */
var _onSnowballHit = function(l,event){ teams = [];
var snowball = event.damager; var players = server.onlinePlayers;
if (!snowball || !(snowball instanceof org.bukkit.entity.Snowball)) for (var i = 0;i < players.length; i++){
return; teams.push(players[i].name);
var throwersTeam = _getTeam(snowball.shooter,_gameState.teams); }
var damageeTeam = _getTeam(event.entity,_gameState.teams); }
if (!throwersTeam || !damageeTeam) //
return; // thrower/damagee wasn't in game // allow for teams param to be either {red:['player1','player2'],blue:['player3']} or
if (throwersTeam != damageeTeam) // ['player1','player2','player3'] if all players are against each other (no teams)
_gameState.teamScores[throwersTeam]++; //
else if (teams instanceof Array){
_gameState.teamScores[throwersTeam]--; _gameState.teams = {};
}; for (var i = 0;i < teams.length; i++)
_gameState.teams[teams[i]] = [teams[i]];
return { }
start: function() { /*
_startGame(_gameState); this function is called every time a player is damaged by another entity/player
_gameState.listener = events.on("entity.EntityDamageByEntityEvent",_onSnowballHit); */
new java.lang.Thread(function(){ var _onSnowballHit = function(l,event){
while (_gameState.duration--) var snowball = event.damager;
java.lang.Thread.sleep(1000); // sleep 1,000 millisecs (1 second) if (!snowball || !(snowball instanceof org.bukkit.entity.Snowball))
_endGame(_gameState); return;
}).start(); var throwersTeam = _getTeam(snowball.shooter,_gameState.teams);
} var damageeTeam = _getTeam(event.entity,_gameState.teams);
}; if (!throwersTeam || !damageeTeam)
return; // thrower/damagee wasn't in game
if (throwersTeam != damageeTeam)
_gameState.teamScores[throwersTeam]++;
else
_gameState.teamScores[throwersTeam]--;
}; };
SnowBallFight = _constructor;
}()); return {
start: function() {
_startGame(_gameState);
_gameState.listener = events.on("entity.EntityDamageByEntityEvent",_onSnowballHit);
new java.lang.Thread(function(){
while (_gameState.duration--)
java.lang.Thread.sleep(1000); // sleep 1,000 millisecs (1 second)
_endGame(_gameState);
}).start();
}
};
};
var SnowBallFight = _constructor;
exports.Game_SnowBallFight = SnowBallFight;

View file

@ -1,18 +1,21 @@
var signs = require('./menu'); var signs = require('signs');
// //
// Usage: // Usage:
// //
// In game, create a sign , target it and type ... // In game, create a sign , target it and type ...
// //
// /js var signExamples = require('./signs/examples'); // /js signs.menu_food();
// /js signExamples.testMenu()
// //
exports.testMenu = signs // ... or ...
.menu("Dinner", //
["Lamb","Pork","Chicken","Duck","Beef"], // /js signs.menu_time()
function(event){ //
event.player.sendMessage("You chose " + event.text); exports.signs = {
}); menu_food: signs.menu("Dinner",
["Lamb","Pork","Chicken","Duck","Beef"],
function(event){
event.player.sendMessage("You chose " + event.text);
}),
// //
// This is an example sign that displays a menu of times of day // This is an example sign that displays a menu of times of day
// interacting with the sign will change the time of day accordingly. // interacting with the sign will change the time of day accordingly.
@ -22,11 +25,10 @@ exports.testMenu = signs
// /js var signExamples = require('./signs/examples'); // /js var signExamples = require('./signs/examples');
// /js signExamples.timeOfDay() // /js signExamples.timeOfDay()
// //
exports.timeOfDay = signs menu_time: signs.menu("Time",
.menu("Time", ["Dawn","Midday","Dusk","Midnight"],
["Dawn","Midday","Dusk","Midnight"], function(event){
function(event){ event.player.location.world.setTime( event.number * 6000 );
event.player.location.world.setTime( event.number * 6000 ); })
}); }