From a8b0fd21bb964cd1111bcd8d3e1fc9dca44d4a9c Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 14 Apr 2019 22:46:01 +1000 Subject: [PATCH] Minor tweaks to work with build.js --- .../com/sk89q/worldedit/command/ScriptingCommands.java | 9 +++++++++ .../java/com/sk89q/worldedit/world/block/BaseBlock.java | 4 ++++ .../java/com/sk89q/worldedit/world/item/ItemType.java | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java index 9693b143c..dd26d49f8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java @@ -30,7 +30,9 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.CommandManager; +import com.sk89q.worldedit.scripting.CraftScriptContext; import com.sk89q.worldedit.scripting.CraftScriptEngine; import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine; import com.sk89q.worldedit.session.request.Request; @@ -138,9 +140,15 @@ public class ScriptingCommands { engine.setTimeLimit(worldEdit.getConfiguration().scriptTimeout); + Player player = actor instanceof Player ? (Player) actor : null; + CraftScriptContext scriptContext = new CraftScriptContext(worldEdit, WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.USER_COMMANDS), + WorldEdit.getInstance().getConfiguration(), session, player, args); + Map vars = new HashMap<>(); vars.put("argv", args); + vars.put("context", scriptContext); vars.put("actor", actor); + vars.put("player", player); try { result = engine.evaluate(script, filename, vars); @@ -155,6 +163,7 @@ public class ScriptingCommands { } catch (Throwable e) { actor.printError(BBC.getPrefix() + "Failed to execute (see console):"); actor.printRaw(e.getClass().getCanonicalName()); + e.printStackTrace(); } if (result instanceof NativeJavaObject) { return (T) ((NativeJavaObject) result).unwrap(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 881daff44..38285926c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -200,6 +200,10 @@ public class BaseBlock implements BlockStateHolder { return blockState.getBlockType(); } + public BlockType getType() { + return getBlockType(); + } + @Override public int getOrdinal() { return blockState.getOrdinal(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java index b4bc13d14..ecaeed331 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.item; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.blocks.BaseItem; +import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.registry.RegistryItem; import com.sk89q.worldedit.registry.NamespacedRegistry; @@ -105,6 +106,9 @@ public class ItemType implements RegistryItem { } public BaseItem getDefaultState() { + if (defaultState == null) { + this.defaultState = new BaseItemStack(this); + } return this.defaultState; }