Fixing Detonator #158
@ -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);
|
||||||
@ -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) {
|
||||||
|
if(!(block.getBlockData() instanceof Powerable))
|
||||||
|
return false;
|
||||||
|
|||||||
return ((Powerable) block.getBlockData()).isPowered();
|
return ((Powerable) block.getBlockData()).isPowered();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
YoyoNow
hat
Kannst du das hier auch noch callen, wenn ich den Detonator aus dem Inventar werfe bzw lösche oder geht das nicht? Oder mach es so, dass du nur immer einen detonator hast. Außerdem bitte auch beim leaven des Servers Detonator#deleteDetonator(Player) aufrufen. Da sonst memory leaks aufkommen können. Kannst du das hier auch noch callen, wenn ich den Detonator aus dem Inventar werfe bzw lösche oder geht das nicht? Oder mach es so, dass du nur immer einen detonator hast. Außerdem bitte auch beim leaven des Servers Detonator#deleteDetonator(Player) aufrufen. Da sonst memory leaks aufkommen können.
Chaoscaot
hat
Wird es schon. Wird es schon.
YoyoNow
hat
habe ich im code nicht gesehen. Also diese Methode wird nicht direkt aufgerufen oder? habe ich im code nicht gesehen. Also diese Methode wird nicht direkt aufgerufen oder?
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void execute() {
|
public void execute() {
|
||||||
@ -86,12 +87,7 @@ public class Detonator implements Listener {
|
|||||||
|
|
||||||
YoyoNow
hat
Unnötige Leerzeile Unnötige Leerzeile
|
|||||||
}, 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);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Bitte den Zeilenumbruch weg machen