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

View file

@ -13,11 +13,11 @@ public class ScriptCraftEvaluator
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);
}
}
@ -253,18 +253,18 @@ public class ScriptCraftEvaluator
return ScriptCraftEvaluator.sc.getBlock(x,y,z);
}
@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];
String[] texts = new String[4];
int i = 0;
for (String s : jsArray){
texts[i++] = s;
texts[i++] = s;
}
/*
for (int i = 0; i < jsArray.size() && i <= 3;i++){
texts[i] = (String)jsArray.get(i);
}
for (int i = 0; i < jsArray.size() && i <= 3;i++){
texts[i] = (String)jsArray.get(i);
}
*/
int x = new Double(args[1].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
{
// right now all ops share the same JS context/scope
// need to look at possibly having context/scope per operator
//protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>();
// right now all ops share the same JS context/scope
// need to look at possibly having context/scope per operator
//protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>();
protected ScriptCraftEvaluator evaluator = null;
@Override
public void onEnable(){
public void onEnable(){
getLogger().info("ScriptCraft enabled.");
if (this.evaluator == null){
this.evaluator = new ScriptCraftEvaluator(new ScriptCraftBukkit(this));
this.evaluator.getScope().defineProperty("plugin", this, ScriptableObject.READONLY);
//
// Auto-load Javascript plugins from the js-plugins directory
// in the current working directory
//
String userDir = System.getProperty("user.dir");
File jsPlugins = new File(userDir + System.getProperty("file.separator") + "js-plugins");
if (jsPlugins.exists()){
File[] files = jsPlugins.listFiles();
for (File f: files){
this.evaluator.eval("load(\"" + f.getAbsolutePath() + "\")", null);
}
}
this.evaluator = new ScriptCraftEvaluator(new ScriptCraftBukkit(this));
this.evaluator.getScope().defineProperty("plugin", this, ScriptableObject.READONLY);
//
// Auto-load Javascript plugins from the js-plugins directory
// in the current working directory
//
String userDir = System.getProperty("user.dir");
File jsPlugins = new File(userDir + System.getProperty("file.separator") + "js-plugins");
if (jsPlugins.exists()){
File[] files = jsPlugins.listFiles();
for (File f: files){
this.evaluator.eval("load(\"" + f.getAbsolutePath() + "\")", null);
}
}
}
}
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);
String javascriptCode = "";
this.evaluator.getScope().defineProperty("self", sender, ScriptableObject.DONTENUM);
String javascriptCode = "";
for (int i = 0;i < args.length; i++){
javascriptCode = javascriptCode + args[i] + " ";
javascriptCode = javascriptCode + args[i] + " ";
}
this.evaluator.eval(javascriptCode, sender);
return true;