From 56f7fddb0ef5a1824d29b1bf4654c51e439a8bad Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 27 Aug 2023 12:54:04 +0200 Subject: [PATCH] Fix Loader convenience with creating NOOP's Signed-off-by: yoyosource --- .../bausystem/features/loader/Loader.java | 42 ++++++++++++------- .../loader/elements/ElementSettings.java | 1 + .../elements/LoaderInteractionElement.java | 40 +++++++++++++++--- .../elements/impl/LoaderComparator.java | 6 +++ .../elements/impl/LoaderDaylightDetector.java | 7 ++++ .../loader/elements/impl/LoaderLectern.java | 5 +++ .../loader/elements/impl/LoaderLever.java | 5 +++ .../loader/elements/impl/LoaderMovement.java | 6 +++ .../loader/elements/impl/LoaderNoteBlock.java | 5 +++ .../loader/elements/impl/LoaderOpenable.java | 5 +++ .../loader/elements/impl/LoaderRepeater.java | 6 +++ .../loader/elements/impl/LoaderTicks.java | 5 +++ .../loader/elements/impl/LoaderWait.java | 8 ++-- 13 files changed, 114 insertions(+), 27 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index c0d8ebc3..8cea017b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -123,26 +123,34 @@ public class Loader implements Listener { public void gui(SettingsSorting settingsSorting) { List> list = new ArrayList<>(); - for (LoaderElement element : elements) { - if (settingsSorting != null) { - if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) { - continue; + Runnable updateRunnable = () -> { + list.clear(); + for (LoaderElement element : elements) { + if (settingsSorting != null) { + if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) { + continue; + } + if (settingsSorting == SettingsSorting.INTERACTIONS && (element instanceof LoaderWait || element instanceof LoaderTNT)) { + continue; + } } - if (settingsSorting == SettingsSorting.INTERACTIONS && (element instanceof LoaderWait || element instanceof LoaderTNT)) { - continue; + SWItem item = element.menu(p); + if (element instanceof LoaderInteractionElement) { + LoaderInteractionElement interactionElement = (LoaderInteractionElement) element; + item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, interactionElement.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p))); + } else { + item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p))); } + list.add(new SWListInv.SWListEntry<>(item, element)); } - SWItem item = element.menu(p); - if (element instanceof LoaderInteractionElement) { - LoaderInteractionElement interactionElement = (LoaderInteractionElement) element; - item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, interactionElement.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p))); - } else { - item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p))); - } - list.add(new SWListInv.SWListEntry<>(item, element)); - } + }; + updateRunnable.run(); + SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {}); - swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); + swListInv.setCallback((clickType, entry) -> entry.click(p, () -> { + updateRunnable.run(); + swListInv.open(); + })); SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_INTERACTIONS", p), clickType -> { gui(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); @@ -173,6 +181,7 @@ public class Loader implements Listener { } gui(settingsSorting); }); + updateRunnable.run(); swAnvilInv.open(); }); swListInv.setItem(50, waitBetweenTNT); @@ -192,6 +201,7 @@ public class Loader implements Listener { } gui(settingsSorting); }); + updateRunnable.run(); swAnvilInv.open(); }); swListInv.setItem(51, waitTime); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java index 55bce084..25b839ff 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java @@ -31,6 +31,7 @@ public interface ElementSettings { void click(Player player, Runnable backAction, Runnable deleteAction); default void playerInteract() {} + void noop(); default String translateItemName(String name, String mode, Player player, Object... args) { return BauSystem.MESSAGE.parse("LOADER_GUI_ITEM_NAME", player, BauSystem.MESSAGE.parse(name, player), BauSystem.MESSAGE.parse(mode, player, args)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java index e90491d8..cc00c662 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.loader.elements; import de.steamwar.bausystem.BauSystem; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import org.bukkit.Location; @@ -60,13 +61,19 @@ public abstract class LoaderInteractionElement implem @Override public void click(Player player, Runnable backAction) { List> entries = new ArrayList<>(); - for (T element : elements) { - entries.add(new SWListInv.SWListEntry<>(element.menu(player), element)); - } + Runnable updateRunnable = () -> { + entries.clear(); + for (T element : elements) { + entries.add(new SWListInv.SWListEntry<>(element.menu(player), element)); + } + }; + updateRunnable.run(); - SWListInv listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> { + SWListInv listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> {}); + listInv.setCallback((clickType, entry) -> { entry.click(player, () -> { - click(player, backAction); + updateRunnable.run(); + listInv.open(); }, () -> { if (elements.size() == 1) return; elements.remove(entry); @@ -79,12 +86,33 @@ public abstract class LoaderInteractionElement implem listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> { T element = createNewElement(); elements.add(element); - element.click(player, () -> click(player, backAction), () -> { + element.click(player, () -> { + updateRunnable.run(); + listInv.open(); + }, () -> { if (elements.size() == 1) return; elements.remove(element); click(player, backAction); }); })); + listInv.setItem(51, new SWItem(Material.STRUCTURE_VOID, "§7Insert NOOP's", clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "§7NOOP Count", "1"); + anvilInv.setCallback(s -> { + try { + int count = Integer.parseInt(s); + for (int i = 0; i < count; i++) { + T element = createNewElement(); + element.noop(); + elements.add(element); + } + updateRunnable.run(); + listInv.open(); + } catch (NumberFormatException e) { + player.sendMessage("§cInvalid Number"); + } + }); + anvilInv.open(); + })); listInv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java index 4ddb1f02..9e446448 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java @@ -120,6 +120,12 @@ public class LoaderComparator extends LoaderInteractionElement __) { - __.accept(delay); + public void execute(Consumer wait) { + wait.accept(delay); } @Override