diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/ItemUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/ItemUtils.java new file mode 100644 index 00000000..8a4bceb5 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/ItemUtils.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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.features.simulator.gui; + +import de.steamwar.inventory.SWItem; +import lombok.experimental.UtilityClass; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; + +import java.util.UUID; + +@UtilityClass +public class ItemUtils { + + public static SWItem unique(SWItem swItem) { + ItemMeta itemMeta = swItem.getItemMeta(); + itemMeta.getPersistentDataContainer().set(NamespacedKey.minecraft(UUID.randomUUID().toString()), PersistentDataType.INTEGER, 0); + swItem.setItemMeta(itemMeta); + return swItem; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java index 1426d3fc..26ed07d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java @@ -35,6 +35,7 @@ import de.steamwar.inventory.SWItem; import lombok.experimental.UtilityClass; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.util.Consumer; import org.bukkit.util.Vector; @@ -43,6 +44,8 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; + @UtilityClass public class TNTElementGUI { @@ -227,11 +230,12 @@ public class TNTElementGUI { AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { // Change Count of spawned TNT - inv.setItem(10, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { + inv.setItem(10, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); tntElement.setCount(tntElement.getCount() + ((clickType.isShiftClick()) ? 5 : 1)); tntElement.change(); - })); + }))); SWItem countItem = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, tntElement.getCount()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT_ANVIL_GUI_NAME", player), tntElement.getCount(), c -> { recalculate.set(true); tntElement.setCount(c); @@ -240,18 +244,20 @@ public class TNTElementGUI { }, () -> editProperties(player, tntElement, back))); countItem.getItemStack().setAmount(tntElement.getCount()); inv.setItem(19, countItem); - inv.setItem(28, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { + inv.setItem(28, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); tntElement.setCount(tntElement.getCount() - ((clickType.isShiftClick()) ? 5 : 1)); tntElement.change(); - })); + }))); // Change TickOffset - inv.setItem(11, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { + inv.setItem(11, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); tntElement.setTickOffset(tntElement.getOwnTickOffset() + (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); - })); + }))); SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntElement.getTickOffset()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tntElement.getTickOffset(), tick -> { recalculate.set(true); tntElement.setTickOffset(tick - tntElement.getParentTickOffset()); @@ -260,18 +266,20 @@ public class TNTElementGUI { }, () -> editProperties(player, tntElement, back))); tickItem.getItemStack().setAmount(Math.max(tntElement.getTickOffset(), 1)); inv.setItem(20, tickItem); - inv.setItem(29, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { + inv.setItem(29, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); tntElement.setTickOffset(tntElement.getOwnTickOffset() - (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); - })); + }))); // Change FuseTicks - inv.setItem(12, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { + inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); tntElement.setFuseTicks(tntElement.getFuseTicks() + (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); - })); + }))); SWItem fuseTickItem = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, tntElement.getFuseTicks()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE_ANVIL_GUI_NAME", player), tntElement.getFuseTicks(), tick -> { recalculate.set(true); tntElement.setFuseTicks(tick); @@ -280,11 +288,12 @@ public class TNTElementGUI { }, () -> editProperties(player, tntElement, back))); fuseTickItem.getItemStack().setAmount(Math.max(tntElement.getFuseTicks(), 1)); inv.setItem(21, fuseTickItem); - inv.setItem(30, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { + inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); tntElement.setFuseTicks(tntElement.getFuseTicks() - (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); - })); + }))); // Velocity Settings inv.setItem(24, Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_NAME", player), clickType -> { 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 88476cc4..88b849d6 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 @@ -28,6 +28,7 @@ import de.steamwar.inventory.SWItem; import lombok.experimental.UtilityClass; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.util.Consumer; import org.bukkit.util.Vector; @@ -37,6 +38,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; import java.util.function.UnaryOperator; +import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; + @UtilityClass public class ChangePosition { @@ -56,13 +59,14 @@ public class ChangePosition { List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); // X Position - inv.setItem(10, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + inv.setItem(10, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); simulatorElement.change(); - })); + }))); inv.setItem(19, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, simulatorElement.getPosition().getX()), lore, false, clickType -> { changePosition(player, simulatorElement.getPosition().getX(), x -> { recalculate.set(true); @@ -73,22 +77,24 @@ public class ChangePosition { back.run(); }, back); })); - inv.setItem(28, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + inv.setItem(28, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); simulatorElement.change(); - })); + }))); // Y Position - inv.setItem(11, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + inv.setItem(11, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); simulatorElement.change(); - })); + }))); inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, simulatorElement.getPosition().getY()), lore, false, clickType -> { changePosition(player, simulatorElement.getPosition().getY(), y -> { recalculate.set(true); @@ -99,22 +105,24 @@ public class ChangePosition { back.run(); }, back); })); - inv.setItem(29, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + inv.setItem(29, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); simulatorElement.change(); - })); + }))); // Z Position - inv.setItem(12, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); simulatorElement.change(); - })); + }))); inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, simulatorElement.getPosition().getZ()), lore, false, clickType -> { changePosition(player, simulatorElement.getPosition().getZ(), z -> { recalculate.set(true); @@ -125,13 +133,14 @@ public class ChangePosition { back.run(); }, back); })); - inv.setItem(30, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); simulatorElement.change(); - })); + }))); } private double clamp(double d) {