Merge pull request 'Fixing Detonator' (#158) from fixing_some_detonator into master
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
8b1d8e5d40
@ -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;
|
||||||
@ -48,10 +49,17 @@ 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);
|
||||||
|
|
||||||
|
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;
|
||||||
@ -90,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")){
|
||||||
@ -111,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 wand §8- §7Legt den Fernzünder ins Inventar");
|
||||||
player.sendMessage("§8/§edetonator detonate §8- §7Benutzt den Fernzünder");
|
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 reset §8- §7Löscht alle markierten Positionen");
|
||||||
|
player.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean permissionCheck(Player player) {
|
private boolean permissionCheck(Player player) {
|
||||||
@ -65,16 +66,20 @@ public class CommandDetonator implements CommandExecutor {
|
|||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
Detonator.getDetonator(player);
|
Detonator.getDetonator(player);
|
||||||
break;
|
break;
|
||||||
case "delete":
|
|
||||||
case "reset":
|
|
||||||
case "remove":
|
case "remove":
|
||||||
Detonator.deleteDetonator(player);
|
Detonator.deleteDetonator(player);
|
||||||
|
player.getInventory().removeItem(Detonator.WAND);
|
||||||
break;
|
break;
|
||||||
case "detonate":
|
case "detonate":
|
||||||
case "click":
|
case "click":
|
||||||
case "use":
|
case "use":
|
||||||
Detonator.getDetonator(player).execute();
|
Detonator.getDetonator(player).execute();
|
||||||
break;
|
break;
|
||||||
|
case "clear":
|
||||||
|
case "delete":
|
||||||
|
case "reset":
|
||||||
|
Detonator.getDetonator(player).clearLocs();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
help(player);
|
help(player);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ public class CommandDetonatorTabCompleter implements TabCompleter {
|
|||||||
tabComplete.add("wand");
|
tabComplete.add("wand");
|
||||||
tabComplete.add("reset");
|
tabComplete.add("reset");
|
||||||
tabComplete.add("detonate");
|
tabComplete.add("detonate");
|
||||||
|
tabComplete.add("remove");
|
||||||
|
|
||||||
if (args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
@ -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;
|
||||||
@ -72,36 +74,28 @@ public class Detonator implements Listener {
|
|||||||
|
|
||||||
public static void deleteDetonator(Player player) {
|
public static void deleteDetonator(Player player) {
|
||||||
if (players.containsKey(player))
|
if (players.containsKey(player))
|
||||||
players.remove(player);
|
HandlerList.unregisterAll(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());
|
||||||
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());
|
|
||||||
AutoLoader_12.setRedstone(activation.location, !powered);
|
AutoLoader_12.setRedstone(activation.location, !powered);
|
||||||
}else switch (Core.getVersion()) {
|
}, 12), new VersionedRunnable(() -> {
|
||||||
case 15:
|
boolean powered = AutoLoader_15.getLever(activation.location.getBlock());
|
||||||
AutoLoader_15.setRedstone(activation.location, true);
|
AutoLoader_15.setRedstone(activation.location, !powered);
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () ->
|
}, 15));
|
||||||
AutoLoader_15.setRedstone(activation.location, false), activation.activation);
|
} else {
|
||||||
break;
|
VersionedRunnable.call(new VersionedRunnable(() -> {
|
||||||
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!"));
|
||||||
@ -111,21 +105,23 @@ 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);
|
||||||
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<>(() -> AutoLoader_12.onPlayerInteractLoader(event), 12),
|
||||||
case 15:
|
new VersionedCallable<>(() -> AutoLoader_15.onPlayerInteractLoader(event), 15));
|
||||||
detoloader = AutoLoader_15.onPlayerInteractLoader(event);
|
|
||||||
break;
|
|
||||||
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) {
|
||||||
@ -162,7 +158,8 @@ public class Detonator implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
deleteDetonator(event.getPlayer());
|
if (event.getPlayer().equals(player))
|
||||||
|
deleteDetonator(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Detoloader.DetonatorActivation> getLocations() {
|
Set<Detoloader.DetonatorActivation> getLocations() {
|
||||||
@ -173,10 +170,15 @@ public class Detonator implements Listener {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearLocs() {
|
||||||
|
locs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void print(String message, boolean withSize) {
|
void print(String message, boolean withSize) {
|
||||||
if(withSize)
|
if (withSize) {
|
||||||
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message + " §8" + getLocations().size()));
|
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message + " §8" + getLocations().size()));
|
||||||
else
|
}else {
|
||||||
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren