Fixing Detonator #158
@ -24,6 +24,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Openable;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
import org.bukkit.block.data.type.Switch;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@ -48,10 +49,17 @@ class AutoLoader_15 {
|
||||
if (!(data instanceof Powerable))
|
||||
return false;
|
||||
|
||||
|
||||
Powerable powerable = (Powerable) data;
|
||||
powerable.setPowered(active);
|
||||
block.setBlockData(powerable);
|
||||
|
||||
if(data instanceof Openable) {
|
||||
Openable openable = (Openable) data;
|
||||
openable.setOpen(active);
|
||||
block.setBlockData(openable);
|
||||
}
|
||||
|
||||
if (data instanceof Switch) {
|
||||
Switch swtch = (Switch) data;
|
||||
Block relative;
|
||||
@ -90,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")){
|
||||
@ -111,6 +115,8 @@ class AutoLoader_15 {
|
||||
}
|
||||
|
||||
static boolean getLever(Block block) {
|
||||
if(!(block.getBlockData() instanceof Powerable))
|
||||
return false;
|
||||
|
||||
return ((Powerable) block.getBlockData()).isPowered();
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public class CommandDetonator implements CommandExecutor {
|
||||
player.sendMessage("§8/§edetonator wand §8- §7Legt den Fernzünder ins Inventar");
|
||||
player.sendMessage("§8/§edetonator detonate §8- §7Benutzt den Fernzünder");
|
||||
player.sendMessage("§8/§edetonator reset §8- §7Löscht alle markierten Positionen");
|
||||
player.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder");
|
||||
}
|
||||
|
||||
private boolean permissionCheck(Player player) {
|
||||
@ -65,16 +66,20 @@ public class CommandDetonator implements CommandExecutor {
|
||||
player.updateInventory();
|
||||
Detonator.getDetonator(player);
|
||||
break;
|
||||
case "delete":
|
||||
case "reset":
|
||||
case "remove":
|
||||
Detonator.deleteDetonator(player);
|
||||
player.getInventory().removeItem(Detonator.WAND);
|
||||
break;
|
||||
case "detonate":
|
||||
case "click":
|
||||
case "use":
|
||||
Detonator.getDetonator(player).execute();
|
||||
break;
|
||||
case "clear":
|
||||
case "delete":
|
||||
case "reset":
|
||||
Detonator.getDetonator(player).clearLocs();
|
||||
break;
|
||||
default:
|
||||
help(player);
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public class CommandDetonatorTabCompleter implements TabCompleter {
|
||||
tabComplete.add("wand");
|
||||
tabComplete.add("reset");
|
||||
tabComplete.add("detonate");
|
||||
tabComplete.add("remove");
|
||||
|
||||
if (args.length >= 2) {
|
||||
return new ArrayList<>();
|
||||
|
@ -20,13 +20,15 @@
|
||||
package de.steamwar.bausystem.world;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.VersionedCallable;
|
||||
import de.steamwar.core.VersionedRunnable;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@ -72,36 +74,28 @@ public class Detonator implements Listener {
|
||||
|
||||
public static void deleteDetonator(Player player) {
|
||||
if (players.containsKey(player))
|
||||
players.remove(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() {
|
||||
for (Detoloader.DetonatorActivation activation : getLocations()) {
|
||||
|
||||
YoyoNow
hat
Die Zeile kann weg Die Zeile kann weg
|
||||
Boolean powered;
|
||||
if(activation.activation == -1) switch (Core.getVersion()) {
|
||||
case 15:
|
||||
try {
|
||||
powered = AutoLoader_15.getLever(activation.location.getBlock());
|
||||
}catch (ClassCastException e) {
|
||||
locs.remove(activation);
|
||||
return;
|
||||
}
|
||||
AutoLoader_15.setRedstone(activation.location, !powered);
|
||||
break;
|
||||
default:
|
||||
powered = AutoLoader_12.getLever(activation.location.getBlock());
|
||||
if (activation.activation == -1) {
|
||||
VersionedRunnable.call(new VersionedRunnable(() -> {
|
||||
boolean powered = AutoLoader_12.getLever(activation.location.getBlock());
|
||||
AutoLoader_12.setRedstone(activation.location, !powered);
|
||||
}else switch (Core.getVersion()) {
|
||||
case 15:
|
||||
AutoLoader_15.setRedstone(activation.location, true);
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () ->
|
||||
AutoLoader_15.setRedstone(activation.location, false), activation.activation);
|
||||
break;
|
||||
default:
|
||||
}, 12), new VersionedRunnable(() -> {
|
||||
YoyoNow
hat
Unnötige Leerzeile Unnötige Leerzeile
|
||||
boolean powered = AutoLoader_15.getLever(activation.location.getBlock());
|
||||
AutoLoader_15.setRedstone(activation.location, !powered);
|
||||
}, 15));
|
||||
} else {
|
||||
VersionedRunnable.call(new VersionedRunnable(() -> {
|
||||
AutoLoader_12.setRedstone(activation.location, true);
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () ->
|
||||
AutoLoader_12.setRedstone(activation.location, false), activation.activation);
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> AutoLoader_12.setRedstone(activation.location, false), activation.activation);
|
||||
}, 12), new VersionedRunnable(() -> {
|
||||
AutoLoader_15.setRedstone(activation.location, true);
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> AutoLoader_15.setRedstone(activation.location, false), activation.activation);
|
||||
}, 15));
|
||||
}
|
||||
}
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§a" + locs.size() + " Punkt" + (locs.size() > 1 ? "e" : "") + " ausgelöst!"));
|
||||
@ -111,21 +105,23 @@ 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);
|
||||
switch (event.getAction()) {
|
||||
case LEFT_CLICK_BLOCK:
|
||||
Detoloader detoloader;
|
||||
switch(Core.getVersion()){
|
||||
case 15:
|
||||
detoloader = AutoLoader_15.onPlayerInteractLoader(event);
|
||||
break;
|
||||
default:
|
||||
detoloader = AutoLoader_12.onPlayerInteractLoader(event);
|
||||
Detoloader detoloader = VersionedCallable.call(
|
||||
new VersionedCallable<>(() -> AutoLoader_12.onPlayerInteractLoader(event), 12),
|
||||
new VersionedCallable<>(() -> AutoLoader_15.onPlayerInteractLoader(event), 15));
|
||||
|
||||
if (detoloader == null) {
|
||||
return;
|
||||
} else if (detoloader.activation == -1) {
|
||||
print(detoloader.getBlock(), detoloader.addBack);
|
||||
return;
|
||||
}
|
||||
if(detoloader == null || detoloader.activation == -1) return;
|
||||
|
||||
|
||||
if (event.getPlayer().isSneaking()) {
|
||||
if (locs.stream().filter(detonatorActivation -> detonatorActivation.location.equals(event.getClickedBlock().getLocation())).collect(Collectors.toList()).size() == 1) {
|
||||
@ -162,7 +158,8 @@ public class Detonator implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
deleteDetonator(event.getPlayer());
|
||||
if (event.getPlayer().equals(player))
|
||||
deleteDetonator(player);
|
||||
}
|
||||
|
||||
Set<Detoloader.DetonatorActivation> getLocations() {
|
||||
@ -173,10 +170,15 @@ public class Detonator implements Listener {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void clearLocs() {
|
||||
locs.clear();
|
||||
}
|
||||
|
||||
void print(String message, boolean withSize) {
|
||||
if(withSize)
|
||||
if (withSize) {
|
||||
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message + " §8" + getLocations().size()));
|
||||
else
|
||||
}else {
|
||||
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Bitte den Zeilenumbruch weg machen