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 58ac95a6..c0d8ebc3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT; import de.steamwar.bausystem.features.loader.elements.impl.LoaderWait; import de.steamwar.bausystem.shared.EnumDisplay; @@ -58,31 +59,32 @@ public class Loader implements Listener { private List elements = new ArrayList<>(); private int currentElement = 0; - private long totalDelay = 0; + private long waitTime = 0; public Loader(Player p) { this.p = p; this.recorder = new LoaderRecorder(p, elements); Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); - } - private void next() { - currentElement++; - if (currentElement >= elements.size()) { - currentElement = 0; - if (totalDelay == 0) { - BauSystem.runTaskLater(BauSystem.getInstance(), this::next, 1); + BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { + if (stage != Stage.RUNNING) return; + if (waitTime > 0) { + waitTime--; return; } - totalDelay = 0; - } - if (stage == Stage.RUNNING) { - LoaderElement element = elements.get(currentElement); - if (element instanceof LoaderWait) { - totalDelay += ((LoaderWait) element).getDelay(); + + while (currentElement < elements.size()) { + LoaderElement element = elements.get(currentElement); + currentElement++; + element.execute(delay -> waitTime = delay); + if (waitTime > 0) { + break; + } } - element.execute(this::next); - } + if (currentElement >= elements.size()) { + currentElement = 0; + } + }, 0, 1); } public void start() { @@ -96,9 +98,7 @@ public class Loader implements Listener { if (elements.isEmpty()) { BauSystem.MESSAGE.send("LOADER_NOTHING_RECORDED", p); stop(); - return; } - elements.get(currentElement).execute(this::next); } public void pause() { @@ -133,7 +133,12 @@ public class Loader implements Listener { } } SWItem item = element.menu(p); - item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, elements.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", 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)); } SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {}); 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 7650878c..55bce084 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 @@ -23,9 +23,11 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; +import java.util.function.Consumer; + public interface ElementSettings { SWItem menu(Player player); - void execute(Runnable nextAction); + void execute(Consumer delay); void click(Player player, Runnable backAction, Runnable deleteAction); default void playerInteract() {} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java index eb173dc5..658a9f8d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java @@ -22,8 +22,10 @@ package de.steamwar.bausystem.features.loader.elements; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; +import java.util.function.Consumer; + public interface LoaderElement { SWItem menu(Player player); - void execute(Runnable nextAction); + void execute(Consumer delay); void click(Player player, Runnable backAction); } 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 dad60ebf..e90491d8 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 @@ -33,6 +33,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; public abstract class LoaderInteractionElement implements LoaderElement { @@ -49,9 +50,9 @@ public abstract class LoaderInteractionElement implem } @Override - public void execute(Runnable nextAction) { + public void execute(Consumer delay) { if (currentShot >= elements.size()) currentShot = 0; - elements.get(currentShot).execute(nextAction); + elements.get(currentShot).execute(delay); currentShot++; if (currentShot >= elements.size()) currentShot = 0; } @@ -122,4 +123,8 @@ public abstract class LoaderInteractionElement implem protected final String translateItemName(String name, Player player) { return BauSystem.MESSAGE.parse("LOADER_SETTING_NAME", player, BauSystem.MESSAGE.parse(name, player)); } + + public int size() { + return elements.size(); + } } 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 fef006f7..4ddb1f02 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 @@ -31,6 +31,7 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; public class LoaderComparator extends LoaderInteractionElement { @@ -62,8 +63,7 @@ public class LoaderComparator extends LoaderInteractionElement delay) { if (location.getBlock().getType() != Material.COMPARATOR) return; Comparator comparator = (Comparator) location.getBlock().getBlockData(); if (interact) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java index 10c2b74c..ed192ba4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java @@ -31,6 +31,7 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; public class LoaderDaylightDetector extends LoaderInteractionElement { @@ -64,8 +65,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement delay) { if (location.getBlock().getType() != Material.DAYLIGHT_DETECTOR) return; DaylightDetector daylightDetector = (DaylightDetector) location.getBlock().getBlockData(); if (noop) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java index b2cf3ff4..ca16eff5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java @@ -32,6 +32,7 @@ import org.bukkit.inventory.meta.BookMeta; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; public class LoaderLectern extends LoaderInteractionElement { @@ -68,8 +69,7 @@ public class LoaderLectern extends LoaderInteractionElement delay) { if (location.getBlock().getType() != Material.LECTERN) return; Lectern lectern = (Lectern) location.getBlock().getState(); if (!((org.bukkit.block.data.type.Lectern) lectern.getBlockData()).hasBook()) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java index 3afa4f04..733a329d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java @@ -31,6 +31,7 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; public class LoaderLever extends LoaderInteractionElement { @@ -63,8 +64,7 @@ public class LoaderLever extends LoaderInteractionElement delay) { if (location.getBlock().getType() != Material.LEVER) return; if (noop) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java index 3bc9ebff..9e88b13c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java @@ -35,6 +35,7 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; public class LoaderMovement extends LoaderInteractionElement { @@ -83,15 +84,9 @@ public class LoaderMovement extends LoaderInteractionElement delay) { + if (!(material == Material.STRING && location.getBlock().getType() == Material.TRIPWIRE) && location.getBlock().getType() != material) return; + if (noop) return; BlockData blockData = location.getBlock().getBlockData(); if (blockData instanceof AnaloguePowerable) { @@ -111,7 +106,9 @@ public class LoaderMovement extends LoaderInteractionElement= 0) { - boolean finalWaitFor = waitFor; + if (waitFor) { + delay.accept(ticks); + } BauSystem.runTaskLater(BauSystem.getInstance(), () -> { if (blockData instanceof AnaloguePowerable) { AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData; @@ -124,13 +121,7 @@ public class LoaderMovement extends LoaderInteractionElement { @@ -60,8 +61,7 @@ public class LoaderNoteBlock extends LoaderInteractionElement delay) { if (location.getBlock().getType() != Material.NOTE_BLOCK) return; NoteBlock noteBlock = (NoteBlock) location.getBlock().getBlockData(); if (interact) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java index de4abe42..f35aed98 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java @@ -31,6 +31,7 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; public class LoaderOpenable extends LoaderInteractionElement { @@ -68,8 +69,7 @@ public class LoaderOpenable extends LoaderInteractionElement delay) { if (location.getBlock().getType() != material) return; Openable openable = (Openable) location.getBlock().getBlockData(); if (noop) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java index 26234c54..153721a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java @@ -31,6 +31,7 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; public class LoaderRepeater extends LoaderInteractionElement { @@ -63,8 +64,7 @@ public class LoaderRepeater extends LoaderInteractionElement __) { if (location.getBlock().getType() != Material.REPEATER) return; Repeater repeater = (Repeater) location.getBlock().getBlockData(); if (interact) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java index be2fb913..964c5df2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java @@ -29,6 +29,7 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.Arrays; +import java.util.function.Consumer; public class LoaderTNT implements LoaderElement { @@ -46,15 +47,14 @@ public class LoaderTNT implements LoaderElement { } @Override - public void execute(Runnable nextAction) { + public void execute(Consumer delay) { Block block = location.getBlock(); if (block.getType() != Material.AIR && block.getType() != Material.WATER) { - BauSystem.runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1); + delay.accept(1L); return; } block.setType(Material.TNT, true); - nextAction.run(); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java index e770c258..b83d5c0b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java @@ -32,6 +32,7 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; public class LoaderTicks extends LoaderInteractionElement { @@ -71,13 +72,11 @@ public class LoaderTicks extends LoaderInteractionElement delay) { if (location.getBlock().getType() != material) { - nextAction.run(); return; } if (noop) { - nextAction.run(); return; } @@ -86,18 +85,14 @@ public class LoaderTicks extends LoaderInteractionElement { powerable.setPowered(false); location.getBlock().setBlockData(powerable, true); update(powerable); - if (finalWaitFor) { - nextAction.run(); - } }, ticks); - if (!finalWaitFor) { - nextAction.run(); - } } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java index 527ee624..b4df1432 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java @@ -32,6 +32,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Listener; import java.util.Arrays; +import java.util.function.Consumer; public class LoaderWait implements LoaderElement, Listener { @@ -53,12 +54,8 @@ public class LoaderWait implements LoaderElement, Listener { } @Override - public void execute(Runnable nextAction) { - if (delay == 0) { - nextAction.run(); - return; - } - BauSystem.runTaskLater(BauSystem.getInstance(), nextAction, delay); + public void execute(Consumer __) { + __.accept(delay); } @Override