SteamWar/BauSystem
Archiviert
13
0

Fixing Detonator

Dieser Commit ist enthalten in:
Chaoscaot 2021-01-05 03:06:27 +01:00
Ursprung bdb575b9c6
Commit 2a1e4578d6
2 geänderte Dateien mit 43 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable; import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.Switch; import org.bukkit.block.data.type.Switch;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -52,6 +53,12 @@ class AutoLoader_15 {
powerable.setPowered(active); powerable.setPowered(active);
block.setBlockData(powerable); block.setBlockData(powerable);
if(data instanceof Openable) {
Openable openable = (Openable) data;
openable.setOpen(active);
block.setBlockData(openable);
}
if (data instanceof Switch){ if (data instanceof Switch){
Switch swtch = (Switch) data; Switch swtch = (Switch) data;
Block relative; Block relative;

Datei anzeigen

@ -20,13 +20,15 @@
package de.steamwar.bausystem.world; package de.steamwar.bausystem.world;
import de.steamwar.bausystem.BauSystem; 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.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -39,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;
@ -59,49 +61,49 @@ 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) {
if(players.containsKey(player)) HandlerList.unregisterAll(PLAYERS.remove(player));
players.remove(player);
} }
public void execute() { public void execute() {
for (Detoloader.DetonatorActivation activation: getLocations()) { for (Detoloader.DetonatorActivation activation: getLocations()) {
Boolean powered; if(activation.activation == -1) {
if(activation.activation == -1) switch (Core.getVersion()) { VersionedRunnable.call(new VersionedRunnable(() -> {
case 15: boolean powered = AutoLoader_12.getLever(activation.location.getBlock());
AutoLoader_12.setRedstone(activation.location, !powered);
}, 12), new VersionedRunnable(() -> {
boolean powered;
try { try {
powered = AutoLoader_15.getLever(activation.location.getBlock()); powered = AutoLoader_15.getLever(activation.location.getBlock());
}catch (ClassCastException e) { } catch (ClassCastException e) {
locs.remove(activation); locs.remove(activation);
return; return;
} }
AutoLoader_15.setRedstone(activation.location, !powered); AutoLoader_15.setRedstone(activation.location, !powered);
break; }, 15));
default: } else {
powered = AutoLoader_12.getLever(activation.location.getBlock()); VersionedRunnable.call(new VersionedRunnable(() -> {
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:
AutoLoader_12.setRedstone(activation.location, true); AutoLoader_12.setRedstone(activation.location, true);
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () ->
AutoLoader_12.setRedstone(activation.location, false), activation.activation); 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!")); 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); event.setCancelled(true);
switch (event.getAction()) { switch (event.getAction()) {
case LEFT_CLICK_BLOCK: case LEFT_CLICK_BLOCK:
Detoloader detoloader; Detoloader detoloader = VersionedCallable.call(
switch(Core.getVersion()){ new VersionedCallable<>(() ->
case 15: AutoLoader_12.onPlayerInteractLoader(event), 12),
detoloader = AutoLoader_15.onPlayerInteractLoader(event); new VersionedCallable<>(() ->
break; AutoLoader_15.onPlayerInteractLoader(event), 15));
default:
detoloader = AutoLoader_12.onPlayerInteractLoader(event);
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(event.getPlayer().isSneaking()) {
if(locs.stream().filter(detonatorActivation -> detonatorActivation.location.equals(event.getClickedBlock().getLocation())).collect(Collectors.toList()).size() == 1) { 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" : print(detoloader.addBack ? "§e" + detoloader.getBlock() + " getsetzt" :
detoloader.getBlock(), detoloader.addBack); detoloader.getBlock(), detoloader.addBack);
} }
break; break;
case RIGHT_CLICK_AIR: case RIGHT_CLICK_AIR:
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_BLOCK:
execute(); execute();