From a21e652ac9ed90942ab0702b4150660ae727bed5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 6 Aug 2022 17:43:07 +0200 Subject: [PATCH] Add create button Fix rounding error Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 3 ++- BauSystem_Main/src/BauSystem_de.properties | 3 ++- .../features/simulator/SimulatorCommand.java | 9 ++++++-- .../simulator/gui/SimulatorSelectionGUI.java | 21 +++++++++++++++++++ .../gui/components/ChangePosition.java | 3 +-- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 231335bc..3f80ea39 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -512,6 +512,8 @@ SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator SIMULATOR_NO_SIM_IN_HAND = §cNo simulator item selected SIMULATOR_GUI_SELECT_SIM = Simulator selection +SIMULATOR_GUI_CREATE_SIM = §eCreate simulator +SIMULATOR_GUI_CREATE_SIM_GUI = Create simulator SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator already exists SIMULATOR_NAME_INVALID = §cInvalid name SIMULATOR_NOT_EXISTS = §cSimulator does not exist @@ -607,7 +609,6 @@ SIMULATOR_TNT_SPAWN_ACTIVATED_WITH = §7Primed by §8- §e{0} SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR = Comparator SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER = Repeater SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_OBSERVER = Observer -SIMULATOR_TNT_SPAWN_ACTIVATED_UNKNOWN = Unknown SIMULATOR_TNT_SPAWN_INACTIVE = §7> §7{0} SIMULATOR_TNT_SPAWN_ACTIVE = §e> §7{0} SIMULATOR_TNT_SPAWN_MATERIAL = §eMaterial diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 515b9407..a849679b 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -513,6 +513,8 @@ SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator SIMULATOR_NO_SIM_IN_HAND = §cKein Simulator Item gewählt SIMULATOR_GUI_SELECT_SIM = Simulator wählen +SIMULATOR_GUI_CREATE_SIM = §eSimulator erstellen +SIMULATOR_GUI_CREATE_SIM_GUI = Simulator erstellen SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator existiert bereits SIMULATOR_NAME_INVALID = §cUngültiger Name SIMULATOR_NOT_EXISTS = §cSimulator existiert nicht @@ -594,7 +596,6 @@ SIMULATOR_TNT_SPAWN_ACTIVATED_WITH = §7Gezündet durch §8- §e{0} SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR = Comparator SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER = Repeater SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_OBSERVER = Observer -SIMULATOR_TNT_SPAWN_ACTIVATED_UNKNOWN = Unbekannt SIMULATOR_TNT_SPAWN_MATERIAL = §eMaterial SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1 = §7Jetziges Material§8: §e{0} SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2 = §eLink-Click §7Zum ändern 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 481e8407..557af0da 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -58,16 +58,21 @@ public class SimulatorCommand extends SWCommand { @Register(value = "create", description = "SIMULATOR_CREATE_HELP") public void create(@Guard Player p, String name) { + createSimulator(p, name); + } + + public static boolean createSimulator(Player p, String name) { if (SimulatorStorage.getSimulatorNames().contains(name)) { BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p); - return; + return false; } if (!name.matches("[a-zA-Z_]+")) { BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p); - return; + return false; } SimulatorStorage.createNewSimulator(name); BauSystem.MESSAGE.send("SIMULATOR_CREATE", p); + return true; } @Register(value = "delete", description = "SIMULATOR_DELETE_HELP") diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java index ae0e822a..b442088a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java @@ -20,11 +20,14 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.simulator.SimulatorCommand; import de.steamwar.bausystem.features.simulator.SimulatorStorage; import de.steamwar.bausystem.features.simulator.TNTSimulator; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import lombok.experimental.UtilityClass; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -53,6 +56,24 @@ public class SimulatorSelectionGUI { player.closeInventory(); }); + inv.setItem(49, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("SIMULATOR_GUI_CREATE_SIM", player), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_CREATE_SIM_GUI", player), ""); + swAnvilInv.setItem(Material.PAPER); + swAnvilInv.setCallback(s -> { + player.closeInventory(); + if (SimulatorCommand.createSimulator(player, s)) { + TNTSimulator current = SimulatorStorage.getSimulator(hand); + if (current != null) { + current.remove(player); + } + TNTSimulator tntSimulator = SimulatorStorage.getSimulator(s); + SimulatorStorage.setSimulator(player, hand, tntSimulator); + player.getInventory().setItemInMainHand(hand); + } + }); + swAnvilInv.open(); + })); + inv.open(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java index 61b76683..cd40c30a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java @@ -34,7 +34,6 @@ import org.bukkit.util.Vector; import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Function; import java.util.function.Supplier; import java.util.function.UnaryOperator; @@ -136,7 +135,7 @@ public class ChangePosition { } private double clamp(double d) { - return (int) (d * 100) * 0.01; + return (int) (d * 10000) * 0.0001; } private void changePosition(Player player, double defaultValue, Consumer result, Runnable failure) {