diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/simulator/SimulatorPreview15.java b/BauSystem_15/src/de/steamwar/bausystem/features/simulator/SimulatorPreview15.java new file mode 100644 index 00000000..200f84ac --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/features/simulator/SimulatorPreview15.java @@ -0,0 +1,30 @@ +/* + * 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; + +import de.steamwar.bausystem.features.tracer.show.Record; + +public class SimulatorPreview15 implements SimulatorPreview { + + @Override + public Record simulate(TNTSimulator tntSimulator) { + return new Record(false); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java index daf831bc..79732249 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; +import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.ShowMode; import lombok.experimental.UtilityClass; import org.bukkit.entity.Player; @@ -30,42 +31,64 @@ import org.bukkit.entity.Player; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Set; @UtilityClass public class SimulatorPreviewStorage { - private Map previews = new HashMap<>(); - private Map> showModes = new HashMap<>(); + private Map>> previews = new HashMap<>(); + private Map>> showModes = new HashMap<>(); public void show(Player player, TNTSimulator tntSimulator) { - hide(player); + if (showModes.containsKey(player)) { + Pair> pair = showModes.get(player); + if (pair.getKey() != tntSimulator) { + pair.getValue().hide(); + Pair> setPair = previews.get(pair.getKey()); + setPair.getValue().remove(player); + if (setPair.getValue().isEmpty()) { + previews.remove(pair.getKey()); + } + } else { + return; + } + } + + Pair> pair = previews.computeIfAbsent(tntSimulator, k -> new Pair<>(SimulatorPreview.impl.simulate(k), new HashSet<>())); + pair.getValue().add(player); - Record record = previews.computeIfAbsent(tntSimulator, SimulatorPreview.impl::simulate); ShowModeParameter showModeParameter = new ShowModeParameter(); showModeParameter.setInterpolate_XZ(true); showModeParameter.setInterpolate_Y(true); TraceEntityShowMode showMode = new TraceEntityShowMode(player, showModeParameter); - record.showAll(showMode); - showModes.put(player, showMode); + pair.getKey().showAll(showMode); + showModes.put(player, new Pair<>(tntSimulator, showMode)); } public void hide(Player player) { if (showModes.containsKey(player)) { - showModes.get(player).hide(); + Pair> pair = showModes.get(player); + pair.getValue().hide(); + Pair> setPair = previews.get(pair.getKey()); + setPair.getValue().remove(player); + if (setPair.getValue().isEmpty()) { + previews.remove(pair.getKey()); + } showModes.remove(player); } } public void recalculate(TNTSimulator tntSimulator) { - previews.remove(tntSimulator); - new HashSet<>(showModes.keySet()).forEach(player -> { - TNTSimulator simulator = SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()); - if (simulator == tntSimulator) { - show(player, simulator); - } + Pair> pair = previews.get(tntSimulator); + if (previews == null) return; + pair.setKey(SimulatorPreview.impl.simulate(tntSimulator)); + pair.getValue().forEach(player -> { + Pair> setPair = showModes.get(player); + setPair.getValue().hide(); + pair.getKey().showAll(setPair.getValue()); }); } public void recalculateAll() { - new HashSet<>(previews.keySet()).forEach(SimulatorPreviewStorage::recalculate); + previews.keySet().forEach(SimulatorPreviewStorage::recalculate); } } 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 d1f490c2..9694db8e 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 @@ -41,6 +41,7 @@ import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; @UtilityClass public class TNTElementGUI { @@ -62,6 +63,7 @@ public class TNTElementGUI { } TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); + AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { List locationLore = new ArrayList<>(); locationLore.add(""); @@ -70,6 +72,7 @@ public class TNTElementGUI { locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, tntElement.getPosition().getZ())); inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_LOCATION", player), locationLore, false, clickType -> { editLocation(player, tntElement, () -> open(player, tntElement, back)); + recalculate.set(true); })); List propertiesLore = new ArrayList<>(); @@ -83,6 +86,7 @@ public class TNTElementGUI { propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, active(player, tntElement.isZVelocity()))); inv.setItem(22, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_PROPERTIES", player), propertiesLore, false, clickType -> { editProperties(player, tntElement, () -> open(player, tntElement, back)); + recalculate.set(true); })); List otherLore = new ArrayList<>(); @@ -95,13 +99,16 @@ public class TNTElementGUI { } inv.setItem(24, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> { editOther(player, tntElement, () -> open(player, tntElement, back)); + recalculate.set(true); })); }; editObserver.run(); tntElement.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { tntElement.unregister(editObserver); - SimulatorPreviewStorage.recalculate(tntSimulator); + if (recalculate.get()) { + SimulatorPreviewStorage.recalculate(tntSimulator); + } }); inv.open(); @@ -113,57 +120,67 @@ public class TNTElementGUI { inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); } + TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); + AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - - ChangePosition.show(inv, player, tntSimulator, tntElement, tntElement::getOwnPosition, x -> x - tntElement.getParentPosition().getX(), y -> y - tntElement.getParentPosition().getY(), z -> z - tntElement.getParentPosition().getZ(), () -> editLocation(player, tntElement, back)); + ChangePosition.show(inv, player, recalculate, tntSimulator, tntElement, tntElement::getOwnPosition, x -> x - tntElement.getParentPosition().getX(), y -> y - tntElement.getParentPosition().getY(), z -> z - tntElement.getParentPosition().getZ(), () -> editLocation(player, tntElement, back)); // Alignment inv.setItem(23, new SWItem(Material.OAK_BUTTON, "§a" + BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_Z", player), clickType -> { // Z negative - if (tntSimulator != null) tntSimulator.hide(tntElement); + recalculate.set(true); + tntSimulator.hide(tntElement); Vector position = tntElement.getPosition(); align(position, new Vector(0, 0, 0.49)); tntElement.getOwnPosition().setZ(position.getZ() - tntElement.getParentPosition().getZ()); - if (tntSimulator != null) tntSimulator.show(tntElement); + tntSimulator.show(tntElement); tntElement.change(); })); inv.setItem(25, new SWItem(Material.OAK_BUTTON, "§b" + BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_Z", player), clickType -> { // Z positive - if (tntSimulator != null) tntSimulator.hide(tntElement); + recalculate.set(true); + tntSimulator.hide(tntElement); Vector position = tntElement.getPosition(); align(position, new Vector(0, 0, 0.51)); tntElement.getOwnPosition().setZ(position.getZ() - tntElement.getParentPosition().getZ()); - if (tntSimulator != null) tntSimulator.show(tntElement); + tntSimulator.show(tntElement); tntElement.change(); })); inv.setItem(15, new SWItem(Material.OAK_BUTTON, "§c" + BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_X", player), clickType -> { // X positive - if (tntSimulator != null) tntSimulator.hide(tntElement); + recalculate.set(true); + tntSimulator.hide(tntElement); Vector position = tntElement.getPosition(); align(position, new Vector(0.51, 0, 0)); tntElement.getOwnPosition().setX(position.getX() - tntElement.getParentPosition().getX()); - if (tntSimulator != null) tntSimulator.show(tntElement); + tntSimulator.show(tntElement); tntElement.change(); })); inv.setItem(33, new SWItem(Material.OAK_BUTTON, "§e" + BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_X", player), clickType -> { // X negative - if (tntSimulator != null) tntSimulator.hide(tntElement); + recalculate.set(true); + tntSimulator.hide(tntElement); Vector position = tntElement.getPosition(); align(position, new Vector(0.49, 0, 0)); tntElement.getOwnPosition().setX(position.getX() - tntElement.getParentPosition().getX()); - if (tntSimulator != null) tntSimulator.show(tntElement); + tntSimulator.show(tntElement); tntElement.change(); })); inv.setItem(24, new SWItem(Material.SUNFLOWER, "§f" + BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_CENTER", player), clickType -> { // CENTER - if (tntSimulator != null) tntSimulator.hide(tntElement); + recalculate.set(true); + tntSimulator.hide(tntElement); Vector position = tntElement.getPosition(); align(position, new Vector(0.5, 0, 0.5)); tntElement.getOwnPosition().setX(position.getX() - tntElement.getParentPosition().getX()); tntElement.getOwnPosition().setZ(position.getZ() - tntElement.getParentPosition().getZ()); - if (tntSimulator != null) tntSimulator.show(tntElement); + tntSimulator.show(tntElement); tntElement.change(); })); }; editObserver.run(); tntElement.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> tntElement.unregister(editObserver)); + inv.addCloseRunnable(() -> { + tntElement.unregister(editObserver); + if (recalculate.get()) { + SimulatorPreviewStorage.recalculate(tntSimulator); + } + }); inv.open(); } @@ -199,13 +216,17 @@ public class TNTElementGUI { List minusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_FIVE_SHIFT", player)); List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); + TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); + AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { // Change Count of spawned TNT inv.setItem(10, new SWItem(SWItem.getDye(10), "§a" + plusOneName, plusOneFiveShiftLore, false, clickType -> { + 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); tntElement.change(); editProperties(player, tntElement, back); @@ -213,16 +234,19 @@ public class TNTElementGUI { countItem.getItemStack().setAmount(tntElement.getCount()); inv.setItem(19, countItem); inv.setItem(28, new SWItem(SWItem.getDye(1), "§a" + minusOneName, minusOneFiveShiftLore, false, clickType -> { + recalculate.set(true); tntElement.setCount(tntElement.getCount() - ((clickType.isShiftClick()) ? 5 : 1)); tntElement.change(); })); // Change TickOffset inv.setItem(11, new SWItem(SWItem.getDye(10), "§b" + plusOneName, plusOneFiveShiftLore, false, clickType -> { + 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()); tntElement.change(); editProperties(player, tntElement, back); @@ -230,16 +254,19 @@ public class TNTElementGUI { tickItem.getItemStack().setAmount(Math.max(tntElement.getTickOffset(), 1)); inv.setItem(20, tickItem); inv.setItem(29, new SWItem(SWItem.getDye(1), "§b" + minusOneName, minusOneFiveShiftLore, false, clickType -> { + recalculate.set(true); tntElement.setTickOffset(tntElement.getOwnTickOffset() - (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); })); // Change FuseTicks inv.setItem(12, new SWItem(SWItem.getDye(10), "§c" + plusOneName, plusOneFiveShiftLore, false, clickType -> { + 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); tntElement.change(); editProperties(player, tntElement, back); @@ -247,12 +274,14 @@ public class TNTElementGUI { fuseTickItem.getItemStack().setAmount(Math.max(tntElement.getFuseTicks(), 1)); inv.setItem(21, fuseTickItem); inv.setItem(30, new SWItem(SWItem.getDye(1), "§c" + minusOneName, minusOneFiveShiftLore, false, clickType -> { + 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 -> { + recalculate.set(true); if (tntElement.isXVelocity() || tntElement.isYVelocity() || tntElement.isZVelocity()) { tntElement.setXVelocity(false); tntElement.setYVelocity(false); @@ -265,21 +294,29 @@ public class TNTElementGUI { tntElement.change(); }); inv.setItem(32, new SWItem(getWool(tntElement.isXVelocity()), getColor(tntElement.isXVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, active(player, tntElement.isXVelocity())), clickType -> { + recalculate.set(true); tntElement.setXVelocity(!tntElement.isXVelocity()); tntElement.change(); })); inv.setItem(15, new SWItem(getWool(tntElement.isYVelocity()), getColor(tntElement.isYVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, active(player, tntElement.isYVelocity())), clickType -> { + recalculate.set(true); tntElement.setYVelocity(!tntElement.isYVelocity()); tntElement.change(); })); inv.setItem(34, new SWItem(getWool(tntElement.isZVelocity()), getColor(tntElement.isZVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, active(player, tntElement.isZVelocity())), clickType -> { + recalculate.set(true); tntElement.setZVelocity(!tntElement.isZVelocity()); tntElement.change(); })); }; editObserver.run(); tntElement.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> tntElement.unregister(editObserver)); + inv.addCloseRunnable(() -> { + tntElement.unregister(editObserver); + if (recalculate.get()) { + SimulatorPreviewStorage.recalculate(tntSimulator); + } + }); inv.open(); } @@ -290,10 +327,11 @@ public class TNTElementGUI { inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); } + TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); + AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - inv.setItem(19, new SWItem(tntElement.getOrder(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_NAME", player), OrderUtils.orderList(tntElement.getOrder(), player), false, clickType -> { + recalculate.set(true); if (clickType.isShiftClick()) { tntElement.setOrder(OrderUtils.previous(tntElement.getOrder())); } else { @@ -303,10 +341,11 @@ public class TNTElementGUI { })); ChangeMaterial.show(inv, player, 21, tntElement, Material.BARREL, () -> editOther(player, tntElement, back)); - Disabled.show(inv, player, 22, tntSimulator, tntElement); + Disabled.show(inv, player, recalculate, 22, tntSimulator, tntElement); if (!tntElement.hasParent()) { inv.setItem(24, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE", player), Arrays.asList(), false, clickType -> { + recalculate.set(true); // Create TNTGroup tntSimulator.getTntElementList().remove(tntElement); Vector vector = tntElement.getOwnPosition().clone(); @@ -335,6 +374,7 @@ public class TNTElementGUI { } inv.setItem(25, new SWItem(Material.DISPENSER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_TNT", player), clickType -> { + recalculate.set(true); Vector vector = tntElement.getOwnPosition().clone(); TNTElement newElement = new TNTElement(vector); if (tntElement.hasParent()) { @@ -351,13 +391,19 @@ public class TNTElementGUI { // Delete tnt inv.setItem(44, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_REMOVE_TNT", player), clickType -> { + recalculate.set(true); tntSimulator.remove(tntElement); player.closeInventory(); })); }; editObserver.run(); tntElement.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> tntElement.unregister(editObserver)); + inv.addCloseRunnable(() -> { + tntElement.unregister(editObserver); + if (recalculate.get()) { + SimulatorPreviewStorage.recalculate(tntSimulator); + } + }); inv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java index 949bcc61..9ab1b561 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java @@ -37,6 +37,7 @@ import org.bukkit.util.Consumer; import java.util.Arrays; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.UnaryOperator; @UtilityClass @@ -61,17 +62,20 @@ public class TNTGroupEditGUI { List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); + AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { - ChangePosition.show(inv, player, tntSimulator, tntGroup, tntGroup::getPosition, UnaryOperator.identity(), UnaryOperator.identity(), UnaryOperator.identity(), () -> open(player, tntGroup, back)); + ChangePosition.show(inv, player, recalculate, tntSimulator, tntGroup, tntGroup::getPosition, UnaryOperator.identity(), UnaryOperator.identity(), UnaryOperator.identity(), () -> open(player, tntGroup, back)); ChangeMaterial.show(inv, player, 14, tntGroup, Material.BARREL, () -> open(player, tntGroup, back)); - Disabled.show(inv, player, 32, tntSimulator, tntGroup); + Disabled.show(inv, player, recalculate, 32, tntSimulator, tntGroup); // Change TickOffset inv.setItem(16, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { + recalculate.set(true); tntGroup.setTickOffset(tntGroup.getTickOffset() + (clickType.isShiftClick() ? 5 : 1)); tntGroup.change(); })); SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntGroup.getTickOffset()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tntGroup.getTickOffset(), tick -> { + recalculate.set(true); tntGroup.setTickOffset(tick); tntGroup.change(); open(player, tntGroup, back); @@ -79,6 +83,7 @@ public class TNTGroupEditGUI { tickItem.getItemStack().setAmount(Math.max(tntGroup.getTickOffset(), 1)); inv.setItem(25, tickItem); inv.setItem(34, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { + recalculate.set(true); tntGroup.setTickOffset(tntGroup.getTickOffset() - (clickType.isShiftClick() ? 5 : 1)); tntGroup.change(); })); 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 36cc57ff..61b76683 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 @@ -33,6 +33,7 @@ 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; @@ -48,7 +49,7 @@ public class ChangePosition { private static final Vector FY_VECTOR = new Vector(0, 1, 0); private static final Vector FZ_VECTOR = new Vector(0, 0, 1); - public void show(SWInventory inv, Player player, TNTSimulator tntSimulator, SimulatorElement simulatorElement, Supplier toChangeVector, UnaryOperator calculatePositionX, UnaryOperator calculatePositionY, UnaryOperator calculatePositionZ, Runnable back) { + public void show(SWInventory inv, Player player, AtomicBoolean recalculate, TNTSimulator tntSimulator, SimulatorElement simulatorElement, Supplier toChangeVector, UnaryOperator calculatePositionX, UnaryOperator calculatePositionY, UnaryOperator calculatePositionZ, Runnable back) { String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player); String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player); List plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player)); @@ -57,6 +58,7 @@ public class ChangePosition { // X Position inv.setItem(10, new SWItem(SWItem.getDye(10), "§a" + plusOneName, plusOnePixelShiftLore, false, clickType -> { + recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); @@ -64,6 +66,7 @@ public class ChangePosition { })); 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); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().setX(clamp(calculatePositionX.apply(x))); if (tntSimulator != null) tntSimulator.show(simulatorElement); @@ -72,6 +75,7 @@ public class ChangePosition { }, back); })); inv.setItem(28, new SWItem(SWItem.getDye(1), "§a" + minusOneName, minusOnePixelShiftLore, false, clickType -> { + recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); @@ -80,6 +84,7 @@ public class ChangePosition { // Y Position inv.setItem(11, new SWItem(SWItem.getDye(10), "§b" + plusOneName, plusOnePixelShiftLore, false, clickType -> { + recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); @@ -87,6 +92,7 @@ public class ChangePosition { })); 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); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().setY(clamp(calculatePositionY.apply(y))); if (tntSimulator != null) tntSimulator.show(simulatorElement); @@ -95,6 +101,7 @@ public class ChangePosition { }, back); })); inv.setItem(29, new SWItem(SWItem.getDye(1), "§b" + minusOneName, minusOnePixelShiftLore, false, clickType -> { + recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); @@ -103,6 +110,7 @@ public class ChangePosition { // Z Position inv.setItem(12, new SWItem(SWItem.getDye(10), "§c" + plusOneName, plusOnePixelShiftLore, false, clickType -> { + recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); @@ -110,6 +118,7 @@ public class ChangePosition { })); 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); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().setZ(clamp(calculatePositionZ.apply(z))); if (tntSimulator != null) tntSimulator.show(simulatorElement); @@ -118,6 +127,7 @@ public class ChangePosition { }, back); })); inv.setItem(30, new SWItem(SWItem.getDye(1), "§c" + minusOneName, minusOnePixelShiftLore, false, clickType -> { + recalculate.set(true); if (tntSimulator != null) tntSimulator.hide(simulatorElement); toChangeVector.get().subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); if (tntSimulator != null) tntSimulator.show(simulatorElement); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java index 3ac98483..dcb0b8bb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java @@ -29,12 +29,14 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; @UtilityClass public class Disabled { - public void show(SWInventory inv, Player player, int position, TNTSimulator tntSimulator, SimulatorElement simulatorElement) { + public void show(SWInventory inv, Player player, AtomicBoolean recalculate, int position, TNTSimulator tntSimulator, SimulatorElement simulatorElement) { inv.setItem(position, new SWItem(simulatorElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, BauSystem.MESSAGE.parse(simulatorElement.isDisabled() ? "SIMULATOR_TNT_SPAWN_DISABLED" : "SIMULATOR_TNT_SPAWN_ENABLED", player), new ArrayList<>(), !simulatorElement.isDisabled(), clickType -> { + recalculate.set(true); if (!simulatorElement.isDisabled()) { tntSimulator.hide(simulatorElement); }