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,28 +13,28 @@ 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 ) {
/*
@ -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,18 +56,14 @@ 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(){
exports.arrows = arrows;
//
// setup functions for the arrow types
//
@ -79,13 +83,7 @@ arrows.store.players = arrows.store.players || {};
};
})(_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()
{
/*
called when the player chooses an arrow option from a menu sign
*/
@ -104,10 +102,12 @@ ready(function()
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 arrowType = arrows.store.players[shooter.name];
switch (arrowType){
case 1:
projectile.remove();
@ -129,10 +129,15 @@ ready(function()
break;
case 5:
projectile.remove();
var launch = function(){
fireworks.firework(projectile.location);
if (--fireworkCount)
setTimeout(launch,2000);
};
launch();
break;
}
}
};
events.on("entity.ProjectileHitEvent",_onArrowHit);
});
events.on('entity.ProjectileHitEvent',_onArrowHit);

View file

@ -1,21 +1,24 @@
/*
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 || {};
},
store: _store
},true);
ready(function()
{
var colors = [
"black", "blue", "darkgreen", "darkaqua", "darkred",
"purple", "gold", "gray", "darkgray", "indigo",
@ -50,4 +53,4 @@ ready(function()
listColors();
}
},colors);
});

View file

@ -1,3 +1,6 @@
var utils = require('utils');
var events = require('events');
/************************************************************************
Classroom Module
================
@ -41,13 +44,10 @@ 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
*/
@ -67,12 +67,13 @@ ready(function(){
});
});
}
classroom.canScript = canScript;
_canScript = canScript;
}
};
events.on("player.PlayerLoginEvent", function(listener, event) {
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,7 +71,7 @@ plugin("homes", {
set: function(player){
player = utils.getPlayerObject(player);
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.y)
,Math.floor(loc.z)
@ -74,7 +80,7 @@ plugin("homes", {
},
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,28 +165,27 @@ 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
*/
(function(){
exports.homes = homes;
/*
define a set of command options that can be used by players
*/
@ -277,14 +282,5 @@ plugin("homes", {
}
},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.
*/
ready(function(){
/*************************************************************************
## Minigame: Guess the number
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);
var number = Math.ceil(Math.random() * 10);
@ -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,11 +30,6 @@ load(__folder + "../events/events.js");
*/
var SnowBallFight = function(teams, duration){};
SnowBallFight.prototype.start = function(){};
(function(){
/*
setup game
*/
@ -173,8 +169,8 @@ SnowBallFight.prototype.start = function(){};
}
};
};
SnowBallFight = _constructor;
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",
// ... 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",
menu_time: signs.menu("Time",
["Dawn","Midday","Dusk","Midnight"],
function(event){
event.player.location.world.setTime( event.number * 6000 );
});
})
}