2013-01-08 00:59:42 +01:00
|
|
|
//
|
2013-01-18 00:28:12 +01:00
|
|
|
// Define these primitive methods used by drone.js (and potentiall others)
|
2013-01-08 00:59:42 +01:00
|
|
|
//
|
2013-01-18 00:28:12 +01:00
|
|
|
// getPlayerPos returns the player's x,y,z and yaw (direction)
|
|
|
|
// getMousePos returns the x,y,z of the current block being targeted.
|
|
|
|
// putBlock(x,y,z,blockId,metadata) puts a block at a location in current world
|
|
|
|
// getBlock(x,y,z) gets the block and metadata (returned as a string in form '35:15')
|
|
|
|
// putSign(texts,x,y,z,blockId,metadata) puts a sign at the given location
|
|
|
|
// notifyAdministrators(msg) sends a message to all admins/ops.
|
|
|
|
// echo(msg) prints a message on screen to current user.
|
2013-01-08 00:59:42 +01:00
|
|
|
//
|
|
|
|
(function(){
|
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
//
|
|
|
|
// only execute once
|
|
|
|
//
|
|
|
|
if (typeof getPlayerPos != "undefined"){
|
|
|
|
return;
|
|
|
|
}
|
2013-01-08 00:59:42 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
var _getPlayerPos = function(){
|
|
|
|
if (typeof __self == "undefined")
|
|
|
|
return;
|
|
|
|
return __self.location;
|
|
|
|
};
|
2013-01-08 00:59:42 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
var _getMousePos = function(){
|
|
|
|
if (typeof __self == "undefined")
|
|
|
|
return;
|
|
|
|
// __self might be CONSOLE or a CommandBlock
|
|
|
|
if (!__self.getTargetBlock)
|
|
|
|
return;
|
|
|
|
var targetedBlock = __self.getTargetBlock(null,5);
|
|
|
|
if (targetedBlock == null || targetedBlock.isEmpty()){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return targetedBlock.location;
|
|
|
|
};
|
2013-01-08 00:59:42 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
var _putBlock = function(x,y,z,blockId,metadata){
|
|
|
|
|
|
|
|
if (typeof metadata == "undefined"){
|
|
|
|
metadata = 0;
|
|
|
|
}
|
|
|
|
var world = _getWorld();
|
|
|
|
if (!world)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var block = world.getBlockAt(x,y,z);
|
2013-01-16 08:07:11 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
if (blockId === 6){
|
|
|
|
var treeType = null;
|
|
|
|
switch (metadata){
|
|
|
|
case 0:
|
|
|
|
treeType = org.bukkit.TreeType.BIG_TREE;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
treeType = org.bukkit.TreeType.REDWOOD;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
treeType = org.bukkit.TreeType.BIRCH;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
treeType = org.bukkit.TreeType.JUNGLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return world.generateTree(block.location,treeType);
|
|
|
|
}else{
|
|
|
|
block.setTypeId(blockId);
|
|
|
|
block.setData(metadata);
|
|
|
|
}
|
|
|
|
};
|
2013-01-08 00:59:42 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
var _putSign = function(texts, x, y, z, blockId, meta){
|
|
|
|
putBlock(x,y,z,blockId,meta);
|
|
|
|
var block = _getBlockObject(x,y,z);
|
|
|
|
state = block.state;
|
|
|
|
if (state instanceof org.bukkit.block.Sign){
|
|
|
|
for (var i = 0;i < texts.length; i++)
|
|
|
|
state.setLine(i%4,texts[i]);
|
|
|
|
state.update(true);
|
|
|
|
}
|
|
|
|
};
|
2013-01-08 00:59:42 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
var _getBlock = function(x,y,z){
|
|
|
|
var block = _getBlockObject(x,y,z);
|
|
|
|
if (block)
|
|
|
|
return "" + block.typeId + ":" + block.data;
|
|
|
|
};
|
2013-01-08 00:59:42 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
var _getBlockObject = function(x,y,z){
|
|
|
|
var world = _getWorld();
|
|
|
|
if (world)
|
|
|
|
return world.getBlockAt(x,y,z);
|
|
|
|
};
|
2013-01-08 00:59:42 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
var _getWorld = function(){
|
|
|
|
if (typeof __self == "undefined")
|
|
|
|
return;
|
|
|
|
if (__self instanceof org.bukkit.command.BlockCommandSender)
|
|
|
|
return __self.block.location.world;
|
|
|
|
if (__self instanceof org.bukkit.entity.Player)
|
|
|
|
return __self.location.world;
|
|
|
|
};
|
|
|
|
|
|
|
|
var _notifyAdministrators = function(msg){
|
|
|
|
var ops = __plugin.server.operators;
|
|
|
|
for (var i = 0; i < ops.size();i++){
|
|
|
|
if (ops[i].isOnline())
|
|
|
|
ops[i].player.chat(msg);
|
|
|
|
}
|
|
|
|
__plugin.logger.info(msg);
|
|
|
|
};
|
|
|
|
var _echo = function(msg){
|
|
|
|
__plugin.logger.info(msg);
|
|
|
|
if (typeof __self == "undefined"){
|
|
|
|
java.lang.System.out.println(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
__self.sendMessage(msg);
|
|
|
|
};
|
2013-01-08 00:59:42 +01:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
getPlayerPos = _getPlayerPos;
|
|
|
|
getMousePos = _getMousePos;
|
|
|
|
putBlock = _putBlock;
|
|
|
|
getBlock = _getBlock;
|
|
|
|
putSign = _putSign;
|
|
|
|
notifyAdministrators = _notifyAdministrators;
|
|
|
|
echo = _echo;
|
|
|
|
|
2013-01-08 00:59:42 +01:00
|
|
|
}());
|