From ef1bdbbcf6bb44d31f0e7d1944d4b9378265c13d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 21 Sep 2021 15:51:54 +0200 Subject: [PATCH] Add Constant for sprinting and offhandmaterial Signed-off-by: yoyosource --- .../features/script/CustomScriptListener.java | 17 ++++++++++++----- .../features/script/ScriptCommand.java | 6 +++++- .../features/script/variables/Constants.java | 6 ++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptListener.java index 37f82cde..c76bc6f9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptListener.java @@ -173,6 +173,13 @@ public class CustomScriptListener implements Listener { List> menuCommands = new ArrayList<>(); playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomScript.MenuScript.class::isInstance).map(CustomScript.MenuScript.class::cast).forEach(menuItem -> { SWItem swItem = menuItem.toItem(); + ItemStack itemStack = swItem.getItemStack(); + if (menuItem instanceof CustomScript.MenuEvent) { + itemStack.setType(Material.REPEATING_COMMAND_BLOCK); + } else { + itemStack.setType(Material.COMMAND_BLOCK); + } + swItem.setItemStack(itemStack); swItem.setLore(Arrays.asList("§7Klicke zum rausnehmen", "§7Middle Klicke zum kopieren")); menuCommands.add(new SWListInv.SWListEntry<>(swItem, menuItem)); @@ -291,9 +298,7 @@ public class CustomScriptListener implements Listener { EventType(Class eventType, Function> eventValues) { this.eventType = eventType; - this.eventValues = event -> { - return eventValues.apply((T) event); - }; + this.eventValues = event -> eventValues.apply((T) event); } } @@ -309,14 +314,16 @@ public class CustomScriptListener implements Listener { if (variables == null) { variables = new HashMap<>(); } + if (e instanceof Cancellable) { + variables.put("cancel", new Value.BooleanValue(false)); + } customEvent.execute(e, p, variables); - if (e instanceof Cancellable && variables.containsKey("cancel")) { + if (variables.containsKey("cancel")) { Value value = variables.get("cancel"); if (value.asBoolean()) { ((Cancellable) e).setCancelled(true); } } - return; } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java index fbf8053b..554f5437 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java @@ -114,11 +114,15 @@ public class ScriptCommand extends SWCommand { }), null)); swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.IRON_BOOTS, "§7Constant §esneak", Arrays.asList("§etrue§7 wenn der Spieler gerade sneakt."), false, clickType -> { }), null)); + swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.DIAMOND_BOOTS, "§7Constant §esprinting", Arrays.asList("§etrue§7 wenn der Spieler gerade rennt."), false, clickType -> { + }), null)); swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, "§7Constant §eslot", Arrays.asList("§e0-8§7 für den ausgewählten slot.", "§eÜberschreibbar"), false, clickType -> { }), null)); swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRASS_BLOCK, "§7Constant §eslotmaterial", Arrays.asList("§eMaterial§7 des Items im Slot"), false, clickType -> { }), null)); - for (int i = 0; i < 4 + 2 * 9; i++) { + swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.IRON_BLOCK, "§7Constant §eoffhandmaterial", Arrays.asList("§eMaterial§7 des Items in oder Off Hand"), false, clickType -> { + }), null)); + for (int i = 0; i < 2 + 2 * 9; i++) { swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", new ArrayList<>(), false, clickType -> { }), null)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index 8a78d10e..eeb53f07 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -195,6 +195,9 @@ public class Constants { CONSTANTS.put("sneaking", player -> { return new ConstantBooleanValue(player::isSneaking); }); + CONSTANTS.put("sprinting", player -> { + return new ConstantBooleanValue(player::isSprinting); + }); CONSTANTS.put("slot", player -> { return new ConstantLongValue(() -> (long) player.getInventory().getHeldItemSlot(), slot -> { if (slot > 8) { @@ -209,6 +212,9 @@ public class Constants { CONSTANTS.put("slotmaterial", player -> { return new ConstantStringValue(() -> player.getInventory().getItemInMainHand().getType().name()); }); + CONSTANTS.put("offhandmaterial", player -> { + return new ConstantStringValue(() -> player.getInventory().getItemInOffHand().getType().name()); + }); } public Set allVariables() {