From b1672be384905cd6e35cfebe99ea703f18e0f4da Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 5 Jan 2021 13:13:05 +0100 Subject: [PATCH] Fixing some Things --- .../bausystem/world/AutoLoader_15.java | 15 +++++++-------- .../steamwar/bausystem/world/Detonator.java | 19 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java index 8353ce9..a69a11f 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java @@ -49,6 +49,7 @@ class AutoLoader_15 { if (!(data instanceof Powerable)) return false; + Powerable powerable = (Powerable) data; powerable.setPowered(active); block.setBlockData(powerable); @@ -59,7 +60,7 @@ class AutoLoader_15 { block.setBlockData(openable); } - if (data instanceof Switch){ + if (data instanceof Switch) { Switch swtch = (Switch) data; Block relative; switch(swtch.getFace()){ @@ -74,7 +75,7 @@ class AutoLoader_15 { break; } updateBlock(relative); - }else if(block.getType() == Material.TRIPWIRE) { + } else if(block.getType() == Material.TRIPWIRE) { updateBlock(block); } return true; @@ -97,11 +98,7 @@ class AutoLoader_15 { Material material = block.getType(); if (material == Material.LEVER) { - if (powerable.isPowered()) { - return new Detoloader("Hebel", 0).setActive(false); - } else { - return new Detoloader("Hebel", 0).setActive(true); - } + return new Detoloader("Hebel", 0).setActive(!powerable.isPowered()); } else if (material == Material.STONE_BUTTON) { return new Detoloader("Knopf", Detoloader.STONE_BUTTON); } else if (material.name().contains("PRESSURE_PLATE")){ @@ -118,6 +115,8 @@ class AutoLoader_15 { } static boolean getLever(Block block) { - return ((Powerable)block.getBlockData()).isPowered(); + if(!(block.getBlockData() instanceof Powerable)) + return false; + return ((Powerable) block.getBlockData()).isPowered(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 0a27f53..e557d30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -41,7 +41,7 @@ import java.util.stream.Collectors; public class Detonator implements Listener { public static final ItemStack WAND; - private static final Map PLAYERS = new HashMap<>(); + private static final Map players = new HashMap<>(); private final Set locs = new HashSet<>(); private final Player player; @@ -61,19 +61,20 @@ public class Detonator implements Listener { } public static Detonator getDetonator(Player player){ - if(!PLAYERS.containsKey(player)) + if(!players.containsKey(player)) return new Detonator(player); - return PLAYERS.get(player); + return players.get(player); } public Detonator(Player player) { this.player = player; Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); - PLAYERS.put(player, this); + players.put(player, this); } public static void deleteDetonator(Player player) { - HandlerList.unregisterAll(PLAYERS.remove(player)); + if(players.containsKey(player)) + HandlerList.unregisterAll(players.remove(player)); } public void execute() { @@ -86,12 +87,7 @@ public class Detonator implements Listener { }, 12), new VersionedRunnable(() -> { boolean powered; - try { - powered = AutoLoader_15.getLever(activation.location.getBlock()); - } catch (ClassCastException e) { - locs.remove(activation); - return; - } + powered = AutoLoader_15.getLever(activation.location.getBlock()); AutoLoader_15.setRedstone(activation.location, !powered); }, 15)); } else { @@ -113,6 +109,7 @@ public class Detonator implements Listener { public void onPlayerInteract(PlayerInteractEvent event) { if(!event.getPlayer().equals(player)) return; + if (event.getItem() == null) return; if (event.getItem().isSimilar(WAND)) { event.setCancelled(true);