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;
|
||||
@ -52,6 +53,12 @@ class AutoLoader_15 {
|
||||
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;
|
||||
|
@ -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;
|
||||
@ -39,7 +41,7 @@ import java.util.stream.Collectors;
|
||||
public class Detonator implements Listener {
|
||||
|
||||
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 Player player;
|
||||
@ -59,49 +61,49 @@ 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) {
|
||||
if(players.containsKey(player))
|
||||
players.remove(player);
|
||||
HandlerList.unregisterAll(PLAYERS.remove(player));
|
||||
}
|
||||
|
||||
|
||||
public void execute() {
|
||||
for (Detoloader.DetonatorActivation activation: getLocations()) {
|
||||
|
||||
Boolean powered;
|
||||
if(activation.activation == -1) switch (Core.getVersion()) {
|
||||
case 15:
|
||||
if(activation.activation == -1) {
|
||||
YoyoNow
hat
Die Zeile kann weg Die Zeile kann weg
|
||||
VersionedRunnable.call(new VersionedRunnable(() -> {
|
||||
boolean powered = AutoLoader_12.getLever(activation.location.getBlock());
|
||||
AutoLoader_12.setRedstone(activation.location, !powered);
|
||||
|
||||
}, 12), new VersionedRunnable(() -> {
|
||||
YoyoNow
hat
Unnötige Leerzeile Unnötige Leerzeile
|
||||
boolean powered;
|
||||
try {
|
||||
powered = AutoLoader_15.getLever(activation.location.getBlock());
|
||||
}catch (ClassCastException e) {
|
||||
} catch (ClassCastException e) {
|
||||
locs.remove(activation);
|
||||
return;
|
||||
}
|
||||
AutoLoader_15.setRedstone(activation.location, !powered);
|
||||
break;
|
||||
default:
|
||||
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:
|
||||
}, 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);
|
||||
}, 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!"));
|
||||
@ -116,16 +118,19 @@ public class Detonator implements Listener {
|
||||
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) {
|
||||
@ -151,7 +156,7 @@ public class Detonator implements Listener {
|
||||
print(detoloader.addBack ? "§e" + detoloader.getBlock() + " getsetzt" :
|
||||
detoloader.getBlock(), detoloader.addBack);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
execute();
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
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.
Wird es schon.
habe ich im code nicht gesehen. Also diese Methode wird nicht direkt aufgerufen oder?