diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index d5d663b5..ea84bddb 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -504,11 +504,14 @@ UNSIGN_HELP=§8/§eunsign §8- §7Make a signed book writable again SIMULATOR_HELP = §8/§esimulator §8-§7 Gives you the simulator wand SIMULATOR_CREATE_HELP = §8/§esimulator create §8[§7name§8] §8-§7 Create a new simulator SIMULATOR_CHANGE_HELP = §8/§esimulator change §8-§7 Change your simulator wand selection +SIMULATOR_DELETE_HELP = §8/§esimulator delete §8[§7name§8] §8-§7 Deletes the simulator +SIMULATOR_START_HELP = §8/§esimulator start §8[§7name§8] §8-§7 Starts the simulator SIMULATOR_NO_PERMS = §cYou are not allowed to use the simulator here SIMULATOR_NO_SIM_IN_HAND = §cNo simulator item selected SIMULATOR_GUI_SELECT_SIM = Simulator selection SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator already exists +SIMULATOR_NOT_EXISTS = §cSimulator does not exist SIMULATOR_CREATE = §aSimulator created SIMULATOR_EDIT_LOCATION = §7Edit position SIMULATOR_EDIT_PROPERTIES = §7Edit properties @@ -538,6 +541,8 @@ SIMULATOR_POSITION_Y = §7y-Position SIMULATOR_POSITION_Z = §7z-Position SIMULATOR_BACK = §eBack +SIMULATOR_DELETED = §cSimulator deleted + ## GUI SIMULATOR_POSITION_EDIT = §eEdit position SIMULATOR_POSITION_ADD = §eSet position @@ -551,9 +556,13 @@ SIMULATOR_GUI_TNT_SPAWN_LORE_6 = §7y§8: §e{0} SIMULATOR_GUI_TNT_SPAWN_LORE_7 = §7z§8: §e{0} SIMULATOR_GUI_TNT_GROUP_NAME = §eTNT group SIMULATOR_GUI_TNT_GROUP_LORE_1 = §7Element count§8: §e{0} +SIMULATOR_GUI_TNT_GROUP_LORE_2 = §7Tick§8: §e{0} +SIMULATOR_GUI_TNT_GROUP_LORE_3 = §7 +SIMULATOR_GUI_TNT_GROUP_LORE_4 = §7x§8: §e{0} +SIMULATOR_GUI_TNT_GROUP_LORE_5 = §7y§8: §e{0} +SIMULATOR_GUI_TNT_GROUP_LORE_6 = §7z§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Simulator -SIMULATOR_GUI_DELETE = §cDelete TNT SIMULATOR_GUI_START = §eStart SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eMove all diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 111bce3c..9ab90867 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -505,11 +505,14 @@ UNSIGN_HELP=§8/§eunsign §8- §7Mache ein Buch beschreibbar SIMULATOR_HELP = §8/§esimulator §8-§7 Legt dir den Simulatorstab ins Inventar SIMULATOR_CREATE_HELP = §8/§esimulator create §8[§7name§8] §8-§7 Erstelle einen neuen Simulator SIMULATOR_CHANGE_HELP = §8/§esimulator change §8-§7 Wechsel zu einem anderen Simulator +SIMULATOR_DELETE_HELP = §8/§esimulator delete §8[§7name§8] §8-§7 Löscht den Simulator +SIMULATOR_START_HELP = §8/§esimulator start §8[§7name§8] §8-§7 Startet die Simulation SIMULATOR_NO_PERMS = §cDu darfst hier nicht den Simulator nutzen SIMULATOR_NO_SIM_IN_HAND = §cKein Simulator Item gewählt SIMULATOR_GUI_SELECT_SIM = Simulator wählen SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator existiert bereits +SIMULATOR_NOT_EXISTS = §cSimulator existiert nicht SIMULATOR_CREATE = §aSimulator erstellt SIMULATOR_EDIT_LOCATION = §7Editiere Positionen SIMULATOR_EDIT_PROPERTIES = §7Editiere Eigenschaften @@ -539,19 +542,18 @@ SIMULATOR_POSITION_Y = §7y-Position SIMULATOR_POSITION_Z = §7z-Position SIMULATOR_BACK = §eZurück +SIMULATOR_DELETED = §cSimulator gelöscht + ## GUI SIMULATOR_POSITION_EDIT = §ePosition bearbeiten SIMULATOR_POSITION_ADD = §ePosition setzen SIMULATOR_GUI_TNT_SPAWN_NAME = §eTNT SIMULATOR_GUI_TNT_SPAWN_LORE_1 = §7TNT-Anzahl§8: §e{0} -SIMULATOR_GUI_TNT_SPAWN_LORE_2 = §7Tick§8: §e{0} SIMULATOR_GUI_TNT_SPAWN_LORE_3 = §7Lebensdauer§8: §e{0} -SIMULATOR_GUI_TNT_SPAWN_LORE_4 = §7 -SIMULATOR_GUI_TNT_SPAWN_LORE_5 = §7x§8: §e{0} -SIMULATOR_GUI_TNT_SPAWN_LORE_6 = §7y§8: §e{0} -SIMULATOR_GUI_TNT_SPAWN_LORE_7 = §7z§8: §e{0} +SIMULATOR_GUI_TNT_GROUP_NAME = §eTNT Gruppe +SIMULATOR_GUI_TNT_GROUP_LORE_1 = §7Elementanzahl§8: §e{0} +SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Kanonensimulator -SIMULATOR_GUI_DELETE = §cTNT löschen SIMULATOR_GUI_START = §eStarten SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eAlle Verschieben diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index 530fd577..c82c3273 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -26,13 +26,13 @@ import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.utils.ItemUtils; -import de.steamwar.command.GuardCheckType; -import de.steamwar.command.GuardChecker; -import de.steamwar.command.GuardResult; -import de.steamwar.command.SWCommand; +import de.steamwar.command.*; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.Collection; + @Linked(LinkageType.COMMAND) public class SimulatorCommand extends SWCommand { @@ -66,6 +66,45 @@ public class SimulatorCommand extends SWCommand { BauSystem.MESSAGE.send("SIMULATOR_CREATE", p); } + @Register(value = "delete", description = "SIMULATOR_DELETE_HELP") + public void delete(@Guard Player p, @Mapper("simulators") String name) { + if (!SimulatorStorage.getSimulatorNames().contains(name)) { + BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p); + return; + } + SimulatorStorage.delete(name); + BauSystem.MESSAGE.send("SIMULATOR_DELETED", p); + } + + @Register(value = "start", description = "SIMULATOR_START_HELP") + public void start(@Guard Player p, @Mapper("simulators") String name) { + TNTSimulator tntSimulator = SimulatorStorage.getSimulator(name); + if (tntSimulator == null) { + BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p); + return; + } + // SimulatorStorage.start(name); + } + + @Mapper("simulators") + public TypeMapper allSimulators() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (SimulatorStorage.getSimulatorNames().contains(s)) { + return s; + } else { + return null; + } + } + + @Override + public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + return SimulatorStorage.getSimulatorNames(); + } + }; + } + @ClassGuard(value = Player.class, local = true) public GuardChecker guardChecker() { return (commandSender, guardCheckType, strings, s) -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java index 2580fc15..05e73e94 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -98,6 +98,10 @@ public class SimulatorStorage implements Enable, Disable { } } + public static void delete(String name) { + tntSimulators.remove(name); + } + public static void removeSimulator(ItemStack itemStack) { if (!ItemUtils.isItem(itemStack, "simulator")) { return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index 84d6cb6d..e084493a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -32,6 +32,8 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerMoveEvent; @@ -47,7 +49,6 @@ import java.util.function.Function; public class TNTSimulatorListener implements Listener { private boolean permissionCheck(Player player) { - if (true) return true; if (!Permission.hasPermission(player, Permission.WORLD)) { BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player); return false; @@ -103,6 +104,11 @@ public class TNTSimulatorListener implements Listener { simulatorShowHide(e.getPlayer(), i -> i.getItem(e.getPreviousSlot()), i -> i.getItem(e.getNewSlot()), e.getPlayer().getLocation()); } + @EventHandler + public void onPlayerDropItem(PlayerDropItemEvent e) { + simulatorShowHide(e.getPlayer(), i -> e.getItemDrop().getItemStack(), i -> null, e.getPlayer().getLocation()); + } + private void simulatorShowHide(Player player, Function oldItemFunction, Function newItemFunction, Location location) { TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory())); SimulatorCursor.hide(player, oldSimulator); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java index d390359f..2061a34c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java @@ -194,8 +194,14 @@ public class TNTElement implements SimulatorElement { } public void setTickOffset(int tickOffset) { - if (tickOffset < 0) tickOffset = 0; - if (tickOffset > 400) tickOffset = 400; + if (getTickOffset() - this.tickOffset + tickOffset < 0) { + this.tickOffset = -this.getParentTickOffset(); + return; + } + if (getTickOffset() - this.tickOffset + tickOffset > 400) { + this.tickOffset = 400 - this.getParentTickOffset(); + return; + } this.tickOffset = tickOffset; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java index 38a990e8..59cfa9d3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java @@ -123,6 +123,11 @@ public class TNTGroup implements SimulatorElement { public SWItem menu(Player p) { List lore = new ArrayList<>(); lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_1", p, elements.size())); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_2", p, tickOffset)); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_3", p)); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_4", p, position.getX())); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_5", p, position.getY())); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_6", p, position.getZ())); if (disabled) { lore.add(""); lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); @@ -141,6 +146,14 @@ public class TNTGroup implements SimulatorElement { public void setTickOffset(int tickOffset) { if (tickOffset < 0) tickOffset = 0; if (tickOffset > 400) tickOffset = 400; + for (TNTElement tntElement : elements) { + if (tntElement.getTickOffset() - this.tickOffset + tickOffset < 0) { + tickOffset = Math.max(tickOffset, -tntElement.getOwnTickOffset()); + } + if (tntElement.getTickOffset() - this.tickOffset + tickOffset > 400) { + tickOffset = Math.min(tickOffset, 400 - tntElement.getOwnTickOffset()); + } + } this.tickOffset = tickOffset; }