untabified.

This commit is contained in:
walterhiggins 2013-01-05 01:25:23 +00:00
parent 52272da33b
commit 49b24fa2cd
3 changed files with 106 additions and 105 deletions

View file

@ -11,78 +11,79 @@ import org.bukkit.plugin.java.JavaPlugin;
public class ScriptCraftBukkit implements IScriptCraft public class ScriptCraftBukkit implements IScriptCraft
{ {
/* (non-Javadoc) /* (non-Javadoc)
* @see net.walterhiggins.scriptcraft.IScriptCraft#putSign(java.lang.String[], int, int, int, int, int) * @see net.walterhiggins.scriptcraft.IScriptCraft#putSign(java.lang.String[], int, int, int, int, int)
*/ */
@Override @Override
public void putSign(String[] texts, int x, int y, int z, int blockId, int meta) { public void putSign(String[] texts, int x, int y, int z, int blockId, int meta) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
putBlock(x,y,z,blockId,meta); putBlock(x,y,z,blockId,meta);
Block block = this.getBlockObjectAt(x, y, z); Block block = this.getBlockObjectAt(x, y, z);
if (block instanceof Sign){ if (block instanceof Sign){
Sign sign = (Sign)block; Sign sign = (Sign)block;
for (int i = 0; i < texts.length;i++){ for (int i = 0; i < texts.length;i++){
sign.setLine(i%4, texts[i]); sign.setLine(i%4, texts[i]);
} }
sign.update(true); sign.update(true);
} }
} }
private void _putBlock(World world,int x, int y, int z, int blockId, int meta){ /* (non-Javadoc)
Block block = world.getBlockAt(x, y, z); * @see net.walterhiggins.scriptcraft.IScriptCraft#putBlock(int, int, int, int, int)
block.setTypeId(blockId); */
block.setData((byte)meta); @Override
public void putBlock(int x, int y, int z, int blockId, int meta) {
World world = this.getInvokerWorld();
this._putBlock(world, x, y, z, blockId, meta);
}
private final World getInvokerWorld(){
if (this.invoker instanceof Player){
Player player = (Player)this.invoker;
return player.getLocation().getWorld();
}
if (this.invoker instanceof BlockCommandSender){
BlockCommandSender bcs = (BlockCommandSender)this.invoker;
return bcs.getBlock().getLocation().getWorld();
}
return null;
}
/* (non-Javadoc)
* @see net.walterhiggins.scriptcraft.IScriptCraft#getBlock(int, int, int)
*/
@Override
public String getBlock(int x, int y, int z) {
Block block = this.getBlockObjectAt(x, y, z);
if (block !=null)
return "" + block.getTypeId() + ":" + block.getData();
return null;
}
/* (non-Javadoc)
* @see net.walterhiggins.scriptcraft.IScriptCraft#notifyAdministrators(java.lang.String)
*/
@Override
public void notifyAdministrators(String message) {
} Set<OfflinePlayer> ops = this.plugin.getServer().getOperators();
/* (non-Javadoc) for (OfflinePlayer op : ops){
* @see net.walterhiggins.scriptcraft.IScriptCraft#putBlock(int, int, int, int, int) if (op.isOnline()){
*/ op.getPlayer().chat(message);
@Override }
public void putBlock(int x, int y, int z, int blockId, int meta) { }
World world = this.getInvokerWorld(); this.plugin.getLogger().info(message);
this._putBlock(world, x, y, z, blockId, meta); }
}
private final World getInvokerWorld(){
if (this.invoker instanceof Player){
Player player = (Player)this.invoker;
return player.getLocation().getWorld();
}
if (this.invoker instanceof BlockCommandSender){
BlockCommandSender bcs = (BlockCommandSender)this.invoker;
return bcs.getBlock().getLocation().getWorld();
}
return null;
}
private final Block getBlockObjectAt(int x,int y, int z){
World world = getInvokerWorld();
if (world != null)
return world.getBlockAt(x, y, z);
return null;
}
/* (non-Javadoc)
* @see net.walterhiggins.scriptcraft.IScriptCraft#getBlock(int, int, int)
*/
@Override
public String getBlock(int x, int y, int z) {
Block block = this.getBlockObjectAt(x, y, z);
if (block !=null)
return "" + block.getTypeId() + ":" + block.getData();
return null;
}
/* (non-Javadoc)
* @see net.walterhiggins.scriptcraft.IScriptCraft#notifyAdministrators(java.lang.String)
*/
@Override
public void notifyAdministrators(String message) {
Set<OfflinePlayer> ops = this.plugin.getServer().getOperators(); private void _putBlock(World world,int x, int y, int z, int blockId, int meta){
for (OfflinePlayer op : ops){ Block block = world.getBlockAt(x, y, z);
if (op.isOnline()){ block.setTypeId(blockId);
op.getPlayer().chat(message); block.setData((byte)meta);
}
} }
this.plugin.getLogger().info(message); private final Block getBlockObjectAt(int x,int y, int z){
} World world = getInvokerWorld();
protected JavaPlugin plugin = null; if (world != null)
return world.getBlockAt(x, y, z);
return null;
}
protected JavaPlugin plugin = null;
public CommandSender invoker = null; public CommandSender invoker = null;
public void setInvoker(Object invoker) public void setInvoker(Object invoker)
@ -90,7 +91,7 @@ public class ScriptCraftBukkit implements IScriptCraft
this.invoker = (CommandSender)invoker; this.invoker = (CommandSender)invoker;
} }
public ScriptCraftBukkit(JavaPlugin plugin){ public ScriptCraftBukkit(JavaPlugin plugin){
this.plugin = plugin; this.plugin = plugin;
} }
public double[] getPlayerPos() public double[] getPlayerPos()
{ {

View file

@ -13,11 +13,11 @@ public class ScriptCraftEvaluator
public static class MCScope extends ImporterTopLevel{ public static class MCScope extends ImporterTopLevel{
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public MCScope(Context ctx){ public MCScope(Context ctx){
super(ctx); super(ctx);
} }
} }
@ -253,18 +253,18 @@ public class ScriptCraftEvaluator
return ScriptCraftEvaluator.sc.getBlock(x,y,z); return ScriptCraftEvaluator.sc.getBlock(x,y,z);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void putSign(Context cx, Scriptable thisObj,Object[] args, Function funObj){ public static void putSign(Context cx, Scriptable thisObj,Object[] args, Function funObj){
List<String> jsArray = (List<String>)args[0]; List<String> jsArray = (List<String>)args[0];
String[] texts = new String[4]; String[] texts = new String[4];
int i = 0; int i = 0;
for (String s : jsArray){ for (String s : jsArray){
texts[i++] = s; texts[i++] = s;
} }
/* /*
for (int i = 0; i < jsArray.size() && i <= 3;i++){ for (int i = 0; i < jsArray.size() && i <= 3;i++){
texts[i] = (String)jsArray.get(i); texts[i] = (String)jsArray.get(i);
} }
*/ */
int x = new Double(args[1].toString()).intValue(); int x = new Double(args[1].toString()).intValue();
int y = new Double(args[2].toString()).intValue(); int y = new Double(args[2].toString()).intValue();

View file

@ -7,41 +7,41 @@ import org.mozilla.javascript.*;
public class ScriptCraftPlugin extends JavaPlugin public class ScriptCraftPlugin extends JavaPlugin
{ {
// right now all ops share the same JS context/scope // right now all ops share the same JS context/scope
// need to look at possibly having context/scope per operator // need to look at possibly having context/scope per operator
//protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>(); //protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>();
protected ScriptCraftEvaluator evaluator = null; protected ScriptCraftEvaluator evaluator = null;
@Override @Override
public void onEnable(){ public void onEnable(){
getLogger().info("ScriptCraft enabled."); getLogger().info("ScriptCraft enabled.");
if (this.evaluator == null){ if (this.evaluator == null){
this.evaluator = new ScriptCraftEvaluator(new ScriptCraftBukkit(this)); this.evaluator = new ScriptCraftEvaluator(new ScriptCraftBukkit(this));
this.evaluator.getScope().defineProperty("plugin", this, ScriptableObject.READONLY); this.evaluator.getScope().defineProperty("plugin", this, ScriptableObject.READONLY);
// //
// Auto-load Javascript plugins from the js-plugins directory // Auto-load Javascript plugins from the js-plugins directory
// in the current working directory // in the current working directory
// //
String userDir = System.getProperty("user.dir"); String userDir = System.getProperty("user.dir");
File jsPlugins = new File(userDir + System.getProperty("file.separator") + "js-plugins"); File jsPlugins = new File(userDir + System.getProperty("file.separator") + "js-plugins");
if (jsPlugins.exists()){ if (jsPlugins.exists()){
File[] files = jsPlugins.listFiles(); File[] files = jsPlugins.listFiles();
for (File f: files){ for (File f: files){
this.evaluator.eval("load(\"" + f.getAbsolutePath() + "\")", null); this.evaluator.eval("load(\"" + f.getAbsolutePath() + "\")", null);
} }
} }
} }
} }
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{ {
if(cmd.getName().equalsIgnoreCase("js")) if(cmd.getName().equalsIgnoreCase("js"))
{ {
this.evaluator.getScope().defineProperty("self", sender, ScriptableObject.DONTENUM); this.evaluator.getScope().defineProperty("self", sender, ScriptableObject.DONTENUM);
String javascriptCode = ""; String javascriptCode = "";
for (int i = 0;i < args.length; i++){ for (int i = 0;i < args.length; i++){
javascriptCode = javascriptCode + args[i] + " "; javascriptCode = javascriptCode + args[i] + " ";
} }
this.evaluator.eval(javascriptCode, sender); this.evaluator.eval(javascriptCode, sender);
return true; return true;