From 24131e5bbe765675ddbe230057a91239e54d98b8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 7 Sep 2020 19:18:14 +0200 Subject: [PATCH 1/5] Reworked Detonator --- .../bausystem/world/AutoLoader_12.java | 57 +++-- .../bausystem/world/Detonator_12.java | 75 ------- .../bausystem/world/AutoLoader_15.java | 38 ++-- .../bausystem/world/Detonator_15.java | 135 ------------ .../steamwar/bausystem/world/Detoloader.java | 63 ++++++ .../steamwar/bausystem/world/IDetonator.java | 60 ++++++ .../src/de/steamwar/bausystem/BauSystem.java | 3 +- .../bausystem/commands/CommandDetonator.java | 102 ++------- .../CommandDetonatorTabCompleter.java | 21 +- .../steamwar/bausystem/world/AutoLoader.java | 20 +- .../steamwar/bausystem/world/Detonator.java | 195 ++++++++++-------- 11 files changed, 346 insertions(+), 423 deletions(-) delete mode 100644 BauSystem_12/src/de/steamwar/bausystem/world/Detonator_12.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/world/Detonator_15.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/world/IDetonator.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java index c011c17..ce874dd 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java @@ -19,11 +19,14 @@ package de.steamwar.bausystem.world; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.material.Tripwire; class AutoLoader_12 { @@ -47,11 +50,11 @@ class AutoLoader_12 { block.setData((byte)(block.getData() | 8)); else block.setData((byte)(block.getData() & -9)); - }else if(material == Material.STONE_PLATE || material == Material.WOOD_PLATE){ - if(active) - block.setData((byte)1); + }else if(material == Material.STONE_PLATE || material == Material.WOOD_PLATE) { + if (active) + block.setData((byte) 1); else - block.setData((byte)0); + block.setData((byte) 0); }else{ return false; } @@ -60,32 +63,28 @@ class AutoLoader_12 { } @SuppressWarnings("deprecation") - static void onPlayerInteract(IAutoLoader loader, PlayerInteractEvent event){ - if(event.getAction() == Action.RIGHT_CLICK_BLOCK){ - Block block = event.getClickedBlock(); - Material material = block.getType(); - if(material == Material.LEVER){ - if((block.getData() & 8) == 8) { - new IAutoLoader.RedstoneActivation(loader, block.getLocation(), loader.getLastActivation(), false); - loader.print("§eHebel zurückgesetzt", true); - }else{ - new IAutoLoader.RedstoneActivation(loader, block.getLocation(), 1, true); - loader.print("§eHebel betätigt", true); - } - }else if(material == Material.STONE_BUTTON){ - new IAutoLoader.TemporaryActivation(loader, block.getLocation(), 20); - loader.print("§eKnopf betätigt", true); - }else if(material == Material.WOOD_BUTTON){ - new IAutoLoader.TemporaryActivation(loader, block.getLocation(), 30); - loader.print("§eKnopf betätigt", true); - } - }else if(event.getAction() == Action.PHYSICAL){ - Block block = event.getClickedBlock(); - Material material = block.getType(); - if(material == Material.STONE_PLATE || material == Material.WOOD_PLATE){ - new IAutoLoader.TemporaryActivation(loader, block.getLocation(), 20); - loader.print("§eDruckplatte betätigt", true); + static Detoloader onPlayerInteractLoader(PlayerInteractEvent event){ + Block block = event.getClickedBlock(); + Material material = block.getType(); + if(material == Material.LEVER){ + if((block.getData() & 8) == 8) { + return new Detoloader("Hebel", 0).setActiv(false); + }else{ + return new Detoloader("Hebel", 0).setActiv(true); } + }else if(material == Material.STONE_BUTTON){ + return new Detoloader("Knopf", 20); + }else if(material == Material.WOOD_BUTTON){ + return new Detoloader("Knopf", 30); + }else if (material == Material.NOTE_BLOCK) { + return new Detoloader("Noteblock", 1); + }else if(material == Material.STONE_PLATE || material == Material.WOOD_PLATE){ + return new Detoloader("Druckplatte", 20); } + return new Detoloader("§eUnbekannter Block betätigt (nicht aufgenommen)", 0).setAddBack(false); + } + + static boolean getLever(Block block) { + return (block.getData() & 8) == 8; } } diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/Detonator_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/Detonator_12.java deleted file mode 100644 index 0d5bd29..0000000 --- a/BauSystem_12/src/de/steamwar/bausystem/world/Detonator_12.java +++ /dev/null @@ -1,75 +0,0 @@ -package de.steamwar.bausystem.world; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.block.NoteBlock; -import org.bukkit.craftbukkit.v1_12_R1.block.CraftNoteBlock; -import org.bukkit.material.*; -import org.bukkit.plugin.Plugin; - -public class Detonator_12 { - - public static void handleSwitch(Location location) { - Block block = location.getBlock(); - switch (block.getType()) { - case WOOD_BUTTON: - handleButton(block, 30); - break; - case STONE_BUTTON: - handleButton(block, 20); - break; - case LEVER: - handleLever(block); - break; - case NOTE_BLOCK: - handleNoteBlock(block); - break; - case TRIPWIRE: - handleTripWire(block); - break; - } - } - - private static void handleButton(Block block, int delay) { - Button btnpow = new Button(block.getType(), block.getData()); - btnpow.setPowered(true); - block.setData(btnpow.getData()); - updateBlock(block); - Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { - btnpow.setPowered(false); - block.setData(btnpow.getData()); - updateBlock(block); - }, delay); - } - - private static void handleNoteBlock(Block block) { - NoteBlock noteBlock = new CraftNoteBlock(block); - if(!noteBlock.getNote().isSharped()) noteBlock.setNote(noteBlock.getNote().sharped()); - else noteBlock.setNote(noteBlock.getNote().flattened()); - block.setData(noteBlock.getRawData()); - updateBlock(block); - } - - private static void handleLever(Block block) { - Lever lever = new Lever(block.getType(), block.getData()); - lever.setPowered(!lever.isPowered()); - block.setData(lever.getData()); - updateBlock(block); - } - - private static void handleTripWire(Block block) { - Tripwire tripwire = new Tripwire(block.getType().getId(), block.getData()); - tripwire.setActivated(!tripwire.isActivated()); - block.setData(tripwire.getData()); - updateBlock(block); - } - - static void updateBlock(Block block) { - block.getState().update(true); - } - - private static Plugin getPlugin() { - return Bukkit.getPluginManager().getPlugin("BauSystem"); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java index c361a75..11ff749 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java @@ -29,6 +29,9 @@ import org.bukkit.block.data.type.Switch; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import javax.annotation.Detainted; +import javax.annotation.Nullable; + class AutoLoader_15 { private AutoLoader_15() { @@ -64,10 +67,12 @@ class AutoLoader_15 { relative = block.getRelative(BlockFace.UP); break; default: - relative = block.getRelative(swtch.getFacing()); + relative = block.getRelative(swtch.getFacing().getOppositeFace()); break; } updateBlock(relative); + }else if(block.getType() == Material.TRIPWIRE) { + updateBlock(block); } return true; } @@ -78,37 +83,38 @@ class AutoLoader_15 { block.setBlockData(data, true); } - static void onPlayerInteract(IAutoLoader loader, PlayerInteractEvent event) { - if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) - return; + static Detoloader onPlayerInteractLoader(PlayerInteractEvent event) { Block block = event.getClickedBlock(); assert block != null; BlockData data = block.getBlockData(); if (!(data instanceof Powerable)) - return; + return new Detoloader("§eUnbekannter Block betätigt (nicht aufgenommen)", -1).setAddBack(false); Powerable powerable = (Powerable) data; Material material = block.getType(); if (material == Material.LEVER) { if (powerable.isPowered()) { - new IAutoLoader.RedstoneActivation(loader, block.getLocation(), loader.getLastActivation(), false); - loader.print("§eHebel zurückgesetzt", true); + return new Detoloader("Hebel", 0).setActiv(false); } else { - new IAutoLoader.RedstoneActivation(loader, block.getLocation(), 1, true); - loader.print("§eHebel betätigt", true); + return new Detoloader("Hebel", 0).setActiv(true); } } else if (material == Material.STONE_BUTTON) { - new IAutoLoader.TemporaryActivation(loader, block.getLocation(), 20); - loader.print("§eKnopf betätigt", true); + return new Detoloader("Knopf", 20); } else if (material.name().contains("PRESSURE_PLATE")){ - new IAutoLoader.TemporaryActivation(loader, block.getLocation(), 20); - loader.print("§eDruckplatte betätigt", true); + return new Detoloader("Druckplatte", 20); } else if (material.name().contains("BUTTON")) { - new IAutoLoader.TemporaryActivation(loader, block.getLocation(), 30); - loader.print("§eKnopf betätigt", true); + return new Detoloader("Knopf", 30); + }else if (material == Material.NOTE_BLOCK) { + return new Detoloader("Noteblock", 1); + }else if (material.name().equals("TRIPWIRE")) { + return new Detoloader("Tripwire", 20); } else { - loader.print("§eUnbekannter Block betätigt (nicht aufgenommen)", false); + return new Detoloader("§eUnbekannter Block betätigt", 0).setAddBack(false); } } + + static boolean getLever(Block block) { + return ((Powerable)block.getBlockData()).isPowered(); + } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/Detonator_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/Detonator_15.java deleted file mode 100644 index 8a01274..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Detonator_15.java +++ /dev/null @@ -1,135 +0,0 @@ -package de.steamwar.bausystem.world; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -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.NoteBlock; -import org.bukkit.block.data.type.Switch; -import org.bukkit.block.data.type.Tripwire; -import org.bukkit.plugin.Plugin; - -public class Detonator_15 { - - public static void handleSwitch(Location location) { - Block block = location.getBlock(); - switch (block.getType()) { - case OAK_BUTTON: - case BIRCH_BUTTON: - case ACACIA_BUTTON: - case DARK_OAK_BUTTON: - case JUNGLE_BUTTON: - case SPRUCE_BUTTON: - case LEGACY_WOOD_BUTTON: - handleButton(block, 30); - break; - case STONE_BUTTON: - case LEGACY_STONE_BUTTON: - handleButton(block, 20); - break; - case NOTE_BLOCK: - case LEGACY_NOTE_BLOCK: - handleNoteBlock(block); - break; - case TRIPWIRE: - handleTripWire(block); - break; - case ACACIA_PRESSURE_PLATE: - case BIRCH_PRESSURE_PLATE: - case DARK_OAK_PRESSURE_PLATE: - case HEAVY_WEIGHTED_PRESSURE_PLATE: - case JUNGLE_PRESSURE_PLATE: - case LIGHT_WEIGHTED_PRESSURE_PLATE: - case OAK_PRESSURE_PLATE: - case SPRUCE_PRESSURE_PLATE: - case STONE_PRESSURE_PLATE: - handlePressurePlate(block); - break; - default: - if(block.getBlockData() instanceof Openable) { - Openable openable = (Openable) block.getBlockData(); - openable.setOpen(!openable.isOpen()); - block.setBlockData(openable); - } else if(block.getBlockData() instanceof Powerable) { - Powerable powerable = (Powerable) block.getBlockData(); - powerable.setPowered(!powerable.isPowered()); - block.setBlockData(powerable); - updateBlockface(block); - } - } - } - - private static void handleButton(Block block, int delay) { - Powerable btnpow = (Powerable) block.getBlockData(); - btnpow.setPowered(true); - block.setBlockData(btnpow); - updateBlockface(block); - Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { - btnpow.setPowered(false); - block.setBlockData(btnpow); - updateBlockface(block); - }, delay); - } - - private static void handleNoteBlock(Block block) { - NoteBlock noteBlock = (NoteBlock) block.getBlockData(); - if(!noteBlock.getNote().isSharped()) noteBlock.setNote(noteBlock.getNote().sharped()); - else noteBlock.setNote(noteBlock.getNote().flattened()); - block.setBlockData(noteBlock); - } - - private static void handleTripWire(Block block) { - Tripwire tripwire = (Tripwire) block.getBlockData(); - if(tripwire.isAttached()) { - tripwire.setPowered(!tripwire.isPowered()); - block.setBlockData(tripwire); - updateBlock(block); - } else { - tripwire.setPowered(!tripwire.isPowered()); - block.setBlockData(tripwire); - } - } - - private static void handlePressurePlate(Block block) { - Powerable pressureSensor = (Powerable) block.getBlockData(); - pressureSensor.setPowered(true); - block.setBlockData(pressureSensor); - updateBlock(block.getRelative(BlockFace.DOWN)); - Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { - pressureSensor.setPowered(false); - block.setBlockData(pressureSensor); - updateBlock(block.getRelative(BlockFace.DOWN)); - }, 20); - } - - static void updateBlock(Block block) { - BlockData data = block.getBlockData(); - block.setType(Material.BARRIER, true); - block.setBlockData(data, true); - } - - static void updateBlockface(Block block) { - Block relativebtn; - if (!(block.getBlockData() instanceof Switch)) return; - switch (((Switch) block.getBlockData()).getFace()) { - case FLOOR: - relativebtn = block.getRelative(BlockFace.DOWN); - break; - case CEILING: - relativebtn = block.getRelative(BlockFace.UP); - break; - default: - relativebtn = block.getRelative(((Switch) block.getBlockData()).getFacing()); - break; - } - updateBlock(relativebtn); - } - - private static Plugin getPlugin() { - return Bukkit.getPluginManager().getPlugin("BauSystem"); - } -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java b/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java new file mode 100644 index 0000000..5f588e0 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java @@ -0,0 +1,63 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.world; + +public class Detoloader { + + String message; + int activation; + boolean activ, addBack = true, useActive = false; + + public Detoloader(String message, int activation) { + this.message = message; + this.activation = activation; + } + + public String getBlock() { + return message; + } + + public void setBlock(String message) { + this.message = message; + } + + public int getActivation() { + return activation; + } + + public boolean isActiv() { + return activ; + } + + public Detoloader setActiv(boolean activ) { + useActive = true; + this.activ = activ; + return this; + } + + public boolean isAddBack() { + return addBack; + } + + public Detoloader setAddBack(boolean addBack) { + this.addBack = addBack; + return this; + } +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/world/IDetonator.java b/BauSystem_API/src/de/steamwar/bausystem/world/IDetonator.java new file mode 100644 index 0000000..138e581 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/world/IDetonator.java @@ -0,0 +1,60 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.world; + +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.Set; + +abstract class IDetonator { + + + abstract Set getLocations(); + abstract boolean setRedstone(Location location, boolean active); + abstract Player getPlayer(); + abstract void execute(); + + + + void print(String message, boolean withSize){ + if(withSize) + getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message + " §8" + getLocations().size())); + else + getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); + } + + static class DetonatorActivation { + + int activation = -1; + Location location; + + public DetonatorActivation(Location location) { + this.location = location; + } + + public DetonatorActivation(int activation, Location location) { + this.activation = activation; + this.location = location; + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index c54c742..4291ad0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -121,7 +121,6 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); Bukkit.getPluginManager().registerEvents(new TraceListener(), this); - Bukkit.getPluginManager().registerEvents(new Detonator(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); new AFKStopper(); TNTTracer.init(); @@ -161,6 +160,8 @@ public class BauSystem extends JavaPlugin implements Listener { if (Core.getVersion() == 15) Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false); + if (p.getInventory().contains(Detonator.WAND)) + Detonator.getDetonator(p); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 749ef9c..181b946 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; @@ -21,10 +40,6 @@ 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 add [X] [Y] [Z] §8- §7Fügt den Block an der Coordinate hinzu"); - player.sendMessage("§8/§edetonator list §8- §7Zeigt dir alle Punkte an"); - player.sendMessage("§8/§edetonator tp [Punkt] §8- §7Teleportiert dich zu dem Punkt"); - player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); } private boolean permissionCheck(Player player) { @@ -54,72 +69,17 @@ public class CommandDetonator implements CommandExecutor { case "item": player.getInventory().setItemInMainHand(Detonator.WAND); player.updateInventory(); + Detonator.getDetonator(player); break; case "delete": case "reset": case "remove": - Detonator.INSTANCE.deleteLocations(player); + Detonator.deleteDetonator(player); break; case "detonate": case "click": case "use": - Detonator.INSTANCE.execute(player); - break; - case "add": - case "location": - case "loc": - if (args.length >= 4) { - try { - int x = Integer.parseInt(args[1]); - int y = Integer.parseInt(args[2]); - int z = Integer.parseInt(args[3]); - Detonator.INSTANCE.addLocation(player, new Location(player.getWorld(), x, y, z), true); - }catch (NumberFormatException e){ - player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine valide Coordinate an!"); - } - }else { - player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine valide Coordinate an!"); - } - break; - case "list": - case "show": - if(!Detonator.INSTANCE.containsPlayer(player) || - Detonator.INSTANCE.getLocations(player).isEmpty()) { - player.sendMessage(BauSystem.PREFIX + "§cDu hast keine Punkte!"); - }else { - player.sendMessage(BauSystem.PREFIX + "§7Deine Punkte:"); - int i = 0; - for (Detonator.Loc loc: Detonator.INSTANCE.getLocations(player)) { - i++; - sendTxtCmd(player, ChatMessageType.SYSTEM, newTxtCmd("§ePunkt " + i + "§8: §7[" + loc.getCords()[0]+ ", " + loc.getCords()[1] + - ", " + loc.getCords()[2] + "]", "/detonator tp " + i)); - } - } - break; - case "tp": - case "teleport": - if(!Detonator.INSTANCE.containsPlayer(player) || - Detonator.INSTANCE.getLocations(player).isEmpty()) { - player.sendMessage(BauSystem.PREFIX + "§cDu hast keine Punkte!"); - return true; - } - if(args.length <= 1) { - player.sendMessage(BauSystem.PREFIX + "§cNicht genug Argumente!"); - return true; - } - - try { - int i = Integer.parseInt(args[1]); - if(Detonator.INSTANCE.getLocations(player).size() <= i || i > 0) { - player.teleport(player.getLocation().zero().add(new ArrayList<>(Detonator.INSTANCE.getLocations(player)).get(i-1).getLocation() - .add(0.5, 0, 0.5))); - TextComponent.fromLegacyText("§aTeleportiert zu Punkt: " + args[1]); - }else { - player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine valide Punkt ein!"); - } - }catch (NumberFormatException e) { - player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine valide Zahl ein!"); - } + Detonator.getDetonator(player).execute(); break; default: help(player); @@ -127,22 +87,4 @@ public class CommandDetonator implements CommandExecutor { return true; } - - public static TextComponent newTxtCmd(String txt, String cmd) { - TextComponent tc = new TextComponent(); - tc.setText(txt); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, cmd)); - return tc; - } - - public static void sendTxtCmd(Player p, ChatMessageType chatMessageType ,TextComponent... tcs) { - TextComponent[] var5 = tcs; - int var4 = tcs.length; - - for(int var3 = 0; var3 < var4; ++var3) { - TextComponent textComponent = var5[var3]; - p.spigot().sendMessage(chatMessageType, textComponent); - } - - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java index afddb42..fb57e72 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.commands; import org.bukkit.command.Command; @@ -20,8 +39,6 @@ public class CommandDetonatorTabCompleter implements TabCompleter { List tabComplete = new ArrayList<>(); tabComplete.add("wand"); tabComplete.add("reset"); - tabComplete.add("delete"); - tabComplete.add("add"); tabComplete.add("list"); tabComplete.add("tp"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java index d484af5..fe8787a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java @@ -28,6 +28,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -155,16 +156,31 @@ public class AutoLoader extends IAutoLoader implements Listener { //BlockRedstoneEvent? @EventHandler public void onPlayerInteract(PlayerInteractEvent event){ + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) + return; + if(!setup || !event.getPlayer().equals(player)) return; + Detoloader detoloader = null; switch(Core.getVersion()){ case 15: - AutoLoader_15.onPlayerInteract(this, event); + detoloader = AutoLoader_15.onPlayerInteractLoader(event); break; default: - AutoLoader_12.onPlayerInteract(this, event); + detoloader = AutoLoader_12.onPlayerInteractLoader(event); + } + if(detoloader == null) return; + if(detoloader.useActive) + new IAutoLoader.RedstoneActivation(this, event.getClickedBlock().getLocation() + , detoloader.getActivation() == 0 ? getLastActivation() : detoloader.getActivation() + , detoloader.isActiv()); + else + new IAutoLoader.TemporaryActivation(this, event.getClickedBlock().getLocation() + , detoloader.getActivation()); + print(detoloader.addBack ? "§e" + detoloader.getBlock() + " betätigt" : + detoloader.getBlock(), detoloader.addBack); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 5f410a1..a17b174 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -1,5 +1,25 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.world; +import de.steamwar.bausystem.BauSystem; import de.steamwar.core.Core; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -18,15 +38,16 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.*; import java.util.stream.Collectors; -public class Detonator implements Listener { - - private final Map> locs; +public class Detonator extends IDetonator implements Listener { - public static Detonator INSTANCE; - public static ItemStack WAND; + public static final ItemStack WAND; + private static final Map players = new HashMap<>(); - public Detonator() { - locs = new HashMap<>(); + private final Set locs = new HashSet<>(); + private final Player player; + + + static { WAND = new ItemStack(Material.TRIPWIRE_HOOK, 1); ItemMeta im = WAND.getItemMeta(); @@ -38,76 +59,98 @@ public class Detonator implements Listener { im.setLore(lorelist); WAND.setItemMeta(im); - INSTANCE = this; } - public void addLocation(Player player, Location location, boolean shift) { - if(!shift) locs.get(player).clear(); - locs.get(player).add(new Loc(location.getBlockX(), - location.getBlockY(), - location.getBlockZ())); + public static Detonator getDetonator(Player player){ + if(!players.containsKey(player)) + return new Detonator(player); + return players.get(player); } - public void deleteLocations(Player player) { - if(locs.containsKey(player)) locs.remove(player); + public Detonator(Player player) { + this.player = player; + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + players.put(player, this); } - public void deleteLocation(Player player, Location location) { - if(locs.get(player).stream().filter(loc -> loc.equals(Loc.getFromLocation(location))).count() >= 1) - locs.get(player).remove(locs.get(player).stream().filter(loc -> Loc.getFromLocation(location) - .equals(loc)).limit(1).collect(Collectors.toList()).get(0)); + public static void deleteDetonator(Player player) { + players.remove(player); } - public Set getLocations(Player player) { - return locs.get(player); - } + @Override + public void execute() { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§a" + locs.size() + " Punkt(e) ausgelöst!")); + for (DetonatorActivation activation: getLocations()) { - public boolean containsPlayer(Player player) { - return locs.containsKey(player); - } - - public void execute(Player player) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§a" + locs.get(player).size() + " Punkt(e) ausgelöst!")); - for (Loc loc: locs.get(player)) { - switch(Core.getVersion()){ + Boolean powered; + if(activation.activation == -1) switch (Core.getVersion()) { case 15: - Detonator_15.handleSwitch(loc.getLocation()); + powered = AutoLoader_15.getLever(activation.location.getBlock()); + AutoLoader_15.setRedstone(activation.location, !powered); break; default: - Detonator_12.handleSwitch(loc.getLocation()); + 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: + AutoLoader_12.setRedstone(activation.location, true); + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> + AutoLoader_12.setRedstone(activation.location, false), activation.activation); } } } @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if(!event.getPlayer().equals(player)) + return; if (event.getItem() == null) return; if (event.getItem().isSimilar(WAND)) { event.setCancelled(true); - if(!locs.containsKey(event.getPlayer())) locs.put(event.getPlayer(), new HashSet<>()); switch (event.getAction()) { case LEFT_CLICK_BLOCK: - Location location = event.getClickedBlock().getLocation(); - if (event.getPlayer().isSneaking()){ - if(locs.get(event.getPlayer()).stream().filter(loc -> loc.equals(Loc.getFromLocation(location))) - .count() >= 1) { - deleteLocation(event.getPlayer(), location); - event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent - .fromLegacyText("§cPunkt entfernt!")); - }else { - addLocation(event.getPlayer(), location, true); - event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent - .fromLegacyText("§aPunkt hinzugefügt!")); - } - } else { - addLocation(event.getPlayer(), location, false); - event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent - .fromLegacyText("§aPunkt gesetzt!")); + Detoloader detoloader = null; + switch(Core.getVersion()){ + case 15: + detoloader = AutoLoader_15.onPlayerInteractLoader(event); + break; + default: + detoloader = AutoLoader_12.onPlayerInteractLoader(event); + } - break; + if(detoloader == null) return; + + if(event.getPlayer().isSneaking()) { + if(locs.stream().filter(detonatorActivation -> detonatorActivation.location.equals(event.getClickedBlock().getLocation())).collect(Collectors.toList()).size() == 1) { + locs.forEach(detonatorActivation -> { + if(detonatorActivation.location.equals(event.getClickedBlock().getLocation())) locs.remove(detonatorActivation); + }); + }else { + if(detoloader.getActivation() == 0) { + locs.add(new DetonatorActivation(event.getClickedBlock().getLocation())); + }else { + locs.add(new DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); + } + } + }else { + locs.clear(); + if(detoloader.getActivation() == 0) { + locs.add(new DetonatorActivation(event.getClickedBlock().getLocation())); + }else { + locs.add(new DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); + } + } + print(detoloader.addBack ? "§e" + detoloader.getBlock() + " hinzugefügt" : + detoloader.getBlock(), detoloader.addBack); + break; case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: - execute(event.getPlayer()); + execute(); break; } } @@ -115,40 +158,26 @@ public class Detonator implements Listener { @EventHandler(ignoreCancelled = true) public void onPlayerQuit(PlayerQuitEvent event) { - if(locs.containsKey(event.getPlayer())) { - locs.remove(event.getPlayer()); + players.remove(event.getPlayer()); + } + + @Override + Set getLocations() { + return locs; + } + + @Override + boolean setRedstone(Location location, boolean active) { + switch(Core.getVersion()){ + case 15: + return AutoLoader_15.setRedstone(location, active); + default: + return AutoLoader_12.setRedstone(location, active); } } - public static class Loc { - - private final int x; - private final int y; - private final int z; - - public Loc(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public int[] getCords() { - return new int[] {x, y, z}; - } - - public Location getLocation() { - return new Location(Bukkit.getWorlds().get(0), x, y, z); - } - - public static Loc getFromLocation(Location location) { - return new Loc(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - } - - @Override - public boolean equals(Object o) { - if(!(o instanceof Loc)) return false; - Loc loc = (Loc) o; - return loc.getCords()[0] == x && loc.getCords()[1] == y && loc.getCords()[2] == z; - } + @Override + Player getPlayer() { + return player; } } -- 2.39.5 From 5ccf3ddf3c5da748785b5890e6aa7b4e24f4dc23 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 7 Sep 2020 21:35:08 +0200 Subject: [PATCH 2/5] Removed Unused Stuff --- .../bausystem/world/AutoLoader_12.java | 4 +- .../bausystem/world/AutoLoader_15.java | 4 +- .../steamwar/bausystem/world/Detoloader.java | 27 +++++++-- .../steamwar/bausystem/world/IDetonator.java | 60 ------------------- .../CommandDetonatorTabCompleter.java | 3 +- .../steamwar/bausystem/world/Detonator.java | 27 +++++---- 6 files changed, 42 insertions(+), 83 deletions(-) delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/world/IDetonator.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java index ce874dd..4ab81c5 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java @@ -68,9 +68,9 @@ class AutoLoader_12 { Material material = block.getType(); if(material == Material.LEVER){ if((block.getData() & 8) == 8) { - return new Detoloader("Hebel", 0).setActiv(false); + return new Detoloader("Hebel", 0).setActive(false); }else{ - return new Detoloader("Hebel", 0).setActiv(true); + return new Detoloader("Hebel", 0).setActive(true); } }else if(material == Material.STONE_BUTTON){ return new Detoloader("Knopf", 20); diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java index 11ff749..38d1ca2 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java @@ -95,9 +95,9 @@ class AutoLoader_15 { if (material == Material.LEVER) { if (powerable.isPowered()) { - return new Detoloader("Hebel", 0).setActiv(false); + return new Detoloader("Hebel", 0).setActive(false); } else { - return new Detoloader("Hebel", 0).setActiv(true); + return new Detoloader("Hebel", 0).setActive(true); } } else if (material == Material.STONE_BUTTON) { return new Detoloader("Knopf", 20); diff --git a/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java b/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java index 5f588e0..9e16e10 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java +++ b/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java @@ -19,11 +19,13 @@ package de.steamwar.bausystem.world; +import org.bukkit.Location; + public class Detoloader { String message; int activation; - boolean activ, addBack = true, useActive = false; + boolean active, addBack = true, useActive = false; public Detoloader(String message, int activation) { this.message = message; @@ -42,13 +44,13 @@ public class Detoloader { return activation; } - public boolean isActiv() { - return activ; + public boolean isActive() { + return active; } - public Detoloader setActiv(boolean activ) { + public Detoloader setActive(boolean active) { useActive = true; - this.activ = activ; + this.active = active; return this; } @@ -60,4 +62,19 @@ public class Detoloader { this.addBack = addBack; return this; } + + static class DetonatorActivation { + + int activation = -1; + Location location; + + public DetonatorActivation(Location location) { + this.location = location; + } + + public DetonatorActivation(int activation, Location location) { + this.activation = activation; + this.location = location; + } + } } diff --git a/BauSystem_API/src/de/steamwar/bausystem/world/IDetonator.java b/BauSystem_API/src/de/steamwar/bausystem/world/IDetonator.java deleted file mode 100644 index 138e581..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/world/IDetonator.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.world; - -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import java.util.Set; - -abstract class IDetonator { - - - abstract Set getLocations(); - abstract boolean setRedstone(Location location, boolean active); - abstract Player getPlayer(); - abstract void execute(); - - - - void print(String message, boolean withSize){ - if(withSize) - getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message + " §8" + getLocations().size())); - else - getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); - } - - static class DetonatorActivation { - - int activation = -1; - Location location; - - public DetonatorActivation(Location location) { - this.location = location; - } - - public DetonatorActivation(int activation, Location location) { - this.activation = activation; - this.location = location; - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java index fb57e72..32d98ec 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java @@ -39,8 +39,7 @@ public class CommandDetonatorTabCompleter implements TabCompleter { List tabComplete = new ArrayList<>(); tabComplete.add("wand"); tabComplete.add("reset"); - tabComplete.add("list"); - tabComplete.add("tp"); + tabComplete.add("detonate"); if (args.length >= 2) { return new ArrayList<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index a17b174..86d49b4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -38,12 +38,12 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.*; import java.util.stream.Collectors; -public class Detonator extends IDetonator implements Listener { +public class Detonator implements Listener { public static final ItemStack WAND; private static final Map players = new HashMap<>(); - private final Set locs = new HashSet<>(); + private final Set locs = new HashSet<>(); private final Player player; @@ -77,10 +77,9 @@ public class Detonator extends IDetonator implements Listener { players.remove(player); } - @Override public void execute() { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§a" + locs.size() + " Punkt(e) ausgelöst!")); - for (DetonatorActivation activation: getLocations()) { + for (Detoloader.DetonatorActivation activation: getLocations()) { Boolean powered; if(activation.activation == -1) switch (Core.getVersion()) { @@ -132,17 +131,17 @@ public class Detonator extends IDetonator implements Listener { }); }else { if(detoloader.getActivation() == 0) { - locs.add(new DetonatorActivation(event.getClickedBlock().getLocation())); + locs.add(new Detoloader.DetonatorActivation(event.getClickedBlock().getLocation())); }else { - locs.add(new DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); + locs.add(new Detoloader.DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); } } }else { locs.clear(); if(detoloader.getActivation() == 0) { - locs.add(new DetonatorActivation(event.getClickedBlock().getLocation())); + locs.add(new Detoloader.DetonatorActivation(event.getClickedBlock().getLocation())); }else { - locs.add(new DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); + locs.add(new Detoloader.DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); } } print(detoloader.addBack ? "§e" + detoloader.getBlock() + " hinzugefügt" : @@ -161,12 +160,10 @@ public class Detonator extends IDetonator implements Listener { players.remove(event.getPlayer()); } - @Override - Set getLocations() { + Set getLocations() { return locs; } - @Override boolean setRedstone(Location location, boolean active) { switch(Core.getVersion()){ case 15: @@ -176,8 +173,14 @@ public class Detonator extends IDetonator implements Listener { } } - @Override Player getPlayer() { return player; } + + void print(String message, boolean withSize){ + if(withSize) + getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message + " §8" + getLocations().size())); + else + getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); + } } -- 2.39.5 From c27a5488666ffb8fb9249698529a3b48132a7358 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 9 Sep 2020 22:45:28 +0200 Subject: [PATCH 3/5] Added Function on Tripwire for 1.12 --- .../bausystem/world/AutoLoader_12.java | 25 ++++++++++++++++--- .../bausystem/world/AutoLoader_15.java | 2 +- .../steamwar/bausystem/world/AutoLoader.java | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java index 4ab81c5..13d2137 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java @@ -23,10 +23,13 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.event.block.Action; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.material.Tripwire; + +import java.util.List; +import java.util.stream.Collectors; class AutoLoader_12 { @@ -55,6 +58,20 @@ class AutoLoader_12 { block.setData((byte) 1); else block.setData((byte) 0); + }else if(material == Material.TRIPWIRE) { + if(active) { + ArmorStand armorStand = (ArmorStand) Bukkit.getWorlds().get(0).spawnEntity(location, EntityType.ARMOR_STAND); + armorStand.setVisible(false); + armorStand.setBasePlate(false); + armorStand.addScoreboardTag("detonator-" + location.getBlockX() + location.getBlockY() + location.getBlockZ()); + }else { + List entityList = Bukkit.getWorlds().get(0).getEntitiesByClasses(ArmorStand.class).stream().filter(entity -> + entity.getScoreboardTags().contains("detonator-" + location.getBlockX() + location.getBlockY() + location.getBlockZ())) + .limit(1) + .collect(Collectors.toList()); + if(entityList.isEmpty()) return false; + entityList.get(0).remove(); + } }else{ return false; } @@ -80,6 +97,8 @@ class AutoLoader_12 { return new Detoloader("Noteblock", 1); }else if(material == Material.STONE_PLATE || material == Material.WOOD_PLATE){ return new Detoloader("Druckplatte", 20); + }else if (material == Material.TRIPWIRE) { + return new Detoloader("Tripwire", 10); } return new Detoloader("§eUnbekannter Block betätigt (nicht aufgenommen)", 0).setAddBack(false); } diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java index 38d1ca2..f76b6c4 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java @@ -108,7 +108,7 @@ class AutoLoader_15 { }else if (material == Material.NOTE_BLOCK) { return new Detoloader("Noteblock", 1); }else if (material.name().equals("TRIPWIRE")) { - return new Detoloader("Tripwire", 20); + return new Detoloader("Tripwire", 10); } else { return new Detoloader("§eUnbekannter Block betätigt", 0).setAddBack(false); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java index fe8787a..4ffb48a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java @@ -175,7 +175,7 @@ public class AutoLoader extends IAutoLoader implements Listener { if(detoloader.useActive) new IAutoLoader.RedstoneActivation(this, event.getClickedBlock().getLocation() , detoloader.getActivation() == 0 ? getLastActivation() : detoloader.getActivation() - , detoloader.isActiv()); + , detoloader.isActive()); else new IAutoLoader.TemporaryActivation(this, event.getClickedBlock().getLocation() , detoloader.getActivation()); -- 2.39.5 From 6f8c3961a2afcac78819c81bd12887fecabd1a00 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 11 Sep 2020 21:32:32 +0200 Subject: [PATCH 4/5] Finishing... --- .../bausystem/world/AutoLoader_12.java | 12 +++++----- .../bausystem/world/AutoLoader_15.java | 12 +++++----- .../steamwar/bausystem/world/Detoloader.java | 7 ++++++ .../src/de/steamwar/bausystem/BauSystem.java | 4 ++-- .../steamwar/bausystem/world/Detonator.java | 24 +++++++------------ 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java index 13d2137..72bfcd1 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/AutoLoader_12.java @@ -90,17 +90,17 @@ class AutoLoader_12 { return new Detoloader("Hebel", 0).setActive(true); } }else if(material == Material.STONE_BUTTON){ - return new Detoloader("Knopf", 20); + return new Detoloader("Knopf", Detoloader.STONE_BUTTON); }else if(material == Material.WOOD_BUTTON){ - return new Detoloader("Knopf", 30); + return new Detoloader("Knopf", Detoloader.WOODEN_BUTTON); }else if (material == Material.NOTE_BLOCK) { - return new Detoloader("Noteblock", 1); + return new Detoloader("Noteblock", Detoloader.NOTE_BLOCK); }else if(material == Material.STONE_PLATE || material == Material.WOOD_PLATE){ - return new Detoloader("Druckplatte", 20); + return new Detoloader("Druckplatte", Detoloader.PRESSURE_PLATE); }else if (material == Material.TRIPWIRE) { - return new Detoloader("Tripwire", 10); + return new Detoloader("Tripwire", Detoloader.TRIPWIRE); } - return new Detoloader("§eUnbekannter Block betätigt (nicht aufgenommen)", 0).setAddBack(false); + return new Detoloader("§eUnbekannter Block betätigt (nicht aufgenommen)", -1).setAddBack(false); } static boolean getLever(Block block) { diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java index f76b6c4..a2c9c42 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java @@ -100,17 +100,17 @@ class AutoLoader_15 { return new Detoloader("Hebel", 0).setActive(true); } } else if (material == Material.STONE_BUTTON) { - return new Detoloader("Knopf", 20); + return new Detoloader("Knopf", Detoloader.STONE_BUTTON); } else if (material.name().contains("PRESSURE_PLATE")){ - return new Detoloader("Druckplatte", 20); + return new Detoloader("Druckplatte", Detoloader.PRESSURE_PLATE); } else if (material.name().contains("BUTTON")) { - return new Detoloader("Knopf", 30); + return new Detoloader("Knopf", Detoloader.WOODEN_BUTTON); }else if (material == Material.NOTE_BLOCK) { - return new Detoloader("Noteblock", 1); + return new Detoloader("Noteblock", Detoloader.NOTE_BLOCK); }else if (material.name().equals("TRIPWIRE")) { - return new Detoloader("Tripwire", 10); + return new Detoloader("Tripwire", Detoloader.TRIPWIRE); } else { - return new Detoloader("§eUnbekannter Block betätigt", 0).setAddBack(false); + return new Detoloader("§eUnbekannter Block betätigt (aufgenommen)", 0).setAddBack(false); } } diff --git a/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java b/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java index 9e16e10..4e1401a 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java +++ b/BauSystem_API/src/de/steamwar/bausystem/world/Detoloader.java @@ -77,4 +77,11 @@ public class Detoloader { this.location = location; } } + + //Timings + public static final int STONE_BUTTON = 20; + public static final int WOODEN_BUTTON = 30; + public static final int PRESSURE_PLATE = 20; + public static final int NOTE_BLOCK = 20; + public static final int TRIPWIRE = 10; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 4291ad0..2ccc71e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -36,9 +36,11 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; @@ -160,8 +162,6 @@ public class BauSystem extends JavaPlugin implements Listener { if (Core.getVersion() == 15) Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false); - if (p.getInventory().contains(Detonator.WAND)) - Detonator.getDetonator(p); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 86d49b4..4d2f046 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -24,7 +24,6 @@ import de.steamwar.core.Core; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -52,7 +51,6 @@ public class Detonator implements Listener { ItemMeta im = WAND.getItemMeta(); im.setDisplayName("§6Fernzünder"); - im.addItemFlags(ItemFlag.HIDE_ENCHANTS); List lorelist = Arrays.asList("§eLinks Klick §8- §7Setzte einen Punkt zum Aktivieren", "§eLinks Klick + Shift §8- §7Füge einen Punkt hinzu", "§eRechts Klick §8- §7Löse alle Punkte aus"); @@ -74,7 +72,8 @@ public class Detonator implements Listener { } public static void deleteDetonator(Player player) { - players.remove(player); + if(players.containsKey(player)) + players.remove(player); } public void execute() { @@ -129,12 +128,16 @@ public class Detonator implements Listener { locs.forEach(detonatorActivation -> { if(detonatorActivation.location.equals(event.getClickedBlock().getLocation())) locs.remove(detonatorActivation); }); + print(detoloader.addBack ? "§e" + detoloader.getBlock() + " entfernt" : + detoloader.getBlock(), detoloader.addBack); }else { if(detoloader.getActivation() == 0) { locs.add(new Detoloader.DetonatorActivation(event.getClickedBlock().getLocation())); }else { locs.add(new Detoloader.DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); } + print(detoloader.addBack ? "§e" + detoloader.getBlock() + " hinzugefügt" : + detoloader.getBlock(), detoloader.addBack); } }else { locs.clear(); @@ -143,9 +146,9 @@ public class Detonator implements Listener { }else { locs.add(new Detoloader.DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); } + print(detoloader.addBack ? "§e" + detoloader.getBlock() + " getsetzt" : + detoloader.getBlock(), detoloader.addBack); } - print(detoloader.addBack ? "§e" + detoloader.getBlock() + " hinzugefügt" : - detoloader.getBlock(), detoloader.addBack); break; case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: @@ -157,22 +160,13 @@ public class Detonator implements Listener { @EventHandler(ignoreCancelled = true) public void onPlayerQuit(PlayerQuitEvent event) { - players.remove(event.getPlayer()); + deleteDetonator(event.getPlayer()); } Set getLocations() { return locs; } - boolean setRedstone(Location location, boolean active) { - switch(Core.getVersion()){ - case 15: - return AutoLoader_15.setRedstone(location, active); - default: - return AutoLoader_12.setRedstone(location, active); - } - } - Player getPlayer() { return player; } -- 2.39.5 From c464cd9df0eae4ff46a0fecdb112c81682a797e9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 11 Sep 2020 21:35:05 +0200 Subject: [PATCH 5/5] Removed Unused Imports --- .../src/de/steamwar/bausystem/world/AutoLoader_15.java | 4 ---- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 2 -- .../de/steamwar/bausystem/commands/CommandDetonator.java | 6 ------ .../src/de/steamwar/bausystem/world/Detonator.java | 1 - 4 files changed, 13 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java index a2c9c42..89fc7fa 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/AutoLoader_15.java @@ -26,12 +26,8 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Powerable; import org.bukkit.block.data.type.Switch; -import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import javax.annotation.Detainted; -import javax.annotation.Nullable; - class AutoLoader_15 { private AutoLoader_15() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 2ccc71e..f73a860 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -36,11 +36,9 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 181b946..bd8317e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -23,17 +23,11 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Welt; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.ArrayList; - public class CommandDetonator implements CommandExecutor { private void help(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 4d2f046..1ce5df1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -30,7 +30,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -- 2.39.5