From b1dcd6d57bf7e2ddb7efb7e48addcac2caeb6876 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 18:00:54 +0200 Subject: [PATCH] Update Loader and fix many things Signed-off-by: yoyosource --- .../bausystem/features/loadern/Loader.java | 18 ++++- .../loadern/LoaderScoreboardElement.java | 6 +- .../elements/LoaderInteractionElement.java | 17 +++-- .../elements/impl/LoaderDaylightDetector.java | 2 +- .../loadern/elements/impl/LoaderLever.java | 2 +- .../loadern/elements/impl/LoaderMovement.java | 18 +++-- .../loadern/elements/impl/LoaderTicks.java | 74 ++++--------------- .../loadern/elements/impl/LoaderWait.java | 2 + 8 files changed, 62 insertions(+), 77 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 40c3f750..0560f1a6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -60,6 +60,7 @@ public class Loader implements Listener { private List elements = new ArrayList<>(); private int currentElement = 0; + private long totalDelay = 0; public Loader(Player p) { this.p = p; @@ -71,9 +72,18 @@ public class Loader implements Listener { currentElement++; if (currentElement >= elements.size()) { currentElement = 0; + if (totalDelay == 0) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1); + return; + } + totalDelay = 0; } if (stage == Stage.RUNNING) { - elements.get(currentElement).execute(this::next); + LoaderElement element = elements.get(currentElement); + if (element instanceof LoaderWait) { + totalDelay += ((LoaderWait) element).getDelay(); + } + element.execute(this::next); } } @@ -136,7 +146,7 @@ public class Loader implements Listener { if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); swListInv.setItem(48, onlyWaitElements); - SWItem onlyInteractionsElements = new SWItem(Material.TNT, "§eNur Interaktionen", clickType -> { + SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); }); if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); @@ -151,6 +161,10 @@ public class Loader implements Listener { stop(); } + public String getProgress() { + return "§7" + (currentElement + 1) + "§8/§7" + elements.size(); + } + public enum SettingsSorting { WAIT, INTERACTIONS, diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java index d0b41cc0..dd0a59c5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java @@ -42,6 +42,10 @@ public class LoaderScoreboardElement implements ScoreboardElement { public String get(Region region, Player p) { Loader loader = Loader.getLoader(p); if (loader == null) return null; - return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + if (loader.getStage() == Loader.Stage.RUNNING || loader.getStage() == Loader.Stage.PAUSE) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p) + " §8(" + loader.getProgress() + "§8)"; + } else { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 8397779a..948a3e1d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -86,10 +86,12 @@ public abstract class LoaderInteractionElement implem listInv.open(); } - protected void update(Block block) { - Material material = block.getType(); - if (block.getBlockData() instanceof Switch) { - Switch sw = (Switch) block.getBlockData(); + protected void update(BlockData blockData) { + Material material = blockData.getMaterial(); + Block block = location.getBlock(); + if (blockData instanceof Switch) { + Switch sw = (Switch) blockData; + updateBlock(block, sw); FaceAttachable.AttachedFace face = sw.getAttachedFace(); if (face == FaceAttachable.AttachedFace.FLOOR) { updateBlock(block.getRelative(BlockFace.DOWN)); @@ -99,14 +101,17 @@ public abstract class LoaderInteractionElement implem updateBlock(block.getRelative(sw.getFacing().getOppositeFace())); } } else if (material == Material.TRIPWIRE) { - updateBlock(block); + updateBlock(block, blockData); } else if (material.name().endsWith("_PLATE")) { updateBlock(block.getRelative(BlockFace.DOWN)); } } protected void updateBlock(Block block) { - BlockData data = block.getBlockData(); + updateBlock(block, block.getBlockData()); + } + + protected void updateBlock(Block block, BlockData data) { block.setType(Material.BARRIER, true); block.setBlockData(data, true); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index cbdcc7dc..d78e6319 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -76,7 +76,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement= 0) { boolean finalWaitFor = waitFor; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { if (blockData instanceof AnaloguePowerable) { - ((AnaloguePowerable) blockData).setPower(0); + AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData; + analoguePowerable.setPower(0); + location.getBlock().setBlockData(analoguePowerable, true); } else { - ((Powerable) blockData).setPowered(false); + Powerable powerable = (Powerable) blockData; + powerable.setPowered(false); + location.getBlock().setBlockData(powerable, true); } - location.getBlock().setBlockData(blockData); - update(location.getBlock()); if (finalWaitFor) { nextAction.run(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 5b615f20..0bdb5228 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -27,8 +27,6 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.block.data.AnaloguePowerable; -import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Powerable; import org.bukkit.entity.Player; @@ -39,22 +37,19 @@ public class LoaderTicks extends LoaderInteractionElement 0); - } else { - powerable.setPowered(true); - } - } + Powerable powerable = (Powerable) location.getBlock().getBlockData(); + powerable.setPowered(true); + location.getBlock().setBlockData(powerable, true); - location.getBlock().setBlockData(blockData); - update(location.getBlock()); - if (ticks >= 0) { - boolean finalWaitFor = waitFor; - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - if (blockData instanceof AnaloguePowerable) { - ((AnaloguePowerable) blockData).setPower(0); - } else { - ((Powerable) blockData).setPowered(false); - } - location.getBlock().setBlockData(blockData); - update(location.getBlock()); - if (finalWaitFor) { - nextAction.run(); - } - }, ticks); - if (!finalWaitFor) { + boolean finalWaitFor = waitFor; + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + powerable.setPowered(false); + location.getBlock().setBlockData(powerable, true); + if (finalWaitFor) { nextAction.run(); } + }, ticks); + if (!finalWaitFor) { + nextAction.run(); } } @Override public void click(Player player, Runnable backAction, Runnable deleteAction) { - SWInventory swInventory = new SWInventory(player, analogue ? 36 : 18, "Settings"); - for (int i = analogue ? 27 : 9; i < (analogue ? 35 : 18); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); - swInventory.setItem(analogue ? 27 : 9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); - swInventory.setItem(analogue ? 35 : 17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; @@ -145,18 +122,6 @@ public class LoaderTicks extends LoaderInteractionElement= 9) finalI2++; - swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> { - power = finalI; - click(player, backAction, deleteAction); - }); - } - } - swInventory.open(); } @@ -168,13 +133,6 @@ public class LoaderTicks extends LoaderInteractionElement