cleanup directory names - every plugin should be in its own directory
This commit is contained in:
parent
1f357197a6
commit
b5f273924a
3 changed files with 169 additions and 2 deletions
90
js-plugins/arrows/arrows.js
Normal file
90
js-plugins/arrows/arrows.js
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*************************************************************************
|
||||||
|
*
|
||||||
|
* The arrows mod adds fancy arrows to the game.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************************/
|
||||||
|
var rootDir = __folder;
|
||||||
|
load(rootDir + "signs/select.js");
|
||||||
|
load(rootDir + "events/events.js");
|
||||||
|
var arrows = arrows || {};
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Private implementation
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
(function(){
|
||||||
|
var _players = {};
|
||||||
|
//
|
||||||
|
// setup functions for the arrow types
|
||||||
|
//
|
||||||
|
var _types = {normal: 0, explosive: 1, teleport: 2, flourish: 3, lightning: 4};
|
||||||
|
for (var i in _types){
|
||||||
|
arrows[[i]] = (function(n){
|
||||||
|
return function(player){
|
||||||
|
if (typeof player == "undefined")
|
||||||
|
player = __self;
|
||||||
|
var playerName = null;
|
||||||
|
if (typeof player == "string")
|
||||||
|
playerName = player;
|
||||||
|
else
|
||||||
|
playerName = player.name;
|
||||||
|
_players[playerName] = n;
|
||||||
|
};
|
||||||
|
})(_types[i]);
|
||||||
|
}
|
||||||
|
if (typeof arrows.sign != "undefined")
|
||||||
|
return;
|
||||||
|
|
||||||
|
var _arrowSign =
|
||||||
|
signs.select("Arrow",
|
||||||
|
["Normal","Explosive","Teleport","Flourish","Lightning"],
|
||||||
|
function(player,sign,selectedText,selectedIndex){
|
||||||
|
_players[player.name] = selectedIndex;
|
||||||
|
});
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
if (projectile instanceof org.bukkit.entity.Arrow &&
|
||||||
|
shooter instanceof org.bukkit.entity.Player)
|
||||||
|
{
|
||||||
|
var arrowType = _players[shooter.name];
|
||||||
|
switch (arrowType){
|
||||||
|
case 1:
|
||||||
|
projectile.remove();
|
||||||
|
world.createExplosion(projectile.location,2.5);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
projectile.remove();
|
||||||
|
shooter.teleport(projectile.location,
|
||||||
|
org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
projectile.remove();
|
||||||
|
world.generateTree(projectile.location, org.bukkit.TreeType.BIG_TREE);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
projectile.remove();
|
||||||
|
world.strikeLightning(projectile.location);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
arrows.sign = _arrowSign;
|
||||||
|
events.on("entity.ProjectileHitEvent",_onArrowHit);
|
||||||
|
}());
|
77
js-plugins/events/events.js
Normal file
77
js-plugins/events/events.js
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
var global = this;
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
//
|
||||||
|
// The following code will print a message on screen every time a block is broken in the game
|
||||||
|
//
|
||||||
|
// events.on("block.BlockBreakEvent", function(listener, evt){
|
||||||
|
// print (evt.player.name + " broke a block!");
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// To handle an event only once and unregister from further events...
|
||||||
|
//
|
||||||
|
// events.on("block.BlockBreakEvent", function(listener, evt){
|
||||||
|
// print (evt.player.name + " broke a block!");
|
||||||
|
// evt.handlers.unregister(listener);
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
var events = events || {
|
||||||
|
//
|
||||||
|
// handle events in Minecraft
|
||||||
|
// --------------------------
|
||||||
|
// eventType can be a string (assumed to be a sub package of org.bukkit.event - e.g.
|
||||||
|
// if the string "block.BlockBreakEvent" is supplied then it's converted to the
|
||||||
|
// org.bukkit.event.block.BlockBreakEvent class . For custom event classes, just
|
||||||
|
// supply the custom event class e.g.
|
||||||
|
// events.on(net.yourdomain.events.YourCustomEvent,function(l,e){ ... });
|
||||||
|
//
|
||||||
|
on: function(
|
||||||
|
/* String or java Class */ eventType,
|
||||||
|
/* function( registeredListener, event) */ handler,
|
||||||
|
/* (optional) String (HIGH, HIGHEST, LOW, LOWEST, NORMAL, MONITOR), */ priority
|
||||||
|
){}
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// private implementation from here on in...
|
||||||
|
//
|
||||||
|
(function(){
|
||||||
|
if (events._eventsLoaded){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var _event = org.bukkit.event;
|
||||||
|
var _plugin = org.bukkit.plugin;
|
||||||
|
//
|
||||||
|
// can't have objects that implement multiple interface in javax.scripts.*
|
||||||
|
//
|
||||||
|
var theListener = new _event.Listener(){};
|
||||||
|
|
||||||
|
var _on = function(eventType, handler, priority)
|
||||||
|
{
|
||||||
|
if (typeof priority == "undefined"){
|
||||||
|
priority = _event.EventPriority.NORMAL;
|
||||||
|
}else{
|
||||||
|
priority = _event.EventPriority[priority];
|
||||||
|
}
|
||||||
|
if (typeof eventType == "string"){
|
||||||
|
var subPkgs = eventType.split('.');
|
||||||
|
eventType = _event[subPkgs[0]];
|
||||||
|
for (var i = 1;i < subPkgs.length; i++){
|
||||||
|
eventType = eventType[subPkgs[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var handlerList = eventType.getHandlerList();
|
||||||
|
var listener = {};
|
||||||
|
var eventExecutor = new _plugin.EventExecutor(){
|
||||||
|
execute: function(l,e){
|
||||||
|
handler(listener.reg,e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
listener.reg = new _plugin.RegisteredListener(
|
||||||
|
theListener,eventExecutor,priority,__plugin,true
|
||||||
|
)
|
||||||
|
handlerList.register(listener.reg);
|
||||||
|
return listener.reg;
|
||||||
|
};
|
||||||
|
events.on = _on;
|
||||||
|
events._eventsLoaded = true;
|
||||||
|
}());
|
|
@ -1,4 +1,4 @@
|
||||||
load(__folder + "../bukkit/events.js");
|
load(__folder + "../events/events.js");
|
||||||
//
|
//
|
||||||
// signs module declaration
|
// signs module declaration
|
||||||
//
|
//
|
||||||
|
@ -87,7 +87,7 @@ signs.select = function(/* String */ label, /* Array */ options, /* Function */
|
||||||
//
|
//
|
||||||
// update it every time player interacts with it.
|
// update it every time player interacts with it.
|
||||||
//
|
//
|
||||||
bukkit.on("player.PlayerInteractEvent",function(listener, event) {
|
events.on("player.PlayerInteractEvent",function(listener, event) {
|
||||||
if (event.clickedBlock.state.equals(sign))
|
if (event.clickedBlock.state.equals(sign))
|
||||||
_updateSign(event.player,sign);
|
_updateSign(event.player,sign);
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue