SteamWar/BauSystem
Archiviert
13
0

Fixing some Things

Dieser Commit ist enthalten in:
Chaoscaot 2021-01-05 13:13:05 +01:00
Ursprung 2a1e4578d6
Commit b1672be384
2 geänderte Dateien mit 15 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -49,6 +49,7 @@ class AutoLoader_15 {
if (!(data instanceof Powerable)) if (!(data instanceof Powerable))
return false; return false;
Powerable powerable = (Powerable) data; Powerable powerable = (Powerable) data;
powerable.setPowered(active); powerable.setPowered(active);
block.setBlockData(powerable); block.setBlockData(powerable);
@ -59,7 +60,7 @@ class AutoLoader_15 {
block.setBlockData(openable); block.setBlockData(openable);
} }
if (data instanceof Switch){ if (data instanceof Switch) {
Switch swtch = (Switch) data; Switch swtch = (Switch) data;
Block relative; Block relative;
switch(swtch.getFace()){ switch(swtch.getFace()){
@ -74,7 +75,7 @@ class AutoLoader_15 {
break; break;
} }
updateBlock(relative); updateBlock(relative);
}else if(block.getType() == Material.TRIPWIRE) { } else if(block.getType() == Material.TRIPWIRE) {
updateBlock(block); updateBlock(block);
} }
return true; return true;
@ -97,11 +98,7 @@ class AutoLoader_15 {
Material material = block.getType(); Material material = block.getType();
if (material == Material.LEVER) { if (material == Material.LEVER) {
if (powerable.isPowered()) { return new Detoloader("Hebel", 0).setActive(!powerable.isPowered());
return new Detoloader("Hebel", 0).setActive(false);
} else {
return new Detoloader("Hebel", 0).setActive(true);
}
} else if (material == Material.STONE_BUTTON) { } else if (material == Material.STONE_BUTTON) {
return new Detoloader("Knopf", Detoloader.STONE_BUTTON); return new Detoloader("Knopf", Detoloader.STONE_BUTTON);
} else if (material.name().contains("PRESSURE_PLATE")){ } else if (material.name().contains("PRESSURE_PLATE")){
@ -118,6 +115,8 @@ class AutoLoader_15 {
} }
static boolean getLever(Block block) { static boolean getLever(Block block) {
return ((Powerable)block.getBlockData()).isPowered(); if(!(block.getBlockData() instanceof Powerable))
return false;
return ((Powerable) block.getBlockData()).isPowered();
} }
} }

Datei anzeigen

@ -41,7 +41,7 @@ import java.util.stream.Collectors;
public class Detonator implements Listener { public class Detonator implements Listener {
public static final ItemStack WAND; public static final ItemStack WAND;
private static final Map<Player, Detonator> PLAYERS = new HashMap<>(); private static final Map<Player, Detonator> players = new HashMap<>();
private final Set<Detoloader.DetonatorActivation> locs = new HashSet<>(); private final Set<Detoloader.DetonatorActivation> locs = new HashSet<>();
private final Player player; private final Player player;
@ -61,19 +61,20 @@ public class Detonator implements Listener {
} }
public static Detonator getDetonator(Player player){ public static Detonator getDetonator(Player player){
if(!PLAYERS.containsKey(player)) if(!players.containsKey(player))
return new Detonator(player); return new Detonator(player);
return PLAYERS.get(player); return players.get(player);
} }
public Detonator(Player player) { public Detonator(Player player) {
this.player = player; this.player = player;
Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
PLAYERS.put(player, this); players.put(player, this);
} }
public static void deleteDetonator(Player player) { public static void deleteDetonator(Player player) {
HandlerList.unregisterAll(PLAYERS.remove(player)); if(players.containsKey(player))
HandlerList.unregisterAll(players.remove(player));
} }
public void execute() { public void execute() {
@ -86,12 +87,7 @@ public class Detonator implements Listener {
}, 12), new VersionedRunnable(() -> { }, 12), new VersionedRunnable(() -> {
boolean powered; boolean powered;
try { powered = AutoLoader_15.getLever(activation.location.getBlock());
powered = AutoLoader_15.getLever(activation.location.getBlock());
} catch (ClassCastException e) {
locs.remove(activation);
return;
}
AutoLoader_15.setRedstone(activation.location, !powered); AutoLoader_15.setRedstone(activation.location, !powered);
}, 15)); }, 15));
} else { } else {
@ -113,6 +109,7 @@ public class Detonator implements Listener {
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if(!event.getPlayer().equals(player)) if(!event.getPlayer().equals(player))
return; return;
if (event.getItem() == null) return; if (event.getItem() == null) return;
if (event.getItem().isSimilar(WAND)) { if (event.getItem().isSimilar(WAND)) {
event.setCancelled(true); event.setCancelled(true);