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(){
return [
"/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){
var aliases = this.store.players;
var aliases = _store.players;
var name = player.name;
if (typeof aliases[name] == "undefined")
aliases[name] = {};
aliases[name][alias] = commands;
},
remove: function(player, alias){
var aliases = this.store.players;
var aliases = _store.players;
if (aliases[player.name])
delete aliases[player.name][alias];
},
list: function(player){
var result = [];
var aliases = this.store.players[player.name];
var aliases = _store.players[player.name];
for (var a in aliases)
result.push(a + " = " + aliases[a].join(";"));
return result;
}
},
store: _store
},true);
if (typeof alias.store.players == "undefined")
alias.store.players = {};
exports.alias = alias;
command("alias",function(params){
command("alias", function ( params ) {
/*
this function also intercepts command options for /jsp
*/
@ -59,7 +62,7 @@ command("alias",function(params){
if (params.length == 0)
return self.sendMessage(alias.help());
var playerHasAliases = alias.store.players[self.name];
var playerHasAliases = _store.players[self.name];
if (!playerHasAliases)
return false;
// 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 arrows.normal() sets arrow type to normal.
/js arrows.explosive() - makes arrows explode.
/js arrows.teleport() - makes player teleport to where arrow has landed.
/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.
/js var arrows = require('./arrows/arrows')
* `/js arrows.sign()` turns a targeted sign into a Arrows menu
* `/js arrows.normal()` sets arrow type to normal.
* `/js arrows.explosive()` - makes arrows explode.
* `/js arrows.teleport()` - makes player teleport to where arrow has landed.
* `/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
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
*/
@ -48,91 +56,88 @@ var arrows = arrows || plugin("arrows",{
/*
launch a firework where the arrow lands
*/
explosiveYield: 2.5
explosiveYield: 2.5,
store: _store
},true);
/*
initialize data
*/
arrows.store.players = arrows.store.players || {};
/*
private implementation of normal, explosive, teleport, flourish and lightning functions
*/
(function(){
//
// 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)
{
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()
exports.arrows = arrows;
//
// 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)
{
/*
called when the player chooses an arrow option from a menu sign
*/
var _onMenuChoice = function(event){
arrows.store.players[event.player.name] = event.number;
};
arrows.sign = signs.menu("Arrow",
["Normal","Explosive","Teleport","Flourish","Lightning","Firework"],
_onMenuChoice );
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]);
}
/*
event handler called when a projectile hits something
*/
var _onArrowHit = function(listener,event)
/*
called when the player chooses an arrow option from a menu sign
*/
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 world = projectile.world;
var shooter = projectile.shooter;
if (projectile instanceof org.bukkit.entity.Arrow &&
shooter instanceof org.bukkit.entity.Player)
{
var arrowType = arrows.store.players[shooter.name];
switch (arrowType){
case 1:
projectile.remove();
world.createExplosion(projectile.location,arrows.explosiveYield);
break;
case 2:
projectile.remove();
var teleportCause =org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
shooter.teleport(projectile.location,
teleportCause.PLUGIN);
break;
case 3:
projectile.remove();
world.generateTree(projectile.location, org.bukkit.TreeType.BIG_TREE);
break;
case 4:
projectile.remove();
world.strikeLightning(projectile.location);
break;
case 5:
projectile.remove();
var arrowType = arrows.store.players[shooter.name];
switch (arrowType){
case 1:
projectile.remove();
world.createExplosion(projectile.location,arrows.explosiveYield);
break;
case 2:
projectile.remove();
var teleportCause =org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
shooter.teleport(projectile.location,
teleportCause.PLUGIN);
break;
case 3:
projectile.remove();
world.generateTree(projectile.location, org.bukkit.TreeType.BIG_TREE);
break;
case 4:
projectile.remove();
world.strikeLightning(projectile.location);
break;
case 5:
projectile.remove();
var launch = function(){
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
*/
var chat = chat || plugin("chat", {
exports.chat = plugin("chat", {
/*
set the color of text for a given player
*/
setColor: function(player, color){
this.store.players[player.name] = color;
}
},true);
/*
initialize the store
*/
chat.store.players = chat.store.players || {};
},
ready(function()
{
var colors = [
"black", "blue", "darkgreen", "darkaqua", "darkred",
"purple", "gold", "gray", "darkgray", "indigo",
"brightgreen", "aqua", "red", "pink", "yellow", "white"
];
var colorCodes = {};
for (var i =0;i < colors.length;i++) {
var hexCode = i.toString(16);
colorCodes[colors[i]] = hexCode;
store: _store
},true);
var colors = [
"black", "blue", "darkgreen", "darkaqua", "darkred",
"purple", "gold", "gray", "darkgray", "indigo",
"brightgreen", "aqua", "red", "pink", "yellow", "white"
];
var colorCodes = {};
for (var i =0;i < colors.length;i++) {
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
================
@ -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.
***/
var classroom = {
allowScripting: function(/* boolean: true or false */ canScript){}
};
var _canScript = false;
ready(function(){
classroom.allowScripting = function(canScript)
{
exports.classroom = {
allowScripting: function (/* boolean: true or false */ canScript) {
/*
only operators should be allowed run this function
*/
*/
if (!self.isOp())
return;
if (canScript){
utils.foreach( server.onlinePlayers, function (player) {
player.addAttachment(__plugin, "scriptcraft.*", true);
});
utils.foreach( server.onlinePlayers, function (player) {
player.addAttachment(__plugin, "scriptcraft.*", true);
});
}else{
utils.foreach( server.onlinePlayers, function(player) {
utils.foreach(player.getEffectivePermissions(), function(perm) {
@ -67,12 +67,13 @@ ready(function(){
});
});
}
classroom.canScript = canScript;
};
events.on("player.PlayerLoginEvent", function(listener, event) {
var player = event.player;
if (classroom.canScript){
player.addAttachment(__plugin, "scriptcraft.*", true);
}
}, "HIGHEST");
});
_canScript = canScript;
}
};
events.on('player.PlayerLoginEvent', function(listener, event) {
var player = event.player;
if (classroom.canScript){
player.addAttachment(__plugin, "scriptcraft.*", true);
}
}, "HIGHEST");

View file

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

View file

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

View file

@ -1,5 +1,5 @@
var Drone = require('../drone');
module.exports = Drone;
var Drone = require('../drone').Drone;
//
// 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 blocks = require('../blocks');
var Drone = require('../drone').Drone;
var blocks = require('../blocks').blocks;
module.exports = Drone;
/**
* Creates a tile pattern of given block types and size
*

View file

@ -1,5 +1,5 @@
var Drone = require('../drone');
module.exports = Drone;
var Drone = require('../drone').Drone;
//
// usage:
// [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');
module.exports = Drone;
var Drone = require('../drone').Drone;
//
// Create a floor of colored tiles some of which emit light.
// The tiles change color every second creating a strobe-lit dance-floor.

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
var Drone = require('../drone');
module.exports = Drone;
var Drone = require('../drone').Drone;
/**
* 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.

View file

@ -1,6 +1,6 @@
var Drone = require('../drone');
var blocks = require('../blocks');
module.exports = Drone;
var Drone = require('../drone').Drone;
var blocks = require('../blocks').blocks;
//
// usage:
// [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 blocks = require('../blocks');
var Drone = require('../drone').Drone;
var blocks = require('../blocks').blocks;
module.exports = Drone;
Drone.extend('skyscraper',function(floors){
if (typeof floors == "undefined")

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
var Drone = require('./drone');
var Drone = require('./drone').Drone;
Drone.prototype.testHorizontalStrokeWidth = function(){
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
other players to their home and also visit other player's homes.
*/
plugin("homes", {
var homes = plugin("homes", {
help: function(){
return [
/* basic functions */
@ -33,7 +39,7 @@ plugin("homes", {
host = guest;
guest = utils.getPlayerObject(guest);
host = utils.getPlayerObject(host);
var loc = this.store.houses[host.name];
var loc = _store.houses[host.name];
if (!loc){
guest.sendMessage(host.name + " has no home");
return;
@ -53,9 +59,9 @@ plugin("homes", {
_canVisit: function(guest, host){
if (guest == host)
return true;
if (this.store.openHouses[host.name])
if (_store.openHouses[host.name])
return true;
var invitations = this.store.invites[host.name];
var invitations = _store.invites[host.name];
if (invitations)
for (var i = 0;i < invitations.length;i++)
if (invitations[i] == guest.name)
@ -65,16 +71,16 @@ plugin("homes", {
set: function(player){
player = utils.getPlayerObject(player);
var loc = player.location;
this.store.houses[player.name] = [""+loc.world.name
,Math.floor(loc.x)
,Math.floor(loc.y)
,Math.floor(loc.z)
,Math.floor(loc.yaw)
,Math.floor(loc.pitch)];
_store.houses[player.name] = [""+loc.world.name
,Math.floor(loc.x)
,Math.floor(loc.y)
,Math.floor(loc.z)
,Math.floor(loc.yaw)
,Math.floor(loc.pitch)];
},
remove: function(player){
player = utils.getPlayerObject(player);
delete this.store.houses[player.name];
delete _store.houses[player.name];
},
/* ========================================================================
social functions
@ -85,11 +91,11 @@ plugin("homes", {
*/
list: function(player){
var result = [];
for (var ohp in this.store.openHouses)
for (var ohp in _store.openHouses)
result.push(ohp);
player = utils.getPlayerObject(player);
for (var host in this.store.invites){
var guests = this.store.invites[host];
for (var host in _store.invites){
var guests = _store.invites[host];
for (var i = 0;i < guests.length; i++)
if (guests[i] == player.name)
result.push(host);
@ -103,14 +109,14 @@ plugin("homes", {
player = utils.getPlayerObject(player);
var result = [];
// if home is public - all players
if (this.store.openHouses[player.name]){
if (_store.openHouses[player.name]){
var online = org.bukkit.Bukkit.getOnlinePlayers();
for (var i = 0;i < online.length; i++)
if (online[i].name != player.name)
result.push(online[i].name);
}else{
if (this.store.invites[player.name])
result = this.store.invites[player.name];
if (_store.invites[player.name])
result = _store.invites[player.name];
else
result = [];
}
@ -123,10 +129,10 @@ plugin("homes", {
host = utils.getPlayerObject(host);
guest = utils.getPlayerObject(guest);
var invitations = [];
if (this.store.invites[host.name])
invitations = this.store.invites[host.name];
if (_store.invites[host.name])
invitations = _store.invites[host.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("type '/jsp home " + host.name + "' to accept");
},
@ -136,21 +142,21 @@ plugin("homes", {
uninvite: function(host, guest){
host = utils.getPlayerObject(host);
guest = utils.getPlayerObject(guest);
var invitations = this.store.invites[host.name];
var invitations = _store.invites[host.name];
if (!invitations)
return;
var revisedInvites = [];
for (var i =0;i < invitations.length; i++)
if (invitations[i] != guest.name)
revisedInvites.push(invitations[i]);
this.store.invites[host.name] = revisedInvites;
_store.invites[host.name] = revisedInvites;
},
/*
make the player's house public
*/
open: function(player, optionalMsg){
player = utils.getPlayerObject(player);
this.store.openHouses[player.name] = true;
_store.openHouses[player.name] = true;
if (typeof optionalMsg != "undefined")
__plugin.server.broadcastMessage(optionalMsg);
},
@ -159,132 +165,122 @@ plugin("homes", {
*/
close: function(player){
player = utils.getPlayerObject(player);
delete this.store.openHouses[player.name];
delete _store.openHouses[player.name];
},
/* ========================================================================
admin functions
======================================================================== */
listall: function(){
var result = [];
for (var home in this.store.houses)
for (var home in _store.houses)
result.push(home);
return result;
},
clear: function(player){
player = utils.getPlayerObject(player);
delete this.store.houses[player.name];
delete this.store.openHouses[player.name];
}
delete _store.houses[player.name];
delete _store.openHouses[player.name];
},
store: _store
}, true);
/*
private implementation
exports.homes = homes;
/*
define a set of command options that can be used by players
*/
(function(){
/*
define a set of command options that can be used by players
*/
var options = {
'set': function(){homes.set();},
'delete': function(){ homes.remove();},
'help': function(){ self.sendMessage(homes.help());},
'list': function(){
var visitable = homes.list();
if (visitable.length == 0){
self.sendMessage("There are no homes to visit");
return;
}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 options = {
'set': function(){homes.set();},
'delete': function(){ homes.remove();},
'help': function(){ self.sendMessage(homes.help());},
'list': function(){
var visitable = homes.list();
if (visitable.length == 0){
self.sendMessage("There are no homes to visit");
return;
}else{
self.sendMessage([
"You can visit any of these " + visitable.length + " homes"
,visitable.join(", ")
]);
}
};
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();
},
'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 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);
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;
}
},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,14 +1,20 @@
/*
A basic number-guessing game that uses the Bukkit Conversation API.
*/
ready(function(){
/*************************************************************************
## Minigame: Guess the number
### Example
global.GuessTheNumber = function()
{
/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);
var number = Math.ceil(Math.random() * 10);
var prompt = new Prompt()
{
getPromptText: function(ctx){
@ -44,5 +50,5 @@ ready(function(){
.withPrefix(new ConversationPrefix(){ getPrefix: function(ctx){ return "[1-10] ";} })
.buildConversation(self);
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.
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 blueTeam = ['<player3>','<player4>,...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...
@ -29,152 +30,147 @@ load(__folder + "../events/events.js");
*/
var SnowBallFight = function(teams, duration){};
SnowBallFight.prototype.start = function(){};
(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]);
for (var teamName in gameState.teams)
{
gameState.teamScores[teamName] = 0;
var team = gameState.teams[teamName];
for (var i = 0;i < team.length;i++) {
var player = server.getPlayer(team[i]);
gameState.savedModes[player.name] = player.gameMode;
player.gameMode = org.bukkit.GameMode.SURVIVAL;
player.inventory.addItem(gameState.ammo);
}
}
};
/*
end the game
*/
var _endGame = function(gameState){
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
*/
var _onSnowballHit = function(l,event){
var snowball = event.damager;
if (!snowball || !(snowball instanceof org.bukkit.entity.Snowball))
return;
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]--;
};
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();
}
};
};
SnowBallFight = _constructor;
/*
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]);
}());
for (var teamName in gameState.teams)
{
gameState.teamScores[teamName] = 0;
var team = gameState.teams[teamName];
for (var i = 0;i < team.length;i++) {
var player = server.getPlayer(team[i]);
gameState.savedModes[player.name] = player.gameMode;
player.gameMode = org.bukkit.GameMode.SURVIVAL;
player.inventory.addItem(gameState.ammo);
}
}
};
/*
end the game
*/
var _endGame = function(gameState){
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
*/
var _onSnowballHit = function(l,event){
var snowball = event.damager;
if (!snowball || !(snowball instanceof org.bukkit.entity.Snowball))
return;
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]--;
};
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:
//
// In game, create a sign , target it and type ...
//
// /js var signExamples = require('./signs/examples');
// /js signExamples.testMenu()
// /js signs.menu_food();
//
exports.testMenu = signs
.menu("Dinner",
["Lamb","Pork","Chicken","Duck","Beef"],
function(event){
event.player.sendMessage("You chose " + event.text);
});
// ... or ...
//
// /js signs.menu_time()
//
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
// 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 signExamples.timeOfDay()
//
exports.timeOfDay = signs
.menu("Time",
["Dawn","Midday","Dusk","Midnight"],
function(event){
event.player.location.world.setTime( event.number * 6000 );
});
menu_time: signs.menu("Time",
["Dawn","Midday","Dusk","Midnight"],
function(event){
event.player.location.world.setTime( event.number * 6000 );
})
}