2013-01-18 00:28:12 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
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 arrows = arrows || plugin("arrows",{
|
|
|
|
/*
|
|
|
|
turn a sign into a menu of arrow choices
|
|
|
|
*/
|
|
|
|
sign: function(sign){},
|
|
|
|
/*
|
|
|
|
change player's arrows to normal
|
|
|
|
*/
|
|
|
|
normal: function(player){},
|
|
|
|
/*
|
|
|
|
change player's arrows to explode on impact
|
|
|
|
*/
|
|
|
|
explosive: function(player){},
|
|
|
|
/*
|
|
|
|
change player's arrows to teleporting
|
|
|
|
*/
|
|
|
|
teleport: function(player){},
|
|
|
|
/*
|
|
|
|
change player's arrows to plant trees where they land
|
|
|
|
*/
|
|
|
|
flourish: function(player){},
|
|
|
|
/*
|
|
|
|
change player's arrows to strike lightning where they land
|
|
|
|
*/
|
|
|
|
lightning: function(player){}
|
|
|
|
},true);
|
2013-01-19 01:44:11 +01:00
|
|
|
/*
|
|
|
|
initialize data
|
|
|
|
*/
|
|
|
|
arrows.store.players = arrows.store.players || {};
|
2013-01-18 00:28:12 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
private implementation of normal, explosive, teleport, flourish and lightning functions
|
|
|
|
*/
|
2013-01-15 21:55:41 +01:00
|
|
|
(function(){
|
2013-01-18 00:28:12 +01:00
|
|
|
//
|
|
|
|
// setup functions for the arrow types
|
|
|
|
//
|
|
|
|
var _types = {normal: 0, explosive: 1, teleport: 2, flourish: 3, lightning: 4};
|
|
|
|
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]);
|
|
|
|
}
|
2013-01-15 21:55:41 +01:00
|
|
|
}());
|
2013-01-18 00:28:12 +01:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
var _onMenuChoice = function(event){
|
|
|
|
arrows.store.players[event.player.name] = event.number;
|
|
|
|
};
|
|
|
|
arrows.sign = signs.menu("Arrow",
|
|
|
|
["Normal","Explosive","Teleport","Flourish","Lightning"],
|
|
|
|
_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;
|
|
|
|
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,2.5);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
projectile.remove();
|
2013-01-20 22:02:56 +01:00
|
|
|
var teleportCause =org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2013-01-18 00:28:12 +01:00
|
|
|
shooter.teleport(projectile.location,
|
2013-01-20 22:02:56 +01:00
|
|
|
teleportCause.PLUGIN);
|
2013-01-18 00:28:12 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
projectile.remove();
|
|
|
|
world.generateTree(projectile.location, org.bukkit.TreeType.BIG_TREE);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
projectile.remove();
|
|
|
|
world.strikeLightning(projectile.location);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
events.on("entity.ProjectileHitEvent",_onArrowHit);
|
|
|
|
});
|