diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java index 246d80fa..b7615379 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java @@ -59,7 +59,7 @@ public class DetonatorCommand extends SWCommand { @Register(help = true) public void genericHelp(Player p, String... args) { - p.sendMessage(ColorConfig.BASE + "---===(" + ColorConfig.HIGHLIGHT + "Fernzünder" + ColorConfig.BASE + ")===---"); + p.sendMessage(ColorConfig.BASE + "---=== (" + ColorConfig.HIGHLIGHT + "Fernzünder" + ColorConfig.BASE + ") ===---"); p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "detonator wand " + ColorConfig.OTHER + "-" + ColorConfig.BASE + " Gibt den Fernzünder"); p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "detonator click " + ColorConfig.OTHER + "-" + ColorConfig.BASE + " Aktiviere einen Fernzünder (Haupthand -> Hotbar -> Inventar)"); p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "detonator clear " + ColorConfig.OTHER + "-" + ColorConfig.BASE + " Cleare einen Fernzünder"); 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 b1af5c77..3b2b9c7d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -32,6 +32,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -48,9 +49,11 @@ public class Loader implements Listener { private final List actions = new LinkedList<>(); private final BukkitTask task; @Getter - private final int ticksBetweenShots = 80; + @Setter + private int ticksBetweenShots = 80; @Getter - private final int ticksBetweenBlocks = 1; + @Setter + private int ticksBetweenBlocks = 1; @Getter private Stage stage; @Getter @@ -84,15 +87,15 @@ public class Loader implements Listener { } public void pause() { - if (stage == Stage.PAUSE) { - resume(); - return; + if (stage == Stage.RUNNING) { + stage = Stage.PAUSE; } - stage = Stage.PAUSE; } public void resume() { - stage = Stage.RUNNING; + if (stage == Stage.PAUSE) { + stage = Stage.RUNNING; + } } public void setup() { @@ -109,7 +112,12 @@ public class Loader implements Listener { } public void clear() { - actions.clear(); + if (stage == Stage.SETUP) { + actions.clear(); + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Loader gecleart"); + } else { + p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Du must im Setup-Modus sein um den Loader zu clearen"); + } } public void run() { @@ -132,15 +140,21 @@ public class Loader implements Listener { current = iterator.next(); - try { - current.execute(); + if (current.execute()) { countdown = current.delay(this); - } catch (Exception e) { - pause(); - p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Ein Fehler beim ausführen ist passiert, Autoloader wurde pausiert."); + } else { + countdown = 1; + iterator.previous(); } } + public void undo() { + if (actions.isEmpty() || stage != Stage.SETUP) { + return; + } + actions.remove(actions.size() - 1); + } + @EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (event.getPlayer() != p) { @@ -169,8 +183,15 @@ public class Loader implements Listener { return; } - if (LoaderButton.fromBlock(event.getClickedBlock()) != LoaderButton.INVALID) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) + return; + if (event.getClickedBlock().getType() == Material.OBSERVER) + return; + LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); + if (button != LoaderButton.INVALID) { actions.add(InteractionActivation.construct(p, event.getClickedBlock().getLocation(), this)); + lastActivation = 0; + SWUtils.sendToActionbar(p, ColorConfig.HIGHLIGHT + button.getName() + " hinzugefügt " + actions.size()); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java index 31bcbc10..ce0b178d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -35,7 +35,16 @@ public class LoaderCommand extends SWCommand { @Register(help = true) public void genericHelp(Player p, String... args) { - p.sendMessage("@Help@"); + p.sendMessage(ColorConfig.BASE + "---=== (" + ColorConfig.HIGHLIGHT + "Loader" + ColorConfig.BASE + ") ===---"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "loader setup " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Startet die Aufnahme der Aktionen"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader undo " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Entfernt die zuletzt aufgenommene Aktion"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "loader start " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Spielt die zuvor aufgenommenen Aktionen ab"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader wait " + ColorConfig.OTHER + "[" + ColorConfig.BASE + "Ticks" + ColorConfig.OTHER + "] - " + ColorConfig.BASE + "Setzt die Wartezeit zwischen Schüssen"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader speed " + ColorConfig.OTHER + "[" + ColorConfig.BASE + "Ticks" + ColorConfig.OTHER + "] - " + ColorConfig.BASE + "Setzt die Wartezeit zwischen Aktionen"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader pause " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Pausiert das Abspielen"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader resume " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Spielt den Loader weiter ab"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "loader stop " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Stoppt die Aufnahme bzw. das Abspielen"); + p.sendMessage(ColorConfig.BASE + "Der Loader arbeitet mit " + ColorConfig.HIGHLIGHT + "Ingame" + ColorConfig.OTHER + "-" + ColorConfig.HIGHLIGHT + "Ticks " + ColorConfig.OTHER + "(20 Ticks pro Sekunde)"); } private boolean loaderNullCheck(Loader loader, Player p) { @@ -51,28 +60,98 @@ public class LoaderCommand extends SWCommand { public void setupLoader(Player p) { if (Loader.getLoader(p) != null) { Loader.getLoader(p).setup(); - p.sendMessage(BauSystem.PREFIX + ColorConfig.HIGHLIGHT + "Dein Loader ist nun wieder im Setup"); + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Dein Loader ist nun wieder im Setup"); } else { Loader.newLoader(p); - p.sendMessage(BauSystem.PREFIX + ColorConfig.HIGHLIGHT + "Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren."); + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren."); + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Führe dann /" + ColorConfig.HIGHLIGHT + "loader start" + ColorConfig.BASE + " um den Loader zu starten"); } } @Register("start") public void startLoader(Player p) { Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) + if (loaderNullCheck(loader, p)) { return; + } loader.start(); - p.sendMessage(BauSystem.PREFIX + ColorConfig.HIGHLIGHT + "Der Loader ist nun aktiviert."); + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Der Loader ist nun aktiviert."); } @Register("stop") public void stopLoader(Player p) { Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) + if (loaderNullCheck(loader, p)) { return; + } loader.stop(); - p.sendMessage(BauSystem.PREFIX + ColorConfig.HIGHLIGHT + "Der Loader ist nun gestoppt."); + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Der Loader ist nun gestoppt."); + } + + @Register("pause") + public void pauseLoader(Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; + } + loader.pause(); + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Der Loader ist nun pausiert."); + } + + @Register("resume") + public void resumeLoader(Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; + } + loader.resume(); + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Der Loader läuft nun weiter."); + } + + @Register("wait") + public void shotDelayLoader(Player p, int delay) { + if (delay < 1) { + p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Die Wartezeit ist zu klein"); + return; + } + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; + } + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Die Schusswartezeit ist nun: " + delay + ", zuvor " + loader.getTicksBetweenShots()); + loader.setTicksBetweenShots(delay); + } + + @Register("speed") + public void speedLoader(Player p, int delay) { + if (delay < 1) { + p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Die Wartezeit ist zu klein"); + return; + } + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; + } + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "die Setzwartezeit ist nun: " + delay + ", zuvor " + loader.getTicksBetweenBlocks()); + loader.setTicksBetweenShots(delay); + } + + @Register("undo") + public void undoLast(Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; + } + p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Undo erfolgreich."); + loader.undo(); + } + + @Register("clear") + public void clearLoader(Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; + } + loader.clear(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java index 3afb8750..7c4d4768 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java @@ -30,7 +30,7 @@ public abstract class AbstractLoaderActivation { this.p = p; } - public abstract void execute(); + public abstract boolean execute(); public abstract int delay(Loader loader); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java index b433000d..910f2071 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java @@ -40,13 +40,14 @@ public class BlockPlaceLoaderActivation extends AbstractLoaderActivation { } @Override - public void execute() { + public boolean execute() { Block currBlock = location.getBlock(); if (currBlock.getType() != Material.AIR && currBlock.getType() != Material.WATER) { - return; + return false; } currBlock.setType(material, true); + return true; } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java index 11957f03..c7f27bd3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java @@ -131,11 +131,14 @@ public abstract class InteractionActivation extends AbstractLoaderActivation { } @Override - public void execute() { + public boolean execute() { + if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID) + return false; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - setBlockPower(getBlockPower()); + setBlockPower(!getBlockPower()); updateButton(); }, delay); + return true; } @Override @@ -151,13 +154,16 @@ public abstract class InteractionActivation extends AbstractLoaderActivation { } @Override - public void execute() { + public boolean execute() { + if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID) + return false; setBlockPower(true); updateButton(); Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - setBlockPower(getBlockPower()); + setBlockPower(false); updateButton(); }, button.getTime()); + return true; } @Override