From 162fbbaa0c9bf2cc0a193c846c102f871eef35a3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 28 Dec 2022 14:23:17 +0100 Subject: [PATCH] Add EventType.Scoreboard Add more Constants Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 19 ++- BauSystem_Main/src/BauSystem_de.properties | 18 ++- .../features/script/CustomScript.java | 19 +-- .../features/script/CustomScriptManager.java | 19 ++- .../bausystem/features/script/EventType.java | 3 + .../features/script/ScriptCommand.java | 58 ++++---- .../features/script/ScriptExecutor.java | 23 ++- .../features/script/ScriptListener.java | 2 +- .../features/script/command/io/Echo.java | 4 +- .../features/script/variables/Constants.java | 134 +++++++----------- .../record/AutoExplodeTraceRecorder.java | 5 + .../record/AutoIgniteTraceRecorder.java | 5 + .../tracer/record/AutoTraceRecorder.java | 14 +- .../features/tracer/record/Recorder.java | 20 +++ .../tracer/record/SimpleTraceRecorder.java | 10 ++ .../tracer/record/SingleTraceRecorder.java | 5 + .../features/tracer/record/TraceRecorder.java | 3 + .../features/world/BauScoreboard.java | 79 ++++++----- 18 files changed, 276 insertions(+), 164 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 668ceb91..b5df1c73 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -401,6 +401,7 @@ SCRIPT_GUI_CUSTOM_EVENTS_LORE_14 = §eSelfJoin §8-§7 x, y, z, playerName SCRIPT_GUI_CUSTOM_EVENTS_LORE_15 = §eSelfLeave §8-§7 x, y, z, playerName SCRIPT_GUI_CUSTOM_EVENTS_LORE_16 = §eDropItem §8-§7 material, x, y, z SCRIPT_GUI_CUSTOM_EVENTS_LORE_17 = §eEntityDeath §8-§7 entityType, x, y, z +SCRIPT_GUI_CUSTOM_EVENTS_LORE_18 = §eScoreboard SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1 = §e* §8-§7 Everything in brackets is only set if the variable before is set on §etrue§7. SCRIPT_GUI_OTHER = §eOther @@ -427,7 +428,11 @@ SCRIPT_GUI_COMMAND_NAME = §7Command: §e{0} SCRIPT_GUI_CUSTOM_VARIABLES = §eCustom Variables -SCRIPT_GUI_CONSTANT_OVERRIDEABLE = §eoverwriteable +SCRIPT_GUI_CONSTANT_TIME_NAME = §7Constant §etime +SCRIPT_GUI_CONSTANT_TIME_LORE = §7Formatted time variable. + +SCRIPT_GUI_CONSTANT_TICKS_NAME = §7Constant §eticks +SCRIPT_GUI_CONSTANT_TICKS_LORE = §7Ticks since server start. SCRIPT_GUI_CONSTANT_TRACE_NAME = §7Constant §etrace SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 if the trace is activated. @@ -435,6 +440,15 @@ SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 if the trace is activated. SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME = §7Constant §eautotrace SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE = §etrue§7 if the auto trace is activated. +SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME = §7Constant §etrace_status +SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE = §7One of: §eOFF§8, §eIDLE§8, §eIDLE_AUTO_EXPLODE§8, §eIDLE_AUTO_IGNITE§8, §eIDLE_SINGLE + +SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME = §7Constant §etrace_time +SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE = §e0§7 if the trace is not active, otherwise the time in ticks since the trace was started. + +SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME = §7Constant §eloader_status +SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE = §7One of: §eOFF§8, §eSETUP§8, §eRUNNING§8, §eSINGLE§8, §ePAUSE§8, §eEND + SCRIPT_GUI_CONSTANT_TNT_NAME = §7Constant §etnt SCRIPT_GUI_CONSTANT_TNT_LORE = §etrue§7 if tnt is not deactivated. @@ -486,6 +500,9 @@ SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE = §eName§7 of the item in t SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME = §7Constant §eregion_type SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eregion type§7 of the current region +SCRIPT_GUI_CONSTANT_REGION_NAME_NAME = §7Constant §eregion_name +SCRIPT_GUI_CONSTANT_REGION_NAME_LORE = §eregion name§7 of the current region + SCRIPT_GUI_CONSTANT_TPS_NAME = §7Constant §etps SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 of the server diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index a6388853..7320b18d 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -421,7 +421,11 @@ SCRIPT_GUI_COMMAND_NAME = §7Command: §e{0} SCRIPT_GUI_CUSTOM_VARIABLES = §eCustom Variables -SCRIPT_GUI_CONSTANT_OVERRIDEABLE = §eÜberschreibbar +SCRIPT_GUI_CONSTANT_TIME_NAME = §7Constant §etime +SCRIPT_GUI_CONSTANT_TIME_LORE = §7Formattierte Uhrzeit + +SCRIPT_GUI_CONSTANT_TICKS_NAME = §7Constant §eticks +SCRIPT_GUI_CONSTANT_TICKS_LORE = §7Ticks seit dem Serverstart SCRIPT_GUI_CONSTANT_TRACE_NAME = §7Constant §etrace SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 wenn gerade der Tracer an ist. @@ -429,6 +433,15 @@ SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 wenn gerade der Tracer an ist. SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME = §7Constant §eautotrace SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE = §etrue§7 wenn gerade der AutoTracer an ist. +SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME = §7Constant §etrace_status +SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE = §7Ein Wert von: §eOFF§8, §eIDLE§8, §eIDLE_AUTO_EXPLODE§8, §eIDLE_AUTO_IGNITE§8, §eIDLE_SINGLE + +SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME = §7Constant §etrace_time +SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE = §e0§7 wenn gerade kein TNT getraced wird, ansonsten die Zeit in Ticks seit dem Start des Tracers. + +SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME = §7Constant §eloader_status +SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE = §7Ein Wert von: §eOFF§8, §eSETUP§8, §eRUNNING§8, §eSINGLE§8, §ePAUSE§8, §eEND + SCRIPT_GUI_CONSTANT_TNT_NAME = §7Constant §etnt SCRIPT_GUI_CONSTANT_TNT_LORE = §etrue§7 wenn TNT nicht ausgeschaltet ist. @@ -480,6 +493,9 @@ SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE = §eName§7 des Items in der SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME = §7Constant §eregion_type SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eRegionstype§7 der jetztigen Region +SCRIPT_GUI_CONSTANT_REGION_NAME_NAME = §7Constant §eregion_name +SCRIPT_GUI_CONSTANT_REGION_NAME_LORE = §eRegionsname§7 der jetztigen Region + SCRIPT_GUI_CONSTANT_TPS_NAME = §7Constant §etps SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 vom Server diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScript.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScript.java index 35298a09..136dea6b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScript.java @@ -35,6 +35,7 @@ import yapion.hierarchy.types.YAPIONMap; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; @UtilityClass public class CustomScript { @@ -67,7 +68,7 @@ public class CustomScript { Map variables = new HashMap<>(); variables.put("pressed", new Value.BooleanValue(pressed)); variables.put("released", new Value.BooleanValue(!pressed)); - new ScriptExecutor(bookMeta, p, variables); + new ScriptExecutor(bookMeta, p, variables, null); return false; } } @@ -87,7 +88,7 @@ public class CustomScript { Map variables = new HashMap<>(); variables.put("pressed", new Value.BooleanValue(pressed)); variables.put("released", new Value.BooleanValue(!pressed)); - new ScriptExecutor(pages, p, variables); + new ScriptExecutor(pages, p, variables, null); return false; } @@ -116,7 +117,7 @@ public class CustomScript { public interface CustomEvent extends Script { String eventName(); - boolean execute(Event e, Player p, Map variables); + boolean execute(Player p, Map variables, Consumer echoConsumer); } @@ -131,8 +132,8 @@ public class CustomScript { } @Override - public boolean execute(Event e, Player p, Map variables) { - new ScriptExecutor(bookMeta, p, variables); + public boolean execute(Player p, Map variables, Consumer echoConsumer) { + new ScriptExecutor(bookMeta, p, variables, echoConsumer); return true; } } @@ -148,8 +149,8 @@ public class CustomScript { } @Override - public boolean execute(Event e, Player p, Map variables) { - new ScriptExecutor(pages, p, variables); + public boolean execute(Player p, Map variables, Consumer echoConsumer) { + new ScriptExecutor(pages, p, variables, echoConsumer); return false; } @@ -253,7 +254,7 @@ public class CustomScript { } e.setCancelled(true); - new ScriptExecutor(bookMeta, e.getPlayer(), arguments); + new ScriptExecutor(bookMeta, e.getPlayer(), arguments, null); return true; } } @@ -275,7 +276,7 @@ public class CustomScript { } e.setCancelled(true); - new ScriptExecutor(pages, e.getPlayer(), arguments); + new ScriptExecutor(pages, e.getPlayer(), arguments, null); return true; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java index a19a5219..914e5cff 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java @@ -48,6 +48,7 @@ import yapion.hierarchy.types.YAPIONValue; import yapion.parser.YAPIONParser; import java.util.*; +import java.util.function.Consumer; import java.util.stream.Collectors; @Linked @@ -267,6 +268,22 @@ public class CustomScriptManager implements Listener { openCommandsMenu(p); } + public boolean callScoreboard(Player p, Map variables, Consumer echoConsumer) { + Map valueMap = new HashMap<>(); + for (Map.Entry entry : variables.entrySet()) { + valueMap.put(entry.getKey(), new Value.StringValue(entry.getValue())); + } + List customEvents = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomScript.CustomEvent.class::isInstance).map(CustomScript.CustomEvent.class::cast).collect(Collectors.toList()); + boolean hasScript = false; + for (CustomScript.CustomEvent customEvent : customEvents) { + if (customEvent.eventName().equals(EventType.Scoreboard.name())) { + customEvent.execute(p, valueMap, echoConsumer); + hasScript = true; + } + } + return hasScript; + } + public void callEvent(EventType eventType, Player p, Event e) { if (eventType == null) return; if (!eventType.getEventType().equals(e.getClass())) return; @@ -281,7 +298,7 @@ public class CustomScriptManager implements Listener { if (e instanceof Cancellable) { variables.put("cancel", new Value.BooleanValue(((Cancellable) e).isCancelled())); } - customEvent.execute(e, p, variables); + customEvent.execute(p, variables, null); if (variables.containsKey("cancel")) { Value value = variables.get("cancel"); ((Cancellable) e).setCancelled(value.asBoolean()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/EventType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/EventType.java index 73d2f19e..728e60e0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/EventType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/EventType.java @@ -106,6 +106,9 @@ public enum EventType { addXYZ(valueMap, event.getEntity().getLocation()); return valueMap; }), + Scoreboard(Event.class, event -> { + return new HashMap<>(); + }), ; private static void addXYZ(Map valueMap, Location location) { 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 d6f6e3d6..d9bed371 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java @@ -39,36 +39,43 @@ public class ScriptCommand extends SWCommand { addEmptyItems(swItems, 2); swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_HOTKEYS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5")), null)); swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_COMMANDS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1", "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2")), null)); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_EVENTS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_1", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_2", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_3", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_4", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_5", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_6", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_7", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_8", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_9", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_10", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_11", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_12", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_13", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_14", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_15", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_16", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_17", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1")), null)); + swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_EVENTS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_1", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_2", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_3", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_4", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_5", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_6", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_7", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_8", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_9", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_10", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_11", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_12", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_13", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_14", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_15", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_16", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_17", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_18", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1")), null)); addEmptyItems(swItems, 1); swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_OTHER", loreBuilder(p, "SCRIPT_GUI_OTHER_LORE_1", "SCRIPT_GUI_OTHER_LORE_2", "SCRIPT_GUI_OTHER_LORE_3", "SCRIPT_GUI_OTHER_LORE_4", "SCRIPT_GUI_OTHER_LORE_5", "SCRIPT_GUI_OTHER_LORE_6", "SCRIPT_GUI_OTHER_LORE_7", "SCRIPT_GUI_OTHER_LORE_8", "SCRIPT_GUI_OTHER_LORE_9", "SCRIPT_GUI_OTHER_LORE_10", "SCRIPT_GUI_OTHER_LORE_11", "SCRIPT_GUI_OTHER_LORE_12", "SCRIPT_GUI_OTHER_LORE_13", "SCRIPT_GUI_OTHER_LORE_14", "SCRIPT_GUI_OTHER_LORE_15", "SCRIPT_GUI_OTHER_LORE_16", "SCRIPT_GUI_OTHER_LORE_17", "SCRIPT_GUI_OTHER_LORE_18")), null)); addEmptyItems(swItems, 2); addCustomScriptsItems(swItems, p); - addEmptyItems(swItems, 16); + addEmptyItems(swItems, 45 - swItems.size() % 45); + addEmptyItems(swItems, 4); swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_VARIABLES", new ArrayList<>()), null)); addEmptyItems(swItems, 4); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_NAME", "SCRIPT_GUI_CONSTANT_TRACE_LORE", false); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME", "SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE", false); - addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_TNT_NAME", "SCRIPT_GUI_CONSTANT_TNT_LORE", false); - addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_ONLY_TB_NAME", "SCRIPT_GUI_CONSTANT_ONLY_TB_LORE", false); - addConstantItem(swItems, p, Material.GUNPOWDER, "SCRIPT_GUI_CONSTANT_FREEZE_NAME", "SCRIPT_GUI_CONSTANT_FREEZE_LORE", false); - addConstantItem(swItems, p, Material.FIRE_CHARGE, "SCRIPT_GUI_CONSTANT_FIRE_NAME", "SCRIPT_GUI_CONSTANT_FIRE_LORE", false); - addConstantItem(swItems, p, Material.OBSIDIAN, "SCRIPT_GUI_CONSTANT_PROTECT_NAME", "SCRIPT_GUI_CONSTANT_PROTECT_LORE", false); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_X_NAME", "SCRIPT_GUI_CONSTANT_X_LORE", true); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Y_NAME", "SCRIPT_GUI_CONSTANT_Y_LORE", true); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Z_NAME", "SCRIPT_GUI_CONSTANT_Z_LORE", true); - addConstantItem(swItems, p, Material.NAME_TAG, "SCRIPT_GUI_CONSTANT_NAME_NAME", "SCRIPT_GUI_CONSTANT_NAME_LORE", false); - addConstantItem(swItems, p, Material.IRON_BOOTS, "SCRIPT_GUI_CONSTANT_SNEAK_NAME", "SCRIPT_GUI_CONSTANT_SNEAK_LORE", false); - addConstantItem(swItems, p, Material.DIAMOND_BOOTS, "SCRIPT_GUI_CONSTANT_SPRINTING_NAME", "SCRIPT_GUI_CONSTANT_SPRINTING_LORE", false); - addConstantItem(swItems, p, Material.ARROW, "SCRIPT_GUI_CONSTANT_SLOT_NAME", "SCRIPT_GUI_CONSTANT_SLOT_LORE", false); - addConstantItem(swItems, p, Material.GRASS_BLOCK, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE", false); - addConstantItem(swItems, p, Material.IRON_BLOCK, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE", false); - addConstantItem(swItems, p, Material.BIRCH_SIGN, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE", false); - addConstantItem(swItems, p, Material.ACACIA_SIGN, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE", false); - addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME", "SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE", false); - addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_NAME", "SCRIPT_GUI_CONSTANT_TPS_LORE", false); - addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME", "SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE", false); - addEmptyItems(swItems, 2 * 9 - 3); + addConstantItem(swItems, p, Material.CLOCK, "SCRIPT_GUI_CONSTANT_TIME_NAME", "SCRIPT_GUI_CONSTANT_TIME_LORE"); + addConstantItem(swItems, p, Material.CLOCK, "SCRIPT_GUI_CONSTANT_TICKS_NAME", "SCRIPT_GUI_CONSTANT_TICKS_LORE"); + addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_NAME", "SCRIPT_GUI_CONSTANT_TRACE_LORE"); + addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME", "SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE"); + addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME", "SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE"); + addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME", "SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE"); + addConstantItem(swItems, p, Material.HOPPER, "SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME", "SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE"); + addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_TNT_NAME", "SCRIPT_GUI_CONSTANT_TNT_LORE"); + addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_ONLY_TB_NAME", "SCRIPT_GUI_CONSTANT_ONLY_TB_LORE"); + addConstantItem(swItems, p, Material.GUNPOWDER, "SCRIPT_GUI_CONSTANT_FREEZE_NAME", "SCRIPT_GUI_CONSTANT_FREEZE_LORE"); + addConstantItem(swItems, p, Material.FIRE_CHARGE, "SCRIPT_GUI_CONSTANT_FIRE_NAME", "SCRIPT_GUI_CONSTANT_FIRE_LORE"); + addConstantItem(swItems, p, Material.OBSIDIAN, "SCRIPT_GUI_CONSTANT_PROTECT_NAME", "SCRIPT_GUI_CONSTANT_PROTECT_LORE"); + addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_X_NAME", "SCRIPT_GUI_CONSTANT_X_LORE"); + addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Y_NAME", "SCRIPT_GUI_CONSTANT_Y_LORE"); + addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Z_NAME", "SCRIPT_GUI_CONSTANT_Z_LORE"); + addConstantItem(swItems, p, Material.NAME_TAG, "SCRIPT_GUI_CONSTANT_NAME_NAME", "SCRIPT_GUI_CONSTANT_NAME_LORE"); + addConstantItem(swItems, p, Material.IRON_BOOTS, "SCRIPT_GUI_CONSTANT_SNEAK_NAME", "SCRIPT_GUI_CONSTANT_SNEAK_LORE"); + addConstantItem(swItems, p, Material.DIAMOND_BOOTS, "SCRIPT_GUI_CONSTANT_SPRINTING_NAME", "SCRIPT_GUI_CONSTANT_SPRINTING_LORE"); + addConstantItem(swItems, p, Material.ARROW, "SCRIPT_GUI_CONSTANT_SLOT_NAME", "SCRIPT_GUI_CONSTANT_SLOT_LORE"); + addConstantItem(swItems, p, Material.GRASS_BLOCK, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE"); + addConstantItem(swItems, p, Material.IRON_BLOCK, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE"); + addConstantItem(swItems, p, Material.BIRCH_SIGN, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE"); + addConstantItem(swItems, p, Material.ACACIA_SIGN, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE"); + addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME", "SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE"); + addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_NAME_NAME", "SCRIPT_GUI_CONSTANT_REGION_NAME_LORE"); + addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_NAME", "SCRIPT_GUI_CONSTANT_TPS_LORE"); + addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME", "SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE"); + addEmptyItems(swItems, 45 - swItems.size() % 45); SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("SCRIPT_GUI_NAME", p), swItems, (clickType, o) -> { if (o != null) { @@ -98,10 +105,9 @@ public class ScriptCommand extends SWCommand { }); } - private void addConstantItem(List> swItems, Player p, Material material, String name, String lore, boolean overrideable) { + private void addConstantItem(List> swItems, Player p, Material material, String name, String lore) { List itemLore = new ArrayList<>(); itemLore.add(BauSystem.MESSAGE.parse(lore, p)); - if (overrideable) itemLore.add(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OVERRIDEABLE", p)); swItems.add(new SWListInv.SWListEntry<>(createItem(p, material, name, itemLore), null)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java index 110b2a13..236c969e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java @@ -17,12 +17,14 @@ import de.steamwar.bausystem.linkage.LinkageUtils; import de.steamwar.bausystem.utils.WorldEditUtils; import lombok.Getter; import lombok.Setter; +import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.inventory.meta.BookMeta; import java.util.*; +import java.util.function.Consumer; import java.util.logging.Level; public final class ScriptExecutor { @@ -58,29 +60,38 @@ public final class ScriptExecutor { @Setter private int index = 0; - public ScriptExecutor(BookMeta bookMeta, Player player) { - this(bookMeta, player, new HashMap<>()); + @Getter + private final Consumer echoConsumer; + + public ScriptExecutor(BookMeta bookMeta, Player player, Consumer echoConsumer) { + this(bookMeta, player, new HashMap<>(), echoConsumer); } - public ScriptExecutor(List pages, Player player) { - this(pages, player, new HashMap<>()); + public ScriptExecutor(List pages, Player player, Consumer echoConsumer) { + this(pages, player, new HashMap<>(), echoConsumer); } - public ScriptExecutor(BookMeta bookMeta, Player player, Map localVariables) { + public ScriptExecutor(BookMeta bookMeta, Player player, Map localVariables, Consumer echoConsumer) { this.player = player; globalVariables = ScriptListener.getGlobalContext(player); parseMeta(bookMeta); + this.echoConsumer = echoConsumer != null ? echoConsumer : s -> { + BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", player, s); + }; if (commands.isEmpty()) return; localVariables.forEach(this.localVariables::putValue); resume(); } - public ScriptExecutor(List pages, Player player, Map localVariables) { + public ScriptExecutor(List pages, Player player, Map localVariables, Consumer echoConsumer) { this.player = player; globalVariables = ScriptListener.getGlobalContext(player); parseList(pages); + this.echoConsumer = echoConsumer != null ? echoConsumer : s -> { + BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", player, s); + }; if (commands.isEmpty()) return; localVariables.forEach(this.localVariables::putValue); resume(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java index 1c472da6..fbdbf0f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -44,7 +44,7 @@ public class ScriptListener implements Listener { } event.setCancelled(true); - new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer()); + new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer(), null); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java index 8c12cf30..da83635c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java @@ -32,7 +32,7 @@ public class Echo implements SpecialCommand { @Override public boolean execute(String[] command, ScriptExecutor scriptExecutor) { if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", scriptExecutor.getPlayer(), ""); + scriptExecutor.getEchoConsumer().accept(""); return true; } StringBuilder st = new StringBuilder(); @@ -42,7 +42,7 @@ public class Echo implements SpecialCommand { } st.append(command[i]); } - BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString())); + scriptExecutor.getEchoConsumer().accept(ChatColor.translateAlternateColorCodes('&', st.toString())); return true; } 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 694461d7..58891d04 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 @@ -1,10 +1,13 @@ package de.steamwar.bausystem.features.script.variables; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loader.Loader; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.record.ActiveTracer; import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder; import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.record.TraceRecorder; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FireMode; @@ -17,6 +20,8 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.meta.ItemMeta; +import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -32,20 +37,12 @@ public class Constants { private static class ConstantDoubleValue extends Value.DoubleValue { private Supplier doubleSupplier; - private Consumer doubleConsumer = ignored -> { - }; public ConstantDoubleValue(Supplier doubleSupplier) { super(doubleSupplier.get()); this.doubleSupplier = doubleSupplier; } - public ConstantDoubleValue(Supplier doubleSupplier, Consumer doubleConsumer) { - super(doubleSupplier.get()); - this.doubleSupplier = doubleSupplier; - this.doubleConsumer = doubleConsumer; - } - @Override public long asLong() { value = doubleSupplier.get(); @@ -69,31 +66,17 @@ public class Constants { value = doubleSupplier.get(); return super.asString(); } - - @Override - public void fromValue(Value value) { - super.fromValue(value); - doubleConsumer.accept(this.value); - } } private static class ConstantLongValue extends Value.LongValue { private Supplier longSupplier; - private Consumer longConsumer = ignored -> { - }; public ConstantLongValue(Supplier longSupplier) { super(longSupplier.get()); this.longSupplier = longSupplier; } - public ConstantLongValue(Supplier longSupplier, Consumer longConsumer) { - super(longSupplier.get()); - this.longSupplier = longSupplier; - this.longConsumer = longConsumer; - } - @Override public long asLong() { value = longSupplier.get(); @@ -117,31 +100,17 @@ public class Constants { value = longSupplier.get(); return super.asString(); } - - @Override - public void fromValue(Value value) { - super.fromValue(value); - longConsumer.accept(this.value); - } } private static class ConstantBooleanValue extends Value.BooleanValue { private Supplier booleanSupplier; - private Consumer booleanConsumer = ignored -> { - }; public ConstantBooleanValue(Supplier booleanSupplier) { super(booleanSupplier.get()); this.booleanSupplier = booleanSupplier; } - public ConstantBooleanValue(Supplier booleanSupplier, Consumer booleanConsumer) { - super(booleanSupplier.get()); - this.booleanSupplier = booleanSupplier; - this.booleanConsumer = booleanConsumer; - } - @Override public long asLong() { value = booleanSupplier.get(); @@ -165,31 +134,17 @@ public class Constants { value = booleanSupplier.get(); return super.asString(); } - - @Override - public void fromValue(Value value) { - super.fromValue(value); - booleanConsumer.accept(this.value); - } } private static class ConstantStringValue extends Value.StringValue { private Supplier stringSupplier; - private Consumer stringConsumer = ignored -> { - }; public ConstantStringValue(Supplier stringSupplier) { super(stringSupplier.get()); this.stringSupplier = stringSupplier; } - public ConstantStringValue(Supplier stringSupplier, Consumer stringConsumer) { - super(stringSupplier.get()); - this.stringSupplier = stringSupplier; - this.stringConsumer = stringConsumer; - } - @Override public long asLong() { value = stringSupplier.get(); @@ -213,12 +168,6 @@ public class Constants { value = stringSupplier.get(); return super.asString(); } - - @Override - public void fromValue(Value value) { - super.fromValue(value); - stringConsumer.accept(this.value); - } } static { @@ -236,41 +185,42 @@ public class Constants { } return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof AutoTraceRecorder); }); + CONSTANTS.put("trace_status", player -> { + TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); + return new ConstantStringValue(recorder::scriptState); + }); + CONSTANTS.put("trace_time", player -> { + TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); + return new ConstantLongValue(recorder::scriptTime); + }); + CONSTANTS.put("tnt", player -> { return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY); }); CONSTANTS.put("tnt_onlytb", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.ONLY_TB); - }); - CONSTANTS.put("freeze", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE); + return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB); }); + CONSTANTS.put("fire", player -> { return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW); }); + + CONSTANTS.put("freeze", player -> { + return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE); + }); + CONSTANTS.put("protect", player -> { return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE); }); + CONSTANTS.put("x", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getX(), aLong -> { - Location location = player.getLocation(); - location.setX((double) aLong); - player.teleport(location); - }); + return new ConstantDoubleValue(() -> player.getLocation().getX()); }); CONSTANTS.put("y", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getY(), aLong -> { - Location location = player.getLocation(); - location.setY((double) aLong); - player.teleport(location); - }); + return new ConstantDoubleValue(() -> player.getLocation().getY()); }); CONSTANTS.put("z", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getZ(), aLong -> { - Location location = player.getLocation(); - location.setZ((double) aLong); - player.teleport(location); - }); + return new ConstantDoubleValue(() -> player.getLocation().getZ()); }); CONSTANTS.put("name", player -> { return new ConstantStringValue(player::getDisplayName); @@ -282,15 +232,7 @@ public class Constants { return new ConstantBooleanValue(player::isSprinting); }); CONSTANTS.put("slot", player -> { - return new ConstantLongValue(() -> (long) player.getInventory().getHeldItemSlot(), slot -> { - if (slot > 8) { - slot = 8L; - } - if (slot < 0) { - slot = 0L; - } - player.getInventory().setHeldItemSlot((int) (long) slot); - }); + return new ConstantLongValue(() -> (long) player.getInventory().getHeldItemSlot()); }); CONSTANTS.put("slotmaterial", player -> { return new ConstantStringValue(() -> player.getInventory().getItemInMainHand().getType().name()); @@ -316,6 +258,7 @@ public class Constants { return itemMeta.getDisplayName(); }); }); + CONSTANTS.put("region_type", player -> { Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { @@ -323,12 +266,35 @@ public class Constants { } return new ConstantStringValue(() -> region.getPrototype().getDisplayName().replace(' ', '_').toLowerCase()); }); + CONSTANTS.put("region_name", player -> { + Region region = Region.getRegion(player.getLocation()); + if (region.isGlobal()) { + return new ConstantStringValue(() -> "Global"); + } + return new ConstantStringValue(() -> region.getPrototype().getDisplayName()); + }); + CONSTANTS.put("tps", player -> { return new ConstantDoubleValue(TPSWatcher::getTPS); }); CONSTANTS.put("tps_limit", player -> { return new ConstantDoubleValue(TPSLimitUtils::getCurrentTPSLimit); }); + + CONSTANTS.put("ticks", player -> { + return new ConstantLongValue(TPSUtils.currentTick); + }); + CONSTANTS.put("time", player -> { + return new ConstantStringValue(() -> new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", player)).format(Calendar.getInstance().getTime())); + }); + + CONSTANTS.put("loader_status", player -> { + Loader loader = Loader.getLoader(player); + if (loader == null) { + return new ConstantStringValue(() -> "OFF"); + } + return new ConstantStringValue(() -> loader.getStage().name()); + }); } public Set allVariables() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoExplodeTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoExplodeTraceRecorder.java index 7e24f441..6ff44728 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoExplodeTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoExplodeTraceRecorder.java @@ -30,4 +30,9 @@ public class AutoExplodeTraceRecorder extends AutoTraceRecorder { protected boolean shouldStartRecording(StartType startType) { return startType == StartType.EXPLODE; } + + @Override + protected String getScriptState() { + return "IDLE_AUTO_EXPLODE"; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoIgniteTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoIgniteTraceRecorder.java index 45988d3e..932634bb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoIgniteTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoIgniteTraceRecorder.java @@ -30,4 +30,9 @@ public class AutoIgniteTraceRecorder extends AutoTraceRecorder implements Active protected boolean shouldStartRecording(StartType startType) { return startType == StartType.IGNITE; } + + @Override + protected String getScriptState() { + return "IDLE_AUTO_IGNITE"; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java index 90e436ee..49253e08 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java @@ -31,7 +31,7 @@ import java.util.function.Supplier; public abstract class AutoTraceRecorder implements TraceRecorder { - private boolean recording = false; + protected boolean recording = false; private long startTime = TPSUtils.currentTick.get(); private long lastExplosion = 0; @@ -121,4 +121,16 @@ public abstract class AutoTraceRecorder implements TraceRecorder { IGNITE, EXPLODE } + + protected abstract String getScriptState(); + + @Override + public String scriptState() { + return recording ? "RECORDING" : getScriptState(); + } + + @Override + public long scriptTime() { + return TPSUtils.currentTick.get() - startTime; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index d24d8a1c..2d74492d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -65,6 +65,16 @@ public class Recorder implements Listener { @Override public void explode(TNTPrimed tntPrimed, boolean b) { } + + @Override + public String scriptState() { + return "OFF"; + } + + @Override + public long scriptTime() { + return 0; + } } private static final NoopTraceRecorder NOOP = new NoopTraceRecorder(); @@ -85,6 +95,16 @@ public class Recorder implements Listener { @Override public void explode(TNTPrimed tntPrimed, boolean b) { } + + @Override + public String scriptState() { + return "IDLE"; + } + + @Override + public long scriptTime() { + return 0; + } } private static final DisabledTracerRecorder DISABLED = new DisabledTracerRecorder(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java index edd6dd48..a1d03f27 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java @@ -72,4 +72,14 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { tntRecord.explode(tntPrimed); recordMap.remove(tntPrimed); } + + @Override + public String scriptState() { + return "RECORD"; + } + + @Override + public long scriptTime() { + return TPSUtils.currentTick.get() - startTime; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SingleTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SingleTraceRecorder.java index 6df0716f..6eae0b06 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SingleTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SingleTraceRecorder.java @@ -43,4 +43,9 @@ public class SingleTraceRecorder extends AutoTraceRecorder { protected void stoppedRecording() { Recorder.INSTANCE.remove(region); } + + @Override + protected String getScriptState() { + return "IDLE_SINGLE"; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java index f89562ef..2c75bf07 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java @@ -38,4 +38,7 @@ public interface TraceRecorder { void explode(TNTPrimed tntPrimed, boolean inBuildRegion); default void tick() { } + + String scriptState(); + long scriptTime(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index d44a3cb0..ace614eb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.script.CustomScriptManager; import de.steamwar.bausystem.features.tpslimit.FreezeUtils; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; @@ -20,17 +21,28 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.HashMap; -import java.util.List; +import java.util.*; @Linked public class BauScoreboard implements Listener { + private static final Random RANDOM = new Random(); + private static final String ALL = "0123456789abcdef"; + + private static String getRandomColorCode() { + StringBuilder st = new StringBuilder(); + for (int i = 0; i < 6; i++) { + st.append("§" + ALL.charAt(RANDOM.nextInt(ALL.length()))); + } + return st.toString(); + } + @LinkedInstance public Recorder recorder; + @LinkedInstance + public CustomScriptManager customScriptManager; + @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); @@ -57,44 +69,47 @@ public class BauScoreboard implements Listener { private HashMap sidebar(Player p) { Region region = Region.getRegion(p.getLocation()); - // String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), p).substring(0, 2); - String colorCode = "§e"; - List strings = new ArrayList<>(); - strings.add("§1"); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TIME", p) + "§8: §7" + new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Calendar.getInstance().getTime())); - if (GlobalRegion.getInstance() != region) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getDisplayName()); - } - - strings.add("§2"); - for (Flag flag : Flag.getFlags()) { - if (!flag.getRegionPredicate().test(region)) { - continue; + if (!customScriptManager.callScoreboard(p, new HashMap<>(), strings::add)) { + // String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), p).substring(0, 2); + String colorCode = "§e"; + strings.add("§1"); + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TIME", p) + "§8: §7" + new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Calendar.getInstance().getTime())); + if (GlobalRegion.getInstance() != region) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getDisplayName()); } - String message = BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode); - strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + message); - } - strings.add("§3"); - String traceScore = recorder.get(region).scoreboard(p); - if (traceScore != null) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore); - } + strings.add("§2"); + for (Flag flag : Flag.getFlags()) { + if (!flag.getRegionPredicate().test(region)) { + continue; + } + strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode)); + } - Loader loader = Loader.getLoader(p); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader != null ? loader.getStage().getChatValue() : "LOADER_OFF", p)); + strings.add("§3"); + String traceScore = recorder.get(region).scoreboard(p); + if (traceScore != null) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore); + } - strings.add("§5"); - if (FreezeUtils.frozen()) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); - } else { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8 " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); + Loader loader = Loader.getLoader(p); + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader != null ? loader.getStage().getChatValue() : "LOADER_OFF", p)); + + strings.add("§5"); + if (FreezeUtils.frozen()) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); + } else { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); + } } int i = strings.size(); HashMap result = new HashMap<>(); for (String s : strings) { + if (s.isEmpty()) { + s = getRandomColorCode(); + } result.put(s, i--); } return result;