From 8f1cac6f1fe51c9697582edcd307d5c7e4808bfd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 12:20:29 +0200 Subject: [PATCH 001/139] Add AntiCursorReCentering --- .../features/world/AntiCursorReCentering.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java new file mode 100644 index 00000000..edf23bba --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.world; + +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.api.Enable; + +@Linked +public class AntiCursorReCentering implements Enable { + + @Override + public void enable() { + // Fix GUI Closing causing a recentering of the Cursor + Class clazz = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutCloseWindow"); + TinyProtocol.instance.addFilter(clazz, (player, object) -> null); + } +} From 758c32e3531346dab089ec2dc76c992576674838 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 24 Oct 2023 18:12:03 +0200 Subject: [PATCH 002/139] Hotfix AntiCursorReCentering --- .../features/world/AntiCursorReCentering.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java index edf23bba..7cf5c4c7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java @@ -21,16 +21,44 @@ package de.steamwar.bausystem.features.world; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.bausystem.BauSystem; import de.steamwar.linkage.Linked; import de.steamwar.linkage.api.Enable; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; @Linked public class AntiCursorReCentering implements Enable { + private final Set CLOSE_PACKETS = new HashSet<>(); + private final Set CLOSE_NOW = new HashSet<>(); + @Override public void enable() { - // Fix GUI Closing causing a recentering of the Cursor - Class clazz = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutCloseWindow"); - TinyProtocol.instance.addFilter(clazz, (player, object) -> null); + Class closeWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutCloseWindow"); + TinyProtocol.instance.addFilter(closeWindow, (player, object) -> { + if (CLOSE_NOW.remove(player)) { + return object; + } + CLOSE_PACKETS.add(player); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (CLOSE_PACKETS.remove(player)) { + CLOSE_NOW.add(player); + TinyProtocol.instance.sendPacket(player, object); + } + }, 0); + return null; + }); + + Class openWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenWindow"); + TinyProtocol.instance.addFilter(openWindow, (player, object) -> { + CLOSE_PACKETS.remove(player); + return object; + }); } } From 0be117c0013f60b3b723ef24cee5b718c4d02cac Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 24 Oct 2023 18:23:12 +0200 Subject: [PATCH 003/139] Hotfix AntiCursorReCentering --- .../features/world/AntiCursorReCentering.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java index 7cf5c4c7..ff04aa5f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java @@ -25,40 +25,24 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.linkage.Linked; import de.steamwar.linkage.api.Enable; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import org.bukkit.event.inventory.InventoryType; @Linked public class AntiCursorReCentering implements Enable { - private final Set CLOSE_PACKETS = new HashSet<>(); - private final Set CLOSE_NOW = new HashSet<>(); - @Override public void enable() { Class closeWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutCloseWindow"); TinyProtocol.instance.addFilter(closeWindow, (player, object) -> { - if (CLOSE_NOW.remove(player)) { + if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) { return object; } - CLOSE_PACKETS.add(player); Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - if (CLOSE_PACKETS.remove(player)) { - CLOSE_NOW.add(player); + if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) { TinyProtocol.instance.sendPacket(player, object); } }, 0); return null; }); - - Class openWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenWindow"); - TinyProtocol.instance.addFilter(openWindow, (player, object) -> { - CLOSE_PACKETS.remove(player); - return object; - }); } } From 44f6d1c15dd8fb66992a0c50b1b19c6f759ed6ff Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sun, 8 Oct 2023 11:58:05 +0200 Subject: [PATCH 004/139] Added new sim data structure --- .../bausystem/features/simulator2/data/Simulator.java | 4 ++++ .../bausystem/features/simulator2/data/SimulatorElement.java | 4 ++++ .../bausystem/features/simulator2/data/SimulatorGroup.java | 4 ++++ .../features/simulator2/data/redstone/RedstoneElement.java | 5 +++++ .../features/simulator2/data/redstone/RedstoneSetting.java | 4 ++++ .../bausystem/features/simulator2/data/tnt/TNTElement.java | 4 ++++ .../bausystem/features/simulator2/data/tnt/TNTSetting.java | 4 ++++ 7 files changed, 29 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java new file mode 100644 index 00000000..9354b78a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.features.simulator2.data; + +public class Simulator { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java new file mode 100644 index 00000000..61f20f42 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.features.simulator2.data; + +public abstract class SimulatorElement { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java new file mode 100644 index 00000000..b212828c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.features.simulator2.data; + +public class SimulatorGroup { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java new file mode 100644 index 00000000..ddcf6c4c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -0,0 +1,5 @@ +package de.steamwar.bausystem.features.simulator2.data.redstone; + +public class RedstoneElement { + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java new file mode 100644 index 00000000..e849a230 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.features.simulator2.data.redstone; + +public class RedstoneSetting { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java new file mode 100644 index 00000000..aeb86a57 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.features.simulator2.data.tnt; + +public class TNTElement { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java new file mode 100644 index 00000000..147aa3fd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.features.simulator2.data.tnt; + +public class TNTSetting { +} From 077a9854a509eba39c1f7a7a48101353937508b5 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sun, 8 Oct 2023 12:06:48 +0200 Subject: [PATCH 005/139] Add class Hierarchy --- .../features/simulator2/data/Simulator.java | 4 ++++ .../simulator2/data/SimulatorElement.java | 8 ++++++- .../simulator2/data/SimulatorGroup.java | 4 ++++ .../simulator2/data/SimulatorSetting.java | 23 +++++++++++++++++++ .../data/redstone/RedstoneElement.java | 4 +++- .../data/redstone/RedstoneSetting.java | 4 +++- .../simulator2/data/tnt/TNTElement.java | 4 +++- .../simulator2/data/tnt/TNTSetting.java | 4 +++- 8 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java index 9354b78a..becfb213 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -1,4 +1,8 @@ package de.steamwar.bausystem.features.simulator2.data; +import java.util.ArrayList; +import java.util.List; + public class Simulator { + private List elements = new ArrayList<>(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 61f20f42..76139dee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -1,4 +1,10 @@ package de.steamwar.bausystem.features.simulator2.data; -public abstract class SimulatorElement { +import java.util.ArrayList; +import java.util.List; + +public abstract class SimulatorElement { + protected List settings = new ArrayList<>(); + + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index b212828c..1ed3aa3a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -1,4 +1,8 @@ package de.steamwar.bausystem.features.simulator2.data; +import java.util.ArrayList; +import java.util.List; + public class SimulatorGroup { + private List> elements = new ArrayList<>(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java new file mode 100644 index 00000000..0f5e36a2 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java @@ -0,0 +1,23 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.data; + +public interface SimulatorSetting { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index ddcf6c4c..eace1fad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -1,5 +1,7 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; -public class RedstoneElement { +import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; + +public class RedstoneElement extends SimulatorElement { } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java index e849a230..931403b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java @@ -1,4 +1,6 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; -public class RedstoneSetting { +import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; + +public class RedstoneSetting implements SimulatorSetting { } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index aeb86a57..96e7ae3c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -1,4 +1,6 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; -public class TNTElement { +import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; + +public class TNTElement extends SimulatorElement { } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java index 147aa3fd..1ba71387 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java @@ -1,4 +1,6 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; -public class TNTSetting { +import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; + +public class TNTSetting implements SimulatorSetting { } From 0f1a8f55315c7fe124e82206787b63bf16a86c32 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sun, 8 Oct 2023 12:22:31 +0200 Subject: [PATCH 006/139] Add final DataStructure --- .../bausystem/features/simulator2/data/Simulator.java | 3 +++ .../features/simulator2/data/SimulatorElement.java | 7 +++++-- .../bausystem/features/simulator2/data/SimulatorGroup.java | 3 +++ .../features/simulator2/data/SimulatorSetting.java | 5 ++++- .../features/simulator2/data/redstone/RedstoneSetting.java | 2 +- .../bausystem/features/simulator2/data/tnt/TNTSetting.java | 7 ++++++- 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java index becfb213..f2b0774e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -1,8 +1,11 @@ package de.steamwar.bausystem.features.simulator2.data; +import org.bukkit.Material; + import java.util.ArrayList; import java.util.List; public class Simulator { + private Material material = Material.BARREL; private List elements = new ArrayList<>(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 76139dee..d369b6a7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -1,10 +1,13 @@ package de.steamwar.bausystem.features.simulator2.data; +import org.bukkit.Material; +import org.bukkit.util.Vector; + import java.util.ArrayList; import java.util.List; public abstract class SimulatorElement { + protected Material material; + protected Vector position; protected List settings = new ArrayList<>(); - - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index 1ed3aa3a..c3bedb7b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -1,8 +1,11 @@ package de.steamwar.bausystem.features.simulator2.data; +import org.bukkit.Material; + import java.util.ArrayList; import java.util.List; public class SimulatorGroup { + private Material material = Material.CHEST; private List> elements = new ArrayList<>(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java index 0f5e36a2..393e03f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java @@ -19,5 +19,8 @@ package de.steamwar.bausystem.features.simulator2.data; -public interface SimulatorSetting { +public abstract class SimulatorSetting { + protected int tickOffset; + protected int lifetime = 80; + protected int order = 1; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java index 931403b6..5c3d9b55 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java @@ -2,5 +2,5 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; -public class RedstoneSetting implements SimulatorSetting { +public class RedstoneSetting extends SimulatorSetting { } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java index 1ba71387..40561321 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java @@ -2,5 +2,10 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; -public class TNTSetting implements SimulatorSetting { +public class TNTSetting extends SimulatorSetting { + private int count = 1; + private boolean xJump = false; + private boolean yJump = false; + private boolean zJump = false; + } From 7980f49dfac3466a280369aecd716084c058e952 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sun, 8 Oct 2023 12:30:38 +0200 Subject: [PATCH 007/139] Add Licence header --- .../features/simulator2/data/Simulator.java | 20 +++++++++++++++++++ .../simulator2/data/SimulatorElement.java | 20 +++++++++++++++++++ .../simulator2/data/SimulatorGroup.java | 20 +++++++++++++++++++ .../data/redstone/RedstoneElement.java | 19 ++++++++++++++++++ .../data/redstone/RedstoneSetting.java | 19 ++++++++++++++++++ .../simulator2/data/tnt/TNTElement.java | 19 ++++++++++++++++++ .../simulator2/data/tnt/TNTSetting.java | 19 ++++++++++++++++++ 7 files changed, 136 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java index f2b0774e..082a1c43 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.data; import org.bukkit.Material; @@ -7,5 +26,6 @@ import java.util.List; public class Simulator { private Material material = Material.BARREL; + private boolean autoTrace = false; private List elements = new ArrayList<>(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index d369b6a7..8b6401ab 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.data; import org.bukkit.Material; @@ -9,5 +28,6 @@ import java.util.List; public abstract class SimulatorElement { protected Material material; protected Vector position; + protected boolean disabled = false; protected List settings = new ArrayList<>(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index c3bedb7b..b02103d6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.data; import org.bukkit.Material; @@ -7,5 +26,6 @@ import java.util.List; public class SimulatorGroup { private Material material = Material.CHEST; + protected boolean disabled = false; private List> elements = new ArrayList<>(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index eace1fad..0c5f8cdc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.data.redstone; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java index 5c3d9b55..522f27a8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.data.redstone; import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index 96e7ae3c..ba79a5f4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.data.tnt; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java index 40561321..8c044fa2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.data.tnt; import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; From fbe4f00ac0852a9333a137e177656ce72d127bc2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 8 Oct 2023 21:37:15 +0200 Subject: [PATCH 008/139] Add basic GUI's Signed-off-by: yoyosource --- .../simulator2/SimulatorTestCommand.java | 56 +++++++ .../features/simulator2/SimulatorWatcher.java | 64 ++++++++ .../features/simulator2/data/Simulator.java | 15 +- .../simulator2/data/SimulatorElement.java | 39 ++++- .../simulator2/data/SimulatorGroup.java | 30 +++- .../simulator2/data/SimulatorSetting.java | 5 + .../data/redstone/RedstoneElement.java | 10 ++ .../simulator2/data/tnt/TNTElement.java | 39 +++++ .../simulator2/data/tnt/TNTSetting.java | 5 +- .../simulator2/gui/SimulatorGroupGui.java | 106 +++++++++++++ .../gui/SimulatorGroupSettingsGui.java | 126 +++++++++++++++ .../features/simulator2/gui/SimulatorGui.java | 94 +++++++++++ .../simulator2/gui/SimulatorRedstoneGui.java | 122 +++++++++++++++ .../gui/SimulatorRedstonePhaseGui.java | 73 +++++++++ .../gui/SimulatorRedstoneSettingsGui.java | 125 +++++++++++++++ .../simulator2/gui/SimulatorSettingsGui.java | 97 ++++++++++++ .../simulator2/gui/SimulatorTNTGui.java | 110 +++++++++++++ .../gui/SimulatorTNTSettingsGui.java | 148 ++++++++++++++++++ .../simulator2/gui/base/SimulatorBaseGui.java | 79 ++++++++++ .../simulator2/gui/base/SimulatorPageGui.java | 82 ++++++++++ .../gui/base/SimulatorScrollGui.java | 80 ++++++++++ .../gui/utils/SimulatorMaterialGui.java | 77 +++++++++ 22 files changed, 1577 insertions(+), 5 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java new file mode 100644 index 00000000..1117a766 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java @@ -0,0 +1,56 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +@Linked +public class SimulatorTestCommand extends SWCommand { + + private static final Simulator SIMULATOR = new Simulator("TestSim"); + + public SimulatorTestCommand() { + super("simtest"); + + SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())).add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())); + SIMULATOR.getElements().add(group1); + + SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())); + SIMULATOR.getElements().add(group2); + + SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(0, 0, 0)).add(new RedstoneSetting())); + SIMULATOR.getElements().add(group3); + } + + @Register + public void genericCommand(Player player, String... args) { + new SimulatorGui(player, SIMULATOR).open(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java new file mode 100644 index 00000000..6c9a0c1e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -0,0 +1,64 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.shared.Pair; +import de.steamwar.linkage.Linked; +import lombok.experimental.UtilityClass; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +@UtilityClass +public class SimulatorWatcher { + + private Map> watchers = new HashMap<>(); + + public void watch(Player player, Simulator simulator, Runnable watcher) { + if (simulator == null || watcher == null) { + watchers.remove(player); + } else { + watchers.put(player, new Pair<>(simulator, watcher)); + } + } + + public void update(Simulator simulator) { + new ArrayList<>(watchers.values()).forEach(simulatorRunnablePair -> { + if (simulatorRunnablePair.getKey() == simulator) { + simulatorRunnablePair.getValue().run(); + } + }); + } + + @Linked + public static class QuitListener implements Listener { + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + watchers.remove(event.getPlayer()); + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java index 082a1c43..a856a54a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -19,13 +19,26 @@ package de.steamwar.bausystem.features.simulator2.data; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.bukkit.Material; import java.util.ArrayList; import java.util.List; +@Getter +@Setter +@RequiredArgsConstructor public class Simulator { private Material material = Material.BARREL; + private final String name; private boolean autoTrace = false; - private List elements = new ArrayList<>(); + private final List elements = new ArrayList<>(); + + public void move(int x, int y, int z) { + elements.forEach(simulatorGroup -> { + simulatorGroup.move(x, y, z); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 8b6401ab..a218ea6b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -19,15 +19,50 @@ package de.steamwar.bausystem.features.simulator2.data; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Material; import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.List; +@Getter +@Setter public abstract class SimulatorElement { protected Material material; - protected Vector position; + protected final Vector position; protected boolean disabled = false; - protected List settings = new ArrayList<>(); + protected final List settings = new ArrayList<>(); + + protected SimulatorElement(Material material, Vector position) { + this.material = material; + this.position = position; + } + + public SimulatorElement add(T setting) { + settings.add(setting); + return this; + } + + public abstract String getName(); + + public int getBaseTick() { + return settings.stream() + .mapToInt(value -> value.tickOffset) + .min() + .orElse(0); + } + + public void changeBaseTicks(int tick) { + settings.forEach(t -> { + t.tickOffset += tick; + }); + } + + public void move(int x, int y, int z) { + position.setX(position.getX() + x); + position.setY(position.getY() + y); + position.setZ(position.getZ() + z); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index b02103d6..b0a705b4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -19,13 +19,41 @@ package de.steamwar.bausystem.features.simulator2.data; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Material; import java.util.ArrayList; import java.util.List; +@Getter +@Setter public class SimulatorGroup { private Material material = Material.CHEST; protected boolean disabled = false; - private List> elements = new ArrayList<>(); + private final List> elements = new ArrayList<>(); + + public SimulatorGroup add(SimulatorElement element) { + elements.add(element); + return this; + } + + public int getBaseTick() { + return elements.stream() + .mapToInt(SimulatorElement::getBaseTick) + .min() + .orElse(0); + } + + public void changeBaseTicks(int tick) { + elements.forEach(simulatorElement -> { + simulatorElement.changeBaseTicks(tick); + }); + } + + public void move(int x, int y, int z) { + elements.forEach(simulatorElement -> { + simulatorElement.move(x, y, z); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java index 393e03f2..b8ecb79c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java @@ -19,6 +19,11 @@ package de.steamwar.bausystem.features.simulator2.data; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter public abstract class SimulatorSetting { protected int tickOffset; protected int lifetime = 80; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index 0c5f8cdc..a633ac45 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -20,7 +20,17 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import org.bukkit.Material; +import org.bukkit.util.Vector; public class RedstoneElement extends SimulatorElement { + public RedstoneElement(Vector position) { + super(Material.REDSTONE_BLOCK, position); + } + + @Override + public String getName() { + return "Redstone"; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index ba79a5f4..bbcfae6f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -20,6 +20,45 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import org.bukkit.Material; +import org.bukkit.util.Vector; public class TNTElement extends SimulatorElement { + + public TNTElement(Vector position) { + super(Material.TNT, position); + } + + @Override + public String getName() { + return "TNT"; + } + + public void move(double x, double y, double z) { + position.setX(position.getX() + x); + position.setY(position.getY() + y); + position.setZ(position.getZ() + z); + } + + public void align(Vector offset) { + if (offset.getX() != 0) { + if (position.getX() - (int) position.getX() == 0.49) { + position.setX(position.getX() + 0.02); + } + if (position.getX() - (int) position.getX() == -0.49) { + position.setX(position.getX() - 0.02); + } + position.setX(position.getBlockX() + offset.getX()); + } + + if (offset.getZ() != 0) { + if (position.getZ() - (int) position.getZ() == 0.49) { + position.setZ(position.getZ() + 0.02); + } + if (position.getZ() - (int) position.getZ() == -0.49) { + position.setZ(position.getZ() - 0.02); + } + position.setZ(position.getBlockZ() + offset.getZ()); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java index 8c044fa2..601c3ac5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java @@ -20,11 +20,14 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; +import lombok.Getter; +import lombok.Setter; +@Getter +@Setter public class TNTSetting extends SimulatorSetting { private int count = 1; private boolean xJump = false; private boolean yJump = false; private boolean zJump = false; - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java new file mode 100644 index 00000000..c9a4c68e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -0,0 +1,106 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class SimulatorGroupGui extends SimulatorPageGui> { + + private final SimulatorGroup simulatorGroup; + private final SimulatorBaseGui back; + + public SimulatorGroupGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, simulatorGroup.getElements()); + this.simulatorGroup = simulatorGroup; + this.back = back; + } + + @Override + public String baseTitle() { + return "Group"; + } + + @Override + public void headerAndFooter() { + if (simulatorGroup.getElements().size() < 2) { + back.open(); + return; + } + + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + List lore = new ArrayList<>(); + lore.add("§7Element count§8:§e " + data.size()); + lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); + if (simulatorGroup.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + inventory.setItem(4, new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); + })); + + inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); + })); + inventory.setItem(50, new SWItem(simulatorGroup.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + simulatorGroup.setDisabled(!simulatorGroup.isDisabled()); + SimulatorWatcher.update(simulator); + })); + } + + @Override + public SWItem convert(SimulatorElement element) { + List lore = new ArrayList<>(); + lore.add("§7Phase count§8:§e " + element.getSettings().size()); + lore.add("§7Tick§8:§e " + element.getBaseTick()); + lore.add(""); + lore.add("§7X§8:§e " + element.getPosition().getX()); + lore.add("§7Y§8:§e " + element.getPosition().getY()); + lore.add("§7Z§8:§e " + element.getPosition().getZ()); + if (element.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { + if (element instanceof TNTElement) { + new SimulatorTNTGui(player, simulator, (TNTElement) element, this).open(); + } else if (element instanceof RedstoneElement) { + new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); + } + }); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java new file mode 100644 index 00000000..905972a0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java @@ -0,0 +1,126 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SimulatorGroupSettingsGui extends SimulatorBaseGui { + + private final SimulatorGroup simulatorGroup; + private final SimulatorBaseGui back; + + public SimulatorGroupSettingsGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) { + super(player, simulator, 5 * 9); + this.simulatorGroup = simulatorGroup; + this.back = back; + } + + @Override + public String title() { + return "Group"; + } + + @Override + public void populate() { + if (simulatorGroup.getElements().size() < 2) { + back.open(); + return; + } + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + List lore = new ArrayList<>(); + lore.add("§7Element count§8:§e " + simulatorGroup.getElements().size()); + lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); + if (simulatorGroup.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + inventory.setItem(4, new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); + })); + + // Base Tick + int baseTicks = simulatorGroup.getBaseTick(); + inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {}); + baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); + inventory.setItem(18, baseTick); + inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) { + simulatorGroup.changeBaseTicks(-baseTicks); + } else { + simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + //Pos X + inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(clickType.isShiftClick() ? 5 : 1, 0, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); + inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(clickType.isShiftClick() ? -5 : -1, 0, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Y + inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(0, clickType.isShiftClick() ? 5 : 1, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); + inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(0, clickType.isShiftClick() ? -5 : -1, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Z + inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(0, 0, clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); + inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(0, 0, clickType.isShiftClick() ? -5 : -1); + SimulatorWatcher.update(simulator); + }); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java new file mode 100644 index 00000000..1a5d5325 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -0,0 +1,94 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class SimulatorGui extends SimulatorPageGui { + + public SimulatorGui(Player player, Simulator simulator) { + super(player, simulator, 6 * 9, simulator.getElements()); + } + + @Override + public String baseTitle() { + return "Simulator - " + simulator.getName(); + } + + @Override + public void headerAndFooter() { + // TODO: Remove empty Groups + inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { + new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); + })); + inventory.setItem(49, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + new SimulatorSettingsGui(player, simulator, this).open(); + })); + } + + @Override + public SWItem convert(SimulatorGroup simulatorGroup) { + List> elements = simulatorGroup.getElements(); + if (elements.size() == 1) { + SimulatorElement element = elements.get(0); + List lore = new ArrayList<>(); + lore.add("§7Phase count§8:§e " + element.getSettings().size()); + lore.add("§7Tick§8:§e " + element.getBaseTick()); + lore.add(""); + lore.add("§7X§8:§e " + element.getPosition().getX()); + lore.add("§7Y§8:§e " + element.getPosition().getY()); + lore.add("§7Z§8:§e " + element.getPosition().getZ()); + if (element.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { + if (element instanceof TNTElement) { + new SimulatorTNTGui(player, simulator, (TNTElement) element, this).open(); + } else if (element instanceof RedstoneElement) { + new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); + } + }); + } + + List lore = new ArrayList<>(); + lore.add("§7Element count§8:§e " + elements.size()); + lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); + if (simulatorGroup.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + new SimulatorGroupGui(player, simulator, simulatorGroup, this).open(); + }); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java new file mode 100644 index 00000000..ae5a019a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -0,0 +1,122 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SimulatorRedstoneGui extends SimulatorScrollGui { + + private final SimulatorGroup simulatorGroup; + private final RedstoneElement redstoneElement; + private final SimulatorBaseGui back; + + public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstoneElement, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, redstoneElement.getSettings()); + this.simulatorGroup = simulatorGroup; + this.redstoneElement = redstoneElement; + this.back = back; + } + + @Override + public String baseTitle() { + return "Redstone"; + } + + @Override + public void headerAndFooter() { + if (redstoneElement.getSettings().isEmpty()) { + simulatorGroup.getElements().remove(redstoneElement); + back.open(); + return; + } + + // TODO Sort Data List + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + List lore = new ArrayList<>(); + lore.add("§7Activation count§8:§e " + data.size()); + lore.add("§7Tick§8:§e " + redstoneElement.getBaseTick()); + lore.add(""); + lore.add("§7X§8:§e " + redstoneElement.getPosition().getX()); + lore.add("§7Y§8:§e " + redstoneElement.getPosition().getY()); + lore.add("§7Z§8:§e " + redstoneElement.getPosition().getZ()); + if (redstoneElement.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + inventory.setItem(4, new SWItem(redstoneElement.getMaterial(), "§eTNT", lore, redstoneElement.isDisabled(), clickType -> { + new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open(); + })); + + //Settings + inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + new SimulatorRedstoneSettingsGui(player, simulator, redstoneElement, this).open(); + })); + + // 49 Lead? + + //Enable/Disable + inventory.setItem(50, new SWItem(redstoneElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstoneElement.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + redstoneElement.setDisabled(!redstoneElement.isDisabled()); + SimulatorWatcher.update(simulator); + })); + } + + @Override + public SWItem[] column(RedstoneSetting redstoneSetting) { + SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Fuse§8:§e " + redstoneSetting.getLifetime(), "", "§7Order§8:§e " + redstoneSetting.getOrder()), false, clickType -> {}); + redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64))); + + return new SWItem[] { + new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + redstoneSetting.setTickOffset(redstoneSetting.getTickOffset() + (clickType.isShiftClick() ? 5 : 1)); + SimulatorWatcher.update(simulator); + }), + redstone, + new SWItem(SWItem.getDye(redstoneSetting.getTickOffset() > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { + redstoneSetting.setTickOffset(Math.max(0, redstoneSetting.getTickOffset() - (clickType.isShiftClick() ? 5 : 1))); + SimulatorWatcher.update(simulator); + }), + new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { + new SimulatorRedstonePhaseGui(player, simulator, redstoneElement, redstoneSetting, this).open(); + }), + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java new file mode 100644 index 00000000..60be2a34 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java @@ -0,0 +1,73 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { + + private final RedstoneElement redstoneElement; + private final RedstoneSetting redstone; + private final SimulatorBaseGui back; + + public SimulatorRedstonePhaseGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstoneSetting redstone, SimulatorBaseGui back) { + super(player, simulator, 5 * 9); + this.redstoneElement = redstoneElement; + this.redstone = redstone; + this.back = back; + } + + @Override + public String title() { + return "Redstone"; + } + + @Override + public void populate() { // TODO: Finalize + if (!redstoneElement.getSettings().contains(redstone)) { + back.open(); + return; + } + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + inventory.setItem(4, new SWItem(redstoneElement.getMaterial(), "§eRedstone", clickType -> { + new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open(); + })); + + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + redstoneElement.getSettings().remove(redstone); + back.open(); + SimulatorWatcher.update(simulator); + })); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java new file mode 100644 index 00000000..c191f862 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java @@ -0,0 +1,125 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { + private final RedstoneElement redstone; + private final SimulatorBaseGui back; + + public SimulatorRedstoneSettingsGui(Player player, Simulator simulator, RedstoneElement redstone, SimulatorBaseGui back) { + super(player, simulator, 5 * 9); + this.redstone = redstone; + this.back = back; + } + + @Override + public String title() { + return "Redstone"; + } + + @Override + public void populate() { + if (redstone.getSettings().isEmpty()) { + back.open(); + return; + } + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + List lore = new ArrayList<>(); + lore.add("§7Activation count§8:§e " + redstone.getSettings().size()); + lore.add("§7Tick§8:§e " + redstone.getBaseTick()); + if (redstone.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + inventory.setItem(4, new SWItem(redstone.getMaterial(), "§eRedstone", lore, redstone.isDisabled(), clickType -> { + new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); + })); + + // Base Tick + int baseTicks = redstone.getBaseTick(); + inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {}); + baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); + inventory.setItem(18, baseTick); + inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) { + redstone.changeBaseTicks(-baseTicks); + } else { + redstone.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + //Pos X + inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.move(clickType.isShiftClick() ? 5 : 1, 0, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); + inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Y + inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.move(0, clickType.isShiftClick() ? 5 : 1, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); + inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Z + inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); + inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1); + SimulatorWatcher.update(simulator); + }); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java new file mode 100644 index 00000000..acaf01da --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java @@ -0,0 +1,97 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Arrays; + +public class SimulatorSettingsGui extends SimulatorBaseGui { + + private final SimulatorBaseGui back; + + public SimulatorSettingsGui(Player player, Simulator simulator, SimulatorBaseGui back) { + super(player, simulator, 5 * 9); + this.back = back; + } + + @Override + public String title() { + return simulator.getName() + " Settings"; + } + + @Override + public void populate() { + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { + new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); + })); + + //AutoTrace + inventory.setItem(20, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, "§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> { + simulator.setAutoTrace(!simulator.isAutoTrace()); + SimulatorWatcher.update(simulator); + })); + + //Pos X + inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); + inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Y + inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); + inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Z + inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); + inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1); + SimulatorWatcher.update(simulator); + }); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java new file mode 100644 index 00000000..b979e930 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -0,0 +1,110 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SimulatorTNTGui extends SimulatorScrollGui { + + private TNTElement tntElement; + private SimulatorBaseGui back; + + public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tntElement, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, tntElement.getSettings()); + this.tntElement = tntElement; + this.back = back; + } + + @Override + public String baseTitle() { + return "TNT"; + } + + @Override + public void headerAndFooter() { + // TODO Back Jump + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // TODO Sort Data List + + // Material Chooser + List lore = new ArrayList<>(); + lore.add("§7Phase count§8:§e " + data.size()); + lore.add("§7Tick§8:§e " + tntElement.getBaseTick()); + lore.add(""); + lore.add("§7X§8:§e " + tntElement.getPosition().getX()); + lore.add("§7Y§8:§e " + tntElement.getPosition().getY()); + lore.add("§7Z§8:§e " + tntElement.getPosition().getZ()); + if (tntElement.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + inventory.setItem(4, new SWItem(tntElement.getMaterial(), "§eTNT", lore, tntElement.isDisabled(), clickType -> { + new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open(); + })); + + inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + // new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); + })); + // 49 Lead? + inventory.setItem(50, new SWItem(tntElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tntElement.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + tntElement.setDisabled(!tntElement.isDisabled()); + SimulatorWatcher.update(simulator); + })); + } + + @Override + public SWItem[] column(TNTSetting tntSetting) { + SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff")), false, clickType -> {}); + tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64)); + + return new SWItem[] { + new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1)); + SimulatorWatcher.update(simulator); + }), + tnt, + new SWItem(SWItem.getDye(tntSetting.getCount() > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { + tntSetting.setCount(Math.max(1, tntSetting.getCount() - (clickType.isShiftClick() ? 5 : 1))); + SimulatorWatcher.update(simulator); + }), + new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> { + // Open Edit Phase menu + }), + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java new file mode 100644 index 00000000..dc90b12b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java @@ -0,0 +1,148 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SimulatorTNTSettingsGui extends SimulatorBaseGui { + private final TNTElement tnt; + private final SimulatorBaseGui back; + + public SimulatorTNTSettingsGui(Player player, Simulator simulator, TNTElement tnt, SimulatorBaseGui back) { + super(player, simulator, 5 * 9); + this.tnt = tnt; + this.back = back; + } + + @Override + public String title() { + return "TNT"; + } + + @Override + public void populate() { + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + List lore = new ArrayList<>(); + lore.add("§7Phase count§8:§e " + tnt.getSettings().size()); + lore.add("§7Tick§8:§e " + tnt.getBaseTick()); + if (tnt.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> { + new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open(); + })); + + // Base Tick + int baseTicks = tnt.getBaseTick(); + inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {}); + baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); + inventory.setItem(18, baseTick); + inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) { + tnt.changeBaseTicks(-baseTicks); + } else { + tnt.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + // Subpixel Alignment + inventory.setItem(24, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { + // tnt.align(new Vector()); TODO Finalize + SimulatorWatcher.update(simulator); + })); + + //z + inventory.setItem(23, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { + + SimulatorWatcher.update(simulator); + })); + + inventory.setItem(25, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { + + SimulatorWatcher.update(simulator); + })); + + //X + inventory.setItem(15, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { + + SimulatorWatcher.update(simulator); + })); + + inventory.setItem(33, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { + + SimulatorWatcher.update(simulator); + })); + + //Pos X + inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { + tnt.move(clickType.isShiftClick() ? 0.0625 : 1, 0, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); + inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { + tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Y + inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { + tnt.move(0, clickType.isShiftClick() ? 0.0625 : 1, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); + inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { + tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Z + inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { + tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 1); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); + inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { + tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1); + SimulatorWatcher.update(simulator); + }); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java new file mode 100644 index 00000000..59079c64 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java @@ -0,0 +1,79 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui.base; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +public abstract class SimulatorBaseGui { + + protected final Player player; + protected final Simulator simulator; + private Inventory inv; + protected SWInventory inventory; + + protected final int size; + + protected SimulatorBaseGui(Player player, Simulator simulator, int size) { + this.player = player; + this.simulator = simulator; + this.size = size; + } + + public final void open() { + if (inv != null) { + if (player.getOpenInventory().getTopInventory() != inv) { + inventory.open(); + SimulatorWatcher.watch(player, simulator, this::open); + } + player.getOpenInventory().setTitle(title()); + populate(); + return; + } + + player.getOpenInventory().close(); + + inventory = new SWInventory(player, () -> { + inv = Bukkit.createInventory(null, size, title()); + return inv; + }); + for (int i = 0; i < 9; i++) { + inventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8", clickType -> {})); + inventory.setItem(size - 9 + i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8", clickType -> {})); + } + inventory.addCloseCallback(clickType -> { + SimulatorWatcher.watch(player, null, null); + }); + + inventory.open(); + SimulatorWatcher.watch(player, simulator, this::open); + populate(); + } + + public abstract String title(); + + public abstract void populate(); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java new file mode 100644 index 00000000..22db341e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java @@ -0,0 +1,82 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui.base; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.core.Core; +import de.steamwar.inventory.SWItem; +import org.bukkit.entity.Player; + +import java.util.List; + +public abstract class SimulatorPageGui extends SimulatorBaseGui { + + protected int page = 0; + protected final List data; + + protected SimulatorPageGui(Player player, Simulator simulator, int size, List data) { + super(player, simulator, size); + this.data = data; + } + + public final int maxPage() { + return data.size() / (size - 18); + } + + @Override + public final String title() { + return baseTitle() + " " + (page + 1) + "/" + (maxPage() + 1); + } + + @Override + public final void populate() { + headerAndFooter(); + page = Math.min(page, maxPage()); + + inventory.setItem(size - 9, SWItem.getDye(page > 0 ? 10 : 8), page > 0 ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(page > 0 ? "SWLISINV_PREVIOUS_PAGE_ACTIVE" : "SWLISINV_PREVIOUS_PAGE_INACTIVE", player), clickType -> { + if (page > 0) { + page--; + open(); + } + }); + boolean hasNext = page < maxPage() - (data.size() % (size - 18) == 0 ? 1 : 0); + inventory.setItem(size - 1, SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { + if (hasNext) { + page++; + open(); + } + }); + + int minElement = page * (size - 18); + int maxElement = Math.min(data.size(), (page + 1) * (size - 18)); + int index = 9; + + for (int i = minElement; i < maxElement; i++) { + T element = data.get(i); + inventory.setItem(index++, convert(element)); + } + } + + public abstract String baseTitle(); + + public void headerAndFooter() { + } + public abstract SWItem convert(T t); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java new file mode 100644 index 00000000..a61a4971 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java @@ -0,0 +1,80 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui.base; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.core.Core; +import de.steamwar.inventory.SWItem; +import org.bukkit.entity.Player; + +import java.util.List; + +public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: Last Column? + protected int scroll = 0; + protected final List data; + + protected SimulatorScrollGui(Player player, Simulator simulator, int size, List data) { + super(player, simulator, size); + this.data = data; + } + + private int maxScroll() { + return Math.max(0, Math.min(scroll, data.size() - 9)); + } + + @Override + public final String title() { + return baseTitle() + " " + scroll + "/" + maxScroll(); + } + + @Override + public final void populate() { + headerAndFooter(); + scroll = maxScroll(); + + inventory.setItem(size - 9, SWItem.getDye(scroll > 0 ? 10 : 8), scroll > 0 ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(scroll > 0 ? "SWLISINV_PREVIOUS_PAGE_ACTIVE" : "SWLISINV_PREVIOUS_PAGE_INACTIVE", player), clickType -> { + if (scroll > 0) { + scroll = Math.max(0, scroll - 9); + open(); + } + }); + boolean hasNext = scroll < maxScroll() - (data.size() % 9 == 0 ? 1 : 0); + inventory.setItem(size - 1, SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { + if (hasNext) { + scroll = Math.min(scroll + 9, maxScroll()); + open(); + } + }); + + for (int i = 0; i < Math.min(9, data.size()); i++) { + T element = data.get(scroll + i); + SWItem[] column = column(element); + for (int j = 0; j < column.length; j++) { + inventory.setItem(i + j * 9 + 9, column[j]); + } + } + } + + public abstract String baseTitle(); + + public void headerAndFooter() { + } + public abstract SWItem[] column(T t); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java new file mode 100644 index 00000000..2acac329 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java @@ -0,0 +1,77 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui.utils; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +public class SimulatorMaterialGui extends SimulatorPageGui { + + private static final List MATERIALS = Arrays.stream(Material.values()) + .filter(material -> !material.isAir()) + .filter(material -> !material.isLegacy()) + .filter(Material::isItem) + .collect(Collectors.toList()); + + private final Supplier currentMaterial; + private Material material; + private final Consumer change; + private final SimulatorBaseGui back; + + public SimulatorMaterialGui(Player player, Simulator simulator, Supplier currentMaterial, Consumer change, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, MATERIALS); + this.currentMaterial = currentMaterial; + this.change = change; + this.back = back; + } + + @Override + public String baseTitle() { + return "Material"; + } + + @Override + public void headerAndFooter() { + material = currentMaterial.get(); + inventory.setItem(4, new SWItem(material, "§eMaterial", clickType -> {})); + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + } + + @Override + public SWItem convert(Material material) { + return new SWItem(material, "§eNew Material", Arrays.asList(material == this.material ? "§eSelected" : "§eClick to select"), material == this.material, clickType -> { + change.accept(material); + SimulatorWatcher.update(simulator); + }); + } +} From 148761fa6387633ff5e43dca08b2d12fb461a29e Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Mon, 9 Oct 2023 16:54:41 +0200 Subject: [PATCH 009/139] Add Subpixel alignment to SimTNTSettingGui --- .../simulator2/gui/SimulatorTNTSettingsGui.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java index dc90b12b..3f338eed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Arrays; @@ -86,29 +87,29 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // Subpixel Alignment inventory.setItem(24, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { - // tnt.align(new Vector()); TODO Finalize + tnt.align(new Vector(0.5, 0, 0.5)); SimulatorWatcher.update(simulator); })); //z inventory.setItem(23, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { - + tnt.align(new Vector(0, 0, 0.49)); SimulatorWatcher.update(simulator); })); inventory.setItem(25, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { - + tnt.align(new Vector(0, 0, 0.51)); SimulatorWatcher.update(simulator); })); //X - inventory.setItem(15, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { - + inventory.setItem(15, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ X", clickType -> { + tnt.align(new Vector(0.49, 0, 0)); SimulatorWatcher.update(simulator); })); - inventory.setItem(33, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { - + inventory.setItem(33, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv X", clickType -> { + tnt.align(new Vector(0.51, 0, 0)); SimulatorWatcher.update(simulator); })); From 420cf4a5b84e0707ce73cd5db35fdd587e229603 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Tue, 10 Oct 2023 00:08:33 +0200 Subject: [PATCH 010/139] Finalize first gui version --- .../simulator2/data/SimulatorSetting.java | 12 ++ .../simulator2/data/tnt/TNTSetting.java | 11 ++ .../gui/SimulatorRedstonePhaseGui.java | 64 +++++- .../simulator2/gui/SimulatorTntPhaseGui.java | 182 ++++++++++++++++++ 4 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java index b8ecb79c..47385a47 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java @@ -28,4 +28,16 @@ public abstract class SimulatorSetting { protected int tickOffset; protected int lifetime = 80; protected int order = 1; + + public void changeOffset(int tick){ + tickOffset += tick; + } + + public void changeLifetime(int tick){ + lifetime += tick; + } + + public void changeOrder(int tick){ + order += tick; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java index 601c3ac5..58c64990 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java @@ -30,4 +30,15 @@ public class TNTSetting extends SimulatorSetting { private boolean xJump = false; private boolean yJump = false; private boolean zJump = false; + + public boolean hasJump(){ + if(xJump || yJump || zJump) return true; + else return false; + } + + public void setJump(boolean jump){ + xJump = jump; + yJump = jump; + zJump = jump; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java index 60be2a34..3a7ac38c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java @@ -29,6 +29,8 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; +import java.util.Arrays; + public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { private final RedstoneElement redstoneElement; @@ -48,7 +50,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { } @Override - public void populate() { // TODO: Finalize + public void populate() { if (!redstoneElement.getSettings().contains(redstone)) { back.open(); return; @@ -69,5 +71,65 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { back.open(); SimulatorWatcher.update(simulator); })); + + //Tick Offset + int offset = redstone.getTickOffset(); + inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.changeOffset(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + + SWItem offsetItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + offset, clickType -> {}); + + offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); + inventory.setItem(20, offsetItem); + inventory.setItem(29, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (offset - (clickType.isShiftClick() ? 5 : 1) < 0) { + redstone.changeOffset(-offset); + } else { + redstone.changeOffset(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + //Lifetime + int lifetime = redstone.getLifetime(); + inventory.setItem(12, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.changeLifetime(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + + SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {}); + + lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); + inventory.setItem(21, lifetimeItem); + inventory.setItem(30, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (lifetime - (clickType.isShiftClick() ? 5 : 1) < 0) { + redstone.changeLifetime(-lifetime); + } else { + redstone.changeLifetime(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + //Order + int order = redstone.getOrder(); + inventory.setItem(14, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.changeOrder(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + + SWItem orderItem = new SWItem(Material.COMPASS, "§eOrder§8:§7 " + order, clickType -> {}); + + orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); + inventory.setItem(23, orderItem); + inventory.setItem(32, SWItem.getDye(order > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (order - (clickType.isShiftClick() ? 5 : 1) < 1) { + redstone.changeOrder(-order); + } else { + redstone.changeOrder(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java new file mode 100644 index 00000000..db009b3c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java @@ -0,0 +1,182 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Arrays; + +public class SimulatorTntPhaseGui extends SimulatorBaseGui{ + private final TNTElement tntElement; + private final TNTSetting tnt; + private final SimulatorBaseGui back; + + public SimulatorTntPhaseGui(Player player, Simulator simulator, TNTElement tntElement, TNTSetting tnt, SimulatorBaseGui back) { + super(player, simulator, 5 * 9); + this.tntElement = tntElement; + this.tnt = tnt; + this.back = back; + } + + @Override + public String title() { + return "Tnt"; + } + + @Override + public void populate() { + if (!tntElement.getSettings().contains(tnt)) { + back.open(); + return; + } + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + inventory.setItem(4, new SWItem(tntElement.getMaterial(), "§TNT", clickType -> { + new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open(); + })); + + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + tntElement.getSettings().remove(tnt); + back.open(); + SimulatorWatcher.update(simulator); + })); + + //Count + int count = tnt.getCount(); + inventory.setItem(10, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + tnt.setCount(count + (clickType.isShiftClick() ? 5 : 1)); + SimulatorWatcher.update(simulator); + }); + + SWItem countItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + count, clickType -> {}); + + countItem.getItemStack().setAmount(Math.max(1, Math.min(count, 64))); + inventory.setItem(19, countItem); + inventory.setItem(28, SWItem.getDye(count > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (count - (clickType.isShiftClick() ? 5 : 1) < 1) { + tnt.setCount(1); + } else { + tnt.setCount(count + (clickType.isShiftClick() ? -5 : -1)); + } + SimulatorWatcher.update(simulator); + }); + + //Tick Offset + int offset = tnt.getTickOffset(); + inventory.setItem(10, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + tnt.changeOffset(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + + SWItem offsetItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + offset, clickType -> {}); + + offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); + inventory.setItem(19, offsetItem); + inventory.setItem(28, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (offset - (clickType.isShiftClick() ? 5 : 1) < 0) { + tnt.changeOffset(-offset); + } else { + tnt.changeOffset(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + //Lifetime + int lifetime = tnt.getLifetime(); + inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + tnt.changeLifetime(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + + SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {}); + + lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); + inventory.setItem(20, lifetimeItem); + inventory.setItem(29, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (lifetime - (clickType.isShiftClick() ? 5 : 1) < 0) { + tnt.changeLifetime(-lifetime); + } else { + tnt.changeLifetime(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + //Order + int order = tnt.getOrder(); + inventory.setItem(13, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + tnt.changeOrder(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + + SWItem orderItem = new SWItem(Material.COMPASS, "§eLifetime§8:§7 " + order, clickType -> {}); + + orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); + inventory.setItem(22, orderItem); + inventory.setItem(31, SWItem.getDye(order > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (order - (clickType.isShiftClick() ? 5 : 1) < 1) { + tnt.changeOrder(-order); + } else { + tnt.changeOrder(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + //Jump + SWItem jumpX = new SWItem(tnt.isXJump() ? Material.GREEN_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { + tnt.setXJump(!tnt.isXJump()); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(33, jumpX); + + SWItem jumpY = new SWItem(tnt.isYJump() ? Material.GREEN_WOOL : Material.RED_WOOL, "§7TNT §eJump Y§8: " + (tnt.isYJump() ? "§aon" : "§coff"), clickType -> { + tnt.setYJump(!tnt.isYJump()); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(16, jumpY); + + SWItem jumpZ = new SWItem(tnt.isZJump() ? Material.GREEN_WOOL : Material.RED_WOOL, "§7TNT §eJump Z§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { + tnt.setZJump(!tnt.isZJump()); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(35, jumpZ); + + SWItem jumpAll = new SWItem(Material.TNT, "§7TNT §eJump §8: " + (tnt.hasJump() ? "§aon" : "§coff"), clickType -> { + tnt.setJump(!tnt.hasJump()); + SimulatorWatcher.update(simulator); + }); + + //inventory.setItem(); + } +} From 273fba879e11d4845abaae717bf8bb44e50d5aa3 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Tue, 10 Oct 2023 00:17:38 +0200 Subject: [PATCH 011/139] Add Phase order upper limit --- .../bausystem/features/simulator2/data/SimulatorSetting.java | 1 + .../features/simulator2/gui/SimulatorRedstonePhaseGui.java | 4 ++-- .../features/simulator2/gui/SimulatorTntPhaseGui.java | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java index 47385a47..bcea1058 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java @@ -25,6 +25,7 @@ import lombok.Setter; @Getter @Setter public abstract class SimulatorSetting { + public static final int ORDER_LIMIT = 64; protected int tickOffset; protected int lifetime = 80; protected int order = 1; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java index 3a7ac38c..bb06e7cb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; @@ -32,7 +33,6 @@ import org.bukkit.entity.Player; import java.util.Arrays; public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { - private final RedstoneElement redstoneElement; private final RedstoneSetting redstone; private final SimulatorBaseGui back; @@ -115,7 +115,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { //Order int order = redstone.getOrder(); inventory.setItem(14, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.changeOrder(clickType.isShiftClick() ? 5 : 1); + redstone.setOrder(Math.min(SimulatorSetting.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java index db009b3c..9d732f03 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; @@ -136,7 +137,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ //Order int order = tnt.getOrder(); inventory.setItem(13, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - tnt.changeOrder(clickType.isShiftClick() ? 5 : 1); + tnt.setOrder(Math.min(SimulatorSetting.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); From f067e55d1fe40234c39b55821abf3a488553fa58 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Tue, 10 Oct 2023 00:37:19 +0200 Subject: [PATCH 012/139] Refactored PhaseGuis --- .../simulator2/data/SimulatorSetting.java | 12 ------ .../gui/SimulatorRedstonePhaseGui.java | 29 +++++--------- .../simulator2/gui/SimulatorTntPhaseGui.java | 38 ++++++------------- 3 files changed, 20 insertions(+), 59 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java index bcea1058..46d5a151 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java @@ -29,16 +29,4 @@ public abstract class SimulatorSetting { protected int tickOffset; protected int lifetime = 80; protected int order = 1; - - public void changeOffset(int tick){ - tickOffset += tick; - } - - public void changeLifetime(int tick){ - lifetime += tick; - } - - public void changeOrder(int tick){ - order += tick; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java index bb06e7cb..fd8b992a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java @@ -66,6 +66,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open(); })); + // Delete inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { redstoneElement.getSettings().remove(redstone); back.open(); @@ -75,40 +76,32 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { //Tick Offset int offset = redstone.getTickOffset(); inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.changeOffset(clickType.isShiftClick() ? 5 : 1); + redstone.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); SWItem offsetItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + offset, clickType -> {}); - offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(20, offsetItem); + inventory.setItem(29, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (offset - (clickType.isShiftClick() ? 5 : 1) < 0) { - redstone.changeOffset(-offset); - } else { - redstone.changeOffset(clickType.isShiftClick() ? -5 : -1); - } + redstone.setTickOffset(Math.max(1, offset - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); //Lifetime int lifetime = redstone.getLifetime(); inventory.setItem(12, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.changeLifetime(clickType.isShiftClick() ? 5 : 1); + redstone.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {}); - lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(21, lifetimeItem); + inventory.setItem(30, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (lifetime - (clickType.isShiftClick() ? 5 : 1) < 0) { - redstone.changeLifetime(-lifetime); - } else { - redstone.changeLifetime(clickType.isShiftClick() ? -5 : -1); - } + redstone.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); @@ -120,15 +113,11 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { }); SWItem orderItem = new SWItem(Material.COMPASS, "§eOrder§8:§7 " + order, clickType -> {}); - orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); inventory.setItem(23, orderItem); + inventory.setItem(32, SWItem.getDye(order > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (order - (clickType.isShiftClick() ? 5 : 1) < 1) { - redstone.changeOrder(-order); - } else { - redstone.changeOrder(clickType.isShiftClick() ? -5 : -1); - } + redstone.setOrder(Math.max(1, order - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java index 9d732f03..c8a45d1f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java @@ -68,6 +68,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open(); })); + //Delete inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { tntElement.getSettings().remove(tnt); back.open(); @@ -82,55 +83,43 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ }); SWItem countItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + count, clickType -> {}); - countItem.getItemStack().setAmount(Math.max(1, Math.min(count, 64))); inventory.setItem(19, countItem); + inventory.setItem(28, SWItem.getDye(count > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (count - (clickType.isShiftClick() ? 5 : 1) < 1) { - tnt.setCount(1); - } else { - tnt.setCount(count + (clickType.isShiftClick() ? -5 : -1)); - } + tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); //Tick Offset int offset = tnt.getTickOffset(); inventory.setItem(10, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - tnt.changeOffset(clickType.isShiftClick() ? 5 : 1); + tnt.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); SWItem offsetItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + offset, clickType -> {}); - offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(19, offsetItem); + inventory.setItem(28, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (offset - (clickType.isShiftClick() ? 5 : 1) < 0) { - tnt.changeOffset(-offset); - } else { - tnt.changeOffset(clickType.isShiftClick() ? -5 : -1); - } + tnt.setTickOffset(Math.max(1, offset - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); //Lifetime int lifetime = tnt.getLifetime(); inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - tnt.changeLifetime(clickType.isShiftClick() ? 5 : 1); + tnt.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {}); - lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(20, lifetimeItem); + inventory.setItem(29, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (lifetime - (clickType.isShiftClick() ? 5 : 1) < 0) { - tnt.changeLifetime(-lifetime); - } else { - tnt.changeLifetime(clickType.isShiftClick() ? -5 : -1); - } + tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); @@ -146,11 +135,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); inventory.setItem(22, orderItem); inventory.setItem(31, SWItem.getDye(order > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (order - (clickType.isShiftClick() ? 5 : 1) < 1) { - tnt.changeOrder(-order); - } else { - tnt.changeOrder(clickType.isShiftClick() ? -5 : -1); - } + tnt.setOrder(Math.max(1, order - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); @@ -177,7 +162,6 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ tnt.setJump(!tnt.hasJump()); SimulatorWatcher.update(simulator); }); - - //inventory.setItem(); + inventory.setItem(25, jumpAll); } } From 1b2d19c31dd816f54f0d4162a9b90183983f1fc9 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Tue, 10 Oct 2023 01:06:46 +0200 Subject: [PATCH 013/139] Add call to tnt phase menu --- .../bausystem/features/simulator2/gui/SimulatorTNTGui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index b979e930..ab522d11 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -103,7 +103,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> { - // Open Edit Phase menu + new SimulatorTntPhaseGui(player, simulator, tntElement, tntSetting, this).open(); }), }; } From 6e39f3e92a283726186b7c77d0d9cf82eb7f5ec1 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Tue, 10 Oct 2023 17:27:55 +0200 Subject: [PATCH 014/139] Made some fixes --- .../simulator2/gui/SimulatorTntPhaseGui.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java index c8a45d1f..e9b3defd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java @@ -86,7 +86,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ countItem.getItemStack().setAmount(Math.max(1, Math.min(count, 64))); inventory.setItem(19, countItem); - inventory.setItem(28, SWItem.getDye(count > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(28, SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); @@ -125,34 +125,34 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ //Order int order = tnt.getOrder(); - inventory.setItem(13, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(13, SWItem.getDye(order < SimulatorSetting.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setOrder(Math.min(SimulatorSetting.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); SWItem orderItem = new SWItem(Material.COMPASS, "§eLifetime§8:§7 " + order, clickType -> {}); - orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); inventory.setItem(22, orderItem); - inventory.setItem(31, SWItem.getDye(order > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + + inventory.setItem(31, SWItem.getDye(order > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setOrder(Math.max(1, order - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); //Jump - SWItem jumpX = new SWItem(tnt.isXJump() ? Material.GREEN_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { + SWItem jumpX = new SWItem(tnt.isXJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { tnt.setXJump(!tnt.isXJump()); SimulatorWatcher.update(simulator); }); inventory.setItem(33, jumpX); - SWItem jumpY = new SWItem(tnt.isYJump() ? Material.GREEN_WOOL : Material.RED_WOOL, "§7TNT §eJump Y§8: " + (tnt.isYJump() ? "§aon" : "§coff"), clickType -> { + SWItem jumpY = new SWItem(tnt.isYJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Y§8: " + (tnt.isYJump() ? "§aon" : "§coff"), clickType -> { tnt.setYJump(!tnt.isYJump()); SimulatorWatcher.update(simulator); }); inventory.setItem(16, jumpY); - SWItem jumpZ = new SWItem(tnt.isZJump() ? Material.GREEN_WOOL : Material.RED_WOOL, "§7TNT §eJump Z§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { + SWItem jumpZ = new SWItem(tnt.isZJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Z§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { tnt.setZJump(!tnt.isZJump()); SimulatorWatcher.update(simulator); }); From b5a81eb6db096dc67570d3384d8e1f054f21a0d8 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Thu, 12 Oct 2023 10:25:40 +0200 Subject: [PATCH 015/139] Add rmoval of empty group --- .../bausystem/features/simulator2/gui/SimulatorGui.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index 1a5d5325..2b019260 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -31,6 +31,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; public class SimulatorGui extends SimulatorPageGui { @@ -46,7 +47,12 @@ public class SimulatorGui extends SimulatorPageGui { @Override public void headerAndFooter() { - // TODO: Remove empty Groups + for(Iterator i = simulator.getElements().iterator(); i.hasNext();){ + if(i.next().getElements().isEmpty()){ + i.remove(); + } + } + inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); })); From 0f7c19da5a523c19e63cb94a2f6638d1a48e8d6f Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Thu, 12 Oct 2023 10:35:42 +0200 Subject: [PATCH 016/139] Add quick delete fo phases --- .../features/simulator2/gui/SimulatorRedstoneGui.java | 6 +++++- .../bausystem/features/simulator2/gui/SimulatorTNTGui.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index ae5a019a..08270b59 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -101,7 +101,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { @Override public SWItem[] column(RedstoneSetting redstoneSetting) { - SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Fuse§8:§e " + redstoneSetting.getLifetime(), "", "§7Order§8:§e " + redstoneSetting.getOrder()), false, clickType -> {}); + SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Fuse§8:§e " + redstoneSetting.getLifetime(), "", "§7Order§8:§e " + redstoneSetting.getOrder()), false, clickType -> { + //Quick remove per rightclick + if (clickType.isRightClick()) redstoneElement.getSettings().remove(redstoneSetting); + SimulatorWatcher.update(simulator); + }); redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64))); return new SWItem[] { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index ab522d11..532cc38c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -89,7 +89,11 @@ public class SimulatorTNTGui extends SimulatorScrollGui { @Override public SWItem[] column(TNTSetting tntSetting) { - SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff")), false, clickType -> {}); + SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff")), false, clickType -> { + //Quick remove per rightclick + if (clickType.isRightClick()) tntElement.getSettings().remove(tntSetting); + SimulatorWatcher.update(simulator); + }); tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64)); return new SWItem[] { From 68f81c8c3ed3f2d3216ed260b8a5eb9cd7b527a2 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Fri, 13 Oct 2023 12:02:55 +0200 Subject: [PATCH 017/139] Add last Phase and option for adding phase Refactored for coherent naming sceme --- .../simulator2/SimulatorTestCommand.java | 10 +++--- .../simulator2/data/SimulatorElement.java | 10 +++--- ...ulatorSetting.java => SimulatorPhase.java} | 7 ++-- .../data/redstone/RedstoneElement.java | 3 +- ...edstoneSetting.java => RedstonePhase.java} | 9 +++-- .../simulator2/data/tnt/TNTElement.java | 2 +- .../tnt/{TNTSetting.java => TNTPhase.java} | 8 +++-- .../simulator2/gui/SimulatorGroupGui.java | 2 +- .../features/simulator2/gui/SimulatorGui.java | 2 +- .../simulator2/gui/SimulatorRedstoneGui.java | 34 ++++++++++++------- ...=> SimulatorRedstonePhaseSettingsGui.java} | 16 ++++----- .../gui/SimulatorRedstoneSettingsGui.java | 4 +-- .../simulator2/gui/SimulatorTNTGui.java | 28 +++++++++++---- .../gui/SimulatorTNTSettingsGui.java | 2 +- ...java => SimulatorTntPhaseSettingsGui.java} | 20 +++++------ .../gui/base/SimulatorScrollGui.java | 29 ++++++++++++---- 16 files changed, 118 insertions(+), 68 deletions(-) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/{SimulatorSetting.java => SimulatorPhase.java} (90%) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/{RedstoneSetting.java => RedstonePhase.java} (76%) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/{TNTSetting.java => TNTPhase.java} (85%) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/{SimulatorRedstonePhaseGui.java => SimulatorRedstonePhaseSettingsGui.java} (89%) rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/{SimulatorTntPhaseGui.java => SimulatorTntPhaseSettingsGui.java} (88%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java index 1117a766..82b7703e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java @@ -22,9 +22,9 @@ package de.steamwar.bausystem.features.simulator2; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; @@ -39,13 +39,13 @@ public class SimulatorTestCommand extends SWCommand { public SimulatorTestCommand() { super("simtest"); - SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())).add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())); + SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())).add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())); SIMULATOR.getElements().add(group1); - SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())); + SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())); SIMULATOR.getElements().add(group2); - SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(0, 0, 0)).add(new RedstoneSetting())); + SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(0, 0, 0)).add(new RedstonePhase())); SIMULATOR.getElements().add(group3); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index a218ea6b..1274f7c8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -29,11 +29,11 @@ import java.util.List; @Getter @Setter -public abstract class SimulatorElement { +public abstract class SimulatorElement { protected Material material; protected final Vector position; protected boolean disabled = false; - protected final List settings = new ArrayList<>(); + protected final List phases = new ArrayList<>(); protected SimulatorElement(Material material, Vector position) { this.material = material; @@ -41,21 +41,21 @@ public abstract class SimulatorElement { } public SimulatorElement add(T setting) { - settings.add(setting); + phases.add(setting); return this; } public abstract String getName(); public int getBaseTick() { - return settings.stream() + return phases.stream() .mapToInt(value -> value.tickOffset) .min() .orElse(0); } public void changeBaseTicks(int tick) { - settings.forEach(t -> { + phases.forEach(t -> { t.tickOffset += tick; }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java similarity index 90% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java index 46d5a151..c77c2396 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java @@ -24,9 +24,12 @@ import lombok.Setter; @Getter @Setter -public abstract class SimulatorSetting { +public abstract class SimulatorPhase { public static final int ORDER_LIMIT = 64; - protected int tickOffset; + + protected int tickOffset = 0; protected int lifetime = 80; protected int order = 1; + + public SimulatorPhase(){}; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index a633ac45..bea1c83d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -23,8 +23,7 @@ import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import org.bukkit.Material; import org.bukkit.util.Vector; -public class RedstoneElement extends SimulatorElement { - +public class RedstoneElement extends SimulatorElement { public RedstoneElement(Vector position) { super(Material.REDSTONE_BLOCK, position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java similarity index 76% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java index 522f27a8..f22b3cee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java @@ -19,7 +19,12 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; -import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; +import org.bukkit.Material; -public class RedstoneSetting extends SimulatorSetting { +public class RedstonePhase extends SimulatorPhase { + public RedstonePhase(){}; + public RedstonePhase(int tickOffset){ + this.tickOffset = tickOffset; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index bbcfae6f..3eb27a82 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -23,7 +23,7 @@ import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import org.bukkit.Material; import org.bukkit.util.Vector; -public class TNTElement extends SimulatorElement { +public class TNTElement extends SimulatorElement { public TNTElement(Vector position) { super(Material.TNT, position); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java similarity index 85% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java index 58c64990..82bd03b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java @@ -19,18 +19,22 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; -import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import lombok.Getter; import lombok.Setter; @Getter @Setter -public class TNTSetting extends SimulatorSetting { +public class TNTPhase extends SimulatorPhase { private int count = 1; private boolean xJump = false; private boolean yJump = false; private boolean zJump = false; + public TNTPhase(){} + + public TNTPhase(int tickOffset){this.tickOffset = tickOffset;} + public boolean hasJump(){ if(xJump || yJump || zJump) return true; else return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index c9a4c68e..c38edc90 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -85,7 +85,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { @Override public SWItem convert(SimulatorElement element) { List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getSettings().size()); + lore.add("§7Phase count§8:§e " + element.getPhases().size()); lore.add("§7Tick§8:§e " + element.getBaseTick()); lore.add(""); lore.add("§7X§8:§e " + element.getPosition().getX()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index 2b019260..309c8b70 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -67,7 +67,7 @@ public class SimulatorGui extends SimulatorPageGui { if (elements.size() == 1) { SimulatorElement element = elements.get(0); List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getSettings().size()); + lore.add("§7Phase count§8:§e " + element.getPhases().size()); lore.add("§7Tick§8:§e " + element.getBaseTick()); lore.add(""); lore.add("§7X§8:§e " + element.getPosition().getX()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 08270b59..0f09eeab 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -23,8 +23,7 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; @@ -36,14 +35,14 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class SimulatorRedstoneGui extends SimulatorScrollGui { +public class SimulatorRedstoneGui extends SimulatorScrollGui { private final SimulatorGroup simulatorGroup; private final RedstoneElement redstoneElement; private final SimulatorBaseGui back; public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstoneElement, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, redstoneElement.getSettings()); + super(player, simulator, 6 * 9, redstoneElement.getPhases()); this.simulatorGroup = simulatorGroup; this.redstoneElement = redstoneElement; this.back = back; @@ -56,12 +55,6 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { @Override public void headerAndFooter() { - if (redstoneElement.getSettings().isEmpty()) { - simulatorGroup.getElements().remove(redstoneElement); - back.open(); - return; - } - // TODO Sort Data List // Back Arrow @@ -100,10 +93,10 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { } @Override - public SWItem[] column(RedstoneSetting redstoneSetting) { + public SWItem[] column(RedstonePhase redstoneSetting) { SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Fuse§8:§e " + redstoneSetting.getLifetime(), "", "§7Order§8:§e " + redstoneSetting.getOrder()), false, clickType -> { //Quick remove per rightclick - if (clickType.isRightClick()) redstoneElement.getSettings().remove(redstoneSetting); + if (clickType.isRightClick()) redstoneElement.getPhases().remove(redstoneSetting); SimulatorWatcher.update(simulator); }); redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64))); @@ -119,8 +112,23 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { - new SimulatorRedstonePhaseGui(player, simulator, redstoneElement, redstoneSetting, this).open(); + new SimulatorRedstonePhaseSettingsGui(player, simulator, redstoneElement, redstoneSetting, this).open(); }), }; } + + @Override + public SWItem[] lastColumn() { + return new SWItem[] { + new SWItem(SWItem.getDye(10), "§aNew Phase", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + RedstonePhase lastElement = redstoneElement.getPhases().get(redstoneElement.getPhases().size() - 1); + RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + 1); + if(clickType.isShiftClick()) newPhase.setTickOffset(newPhase.getTickOffset() + 4); + redstoneElement.add(newPhase); + SimulatorWatcher.update(simulator); + }), + new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§a New Phase", Arrays.asList(), false, clickType -> {}), + new SWItem(SWItem.getDye(8), "", Arrays.asList(), false, clickType -> {}), + }; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java similarity index 89% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java index fd8b992a..4479d75d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java @@ -21,9 +21,9 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; @@ -32,12 +32,12 @@ import org.bukkit.entity.Player; import java.util.Arrays; -public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { +public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { private final RedstoneElement redstoneElement; - private final RedstoneSetting redstone; + private final RedstonePhase redstone; private final SimulatorBaseGui back; - public SimulatorRedstonePhaseGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstoneSetting redstone, SimulatorBaseGui back) { + public SimulatorRedstonePhaseSettingsGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstonePhase redstone, SimulatorBaseGui back) { super(player, simulator, 5 * 9); this.redstoneElement = redstoneElement; this.redstone = redstone; @@ -51,7 +51,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { @Override public void populate() { - if (!redstoneElement.getSettings().contains(redstone)) { + if (!redstoneElement.getPhases().contains(redstone)) { back.open(); return; } @@ -68,7 +68,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { // Delete inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { - redstoneElement.getSettings().remove(redstone); + redstoneElement.getPhases().remove(redstone); back.open(); SimulatorWatcher.update(simulator); })); @@ -108,7 +108,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { //Order int order = redstone.getOrder(); inventory.setItem(14, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.setOrder(Math.min(SimulatorSetting.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); + redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java index c191f862..6461eb80 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java @@ -49,7 +49,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { @Override public void populate() { - if (redstone.getSettings().isEmpty()) { + if (redstone.getPhases().isEmpty()) { back.open(); return; } @@ -61,7 +61,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { // Material Chooser List lore = new ArrayList<>(); - lore.add("§7Activation count§8:§e " + redstone.getSettings().size()); + lore.add("§7Activation count§8:§e " + redstone.getPhases().size()); lore.add("§7Tick§8:§e " + redstone.getBaseTick()); if (redstone.isDisabled()) { lore.add(""); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index 532cc38c..15451b16 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -21,8 +21,9 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; @@ -34,13 +35,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class SimulatorTNTGui extends SimulatorScrollGui { +public class SimulatorTNTGui extends SimulatorScrollGui { private TNTElement tntElement; private SimulatorBaseGui back; public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tntElement, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, tntElement.getSettings()); + super(player, simulator, 6 * 9, tntElement.getPhases()); this.tntElement = tntElement; this.back = back; } @@ -88,10 +89,10 @@ public class SimulatorTNTGui extends SimulatorScrollGui { } @Override - public SWItem[] column(TNTSetting tntSetting) { + public SWItem[] column(TNTPhase tntSetting) { SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff")), false, clickType -> { //Quick remove per rightclick - if (clickType.isRightClick()) tntElement.getSettings().remove(tntSetting); + if (clickType.isRightClick()) tntElement.getPhases().remove(tntSetting); SimulatorWatcher.update(simulator); }); tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64)); @@ -107,8 +108,23 @@ public class SimulatorTNTGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> { - new SimulatorTntPhaseGui(player, simulator, tntElement, tntSetting, this).open(); + new SimulatorTntPhaseSettingsGui(player, simulator, tntElement, tntSetting, this).open(); }), }; } + + @Override + public SWItem[] lastColumn() { + return new SWItem[] { + new SWItem(SWItem.getDye(10), "§aNew Phase", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + TNTPhase lastElement = tntElement.getPhases().get(tntElement.getPhases().size() - 1); + TNTPhase newPhase = new TNTPhase(lastElement.getTickOffset() + 1); + if(clickType.isShiftClick()) newPhase.setCount(newPhase.getCount() + 4); + tntElement.add(newPhase); + SimulatorWatcher.update(simulator); + }), + new SWItem(Material.TNT, "§TNT§8:§a New Phase", Arrays.asList(), false, clickType -> {}), + new SWItem(SWItem.getDye(8), "", Arrays.asList(), false, clickType -> {}), + }; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java index 3f338eed..aaaed03e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java @@ -57,7 +57,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // Material Chooser List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + tnt.getSettings().size()); + lore.add("§7Phase count§8:§e " + tnt.getPhases().size()); lore.add("§7Tick§8:§e " + tnt.getBaseTick()); if (tnt.isDisabled()) { lore.add(""); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java similarity index 88% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java index e9b3defd..3c0a7daf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java @@ -21,11 +21,9 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; @@ -34,12 +32,12 @@ import org.bukkit.entity.Player; import java.util.Arrays; -public class SimulatorTntPhaseGui extends SimulatorBaseGui{ +public class SimulatorTntPhaseSettingsGui extends SimulatorBaseGui{ private final TNTElement tntElement; - private final TNTSetting tnt; + private final TNTPhase tnt; private final SimulatorBaseGui back; - public SimulatorTntPhaseGui(Player player, Simulator simulator, TNTElement tntElement, TNTSetting tnt, SimulatorBaseGui back) { + public SimulatorTntPhaseSettingsGui(Player player, Simulator simulator, TNTElement tntElement, TNTPhase tnt, SimulatorBaseGui back) { super(player, simulator, 5 * 9); this.tntElement = tntElement; this.tnt = tnt; @@ -53,7 +51,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ @Override public void populate() { - if (!tntElement.getSettings().contains(tnt)) { + if (!tntElement.getPhases().contains(tnt)) { back.open(); return; } @@ -70,7 +68,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ //Delete inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { - tntElement.getSettings().remove(tnt); + tntElement.getPhases().remove(tnt); back.open(); SimulatorWatcher.update(simulator); })); @@ -125,8 +123,8 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ //Order int order = tnt.getOrder(); - inventory.setItem(13, SWItem.getDye(order < SimulatorSetting.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - tnt.setOrder(Math.min(SimulatorSetting.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); + inventory.setItem(13, SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java index a61a4971..ab1bd0a7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java @@ -19,11 +19,15 @@ package de.steamwar.bausystem.features.simulator2.gui.base; +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; +import org.bukkit.Material; import org.bukkit.entity.Player; +import java.util.Arrays; import java.util.List; public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: Last Column? @@ -36,7 +40,7 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: } private int maxScroll() { - return Math.max(0, Math.min(scroll, data.size() - 9)); + return Math.max(0, Math.min(scroll, data.size() - 9 + 1)); } @Override @@ -63,11 +67,16 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: } }); - for (int i = 0; i < Math.min(9, data.size()); i++) { - T element = data.get(scroll + i); - SWItem[] column = column(element); - for (int j = 0; j < column.length; j++) { - inventory.setItem(i + j * 9 + 9, column[j]); + for (int i = 0; i < 9; i++) { + if(i < data.size()){ + T element = data.get(scroll + i); + SWItem[] column = column(element); + populateColumn(column, i); + } + else { + SWItem[] column = lastColumn(); + populateColumn(column, i); + break; } } } @@ -76,5 +85,13 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: public void headerAndFooter() { } + + public void populateColumn(SWItem[] column, int index){ + for (int j = 0; j < column.length; j++) { + inventory.setItem(index + j * 9 + 9, column[j]); + } + } public abstract SWItem[] column(T t); + + public abstract SWItem[] lastColumn(); } From 4eb3a310a787cd0a660a56eabd1f754b2dd3049b Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Fri, 13 Oct 2023 13:00:36 +0200 Subject: [PATCH 018/139] Add sorting of phases --- .../features/simulator2/data/SimulatorElement.java | 5 +++++ .../features/simulator2/gui/SimulatorRedstoneGui.java | 2 +- .../bausystem/features/simulator2/gui/SimulatorTNTGui.java | 5 +---- .../features/simulator2/gui/base/SimulatorScrollGui.java | 7 ++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 1274f7c8..477c59e4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -25,6 +25,7 @@ import org.bukkit.Material; import org.bukkit.util.Vector; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; @Getter @@ -45,6 +46,10 @@ public abstract class SimulatorElement { return this; } + public void sort(){ + phases.sort(Comparator.comparingInt(SimulatorPhase::getTickOffset)); + } + public abstract String getName(); public int getBaseTick() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 0f09eeab..77637112 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -55,7 +55,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { @Override public void headerAndFooter() { - // TODO Sort Data List + redstoneElement.sort(); // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index 15451b16..1cf8f6a4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; @@ -53,15 +52,13 @@ public class SimulatorTNTGui extends SimulatorScrollGui { @Override public void headerAndFooter() { - // TODO Back Jump + tntElement.sort(); // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); })); - // TODO Sort Data List - // Material Chooser List lore = new ArrayList<>(); lore.add("§7Phase count§8:§e " + data.size()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java index ab1bd0a7..d23d491b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java @@ -19,18 +19,15 @@ package de.steamwar.bausystem.features.simulator2.gui.base; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; + import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; -import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.Arrays; import java.util.List; -public abstract class SimulatorScrollGui extends SimulatorBaseGui { // TODO: Last Column? +public abstract class SimulatorScrollGui extends SimulatorBaseGui { protected int scroll = 0; protected final List data; From e47cf80d60a18c66966f6dd071ad233175e243e2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 17 Oct 2023 15:02:48 +0200 Subject: [PATCH 019/139] Finalize GUI --- .../features/simulator2/SimulatorWatcher.java | 2 +- .../simulator2/data/SimulatorElement.java | 2 +- .../simulator2/data/SimulatorGroup.java | 5 ++ .../simulator2/data/SimulatorPhase.java | 4 +- .../data/redstone/RedstoneElement.java | 1 + .../data/redstone/RedstonePhase.java | 10 ++- .../simulator2/data/tnt/TNTPhase.java | 17 ++--- .../features/simulator2/execute/.gitkeep | 0 .../simulator2/gui/SimulatorGroupGui.java | 2 + .../gui/SimulatorGroupSettingsGui.java | 3 +- .../features/simulator2/gui/SimulatorGui.java | 4 +- .../simulator2/gui/SimulatorRedstoneGui.java | 71 +++++++++++-------- .../SimulatorRedstonePhaseSettingsGui.java | 11 ++- .../gui/SimulatorRedstoneSettingsGui.java | 12 ++-- .../simulator2/gui/SimulatorSettingsGui.java | 2 +- .../simulator2/gui/SimulatorTNTGui.java | 71 +++++++++++-------- ...java => SimulatorTNTPhaseSettingsGui.java} | 24 ++++--- .../gui/SimulatorTNTSettingsGui.java | 39 ++++++---- .../simulator2/gui/base/SimulatorBaseGui.java | 21 ++++-- .../simulator2/gui/base/SimulatorPageGui.java | 3 +- .../gui/base/SimulatorScrollGui.java | 14 ++-- .../gui/utils/SimulatorMaterialGui.java | 3 +- .../features/simulator2/world/.gitkeep | 0 23 files changed, 197 insertions(+), 124 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/.gitkeep rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/{SimulatorTntPhaseSettingsGui.java => SimulatorTNTPhaseSettingsGui.java} (90%) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/world/.gitkeep diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java index 6c9a0c1e..2c6f8cbf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -36,7 +36,7 @@ import java.util.Map; public class SimulatorWatcher { private Map> watchers = new HashMap<>(); - + public void watch(Player player, Simulator simulator, Runnable watcher) { if (simulator == null || watcher == null) { watchers.remove(player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 477c59e4..59e39852 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -46,7 +46,7 @@ public abstract class SimulatorElement { return this; } - public void sort(){ + public void sort() { phases.sort(Comparator.comparingInt(SimulatorPhase::getTickOffset)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index b0a705b4..db52d1c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -24,6 +24,7 @@ import lombok.Setter; import org.bukkit.Material; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; @Getter @@ -38,6 +39,10 @@ public class SimulatorGroup { return this; } + public void sort() { + elements.sort(Comparator.comparingInt(SimulatorElement::getBaseTick)); + } + public int getBaseTick() { return elements.stream() .mapToInt(SimulatorElement::getBaseTick) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java index c77c2396..cc9c0011 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java @@ -25,11 +25,9 @@ import lombok.Setter; @Getter @Setter public abstract class SimulatorPhase { - public static final int ORDER_LIMIT = 64; + public static final int ORDER_LIMIT = 30; protected int tickOffset = 0; protected int lifetime = 80; protected int order = 1; - - public SimulatorPhase(){}; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index bea1c83d..f6acc458 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -24,6 +24,7 @@ import org.bukkit.Material; import org.bukkit.util.Vector; public class RedstoneElement extends SimulatorElement { + public RedstoneElement(Vector position) { super(Material.REDSTONE_BLOCK, position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java index f22b3cee..54686631 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java @@ -20,11 +20,17 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; +import lombok.NoArgsConstructor; import org.bukkit.Material; +@NoArgsConstructor public class RedstonePhase extends SimulatorPhase { - public RedstonePhase(){}; - public RedstonePhase(int tickOffset){ + + public RedstonePhase(int tickOffset) { this.tickOffset = tickOffset; } + + { + this.lifetime = 1; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java index 82bd03b6..0f04cdd9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java @@ -21,26 +21,27 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; @Getter @Setter +@NoArgsConstructor public class TNTPhase extends SimulatorPhase { private int count = 1; private boolean xJump = false; private boolean yJump = false; private boolean zJump = false; - public TNTPhase(){} - - public TNTPhase(int tickOffset){this.tickOffset = tickOffset;} - - public boolean hasJump(){ - if(xJump || yJump || zJump) return true; - else return false; + public TNTPhase(int tickOffset) { + this.tickOffset = tickOffset; } - public void setJump(boolean jump){ + public boolean hasJump() { + return xJump || yJump || zJump; + } + + public void setJump(boolean jump) { xJump = jump; yJump = jump; zJump = jump; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index c38edc90..85addcb4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -58,6 +58,8 @@ public class SimulatorGroupGui extends SimulatorPageGui> { return; } + simulatorGroup.sort(); + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java index 905972a0..2e335524 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java @@ -78,7 +78,8 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); }); - SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {}); + SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { + }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index 309c8b70..8387c540 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -47,8 +47,8 @@ public class SimulatorGui extends SimulatorPageGui { @Override public void headerAndFooter() { - for(Iterator i = simulator.getElements().iterator(); i.hasNext();){ - if(i.next().getElements().isEmpty()){ + for (Iterator i = simulator.getElements().iterator(); i.hasNext(); ) { + if (i.next().getElements().isEmpty()) { i.remove(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 77637112..759aa0ed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -30,6 +30,7 @@ import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import java.util.ArrayList; import java.util.Arrays; @@ -38,13 +39,13 @@ import java.util.List; public class SimulatorRedstoneGui extends SimulatorScrollGui { private final SimulatorGroup simulatorGroup; - private final RedstoneElement redstoneElement; + private final RedstoneElement redstone; private final SimulatorBaseGui back; - public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstoneElement, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, redstoneElement.getPhases()); + public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstone, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, redstone.getPhases()); this.simulatorGroup = simulatorGroup; - this.redstoneElement = redstoneElement; + this.redstone = redstone; this.back = back; } @@ -55,7 +56,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { @Override public void headerAndFooter() { - redstoneElement.sort(); + if (redstone.getPhases().isEmpty()) { + back.open(); + return; + } + + redstone.sort(); // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { @@ -65,43 +71,42 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { // Material Chooser List lore = new ArrayList<>(); lore.add("§7Activation count§8:§e " + data.size()); - lore.add("§7Tick§8:§e " + redstoneElement.getBaseTick()); + lore.add("§7Tick§8:§e " + redstone.getBaseTick()); lore.add(""); - lore.add("§7X§8:§e " + redstoneElement.getPosition().getX()); - lore.add("§7Y§8:§e " + redstoneElement.getPosition().getY()); - lore.add("§7Z§8:§e " + redstoneElement.getPosition().getZ()); - if (redstoneElement.isDisabled()) { + lore.add("§7X§8:§e " + redstone.getPosition().getX()); + lore.add("§7Y§8:§e " + redstone.getPosition().getY()); + lore.add("§7Z§8:§e " + redstone.getPosition().getZ()); + if (redstone.isDisabled()) { lore.add(""); lore.add("§cDisabled"); } - inventory.setItem(4, new SWItem(redstoneElement.getMaterial(), "§eTNT", lore, redstoneElement.isDisabled(), clickType -> { - new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open(); + inventory.setItem(4, new SWItem(redstone.getMaterial(), "§eTNT", lore, redstone.isDisabled(), clickType -> { + new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); })); //Settings inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { - new SimulatorRedstoneSettingsGui(player, simulator, redstoneElement, this).open(); + new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open(); })); // 49 Lead? //Enable/Disable - inventory.setItem(50, new SWItem(redstoneElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstoneElement.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { - redstoneElement.setDisabled(!redstoneElement.isDisabled()); + inventory.setItem(50, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + redstone.setDisabled(!redstone.isDisabled()); SimulatorWatcher.update(simulator); })); } @Override public SWItem[] column(RedstonePhase redstoneSetting) { - SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Fuse§8:§e " + redstoneSetting.getLifetime(), "", "§7Order§8:§e " + redstoneSetting.getOrder()), false, clickType -> { - //Quick remove per rightclick - if (clickType.isRightClick()) redstoneElement.getPhases().remove(redstoneSetting); + SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Activation Time§8:§e " + redstoneSetting.getLifetime(), "", "§7Middle-Click§8:§e Remove"), false, clickType -> { + if (clickType == ClickType.MIDDLE) this.redstone.getPhases().remove(redstoneSetting); SimulatorWatcher.update(simulator); }); redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64))); - return new SWItem[] { + return new SWItem[]{ new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { redstoneSetting.setTickOffset(redstoneSetting.getTickOffset() + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); @@ -112,23 +117,31 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { - new SimulatorRedstonePhaseSettingsGui(player, simulator, redstoneElement, redstoneSetting, this).open(); + new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSetting, this).open(); }), }; } @Override public SWItem[] lastColumn() { - return new SWItem[] { - new SWItem(SWItem.getDye(10), "§aNew Phase", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { - RedstonePhase lastElement = redstoneElement.getPhases().get(redstoneElement.getPhases().size() - 1); - RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + 1); - if(clickType.isShiftClick()) newPhase.setTickOffset(newPhase.getTickOffset() + 4); - redstoneElement.add(newPhase); - SimulatorWatcher.update(simulator); + return new SWItem[]{ + new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + addNewPhase(clickType.isShiftClick()); + }), + new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§a New Phase", clickType -> { + addNewPhase(false); + }), + new SWItem(SWItem.getDye(8), "§7", clickType -> { }), - new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§a New Phase", Arrays.asList(), false, clickType -> {}), - new SWItem(SWItem.getDye(8), "", Arrays.asList(), false, clickType -> {}), }; } + + private void addNewPhase(boolean shift) { + RedstonePhase lastElement = redstone.getPhases().get(redstone.getPhases().size() - 1); + RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + 1); + if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5); + scroll++; + redstone.add(newPhase); + SimulatorWatcher.update(simulator); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java index 4479d75d..72f56fb3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java @@ -80,7 +80,8 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); - SWItem offsetItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + offset, clickType -> {}); + SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { + }); offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(20, offsetItem); @@ -96,7 +97,8 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); - SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {}); + SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> { + }); lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(21, lifetimeItem); @@ -106,13 +108,15 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { }); //Order + /* int order = redstone.getOrder(); inventory.setItem(14, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); - SWItem orderItem = new SWItem(Material.COMPASS, "§eOrder§8:§7 " + order, clickType -> {}); + SWItem orderItem = new SWItem(Material.COMPASS, "§eOrder§8:§7 " + order, clickType -> { + }); orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); inventory.setItem(23, orderItem); @@ -120,5 +124,6 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { redstone.setOrder(Math.max(1, order - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); + */ } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java index 6461eb80..692a6858 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java @@ -77,7 +77,8 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); }); - SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {}); + SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { + }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { @@ -94,7 +95,8 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { redstone.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + redstone.getPosition().getBlockX(), clickType -> { + })); inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); @@ -105,7 +107,8 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { redstone.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + redstone.getPosition().getBlockY(), clickType -> { + })); inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); @@ -116,7 +119,8 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); }); - inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7" + redstone.getPosition().getBlockZ(), clickType -> { + })); inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java index acaf01da..d7d92bac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java @@ -49,7 +49,7 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); })); - + // Material Chooser inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index 1cf8f6a4..9ea81ce6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import java.util.ArrayList; import java.util.Arrays; @@ -36,12 +37,12 @@ import java.util.List; public class SimulatorTNTGui extends SimulatorScrollGui { - private TNTElement tntElement; + private TNTElement tnt; private SimulatorBaseGui back; - public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tntElement, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, tntElement.getPhases()); - this.tntElement = tntElement; + public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tnt, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, tnt.getPhases()); + this.tnt = tnt; this.back = back; } @@ -52,7 +53,12 @@ public class SimulatorTNTGui extends SimulatorScrollGui { @Override public void headerAndFooter() { - tntElement.sort(); + if (tnt.getPhases().isEmpty()) { + back.open(); + return; + } + + tnt.sort(); // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { @@ -62,39 +68,38 @@ public class SimulatorTNTGui extends SimulatorScrollGui { // Material Chooser List lore = new ArrayList<>(); lore.add("§7Phase count§8:§e " + data.size()); - lore.add("§7Tick§8:§e " + tntElement.getBaseTick()); + lore.add("§7Tick§8:§e " + tnt.getBaseTick()); lore.add(""); - lore.add("§7X§8:§e " + tntElement.getPosition().getX()); - lore.add("§7Y§8:§e " + tntElement.getPosition().getY()); - lore.add("§7Z§8:§e " + tntElement.getPosition().getZ()); - if (tntElement.isDisabled()) { + lore.add("§7X§8:§e " + tnt.getPosition().getX()); + lore.add("§7Y§8:§e " + tnt.getPosition().getY()); + lore.add("§7Z§8:§e " + tnt.getPosition().getZ()); + if (tnt.isDisabled()) { lore.add(""); lore.add("§cDisabled"); } - inventory.setItem(4, new SWItem(tntElement.getMaterial(), "§eTNT", lore, tntElement.isDisabled(), clickType -> { - new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open(); + inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> { + new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open(); })); inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { - // new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); + new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); // 49 Lead? - inventory.setItem(50, new SWItem(tntElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tntElement.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { - tntElement.setDisabled(!tntElement.isDisabled()); + inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + tnt.setDisabled(!tnt.isDisabled()); SimulatorWatcher.update(simulator); })); } @Override public SWItem[] column(TNTPhase tntSetting) { - SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff")), false, clickType -> { - //Quick remove per rightclick - if (clickType.isRightClick()) tntElement.getPhases().remove(tntSetting); + SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "", "§7Middle-Click§8:§e Remove"), false, clickType -> { + if (clickType == ClickType.MIDDLE) this.tnt.getPhases().remove(tntSetting); SimulatorWatcher.update(simulator); }); tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64)); - return new SWItem[] { + return new SWItem[]{ new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); @@ -105,23 +110,31 @@ public class SimulatorTNTGui extends SimulatorScrollGui { SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> { - new SimulatorTntPhaseSettingsGui(player, simulator, tntElement, tntSetting, this).open(); + new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open(); }), }; } @Override public SWItem[] lastColumn() { - return new SWItem[] { - new SWItem(SWItem.getDye(10), "§aNew Phase", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { - TNTPhase lastElement = tntElement.getPhases().get(tntElement.getPhases().size() - 1); - TNTPhase newPhase = new TNTPhase(lastElement.getTickOffset() + 1); - if(clickType.isShiftClick()) newPhase.setCount(newPhase.getCount() + 4); - tntElement.add(newPhase); - SimulatorWatcher.update(simulator); + return new SWItem[]{ + new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + addNewPhase(clickType.isShiftClick()); + }), + new SWItem(Material.TNT, "§eTNT§8:§a New Phase", clickType -> { + addNewPhase(false); + }), + new SWItem(SWItem.getDye(8), "§7", clickType -> { }), - new SWItem(Material.TNT, "§TNT§8:§a New Phase", Arrays.asList(), false, clickType -> {}), - new SWItem(SWItem.getDye(8), "", Arrays.asList(), false, clickType -> {}), }; } + + private void addNewPhase(boolean shift) { + TNTPhase lastElement = tnt.getPhases().get(tnt.getPhases().size() - 1); + TNTPhase newPhase = new TNTPhase(lastElement.getTickOffset() + 1); + if (shift) newPhase.setCount(newPhase.getCount() + 5); + scroll++; + tnt.add(newPhase); + SimulatorWatcher.update(simulator); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java similarity index 90% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java index 3c0a7daf..4f5fafad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java @@ -32,12 +32,12 @@ import org.bukkit.entity.Player; import java.util.Arrays; -public class SimulatorTntPhaseSettingsGui extends SimulatorBaseGui{ +public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { private final TNTElement tntElement; private final TNTPhase tnt; private final SimulatorBaseGui back; - public SimulatorTntPhaseSettingsGui(Player player, Simulator simulator, TNTElement tntElement, TNTPhase tnt, SimulatorBaseGui back) { + public SimulatorTNTPhaseSettingsGui(Player player, Simulator simulator, TNTElement tntElement, TNTPhase tnt, SimulatorBaseGui back) { super(player, simulator, 5 * 9); this.tntElement = tntElement; this.tnt = tnt; @@ -46,7 +46,7 @@ public class SimulatorTntPhaseSettingsGui extends SimulatorBaseGui{ @Override public String title() { - return "Tnt"; + return "TNT"; } @Override @@ -75,14 +75,15 @@ public class SimulatorTntPhaseSettingsGui extends SimulatorBaseGui{ //Count int count = tnt.getCount(); - inventory.setItem(10, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { tnt.setCount(count + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); - SWItem countItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + count, clickType -> {}); + SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> { + }); countItem.getItemStack().setAmount(Math.max(1, Math.min(count, 64))); - inventory.setItem(19, countItem); + inventory.setItem(18, countItem); inventory.setItem(28, SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? -5 : -1))); @@ -96,7 +97,8 @@ public class SimulatorTntPhaseSettingsGui extends SimulatorBaseGui{ SimulatorWatcher.update(simulator); }); - SWItem offsetItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + offset, clickType -> {}); + SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { + }); offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(19, offsetItem); @@ -112,7 +114,8 @@ public class SimulatorTntPhaseSettingsGui extends SimulatorBaseGui{ SimulatorWatcher.update(simulator); }); - SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {}); + SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> { + }); lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(20, lifetimeItem); @@ -128,8 +131,9 @@ public class SimulatorTntPhaseSettingsGui extends SimulatorBaseGui{ SimulatorWatcher.update(simulator); }); - SWItem orderItem = new SWItem(Material.COMPASS, "§eLifetime§8:§7 " + order, clickType -> {}); - orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); + SWItem orderItem = new SWItem(Material.COMPASS, "§eCalculation Order§8:§7 " + order, clickType -> { + }); + orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 30))); inventory.setItem(22, orderItem); inventory.setItem(31, SWItem.getDye(order > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java index aaaed03e..c9d47366 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java @@ -50,6 +50,11 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { @Override public void populate() { + if (tnt.getPhases().isEmpty()) { + back.open(); + return; + } + // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); @@ -73,7 +78,8 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); }); - SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {}); + SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { + }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { @@ -86,61 +92,64 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { }); // Subpixel Alignment - inventory.setItem(24, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { + inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { tnt.align(new Vector(0.5, 0, 0.5)); SimulatorWatcher.update(simulator); })); - - //z - inventory.setItem(23, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { + + // Z + inventory.setItem(20, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { tnt.align(new Vector(0, 0, 0.49)); SimulatorWatcher.update(simulator); })); - inventory.setItem(25, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { + inventory.setItem(22, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { tnt.align(new Vector(0, 0, 0.51)); SimulatorWatcher.update(simulator); })); - //X - inventory.setItem(15, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ X", clickType -> { + // X + inventory.setItem(12, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ X", clickType -> { tnt.align(new Vector(0.49, 0, 0)); SimulatorWatcher.update(simulator); })); - inventory.setItem(33, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv X", clickType -> { + inventory.setItem(30, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv X", clickType -> { tnt.align(new Vector(0.51, 0, 0)); SimulatorWatcher.update(simulator); })); - //Pos X + // Pos X inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? 0.0625 : 1, 0, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + tnt.getPosition().getX(), clickType -> { + })); inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0); SimulatorWatcher.update(simulator); }); - //Pos Y + // Pos Y inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? 0.0625 : 1, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + tnt.getPosition().getY(), clickType -> { + })); inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0); SimulatorWatcher.update(simulator); }); - //Pos Z + // Pos Z inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 1); SimulatorWatcher.update(simulator); }); - inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + tnt.getPosition().getZ(), clickType -> { + })); inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1); SimulatorWatcher.update(simulator); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java index 59079c64..5d1b667e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulator2.gui.base; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.core.Core; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; @@ -44,7 +45,9 @@ public abstract class SimulatorBaseGui { } public final void open() { - if (inv != null) { + if (inv != null && Core.getVersion() > 19) { + inv.clear(); + setup(); if (player.getOpenInventory().getTopInventory() != inv) { inventory.open(); SimulatorWatcher.watch(player, simulator, this::open); @@ -60,10 +63,7 @@ public abstract class SimulatorBaseGui { inv = Bukkit.createInventory(null, size, title()); return inv; }); - for (int i = 0; i < 9; i++) { - inventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8", clickType -> {})); - inventory.setItem(size - 9 + i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8", clickType -> {})); - } + setup(); inventory.addCloseCallback(clickType -> { SimulatorWatcher.watch(player, null, null); }); @@ -72,7 +72,16 @@ public abstract class SimulatorBaseGui { SimulatorWatcher.watch(player, simulator, this::open); populate(); } - + + private void setup() { + for (int i = 0; i < 9; i++) { + inventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8", clickType -> { + })); + inventory.setItem(size - 9 + i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8", clickType -> { + })); + } + } + public abstract String title(); public abstract void populate(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java index 22db341e..42eb1e17 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java @@ -69,7 +69,7 @@ public abstract class SimulatorPageGui extends SimulatorBaseGui { int index = 9; for (int i = minElement; i < maxElement; i++) { - T element = data.get(i); + T element = data.get(i); inventory.setItem(index++, convert(element)); } } @@ -78,5 +78,6 @@ public abstract class SimulatorPageGui extends SimulatorBaseGui { public void headerAndFooter() { } + public abstract SWItem convert(T t); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java index d23d491b..4a4fb128 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java @@ -42,7 +42,7 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { @Override public final String title() { - return baseTitle() + " " + scroll + "/" + maxScroll(); + return baseTitle() + " " + maxScroll() + "/" + Math.max((data.size() - 9 + 1), 0); } @Override @@ -56,21 +56,20 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { open(); } }); - boolean hasNext = scroll < maxScroll() - (data.size() % 9 == 0 ? 1 : 0); + boolean hasNext = (data.size() + 1) - scroll > 9; inventory.setItem(size - 1, SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> { if (hasNext) { - scroll = Math.min(scroll + 9, maxScroll()); + scroll = Math.min(scroll + 9, data.size() + 1 - 9); open(); } }); for (int i = 0; i < 9; i++) { - if(i < data.size()){ + if (scroll + i < data.size()) { T element = data.get(scroll + i); SWItem[] column = column(element); populateColumn(column, i); - } - else { + } else { SWItem[] column = lastColumn(); populateColumn(column, i); break; @@ -83,11 +82,12 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { public void headerAndFooter() { } - public void populateColumn(SWItem[] column, int index){ + public void populateColumn(SWItem[] column, int index) { for (int j = 0; j < column.length; j++) { inventory.setItem(index + j * 9 + 9, column[j]); } } + public abstract SWItem[] column(T t); public abstract SWItem[] lastColumn(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java index 2acac329..95d321a7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java @@ -61,7 +61,8 @@ public class SimulatorMaterialGui extends SimulatorPageGui { @Override public void headerAndFooter() { material = currentMaterial.get(); - inventory.setItem(4, new SWItem(material, "§eMaterial", clickType -> {})); + inventory.setItem(4, new SWItem(material, "§eMaterial", clickType -> { + })); inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { back.open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/world/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/world/.gitkeep new file mode 100644 index 00000000..e69de29b From b090b3150325d112e869681de8e15255378125a9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 17 Oct 2023 15:03:08 +0200 Subject: [PATCH 020/139] Finalize GUI --- .../gui/SimulatorRedstonePhaseSettingsGui.java | 6 +++--- .../simulator2/gui/SimulatorTNTPhaseSettingsGui.java | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java index 72f56fb3..0bce321f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java @@ -86,7 +86,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(20, offsetItem); inventory.setItem(29, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - redstone.setTickOffset(Math.max(1, offset - (clickType.isShiftClick() ? -5 : -1))); + redstone.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); @@ -103,7 +103,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(21, lifetimeItem); inventory.setItem(30, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - redstone.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? -5 : -1))); + redstone.setLifetime(Math.max(0, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); @@ -121,7 +121,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(23, orderItem); inventory.setItem(32, SWItem.getDye(order > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - redstone.setOrder(Math.max(1, order - (clickType.isShiftClick() ? -5 : -1))); + redstone.setOrder(Math.max(1, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); */ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java index 4f5fafad..852eadd3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java @@ -85,8 +85,8 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { countItem.getItemStack().setAmount(Math.max(1, Math.min(count, 64))); inventory.setItem(18, countItem); - inventory.setItem(28, SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? -5 : -1))); + inventory.setItem(27, SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); @@ -103,7 +103,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(19, offsetItem); inventory.setItem(28, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - tnt.setTickOffset(Math.max(1, offset - (clickType.isShiftClick() ? -5 : -1))); + tnt.setTickOffset(Math.max(1, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); @@ -120,7 +120,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(20, lifetimeItem); inventory.setItem(29, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? -5 : -1))); + tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); @@ -136,8 +136,8 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 30))); inventory.setItem(22, orderItem); - inventory.setItem(31, SWItem.getDye(order > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - tnt.setOrder(Math.max(1, order - (clickType.isShiftClick() ? -5 : -1))); + inventory.setItem(31, SWItem.getDye(order > -30 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + tnt.setOrder(Math.max(-30, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); From aef8edca07e4a622a71a41ae3a0c4913413fefc8 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Thu, 19 Oct 2023 10:29:59 +0200 Subject: [PATCH 021/139] Add group choosing and creation --- .../gui/SimulatorGroupChooserGui.java | 113 ++++++++++++++++++ .../simulator2/gui/SimulatorGroupGui.java | 4 +- .../features/simulator2/gui/SimulatorGui.java | 10 +- .../simulator2/gui/SimulatorRedstoneGui.java | 4 +- .../simulator2/gui/SimulatorTNTGui.java | 9 +- .../gui/SimulatorTNTSettingsGui.java | 4 +- 6 files changed, 130 insertions(+), 14 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java new file mode 100644 index 00000000..3a2e78f7 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java @@ -0,0 +1,113 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.gui; + +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class SimulatorGroupChooserGui extends SimulatorPageGui { + + private final SimulatorElement subject; + private final SimulatorGroup parent; + private final SimulatorBaseGui back; + + public SimulatorGroupChooserGui(Player player, Simulator simulator, List data, SimulatorElement subject, SimulatorGroup parent, SimulatorBaseGui back){ + super(player, simulator, 6*9, data); + this.subject = subject; + this.parent = parent; + this.back = back; + } + + @Override + public void headerAndFooter() { + simulator.getElements().removeIf(element -> element.getElements().isEmpty()); + + inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {})); + if(parent.getElements().size() != 1){ + inventory.setItem(49 , new SWItem(Material.BARRIER, "§c Remove from Group", clickType -> { + SimulatorGroup newParent = new SimulatorGroup(); + newParent.add(subject); + simulator.getElements().add(newParent); + back.open(); + SimulatorWatcher.update(simulator); + })); + } + } + @Override + public String baseTitle() { + return "§eChoose group to add to or element, to create new group"; + } + + @Override + public SWItem convert(SimulatorGroup simulatorGroup) { + List> elements = simulatorGroup.getElements(); + if (elements.size() == 1) { + SimulatorElement element = elements.get(0); + List lore = new ArrayList<>(); + lore.add("§7Phase count§8:§e " + element.getPhases().size()); + lore.add("§7Tick§8:§e " + element.getBaseTick()); + lore.add(""); + lore.add("§7X§8:§e " + element.getPosition().getX()); + lore.add("§7Y§8:§e " + element.getPosition().getY()); + lore.add("§7Z§8:§e " + element.getPosition().getZ()); + if (element.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { + SimulatorGroup newParent = new SimulatorGroup(); + newParent.add(subject); + newParent.add(element); + simulatorGroup.getElements().remove(element); + parent.getElements().remove(subject); + simulator.getElements().add(newParent); + back.open(); + SimulatorWatcher.update(simulator); + }); + } + + List lore = new ArrayList<>(); + lore.add("§7Element count§8:§e " + elements.size()); + lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); + if (simulatorGroup.isDisabled()) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + simulatorGroup.add(subject); + parent.getElements().remove(subject); + back.open(); + SimulatorWatcher.update(simulator); + }); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index 85addcb4..47dc1586 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -35,7 +35,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; -public class SimulatorGroupGui extends SimulatorPageGui> { +public class SimulatorGroupGui extends SimulatorPageGui> { //TODO Disolve group option ? private final SimulatorGroup simulatorGroup; private final SimulatorBaseGui back; @@ -99,7 +99,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { } return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { if (element instanceof TNTElement) { - new SimulatorTNTGui(player, simulator, (TNTElement) element, this).open(); + new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup, this).open(); } else if (element instanceof RedstoneElement) { new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index 8387c540..c4e233e6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -34,7 +34,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -public class SimulatorGui extends SimulatorPageGui { +public class SimulatorGui extends SimulatorPageGui {//TODO Groupcreation public SimulatorGui(Player player, Simulator simulator) { super(player, simulator, 6 * 9, simulator.getElements()); @@ -47,11 +47,7 @@ public class SimulatorGui extends SimulatorPageGui { @Override public void headerAndFooter() { - for (Iterator i = simulator.getElements().iterator(); i.hasNext(); ) { - if (i.next().getElements().isEmpty()) { - i.remove(); - } - } + simulator.getElements().removeIf(element -> element.getElements().isEmpty()); inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); @@ -79,7 +75,7 @@ public class SimulatorGui extends SimulatorPageGui { } return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { if (element instanceof TNTElement) { - new SimulatorTNTGui(player, simulator, (TNTElement) element, this).open(); + new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup,this).open(); } else if (element instanceof RedstoneElement) { new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 759aa0ed..6d66cd33 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -89,7 +89,9 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open(); })); - // 49 Lead? + inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { + new SimulatorGroupChooserGui(player, simulator, simulator.getElements(), redstone, simulatorGroup, this).open(); + })); //Enable/Disable inventory.setItem(50, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index 9ea81ce6..1672564f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -21,11 +21,13 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.bausystem.features.simulator2.gui.SimulatorTNTPhaseSettingsGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -38,9 +40,10 @@ import java.util.List; public class SimulatorTNTGui extends SimulatorScrollGui { private TNTElement tnt; + private SimulatorGroup parent; private SimulatorBaseGui back; - public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tnt, SimulatorBaseGui back) { + public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tnt, SimulatorGroup parent, SimulatorBaseGui back) { super(player, simulator, 6 * 9, tnt.getPhases()); this.tnt = tnt; this.back = back; @@ -84,7 +87,9 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); - // 49 Lead? + inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { + new SimulatorGroupChooserGui(player, simulator, simulator.getElements(), tnt, parent, this).open(); + })); inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); SimulatorWatcher.update(simulator); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java index c9d47366..1daf0ae4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java @@ -109,12 +109,12 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { })); // X - inventory.setItem(12, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ X", clickType -> { + inventory.setItem(12, new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { tnt.align(new Vector(0.49, 0, 0)); SimulatorWatcher.update(simulator); })); - inventory.setItem(30, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv X", clickType -> { + inventory.setItem(30, new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { tnt.align(new Vector(0.51, 0, 0)); SimulatorWatcher.update(simulator); })); From 647ef97bfb2ed5b23917235cebd8d2fdb159c1de Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sun, 22 Oct 2023 12:23:33 +0200 Subject: [PATCH 022/139] Add group chooser fix --- .../bausystem/features/simulator2/gui/SimulatorRedstoneGui.java | 1 + .../bausystem/features/simulator2/gui/SimulatorTNTGui.java | 1 + 2 files changed, 2 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 6d66cd33..a283e898 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -89,6 +89,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open(); })); + //Group chooser inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { new SimulatorGroupChooserGui(player, simulator, simulator.getElements(), redstone, simulatorGroup, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index 1672564f..091315b4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -46,6 +46,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tnt, SimulatorGroup parent, SimulatorBaseGui back) { super(player, simulator, 6 * 9, tnt.getPhases()); this.tnt = tnt; + this.parent = parent; this.back = back; } From 9ceb8b40aeb3bceac7b5120f1a6ec1b86f65bf62 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 12:29:38 +0200 Subject: [PATCH 023/139] Fix useless reopening in old versions --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 5 ----- .../features/simulator2/gui/base/SimulatorBaseGui.java | 9 +++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 88a46ddc..bb60156f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -31,7 +31,6 @@ import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.message.Message; import lombok.Getter; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -53,12 +52,8 @@ public class BauSystem extends JavaPlugin implements Listener { @Getter private static BauSystem instance; - private World world; - @Override public void onEnable() { - world = Bukkit.getWorlds().get(0); - // LOGGER fixLogging(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java index 5d1b667e..00ef9c24 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java @@ -45,14 +45,19 @@ public abstract class SimulatorBaseGui { } public final void open() { - if (inv != null && Core.getVersion() > 19) { + String newTitle = title(); + String originalTitle = player.getOpenInventory().getTitle(); + + if (inv != null && (newTitle.equals(originalTitle) || Core.getVersion() > 19)) { inv.clear(); setup(); if (player.getOpenInventory().getTopInventory() != inv) { inventory.open(); SimulatorWatcher.watch(player, simulator, this::open); } - player.getOpenInventory().setTitle(title()); + if (Core.getVersion() > 19) { + player.getOpenInventory().setTitle(title()); + } populate(); return; } From f6ee55c44fdcca521de84084a09cf2875f417631 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 12:31:19 +0200 Subject: [PATCH 024/139] Optimize SimulatorBaseGui --- .../features/simulator2/gui/base/SimulatorBaseGui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java index 00ef9c24..b15ba629 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java @@ -48,7 +48,7 @@ public abstract class SimulatorBaseGui { String newTitle = title(); String originalTitle = player.getOpenInventory().getTitle(); - if (inv != null && (newTitle.equals(originalTitle) || Core.getVersion() > 19)) { + if (inv != null && (Core.getVersion() > 19 || newTitle.equals(originalTitle))) { inv.clear(); setup(); if (player.getOpenInventory().getTopInventory() != inv) { From 933e4fe7d9e9a1c0fe968b4e8001d580749ffaea Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sun, 22 Oct 2023 12:43:20 +0200 Subject: [PATCH 025/139] Removed parent group from group chooser menu --- .../features/simulator2/gui/SimulatorRedstoneGui.java | 3 ++- .../bausystem/features/simulator2/gui/SimulatorTNTGui.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index a283e898..23af0ac4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -35,6 +35,7 @@ import org.bukkit.event.inventory.ClickType; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; public class SimulatorRedstoneGui extends SimulatorScrollGui { @@ -91,7 +92,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { //Group chooser inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { - new SimulatorGroupChooserGui(player, simulator, simulator.getElements(), redstone, simulatorGroup, this).open(); + new SimulatorGroupChooserGui(player, simulator, simulator.getElements().stream().filter( e -> e != simulatorGroup).collect(Collectors.toList()), redstone, simulatorGroup, this).open(); })); //Enable/Disable diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index 091315b4..d6dc192a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -36,6 +36,7 @@ import org.bukkit.event.inventory.ClickType; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; public class SimulatorTNTGui extends SimulatorScrollGui { @@ -89,7 +90,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { - new SimulatorGroupChooserGui(player, simulator, simulator.getElements(), tnt, parent, this).open(); + new SimulatorGroupChooserGui(player, simulator, simulator.getElements().stream().filter( e -> e != parent).collect(Collectors.toList()), tnt, parent, this).open(); })); inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); From 327dded73b8d000fe62d291a4e9eb26232392aec Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 13:24:50 +0200 Subject: [PATCH 026/139] Consolidate Item Generation Fix Back arrow in element gui --- .../features/simulator2/data/Simulator.java | 7 +++ .../simulator2/data/SimulatorElement.java | 18 ++++++ .../simulator2/data/SimulatorGroup.java | 18 ++++++ .../gui/SimulatorGroupChooserGui.java | 61 ++++--------------- .../simulator2/gui/SimulatorGroupGui.java | 29 ++------- .../gui/SimulatorGroupSettingsGui.java | 13 +--- .../features/simulator2/gui/SimulatorGui.java | 47 +++----------- .../simulator2/gui/SimulatorRedstoneGui.java | 41 +++++++------ .../SimulatorRedstonePhaseSettingsGui.java | 2 +- .../gui/SimulatorRedstoneSettingsGui.java | 9 +-- .../simulator2/gui/SimulatorSettingsGui.java | 2 +- .../simulator2/gui/SimulatorTNTGui.java | 34 ++++++----- .../gui/SimulatorTNTPhaseSettingsGui.java | 2 +- .../gui/SimulatorTNTSettingsGui.java | 2 +- 14 files changed, 120 insertions(+), 165 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java index a856a54a..df486e6c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -19,10 +19,13 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.inventory.InvCallback; +import de.steamwar.inventory.SWItem; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; import org.bukkit.Material; +import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; @@ -41,4 +44,8 @@ public class Simulator { simulatorGroup.move(x, y, z); }); } + + public SWItem toItem(Player player, InvCallback invCallback) { + return new SWItem(material, "§e" + name, invCallback); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 59e39852..3a5cf861 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -19,9 +19,12 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.inventory.InvCallback; +import de.steamwar.inventory.SWItem; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.util.ArrayList; @@ -70,4 +73,19 @@ public abstract class SimulatorElement { position.setY(position.getY() + y); position.setZ(position.getZ() + z); } + + public SWItem toItem(Player player, InvCallback invCallback) { + List lore = new ArrayList<>(); + lore.add("§7Phase count§8:§e " + phases.size()); + lore.add("§7Tick§8:§e " + getBaseTick()); + lore.add(""); + lore.add("§7X§8:§e " + position.getX()); + lore.add("§7Y§8:§e " + position.getY()); + lore.add("§7Z§8:§e " + position.getZ()); + if (disabled) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(material, "§e" + getName(), lore, disabled, invCallback); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index db52d1c3..86bcba99 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -19,9 +19,12 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.inventory.InvCallback; +import de.steamwar.inventory.SWItem; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; +import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Comparator; @@ -61,4 +64,19 @@ public class SimulatorGroup { simulatorElement.move(x, y, z); }); } + + public SWItem toItem(Player player, InvCallback groupCallback, InvCallback itemCallback) { + if (elements.size() == 1) { + return elements.get(0).toItem(player, itemCallback); + } else { + List lore = new ArrayList<>(); + lore.add("§7Element count§8:§e " + elements.size()); + lore.add("§7Tick§8:§e " + getBaseTick()); + if (disabled) { + lore.add(""); + lore.add("§cDisabled"); + } + return new SWItem(material, "§eGroup", lore, disabled, groupCallback); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java index 3a2e78f7..8cecb246 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java @@ -23,17 +23,14 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; +import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; +import java.util.stream.Collectors; public class SimulatorGroupChooserGui extends SimulatorPageGui { @@ -41,8 +38,8 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { private final SimulatorGroup parent; private final SimulatorBaseGui back; - public SimulatorGroupChooserGui(Player player, Simulator simulator, List data, SimulatorElement subject, SimulatorGroup parent, SimulatorBaseGui back){ - super(player, simulator, 6*9, data); + public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement subject, SimulatorGroup parent, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, simulator.getElements().stream().filter(e -> e != parent).collect(Collectors.toList())); this.subject = subject; this.parent = parent; this.back = back; @@ -50,11 +47,10 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { @Override public void headerAndFooter() { - simulator.getElements().removeIf(element -> element.getElements().isEmpty()); - - inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {})); - if(parent.getElements().size() != 1){ - inventory.setItem(49 , new SWItem(Material.BARRIER, "§c Remove from Group", clickType -> { + inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { + })); + if (parent.getElements().size() != 1) { + inventory.setItem(49, new SWItem(Material.BARRIER, "§cRemove from Group", clickType -> { SimulatorGroup newParent = new SimulatorGroup(); newParent.add(subject); simulator.getElements().add(newParent); @@ -63,51 +59,20 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { })); } } + @Override public String baseTitle() { - return "§eChoose group to add to or element, to create new group"; + return "Choose Group"; } @Override public SWItem convert(SimulatorGroup simulatorGroup) { - List> elements = simulatorGroup.getElements(); - if (elements.size() == 1) { - SimulatorElement element = elements.get(0); - List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getPhases().size()); - lore.add("§7Tick§8:§e " + element.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + element.getPosition().getX()); - lore.add("§7Y§8:§e " + element.getPosition().getY()); - lore.add("§7Z§8:§e " + element.getPosition().getZ()); - if (element.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { - SimulatorGroup newParent = new SimulatorGroup(); - newParent.add(subject); - newParent.add(element); - simulatorGroup.getElements().remove(element); - parent.getElements().remove(subject); - simulator.getElements().add(newParent); - back.open(); - SimulatorWatcher.update(simulator); - }); - } - - List lore = new ArrayList<>(); - lore.add("§7Element count§8:§e " + elements.size()); - lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); - if (simulatorGroup.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + InvCallback invCallback = clickType -> { simulatorGroup.add(subject); parent.getElements().remove(subject); back.open(); SimulatorWatcher.update(simulator); - }); + }; + return simulatorGroup.toItem(player, invCallback, invCallback); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index 47dc1586..23a2354c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -32,10 +32,7 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; - -public class SimulatorGroupGui extends SimulatorPageGui> { //TODO Disolve group option ? +public class SimulatorGroupGui extends SimulatorPageGui> { private final SimulatorGroup simulatorGroup; private final SimulatorBaseGui back; @@ -64,16 +61,9 @@ public class SimulatorGroupGui extends SimulatorPageGui> { / back.open(); })); - List lore = new ArrayList<>(); - lore.add("§7Element count§8:§e " + data.size()); - lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); - if (simulatorGroup.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); - })); + }, clickType -> {})); inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); @@ -86,18 +76,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { / @Override public SWItem convert(SimulatorElement element) { - List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getPhases().size()); - lore.add("§7Tick§8:§e " + element.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + element.getPosition().getX()); - lore.add("§7Y§8:§e " + element.getPosition().getY()); - lore.add("§7Z§8:§e " + element.getPosition().getZ()); - if (element.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { + return element.toItem(player, clickType -> { if (element instanceof TNTElement) { new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup, this).open(); } else if (element instanceof RedstoneElement) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java index 2e335524..df5b06fe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java @@ -28,9 +28,7 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class SimulatorGroupSettingsGui extends SimulatorBaseGui { @@ -61,16 +59,9 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { })); // Material Chooser - List lore = new ArrayList<>(); - lore.add("§7Element count§8:§e " + simulatorGroup.getElements().size()); - lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); - if (simulatorGroup.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); - })); + }, clickType -> {})); // Base Tick int baseTicks = simulatorGroup.getBaseTick(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index c4e233e6..932fc4a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -30,11 +30,7 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class SimulatorGui extends SimulatorPageGui {//TODO Groupcreation +public class SimulatorGui extends SimulatorPageGui { public SimulatorGui(Player player, Simulator simulator) { super(player, simulator, 6 * 9, simulator.getElements()); @@ -49,7 +45,7 @@ public class SimulatorGui extends SimulatorPageGui {//TODO Group public void headerAndFooter() { simulator.getElements().removeIf(element -> element.getElements().isEmpty()); - inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { + inventory.setItem(4, simulator.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); })); inventory.setItem(49, new SWItem(Material.REPEATER, "§eSettings", clickType -> { @@ -59,38 +55,15 @@ public class SimulatorGui extends SimulatorPageGui {//TODO Group @Override public SWItem convert(SimulatorGroup simulatorGroup) { - List> elements = simulatorGroup.getElements(); - if (elements.size() == 1) { - SimulatorElement element = elements.get(0); - List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + element.getPhases().size()); - lore.add("§7Tick§8:§e " + element.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + element.getPosition().getX()); - lore.add("§7Y§8:§e " + element.getPosition().getY()); - lore.add("§7Z§8:§e " + element.getPosition().getZ()); - if (element.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> { - if (element instanceof TNTElement) { - new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup,this).open(); - } else if (element instanceof RedstoneElement) { - new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); - } - }); - } - - List lore = new ArrayList<>(); - lore.add("§7Element count§8:§e " + elements.size()); - lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick()); - if (simulatorGroup.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - return new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> { + return simulatorGroup.toItem(player, clickType -> { new SimulatorGroupGui(player, simulator, simulatorGroup, this).open(); + }, clickType -> { + SimulatorElement element = simulatorGroup.getElements().get(0); + if (element instanceof TNTElement) { + new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup,this).open(); + } else if (element instanceof RedstoneElement) { + new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); + } }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 23af0ac4..efb64277 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -35,17 +35,16 @@ import org.bukkit.event.inventory.ClickType; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; public class SimulatorRedstoneGui extends SimulatorScrollGui { - private final SimulatorGroup simulatorGroup; + private final SimulatorGroup parent; private final RedstoneElement redstone; private final SimulatorBaseGui back; - public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstone, SimulatorBaseGui back) { + public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup parent, RedstoneElement redstone, SimulatorBaseGui back) { super(player, simulator, 6 * 9, redstone.getPhases()); - this.simulatorGroup = simulatorGroup; + this.parent = parent; this.redstone = redstone; this.back = back; } @@ -66,22 +65,28 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { - back.open(); + if (parent.getElements().contains(redstone)) { + back.open(); + } else { + SimulatorGroup newParent = simulator.getElements().stream() + .filter(simulatorGroup -> simulatorGroup.getElements().contains(redstone)) + .findFirst() + .orElse(null); + if (newParent == null) { + player.closeInventory(); + return; + } + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + if (newParent.getElements().size() == 1) { + simulatorGui.open(); + } else { + new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); + } + } })); // Material Chooser - List lore = new ArrayList<>(); - lore.add("§7Activation count§8:§e " + data.size()); - lore.add("§7Tick§8:§e " + redstone.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + redstone.getPosition().getX()); - lore.add("§7Y§8:§e " + redstone.getPosition().getY()); - lore.add("§7Z§8:§e " + redstone.getPosition().getZ()); - if (redstone.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(redstone.getMaterial(), "§eTNT", lore, redstone.isDisabled(), clickType -> { + inventory.setItem(4, redstone.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); })); @@ -92,7 +97,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { //Group chooser inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { - new SimulatorGroupChooserGui(player, simulator, simulator.getElements().stream().filter( e -> e != simulatorGroup).collect(Collectors.toList()), redstone, simulatorGroup, this).open(); + new SimulatorGroupChooserGui(player, simulator, redstone, parent, this).open(); })); //Enable/Disable diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java index 0bce321f..7835261d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java @@ -62,7 +62,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { })); // Material Chooser - inventory.setItem(4, new SWItem(redstoneElement.getMaterial(), "§eRedstone", clickType -> { + inventory.setItem(4, redstoneElement.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java index 692a6858..7152cc6f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java @@ -60,14 +60,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { })); // Material Chooser - List lore = new ArrayList<>(); - lore.add("§7Activation count§8:§e " + redstone.getPhases().size()); - lore.add("§7Tick§8:§e " + redstone.getBaseTick()); - if (redstone.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(redstone.getMaterial(), "§eRedstone", lore, redstone.isDisabled(), clickType -> { + inventory.setItem(4, redstone.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java index d7d92bac..b9e75a5e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java @@ -51,7 +51,7 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { })); // Material Chooser - inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> { + inventory.setItem(4, simulator.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index d6dc192a..34906cd0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -67,22 +67,28 @@ public class SimulatorTNTGui extends SimulatorScrollGui { // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { - back.open(); + if (parent.getElements().contains(tnt)) { + back.open(); + } else { + SimulatorGroup newParent = simulator.getElements().stream() + .filter(simulatorGroup -> simulatorGroup.getElements().contains(tnt)) + .findFirst() + .orElse(null); + if (newParent == null) { + player.closeInventory(); + return; + } + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + if (newParent.getElements().size() == 1) { + simulatorGui.open(); + } else { + new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); + } + } })); // Material Chooser - List lore = new ArrayList<>(); - lore.add("§7Phase count§8:§e " + data.size()); - lore.add("§7Tick§8:§e " + tnt.getBaseTick()); - lore.add(""); - lore.add("§7X§8:§e " + tnt.getPosition().getX()); - lore.add("§7Y§8:§e " + tnt.getPosition().getY()); - lore.add("§7Z§8:§e " + tnt.getPosition().getZ()); - if (tnt.isDisabled()) { - lore.add(""); - lore.add("§cDisabled"); - } - inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> { + inventory.setItem(4, tnt.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open(); })); @@ -90,7 +96,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { - new SimulatorGroupChooserGui(player, simulator, simulator.getElements().stream().filter( e -> e != parent).collect(Collectors.toList()), tnt, parent, this).open(); + new SimulatorGroupChooserGui(player, simulator, tnt, parent, this).open(); })); inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java index 852eadd3..2f8d548a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java @@ -62,7 +62,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { })); // Material Chooser - inventory.setItem(4, new SWItem(tntElement.getMaterial(), "§TNT", clickType -> { + inventory.setItem(4, tntElement.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java index 1daf0ae4..074e86c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java @@ -68,7 +68,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { lore.add(""); lore.add("§cDisabled"); } - inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> { + inventory.setItem(4, tnt.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open(); })); From 834039c4d403b30f554f4c0e722cdc65c9d60f89 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 13:25:00 +0200 Subject: [PATCH 027/139] Consolidate Item Generation Fix Back arrow in element gui --- .../features/simulator2/gui/SimulatorGroupChooserGui.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java index 8cecb246..503feb86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java @@ -54,6 +54,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { SimulatorGroup newParent = new SimulatorGroup(); newParent.add(subject); simulator.getElements().add(newParent); + parent.getElements().remove(subject); back.open(); SimulatorWatcher.update(simulator); })); From 35060834168ed1299dd6e9ca18483306a8cb0cec Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 14:25:54 +0200 Subject: [PATCH 028/139] Add SimulatorExecutor --- .../simulator2/SimulatorTestCommand.java | 17 ++-- .../features/simulator2/data/Simulator.java | 8 ++ .../simulator2/data/SimulatorElement.java | 9 +++ .../simulator2/data/SimulatorGroup.java | 9 +++ .../simulator2/data/SimulatorPhase.java | 7 ++ .../data/redstone/RedstonePhase.java | 32 ++++++++ .../simulator2/data/tnt/TNTPhase.java | 22 +++++ .../features/simulator2/execute/.gitkeep | 0 .../simulator2/execute/SimulatorAction.java | 36 +++++++++ .../simulator2/execute/SimulatorExecutor.java | 81 +++++++++++++++++++ .../gui/SimulatorTNTPhaseSettingsGui.java | 2 +- 11 files changed, 217 insertions(+), 6 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/.gitkeep create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorAction.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorExecutor.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java index 82b7703e..e66d7f21 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java @@ -25,9 +25,11 @@ import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; +import jdk.jfr.Registered; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -39,18 +41,23 @@ public class SimulatorTestCommand extends SWCommand { public SimulatorTestCommand() { super("simtest"); - SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())).add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())); + SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(-477.5, 46, 311.5)).add(new TNTPhase())); SIMULATOR.getElements().add(group1); - SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTPhase())); + SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(-477.5, 47, 312.5)).add(new TNTPhase())); SIMULATOR.getElements().add(group2); - SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(0, 0, 0)).add(new RedstonePhase())); + SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(-484, 47, 307)).add(new RedstonePhase())); SIMULATOR.getElements().add(group3); } - @Register - public void genericCommand(Player player, String... args) { + @Register("open") + public void openCommand(Player player) { new SimulatorGui(player, SIMULATOR).open(); } + + @Register("run") + public void runCommand(Player player) { + SimulatorExecutor.run(SIMULATOR); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java index df486e6c..73f0ab1d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import lombok.Getter; @@ -29,6 +30,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; +import java.util.Map; @Getter @Setter @@ -48,4 +50,10 @@ public class Simulator { public SWItem toItem(Player player, InvCallback invCallback) { return new SWItem(material, "§e" + name, invCallback); } + + public void toSimulatorActions(Map> actions) { + elements.forEach(simulatorGroup -> { + simulatorGroup.toSimulatorActions(actions); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 3a5cf861..3f5136c0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import lombok.Getter; @@ -30,6 +31,7 @@ import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Map; @Getter @Setter @@ -88,4 +90,11 @@ public abstract class SimulatorElement { } return new SWItem(material, "§e" + getName(), lore, disabled, invCallback); } + + public void toSimulatorActions(Map> actions) { + if (disabled) return; + phases.forEach(phase -> { + phase.toSimulatorActions(actions, position.clone()); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index 86bcba99..1c3ac29c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import lombok.Getter; @@ -29,6 +30,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Map; @Getter @Setter @@ -79,4 +81,11 @@ public class SimulatorGroup { return new SWItem(material, "§eGroup", lore, disabled, groupCallback); } } + + public void toSimulatorActions(Map> actions) { + if (disabled) return; + elements.forEach(simulatorElement -> { + simulatorElement.toSimulatorActions(actions); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java index cc9c0011..126775b5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java @@ -19,8 +19,13 @@ package de.steamwar.bausystem.features.simulator2.data; +import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; import lombok.Getter; import lombok.Setter; +import org.bukkit.util.Vector; + +import java.util.List; +import java.util.Map; @Getter @Setter @@ -30,4 +35,6 @@ public abstract class SimulatorPhase { protected int tickOffset = 0; protected int lifetime = 80; protected int order = 1; + + public abstract void toSimulatorActions(Map> actions, Vector position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java index 54686631..e8b1c210 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java @@ -20,8 +20,18 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; import lombok.NoArgsConstructor; import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; @NoArgsConstructor public class RedstonePhase extends SimulatorPhase { @@ -33,4 +43,26 @@ public class RedstonePhase extends SimulatorPhase { { this.lifetime = 1; } + + @Override + public void toSimulatorActions(Map> actions, Vector position) { + AtomicReference previousBlockState = new AtomicReference<>(); + actions.computeIfAbsent(tickOffset, __ -> new ArrayList<>()) + .add(new SimulatorAction(0, 1) { + @Override + public void accept(World world) { + Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + previousBlockState.set(block.getState()); + block.setType(Material.REDSTONE_BLOCK); + } + }); + + actions.computeIfAbsent(tickOffset + lifetime, __ -> new ArrayList<>()) + .add(new SimulatorAction(0, 1) { + @Override + public void accept(World world) { + previousBlockState.get().update(true, true); + } + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java index 0f04cdd9..36c2d2f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java @@ -20,9 +20,17 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.bukkit.World; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; @Getter @Setter @@ -46,4 +54,18 @@ public class TNTPhase extends SimulatorPhase { yJump = jump; zJump = jump; } + + @Override + public void toSimulatorActions(Map> actions, Vector position) { + actions.computeIfAbsent(tickOffset, __ -> new ArrayList<>()).add(new SimulatorAction(order, count) { + @Override + public void accept(World world) { + TNTPrimed tnt = world.spawn(position.toLocation(world), TNTPrimed.class); + if (!xJump) tnt.setVelocity(tnt.getVelocity().setX(0)); + if (!yJump) tnt.setVelocity(tnt.getVelocity().setY(0)); + if (!zJump) tnt.setVelocity(tnt.getVelocity().setZ(0)); + tnt.setFuseTicks(lifetime); + } + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorAction.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorAction.java new file mode 100644 index 00000000..bacc0ffd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorAction.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.execute; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.World; + +import java.util.function.Consumer; + +@Getter +@AllArgsConstructor +public abstract class SimulatorAction implements Consumer { + private int order; + + @Setter + private int count; +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorExecutor.java new file mode 100644 index 00000000..0f755aa6 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorExecutor.java @@ -0,0 +1,81 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.execute; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import lombok.experimental.UtilityClass; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; + +@UtilityClass +public class SimulatorExecutor { + + private static final World WORLD = Bukkit.getWorlds().get(0); + private static Set currentlyRunning = new HashSet<>(); + + public boolean run(Simulator simulator) { + if (currentlyRunning.contains(simulator)) return false; + + Map> map = new HashMap<>(); + simulator.toSimulatorActions(map); + + Map>> actions = new HashMap<>(); + map.forEach((integer, simulatorActions) -> { + simulatorActions.forEach(simulatorAction -> { + actions.computeIfAbsent(integer, __ -> new HashMap<>()).computeIfAbsent(simulatorAction.getOrder(), __ -> new ArrayList<>()).add(simulatorAction); + }); + }); + + AtomicInteger tick = new AtomicInteger(); + BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> { + if (actions.isEmpty()) { + bukkitTask.cancel(); + currentlyRunning.remove(simulator); + return; + } + + int currentTick = tick.getAndIncrement(); + Map> actionsToRun = actions.remove(currentTick); + if (actionsToRun == null) return; + List keys = new ArrayList<>(actionsToRun.keySet()); + keys.sort(null); + + for (int actionKey : keys) { + List keyedActions = actionsToRun.get(actionKey); + while (!keyedActions.isEmpty()) { + Collections.shuffle(keyedActions); + for (int i = keyedActions.size() - 1 ; i >= 0; i--) { + SimulatorAction action = keyedActions.get(i); + action.accept(WORLD); + action.setCount(action.getCount() - 1); + if (action.getCount() == 0) { + keyedActions.remove(i); + } + } + } + } + }, 0, 1); + return true; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java index 2f8d548a..4e68d0dd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java @@ -136,7 +136,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 30))); inventory.setItem(22, orderItem); - inventory.setItem(31, SWItem.getDye(order > -30 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { tnt.setOrder(Math.max(-30, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); From 4e6ee3b95b58ebb9f094276fc49f93fc72599b2f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 18:05:13 +0200 Subject: [PATCH 029/139] Add SimulatorWatcher.show, SimulatorWatcher.hide --- .../simulator2/SimulatorTestCommand.java | 10 ++++ .../features/simulator2/SimulatorWatcher.java | 54 +++++++++++++++++-- .../simulator2/data/SimulatorElement.java | 6 +++ .../data/redstone/RedstoneElement.java | 10 ++++ .../simulator2/data/tnt/TNTElement.java | 16 ++++++ .../simulator2/gui/SimulatorGroupGui.java | 4 +- .../features/simulator2/gui/SimulatorGui.java | 4 +- 7 files changed, 98 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java index e66d7f21..d7f8a766 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java @@ -60,4 +60,14 @@ public class SimulatorTestCommand extends SWCommand { public void runCommand(Player player) { SimulatorExecutor.run(SIMULATOR); } + + @Register("show") + public void showCommand(Player player) { + SimulatorWatcher.show(SIMULATOR, player); + } + + @Register("hide") + public void hideCommand(Player player) { + SimulatorWatcher.hide(SIMULATOR, player); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java index 2c6f8cbf..5c1e8ddb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -20,21 +20,32 @@ package de.steamwar.bausystem.features.simulator2; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.shared.Pair; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.linkage.Linked; import lombok.experimental.UtilityClass; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @UtilityClass public class SimulatorWatcher { + private final World WORLD = Bukkit.getWorlds().get(0); + private Map entityServers = new HashMap<>(); private Map> watchers = new HashMap<>(); public void watch(Player player, Simulator simulator, Runnable watcher) { @@ -46,6 +57,10 @@ public class SimulatorWatcher { } public void update(Simulator simulator) { + REntityServer rEntityServer = entityServers.get(simulator); + rEntityServer.getEntities().forEach(REntity::die); + createSim(rEntityServer, simulator); + new ArrayList<>(watchers.values()).forEach(simulatorRunnablePair -> { if (simulatorRunnablePair.getKey() == simulator) { simulatorRunnablePair.getValue().run(); @@ -59,6 +74,39 @@ public class SimulatorWatcher { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { watchers.remove(event.getPlayer()); + hide(event.getPlayer()); } } + + private REntityServer createSim(REntityServer server, Simulator simulator) { + Map>> positionCache = new HashMap<>(); + simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).forEach(simulatorElement -> { + boolean wasNotPresent = positionCache.computeIfAbsent(simulatorElement.getPosition(), __ -> new HashSet<>()) + .add(simulatorElement.getClass()); + if (!wasNotPresent) return; + Material material = simulatorElement.getWorldMaterial(); + Location location = simulatorElement.getWorldPos().toLocation(WORLD); + RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material); + rFallingBlockEntity.setNoGravity(true); + }); + return server; + } + + public void show(Simulator sim, Player player) { + entityServers.computeIfAbsent(sim, __ -> createSim(new REntityServer(), sim)).addPlayer(player); + } + + public void hide(Player player) { + entityServers.replaceAll((simulator, rEntityServer) -> { + rEntityServer.removePlayer(player); + return rEntityServer.getPlayers().isEmpty() ? null : rEntityServer; + }); + } + + public void hide(Simulator sim, Player player) { + entityServers.computeIfPresent(sim, (simulator, rEntityServer) -> { + rEntityServer.removePlayer(player); + return rEntityServer.getPlayers().isEmpty() ? null : rEntityServer; + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index 3f5136c0..c61e33d9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -76,6 +76,12 @@ public abstract class SimulatorElement { position.setZ(position.getZ() + z); } + public abstract Material getWorldMaterial(); + + public Vector getWorldPos() { + return position; + } + public SWItem toItem(Player player, InvCallback invCallback) { List lore = new ArrayList<>(); lore.add("§7Phase count§8:§e " + phases.size()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index f6acc458..85158939 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -33,4 +33,14 @@ public class RedstoneElement extends SimulatorElement { public String getName() { return "Redstone"; } + + @Override + public Material getWorldMaterial() { + return Material.REDSTONE_BLOCK; + } + + @Override + public Vector getWorldPos() { + return position.clone().add(new Vector(0.5, 0, 0.5)); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index 3eb27a82..f5335903 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -20,7 +20,10 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.inventory.InvCallback; +import de.steamwar.inventory.SWItem; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.util.Vector; public class TNTElement extends SimulatorElement { @@ -61,4 +64,17 @@ public class TNTElement extends SimulatorElement { position.setZ(position.getBlockZ() + offset.getZ()); } } + + @Override + public SWItem toItem(Player player, InvCallback invCallback) { + long sum = phases.stream().mapToInt(TNTPhase::getCount).sum(); + SWItem swItem = super.toItem(player, invCallback); + swItem.getItemStack().setAmount((int) Math.min(64, Math.max(1, sum))); + return swItem; + } + + @Override + public Material getWorldMaterial() { + return Material.TNT; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index 23a2354c..2cab54cc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -50,6 +50,7 @@ public class SimulatorGroupGui extends SimulatorPageGui> { @Override public void headerAndFooter() { + simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty()); if (simulatorGroup.getElements().size() < 2) { back.open(); return; @@ -63,7 +64,8 @@ public class SimulatorGroupGui extends SimulatorPageGui> { inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); - }, clickType -> {})); + }, clickType -> { + })); inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index 932fc4a5..757918a3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -43,7 +43,7 @@ public class SimulatorGui extends SimulatorPageGui { @Override public void headerAndFooter() { - simulator.getElements().removeIf(element -> element.getElements().isEmpty()); + simulator.getElements().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty())); inventory.setItem(4, simulator.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); @@ -60,7 +60,7 @@ public class SimulatorGui extends SimulatorPageGui { }, clickType -> { SimulatorElement element = simulatorGroup.getElements().get(0); if (element instanceof TNTElement) { - new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup,this).open(); + new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup, this).open(); } else if (element instanceof RedstoneElement) { new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); } From 648482183a0c946bdecf9d72654ba60e43974e8a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 22:54:59 +0200 Subject: [PATCH 030/139] Move some stuff and add SimulatorCursor --- .../features/simulator2/SimulatorCursor.java | 199 ++++++++++++++++++ .../simulator2/gui/SimulatorGroupGui.java | 1 - .../gui/SimulatorGroupSettingsGui.java | 1 - .../features/simulator2/gui/SimulatorGui.java | 1 - .../gui/{utils => }/SimulatorMaterialGui.java | 2 +- .../simulator2/gui/SimulatorRedstoneGui.java | 3 - .../SimulatorRedstonePhaseSettingsGui.java | 2 - .../gui/SimulatorRedstoneSettingsGui.java | 3 - .../simulator2/gui/SimulatorSettingsGui.java | 1 - .../simulator2/gui/SimulatorTNTGui.java | 5 - .../gui/SimulatorTNTPhaseSettingsGui.java | 1 - .../gui/SimulatorTNTSettingsGui.java | 1 - 12 files changed, 200 insertions(+), 20 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java rename BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/{utils => }/SimulatorMaterialGui.java (97%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java new file mode 100644 index 00000000..485bcd83 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java @@ -0,0 +1,199 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2; + +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.utils.ItemUtils; +import de.steamwar.bausystem.utils.RayTraceUtils; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.api.Plain; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.function.BiFunction; + +@Linked +public class SimulatorCursor implements Plain, Listener { + + private final World WORLD = Bukkit.getWorlds().get(0); + private Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); + private Class look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook"); + private Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); + + private Map cursors = new HashMap<>(); + + public static boolean isSimulatorItem(ItemStack itemStack) { + return ItemUtils.isItem(itemStack, "simulator"); + } + + public SimulatorCursor() { + BiFunction function = (player, object) -> { + if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + removeCursor(player); + return object; + } + RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), new ArrayList<>()); + if (rayTraceResult == null) { + removeCursor(player); + return object; + } + + showCursor(player, rayTraceResult); + return object; + }; + TinyProtocol.instance.addFilter(position, function); + TinyProtocol.instance.addFilter(look, function); + TinyProtocol.instance.addFilter(positionLook, function); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + return; + } + RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), new ArrayList<>()); + if (rayTraceResult == null) { + return; + } + + showCursor(player, rayTraceResult); + } + + @EventHandler + public void onPlayerDropItem(PlayerDropItemEvent event) { + Player player = event.getPlayer(); + if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + removeCursor(player); + return; + } + RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), new ArrayList<>()); + if (rayTraceResult == null) { + removeCursor(player); + return; + } + + showCursor(player, rayTraceResult); + } + + @EventHandler + public void onPlayerItemHeld(PlayerItemHeldEvent event) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + Player player = event.getPlayer(); + if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + removeCursor(player); + return; + } + RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), new ArrayList<>()); + if (rayTraceResult == null) { + removeCursor(player); + return; + } + + showCursor(player, rayTraceResult); + }, 1); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + cursors.remove(event.getPlayer()); + } + + private void removeCursor(Player player) { + cursors.computeIfPresent(player, (player1, rEntityServer) -> { + rEntityServer.close(); + return null; + }); + } + + private void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult) { + REntityServer entityServer = cursors.computeIfAbsent(player, __ -> { + REntityServer rEntityServer = new REntityServer(); + rEntityServer.addPlayer(player); + RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(rEntityServer, new Location(WORLD, 0, 0, 0, 0, 0), Material.GLASS); + rFallingBlockEntity.setNoGravity(true); + return rEntityServer; + }); + entityServer.getEntities().forEach(rEntity -> { + rEntity.move(getPos(player, rayTraceResult).toLocation(WORLD)); + }); + } + + public static Vector getPos(Player player, RayTraceUtils.RRayTraceResult result) { + Vector pos = result.getHitPosition(); + + BlockFace face = result.getHitBlockFace(); + if (face != null) { + switch (face) { + case DOWN: + pos.setY(pos.getY() - 0.98); + break; + case EAST: + pos.setX(pos.getX() + 0.49); + break; + case WEST: + pos.setX(pos.getX() - 0.49); + break; + case NORTH: + pos.setZ(pos.getZ() - 0.49); + break; + case SOUTH: + pos.setZ(pos.getZ() + 0.49); + break; + default: + break; + } + + if (face.getModY() == 0 && player.isSneaking()) { + pos.setY(pos.getY() - 0.49); + } + } + + if (!player.isSneaking()) { + pos.setX(pos.getBlockX() + 0.5); + if (face == null || face.getModY() == 0) + pos.setY(pos.getBlockY() + 0.0); + pos.setZ(pos.getBlockZ() + 0.5); + } + + return pos; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index 2cab54cc..f1bce0f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -27,7 +27,6 @@ import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java index df5b06fe..6f945bdf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index 757918a3..d2e5ce95 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorMaterialGui.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorMaterialGui.java index 95d321a7..9e8e6081 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/utils/SimulatorMaterialGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorMaterialGui.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui.utils; +package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index efb64277..27222540 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -26,15 +26,12 @@ import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class SimulatorRedstoneGui extends SimulatorScrollGui { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java index 7835261d..7b93f595 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java @@ -21,11 +21,9 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java index 7152cc6f..ed4a99cb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java @@ -23,14 +23,11 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { private final RedstoneElement redstone; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java index b9e75a5e..8ed72b0e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.features.simulator2.gui; import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index 34906cd0..a21cf414 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -26,17 +26,12 @@ import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; -import de.steamwar.bausystem.features.simulator2.gui.SimulatorTNTPhaseSettingsGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; public class SimulatorTNTGui extends SimulatorScrollGui { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java index 4e68d0dd..fffb767a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java index 074e86c4..f93cc648 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; From c0551c0cf89604df7d6ff4b6a185c7e13907a739 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 23 Oct 2023 21:22:17 +0200 Subject: [PATCH 031/139] Fix SimulatorWatcher for non watched Simulator --- .../bausystem/features/simulator2/SimulatorWatcher.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java index 5c1e8ddb..8bc0d8c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -58,8 +58,10 @@ public class SimulatorWatcher { public void update(Simulator simulator) { REntityServer rEntityServer = entityServers.get(simulator); - rEntityServer.getEntities().forEach(REntity::die); - createSim(rEntityServer, simulator); + if (rEntityServer != null) { + rEntityServer.getEntities().forEach(REntity::die); + createSim(rEntityServer, simulator); + } new ArrayList<>(watchers.values()).forEach(simulatorRunnablePair -> { if (simulatorRunnablePair.getKey() == simulator) { From d09c3548a78d07744426b05e29b55e6771ffc60d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 24 Oct 2023 18:11:04 +0200 Subject: [PATCH 032/139] Add SimulatorStorage Add SimulatorCursor showing highlighted entity --- .../features/simulator/SimulatorCursor.java | 1 + .../features/simulator2/SimulatorCursor.java | 198 ++++++++++++------ .../features/simulator2/SimulatorStorage.java | 57 +++++ .../simulator2/SimulatorTestCommand.java | 2 +- .../features/simulator2/SimulatorWatcher.java | 8 + .../features/simulator2/world/.gitkeep | 0 6 files changed, 200 insertions(+), 66 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/world/.gitkeep diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index e8fc1bac..eede5d32 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -44,6 +44,7 @@ public class SimulatorCursor { private Map rEntityServerMap = new HashMap<>(); public void show(Player player, TNTSimulator tntSimulator, RayTraceUtils.RRayTraceResult result) { + if (true) return; REntityServer cursor = rEntityServerMap.get(player); if (cursor != null) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java index 485bcd83..323ef04a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.simulator2; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.entity.REntity; @@ -30,6 +30,8 @@ import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.linkage.Linked; import de.steamwar.linkage.api.Plain; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -37,17 +39,13 @@ import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerItemHeldEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.function.BiFunction; @Linked @@ -58,7 +56,8 @@ public class SimulatorCursor implements Plain, Listener { private Class look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook"); private Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); - private Map cursors = new HashMap<>(); + private Map cursorType = Collections.synchronizedMap(new HashMap<>()); + private Map cursors = Collections.synchronizedMap(new HashMap<>()); public static boolean isSimulatorItem(ItemStack itemStack) { return ItemUtils.isItem(itemStack, "simulator"); @@ -66,17 +65,7 @@ public class SimulatorCursor implements Plain, Listener { public SimulatorCursor() { BiFunction function = (player, object) -> { - if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { - removeCursor(player); - return object; - } - RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), new ArrayList<>()); - if (rayTraceResult == null) { - removeCursor(player); - return object; - } - - showCursor(player, rayTraceResult); + calcCursor(player); return object; }; TinyProtocol.instance.addFilter(position, function); @@ -86,78 +75,107 @@ public class SimulatorCursor implements Plain, Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { - return; - } - RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), new ArrayList<>()); - if (rayTraceResult == null) { - return; - } - - showCursor(player, rayTraceResult); + calcCursor(event.getPlayer()); } @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { - Player player = event.getPlayer(); - if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { - removeCursor(player); - return; - } - RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), new ArrayList<>()); - if (rayTraceResult == null) { - removeCursor(player); - return; - } - - showCursor(player, rayTraceResult); + calcCursor(event.getPlayer()); } @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - Player player = event.getPlayer(); - if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { - removeCursor(player); - return; - } - RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), new ArrayList<>()); - if (rayTraceResult == null) { - removeCursor(player); - return; - } - - showCursor(player, rayTraceResult); + calcCursor(event.getPlayer()); }, 1); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { + cursorType.remove(event.getPlayer()); cursors.remove(event.getPlayer()); } - private void removeCursor(Player player) { - cursors.computeIfPresent(player, (player1, rEntityServer) -> { - rEntityServer.close(); - return null; - }); + private static final Map LAST_SNEAKS = new HashMap<>(); + + static { + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + long millis = System.currentTimeMillis(); + LAST_SNEAKS.entrySet().removeIf(entry -> millis - entry.getValue() > 200); + }, 1, 1); } - private void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult) { + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { + if (!event.isSneaking()) return; + Player player = event.getPlayer(); + if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + return; + } + if (LAST_SNEAKS.containsKey(player)) { + CursorType type = cursorType.getOrDefault(player, CursorType.TNT).switchType(); + cursorType.put(player, type); + calcCursor(player); + } else { + LAST_SNEAKS.put(player, System.currentTimeMillis()); + } + } + + private void calcCursor(Player player) { + if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + removeCursor(player); + return; + } + Simulator simulator = SimulatorStorage.getSimulator(player); + List entities = SimulatorWatcher.getEntitiesOfSimulator(simulator); + RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities); + if (rayTraceResult == null) { + removeCursor(player); + return; + } + + showCursor(player, rayTraceResult); + } + + private void removeCursor(Player player) { + REntityServer entityServer = cursors.get(player); + if (entityServer != null) { + entityServer.getEntities().forEach(REntity::die); + } + } + + private synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult) { REntityServer entityServer = cursors.computeIfAbsent(player, __ -> { REntityServer rEntityServer = new REntityServer(); rEntityServer.addPlayer(player); - RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(rEntityServer, new Location(WORLD, 0, 0, 0, 0, 0), Material.GLASS); - rFallingBlockEntity.setNoGravity(true); return rEntityServer; }); - entityServer.getEntities().forEach(rEntity -> { - rEntity.move(getPos(player, rayTraceResult).toLocation(WORLD)); + + CursorType type = cursorType.getOrDefault(player, CursorType.TNT); + REntity hitEntity = rayTraceResult.getHitEntity(); + Location location = hitEntity != null ? new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD) : + type.position.apply(player, rayTraceResult).toLocation(WORLD); + + Material material = hitEntity != null ? Material.GLASS : type.getMaterial(); + List entities = entityServer.getEntitiesByType(RFallingBlockEntity.class); + entities.removeIf(rFallingBlockEntity -> { + if (rFallingBlockEntity.getMaterial() != material) { + rFallingBlockEntity.die(); + return true; + } + rFallingBlockEntity.move(location); + return false; }); + if (entities.isEmpty()) { + RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, location, material); + rFallingBlockEntity.setNoGravity(true); + if (material == Material.GLASS) { + rFallingBlockEntity.setGlowing(true); + } + } } - public static Vector getPos(Player player, RayTraceUtils.RRayTraceResult result) { + public static Vector getPosTNT(Player player, RayTraceUtils.RRayTraceResult result) { Vector pos = result.getHitPosition(); BlockFace face = result.getHitBlockFace(); @@ -196,4 +214,54 @@ public class SimulatorCursor implements Plain, Listener { return pos; } + + private static Vector getPosRedstoneBlock(Player player, RayTraceUtils.RRayTraceResult result) { + Vector pos = result.getHitPosition(); + + BlockFace face = result.getHitBlockFace(); + if (face != null) { + switch (face) { + case DOWN: + pos.setY(pos.getY() - 0.98); + break; + case EAST: + pos.setX(pos.getX() + 0.49); + break; + case WEST: + pos.setX(pos.getX() - 0.49); + break; + case NORTH: + pos.setZ(pos.getZ() - 0.49); + break; + case SOUTH: + pos.setZ(pos.getZ() + 0.49); + break; + default: + break; + } + } + + pos.setX(pos.getBlockX() + 0.5); + pos.setY(pos.getBlockY()); + pos.setZ(pos.getBlockZ() + 0.5); + return pos; + } + + @Getter + @AllArgsConstructor + public enum CursorType { + TNT(Material.TNT, SimulatorCursor::getPosTNT), + REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock), + ; + + private Material material; + private BiFunction position; + + public CursorType switchType() { + if (this == TNT) { + return REDSTONE_BLOCK; + } + return TNT; + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java new file mode 100644 index 00000000..a4b7b7e6 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java @@ -0,0 +1,57 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2; + +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.utils.ItemUtils; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; + +public class SimulatorStorage { + + private static Map simulatorMap = new HashMap<>(); + private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection"); + + public static Simulator getSimulator(Player player) { + Simulator simulator = getSimulator(player.getInventory().getItemInMainHand()); + if (simulator != null) return simulator; + return getSimulator(player.getInventory().getItemInOffHand()); + } + + public static Simulator getSimulator(ItemStack itemStack) { + if (!SimulatorCursor.isSimulatorItem(itemStack)) { + return null; + } + String selection = ItemUtils.getTag(itemStack, simulatorSelection); + if (selection == null) { + return null; + } + return simulatorMap.computeIfAbsent(selection, SimulatorStorage::loadSimulator); + } + + private static Simulator loadSimulator(String name) { + return SimulatorTestCommand.SIMULATOR; // TODO: Implement Loading and legacy Loading + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java index d7f8a766..4a739a77 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java @@ -36,7 +36,7 @@ import org.bukkit.util.Vector; @Linked public class SimulatorTestCommand extends SWCommand { - private static final Simulator SIMULATOR = new Simulator("TestSim"); + static final Simulator SIMULATOR = new Simulator("TestSim"); public SimulatorTestCommand() { super("simtest"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java index 8bc0d8c6..b15e6889 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -111,4 +111,12 @@ public class SimulatorWatcher { return rEntityServer.getPlayers().isEmpty() ? null : rEntityServer; }); } + + List getEntitiesOfSimulator(Simulator simulator) { + REntityServer entityServer = entityServers.get(simulator); + if (entityServer == null) { + return Collections.emptyList(); + } + return entityServer.getEntities(); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/world/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/world/.gitkeep deleted file mode 100644 index e69de29b..00000000 From 20b116f228feed17ce7f42a7bbb58ef710bb4fd1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 24 Oct 2023 23:05:16 +0200 Subject: [PATCH 033/139] Update many GUI's Add SimulatorCursor.onPlayerInteract --- .../simulator/TNTSimulatorListener.java | 2 +- .../features/simulator2/SimulatorCursor.java | 142 ++++++++++++++++-- .../simulator2/SimulatorTestCommand.java | 10 -- .../features/simulator2/SimulatorWatcher.java | 26 ++-- .../simulator2/data/SimulatorElement.java | 10 ++ .../simulator2/data/SimulatorGroup.java | 2 +- .../simulator2/data/SimulatorPhase.java | 2 +- .../data/redstone/RedstoneElement.java | 10 ++ .../data/redstone/RedstonePhase.java | 5 + .../simulator2/data/tnt/TNTElement.java | 9 ++ .../simulator2/gui/SimulatorGroupGui.java | 23 +-- .../gui/SimulatorGroupSettingsGui.java | 1 + .../features/simulator2/gui/SimulatorGui.java | 11 +- .../simulator2/gui/SimulatorRedstoneGui.java | 6 +- .../gui/SimulatorRedstoneSettingsGui.java | 2 +- .../simulator2/gui/SimulatorTNTGui.java | 6 +- .../gui/SimulatorTNTPhaseSettingsGui.java | 6 +- 17 files changed, 207 insertions(+), 66 deletions(-) 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 a3862c9f..bfead637 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -35,7 +35,7 @@ import org.bukkit.inventory.PlayerInventory; import java.util.function.Function; -@Linked +// @Linked public class TNTSimulatorListener implements Listener { private boolean permissionCheck(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java index 323ef04a..b7a38046 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java @@ -22,14 +22,25 @@ package de.steamwar.bausystem.features.simulator2; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor; +import de.steamwar.bausystem.features.simulator2.gui.SimulatorGroupGui; +import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.api.Plain; import lombok.AllArgsConstructor; import lombok.Getter; import org.bukkit.Bukkit; @@ -41,15 +52,21 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Collectors; @Linked -public class SimulatorCursor implements Plain, Listener { +public class SimulatorCursor implements Listener { private final World WORLD = Bukkit.getWorlds().get(0); private Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); @@ -113,8 +130,7 @@ public class SimulatorCursor implements Plain, Listener { return; } if (LAST_SNEAKS.containsKey(player)) { - CursorType type = cursorType.getOrDefault(player, CursorType.TNT).switchType(); - cursorType.put(player, type); + cursorType.put(player, cursorType.getOrDefault(player, CursorType.TNT).switchType()); calcCursor(player); } else { LAST_SNEAKS.put(player, System.currentTimeMillis()); @@ -124,27 +140,32 @@ public class SimulatorCursor implements Plain, Listener { private void calcCursor(Player player) { if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { removeCursor(player); + SimulatorWatcher.show(null, player); + SWUtils.sendToActionbar(player, ""); return; } Simulator simulator = SimulatorStorage.getSimulator(player); + SimulatorWatcher.show(simulator, player); + List entities = SimulatorWatcher.getEntitiesOfSimulator(simulator); RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities); if (rayTraceResult == null) { removeCursor(player); + SWUtils.sendToActionbar(player, ""); return; } - showCursor(player, rayTraceResult); + showCursor(player, rayTraceResult, simulator != null); } - private void removeCursor(Player player) { + private synchronized void removeCursor(Player player) { REntityServer entityServer = cursors.get(player); if (entityServer != null) { entityServer.getEntities().forEach(REntity::die); } } - private synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult) { + private synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, boolean hasSimulatorSelected) { REntityServer entityServer = cursors.computeIfAbsent(player, __ -> { REntityServer rEntityServer = new REntityServer(); rEntityServer.addPlayer(player); @@ -173,6 +194,16 @@ public class SimulatorCursor implements Plain, Listener { rFallingBlockEntity.setGlowing(true); } } + + if (hasSimulatorSelected) { + if (hitEntity != null) { + SWUtils.sendToActionbar(player, "§eEdit Position"); + } else { + SWUtils.sendToActionbar(player, "§eAdd new " + type.name); + } + } else { + SWUtils.sendToActionbar(player, "§eCreate new Simulator"); + } } public static Vector getPosTNT(Player player, RayTraceUtils.RRayTraceResult result) { @@ -250,12 +281,14 @@ public class SimulatorCursor implements Plain, Listener { @Getter @AllArgsConstructor public enum CursorType { - TNT(Material.TNT, SimulatorCursor::getPosTNT), - REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock), + TNT(Material.TNT, SimulatorCursor::getPosTNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())), + REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())), ; private Material material; private BiFunction position; + private String name; + private Function> elementFunction; public CursorType switchType() { if (this == TNT) { @@ -264,4 +297,93 @@ public class SimulatorCursor implements Plain, Listener { return TNT; } } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (!ItemUtils.isItem(event.getItem(), "simulator")) { + return; + } + + event.setCancelled(true); + Player player = event.getPlayer(); + Simulator simulator = SimulatorStorage.getSimulator(player); + + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { + if (simulator == null) { + return; + } + SimulatorExecutor.run(simulator); + return; + } + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) { + return; + } + + + RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator)); + if (simulator == null) { + if (rayTraceResult == null) { + // TODO: Open Simulator Selection GUI + } else { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Name"); + anvilInv.setCallback(s -> { + // TODO: Check if Sim exists then close and message, otherwise create sim and add first tnt open that! + }); + anvilInv.open(); + } + return; + } + + if (rayTraceResult == null) { + new SimulatorGui(player, simulator).open(); + return; + } + + if (rayTraceResult.getHitEntity() != null) { + REntity hitEntity = rayTraceResult.getHitEntity(); + Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()); + List> elements = simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> { + return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0); + }).collect(Collectors.toList()); + + switch (elements.size()) { + case 0: + return; + case 1: + // Open single element present in Simulator + SimulatorElement element = elements.get(0); + SimulatorGroup group1 = element.getGroup(simulator); + SimulatorBaseGui back = new SimulatorGui(player, simulator); + if (group1.getElements().size() > 1) { + back = new SimulatorGroupGui(player, simulator, group1, back); + } + element.open(player, simulator, group1, back); + break; + default: + // Open multi element present in Simulator + SimulatorGroup group2 = new SimulatorGroup(); + group2.setMaterial(null); + group2.getElements().addAll(elements); + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + new SimulatorGroupGui(player, simulator, group2, simulatorGui).open(); + break; + } + return; + } + + // Add new Element to current simulator + CursorType type = cursorType.getOrDefault(player, CursorType.TNT); + Vector vector = type.position.apply(player, rayTraceResult); + if (type == CursorType.REDSTONE_BLOCK) { + vector.subtract(new Vector(0.5, 0, 0.5)); + } + SimulatorElement element = type.elementFunction.apply(vector); + SimulatorGroup group = new SimulatorGroup().add(element); + simulator.getElements().add(group); + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + element.open(player, simulator, group, simulatorGui); + SimulatorWatcher.update(simulator); + calcCursor(player); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java index 4a739a77..be44ee99 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java @@ -60,14 +60,4 @@ public class SimulatorTestCommand extends SWCommand { public void runCommand(Player player) { SimulatorExecutor.run(SIMULATOR); } - - @Register("show") - public void showCommand(Player player) { - SimulatorWatcher.show(SIMULATOR, player); - } - - @Register("hide") - public void hideCommand(Player player) { - SimulatorWatcher.hide(SIMULATOR, player); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java index b15e6889..dc239c0d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -76,11 +76,14 @@ public class SimulatorWatcher { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { watchers.remove(event.getPlayer()); - hide(event.getPlayer()); + show(null, event.getPlayer()); } } private REntityServer createSim(REntityServer server, Simulator simulator) { + if (simulator == null) { + return null; + } Map>> positionCache = new HashMap<>(); simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).forEach(simulatorElement -> { boolean wasNotPresent = positionCache.computeIfAbsent(simulatorElement.getPosition(), __ -> new HashSet<>()) @@ -95,23 +98,16 @@ public class SimulatorWatcher { } public void show(Simulator sim, Player player) { + entityServers.forEach((simulator, rEntityServer) -> { + if (rEntityServer == null) return; + if (rEntityServer.getPlayers().contains(player) && sim != simulator) { + rEntityServer.removePlayer(player); + } + }); + if (sim == null) return; entityServers.computeIfAbsent(sim, __ -> createSim(new REntityServer(), sim)).addPlayer(player); } - public void hide(Player player) { - entityServers.replaceAll((simulator, rEntityServer) -> { - rEntityServer.removePlayer(player); - return rEntityServer.getPlayers().isEmpty() ? null : rEntityServer; - }); - } - - public void hide(Simulator sim, Player player) { - entityServers.computeIfPresent(sim, (simulator, rEntityServer) -> { - rEntityServer.removePlayer(player); - return rEntityServer.getPlayers().isEmpty() ? null : rEntityServer; - }); - } - List getEntitiesOfSimulator(Simulator simulator) { REntityServer entityServer = entityServers.get(simulator); if (entityServer == null) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index c61e33d9..b3c2b934 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.simulator2.data; import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import lombok.Getter; @@ -103,4 +104,13 @@ public abstract class SimulatorElement { phase.toSimulatorActions(actions, position.clone()); }); } + + public abstract void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back); + + public SimulatorGroup getGroup(Simulator simulator) { + return simulator.getElements().stream() + .filter(simulatorGroup -> simulatorGroup.getElements().contains(this)) + .findFirst() + .orElse(null); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index 1c3ac29c..4e643fda 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -78,7 +78,7 @@ public class SimulatorGroup { lore.add(""); lore.add("§cDisabled"); } - return new SWItem(material, "§eGroup", lore, disabled, groupCallback); + return new SWItem(material != null ? material : Material.ENDER_CHEST, "§eGroup", lore, disabled, groupCallback); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java index 126775b5..d70acee5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java @@ -34,7 +34,7 @@ public abstract class SimulatorPhase { protected int tickOffset = 0; protected int lifetime = 80; - protected int order = 1; + protected int order = 0; public abstract void toSimulatorActions(Map> actions, Vector position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index 85158939..158dfef4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -19,8 +19,13 @@ package de.steamwar.bausystem.features.simulator2.data.redstone; +import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.gui.SimulatorRedstoneGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.util.Vector; public class RedstoneElement extends SimulatorElement { @@ -43,4 +48,9 @@ public class RedstoneElement extends SimulatorElement { public Vector getWorldPos() { return position.clone().add(new Vector(0.5, 0, 0.5)); } + + @Override + public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) { + new SimulatorRedstoneGui(player, simulator, group, this, back).open(); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java index e8b1c210..cd269703 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java @@ -51,12 +51,17 @@ public class RedstonePhase extends SimulatorPhase { .add(new SimulatorAction(0, 1) { @Override public void accept(World world) { + // TODO: 0 Tick Pistons not working Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); previousBlockState.set(block.getState()); block.setType(Material.REDSTONE_BLOCK); + previousBlockState.get().update(true, true); } }); + if (lifetime == 0) { + return; + } actions.computeIfAbsent(tickOffset + lifetime, __ -> new ArrayList<>()) .add(new SimulatorAction(0, 1) { @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index f5335903..2a3037e0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -19,7 +19,11 @@ package de.steamwar.bausystem.features.simulator2.data.tnt; +import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.gui.SimulatorTNTGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import org.bukkit.Material; @@ -77,4 +81,9 @@ public class TNTElement extends SimulatorElement { public Material getWorldMaterial() { return Material.TNT; } + + @Override + public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) { + new SimulatorTNTGui(player, simulator, this, group, back).open(); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index f1bce0f2..4360bcef 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -49,7 +49,9 @@ public class SimulatorGroupGui extends SimulatorPageGui> { @Override public void headerAndFooter() { - simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty()); + if (simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty())) { + SimulatorWatcher.update(simulator); + } if (simulatorGroup.getElements().size() < 2) { back.open(); return; @@ -62,27 +64,26 @@ public class SimulatorGroupGui extends SimulatorPageGui> { })); inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { + if (simulatorGroup.getMaterial() == null) return; new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); }, clickType -> { })); - inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + inventory.setItem(simulatorGroup.getMaterial() != null ? 48 : 49, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); })); - inventory.setItem(50, new SWItem(simulatorGroup.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { - simulatorGroup.setDisabled(!simulatorGroup.isDisabled()); - SimulatorWatcher.update(simulator); - })); + if (simulatorGroup.getMaterial() != null) { + inventory.setItem(50, new SWItem(simulatorGroup.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + simulatorGroup.setDisabled(!simulatorGroup.isDisabled()); + SimulatorWatcher.update(simulator); + })); + } } @Override public SWItem convert(SimulatorElement element) { return element.toItem(player, clickType -> { - if (element instanceof TNTElement) { - new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup, this).open(); - } else if (element instanceof RedstoneElement) { - new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); - } + element.open(player, simulator, simulatorGroup, this); }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java index 6f945bdf..eb27c8b2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java @@ -59,6 +59,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { // Material Chooser inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { + if (simulatorGroup.getMaterial() == null) return; new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); }, clickType -> {})); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java index d2e5ce95..192d239c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulator2.gui; +import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; @@ -42,7 +43,9 @@ public class SimulatorGui extends SimulatorPageGui { @Override public void headerAndFooter() { - simulator.getElements().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty())); + if (simulator.getElements().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) { + SimulatorWatcher.update(simulator); + } inventory.setItem(4, simulator.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); @@ -58,11 +61,7 @@ public class SimulatorGui extends SimulatorPageGui { new SimulatorGroupGui(player, simulator, simulatorGroup, this).open(); }, clickType -> { SimulatorElement element = simulatorGroup.getElements().get(0); - if (element instanceof TNTElement) { - new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup, this).open(); - } else if (element instanceof RedstoneElement) { - new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open(); - } + element.open(player, simulator, simulatorGroup, this); }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 27222540..81c58b4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -55,6 +55,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { public void headerAndFooter() { if (redstone.getPhases().isEmpty()) { back.open(); + SimulatorWatcher.update(simulator); return; } @@ -65,10 +66,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { if (parent.getElements().contains(redstone)) { back.open(); } else { - SimulatorGroup newParent = simulator.getElements().stream() - .filter(simulatorGroup -> simulatorGroup.getElements().contains(redstone)) - .findFirst() - .orElse(null); + SimulatorGroup newParent = redstone.getGroup(simulator); if (newParent == null) { player.closeInventory(); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java index ed4a99cb..25db707e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java @@ -109,7 +109,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); }); - inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7" + redstone.getPosition().getBlockZ(), clickType -> { + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + redstone.getPosition().getBlockZ(), clickType -> { })); inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index a21cf414..c046a756 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -55,6 +55,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { public void headerAndFooter() { if (tnt.getPhases().isEmpty()) { back.open(); + SimulatorWatcher.update(simulator); return; } @@ -65,10 +66,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { if (parent.getElements().contains(tnt)) { back.open(); } else { - SimulatorGroup newParent = simulator.getElements().stream() - .filter(simulatorGroup -> simulatorGroup.getElements().contains(tnt)) - .findFirst() - .orElse(null); + SimulatorGroup newParent = tnt.getGroup(simulator); if (newParent == null) { player.closeInventory(); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java index fffb767a..613f1dc7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -130,9 +131,10 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); - SWItem orderItem = new SWItem(Material.COMPASS, "§eCalculation Order§8:§7 " + order, clickType -> { + Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); + SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eCalculation Order§8:§7 " + order, clickType -> { }); - orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 30))); + orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); inventory.setItem(22, orderItem); inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { From 21ec66b4e2373f851be204316bf6e5fa5c2acb7d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 25 Oct 2023 14:13:45 +0200 Subject: [PATCH 034/139] Fix many things --- .../features/simulator2/SimulatorCursor.java | 25 ++++++++++++++--- .../features/simulator2/SimulatorStorage.java | 28 +++++++++++++++++++ .../features/simulator2/SimulatorWatcher.java | 21 ++++++++------ .../data/redstone/RedstonePhase.java | 4 ++- 4 files changed, 65 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java index b7a38046..3f443d26 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java @@ -34,12 +34,14 @@ import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGroupGui; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import lombok.AllArgsConstructor; import lombok.Getter; @@ -137,7 +139,7 @@ public class SimulatorCursor implements Listener { } } - private void calcCursor(Player player) { + private synchronized void calcCursor(Player player) { if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { removeCursor(player); SimulatorWatcher.show(null, player); @@ -151,7 +153,11 @@ public class SimulatorCursor implements Listener { RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities); if (rayTraceResult == null) { removeCursor(player); - SWUtils.sendToActionbar(player, ""); + if (simulator == null) { + SWUtils.sendToActionbar(player, "§eSelect Simulator"); + } else { + SWUtils.sendToActionbar(player, "§eOpen Simulator"); + } return; } @@ -324,11 +330,18 @@ public class SimulatorCursor implements Listener { RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator)); if (simulator == null) { if (rayTraceResult == null) { - // TODO: Open Simulator Selection GUI + SimulatorStorage.openSimulatorSelector(player); } else { SWAnvilInv anvilInv = new SWAnvilInv(player, "Name"); anvilInv.setCallback(s -> { - // TODO: Check if Sim exists then close and message, otherwise create sim and add first tnt open that! + Simulator sim = SimulatorStorage.getSimulator(s); + if (sim != null) { + player.sendMessage("§cThe simulator " + s + " already exists"); + return; + } + sim = new Simulator(s); + SimulatorStorage.addSimulator(s, sim); + createElement(player, rayTraceResult, sim); }); anvilInv.open(); } @@ -373,6 +386,10 @@ public class SimulatorCursor implements Listener { } // Add new Element to current simulator + createElement(player, rayTraceResult, simulator); + } + + private void createElement(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, Simulator simulator) { CursorType type = cursorType.getOrDefault(player, CursorType.TNT); Vector vector = type.position.apply(player, rayTraceResult); if (type == CursorType.REDSTONE_BLOCK) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java index a4b7b7e6..0dca6740 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java @@ -21,11 +21,14 @@ package de.steamwar.bausystem.features.simulator2; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; import de.steamwar.bausystem.utils.ItemUtils; +import de.steamwar.inventory.SWItem; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -51,7 +54,32 @@ public class SimulatorStorage { return simulatorMap.computeIfAbsent(selection, SimulatorStorage::loadSimulator); } + public static Simulator getSimulator(String name) { + return simulatorMap.computeIfAbsent(name, SimulatorStorage::loadSimulator); + } + + public static void addSimulator(String name, Simulator simulator) { + simulatorMap.putIfAbsent(name, simulator); + } + private static Simulator loadSimulator(String name) { return SimulatorTestCommand.SIMULATOR; // TODO: Implement Loading and legacy Loading } + + public static void openSimulatorSelector(Player player) { + SimulatorPageGui simulatorPageGui = new SimulatorPageGui(player, null, 6*9, new ArrayList<>(simulatorMap.values())) { + @Override + public String baseTitle() { + return "Simulators"; + } + + @Override + public SWItem convert(Simulator simulator) { + return simulator.toItem(player, clickType -> { + System.out.println(clickType); + }); + } + }; + simulatorPageGui.open(); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java index dc239c0d..470f9f12 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -40,6 +40,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.util.Vector; import java.util.*; +import java.util.stream.Collectors; @UtilityClass public class SimulatorWatcher { @@ -56,7 +57,7 @@ public class SimulatorWatcher { } } - public void update(Simulator simulator) { + public synchronized void update(Simulator simulator) { REntityServer rEntityServer = entityServers.get(simulator); if (rEntityServer != null) { rEntityServer.getEntities().forEach(REntity::die); @@ -85,19 +86,23 @@ public class SimulatorWatcher { return null; } Map>> positionCache = new HashMap<>(); - simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).forEach(simulatorElement -> { - boolean wasNotPresent = positionCache.computeIfAbsent(simulatorElement.getPosition(), __ -> new HashSet<>()) - .add(simulatorElement.getClass()); + simulator.getElements().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> { + SimulatorGroup group = pair.getKey(); + // TODO: Disabled material + SimulatorElement element = pair.getValue(); + + boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>()) + .add(element.getClass()); if (!wasNotPresent) return; - Material material = simulatorElement.getWorldMaterial(); - Location location = simulatorElement.getWorldPos().toLocation(WORLD); + Material material = element.getWorldMaterial(); + Location location = element.getWorldPos().toLocation(WORLD); RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material); rFallingBlockEntity.setNoGravity(true); }); return server; } - public void show(Simulator sim, Player player) { + public synchronized void show(Simulator sim, Player player) { entityServers.forEach((simulator, rEntityServer) -> { if (rEntityServer == null) return; if (rEntityServer.getPlayers().contains(player) && sim != simulator) { @@ -108,7 +113,7 @@ public class SimulatorWatcher { entityServers.computeIfAbsent(sim, __ -> createSim(new REntityServer(), sim)).addPlayer(player); } - List getEntitiesOfSimulator(Simulator simulator) { + synchronized List getEntitiesOfSimulator(Simulator simulator) { REntityServer entityServer = entityServers.get(simulator); if (entityServer == null) { return Collections.emptyList(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java index cd269703..df2e06e2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java @@ -55,7 +55,9 @@ public class RedstonePhase extends SimulatorPhase { Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); previousBlockState.set(block.getState()); block.setType(Material.REDSTONE_BLOCK); - previousBlockState.get().update(true, true); + if (lifetime == 0) { + previousBlockState.get().update(true, true); + } } }); From 4ee93b59dda1f537e8c8bc0c1d3278f05eb38179 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 25 Oct 2023 14:35:15 +0200 Subject: [PATCH 035/139] Fix AutostartListener for specific GameMode configs --- .../features/autostart/AutostartListener.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 232962a1..7da0fea1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -31,6 +31,8 @@ import de.steamwar.linkage.Linked; import lombok.Getter; import org.bukkit.Material; import org.bukkit.block.data.type.Chest; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -39,11 +41,9 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; +import java.io.File; import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @Linked public class AutostartListener implements Listener { @@ -117,15 +117,24 @@ public class AutostartListener implements Listener { if (regionStartTime.isEmpty()) { return; } + event.blockList().forEach(block -> { Region region = Region.getRegion(block.getLocation()); if (!regionStartTime.containsKey(region)) return; if (!region.hasType(RegionType.TESTBLOCK)) return; if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return; long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region); + long preFightDurationInSeconds = getPreFightDurationInSeconds(region); RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT1", tickDiff); - RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", 30, (600 - tickDiff)); + RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", preFightDurationInSeconds, ((preFightDurationInSeconds * 20) - tickDiff)); RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3"); }); } + + private int getPreFightDurationInSeconds(Region region) { + File file = region.gameModeConfig(); + if (file == null) return 30; + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + return config.getInt("Times.PreFightDuration", 30); + } } From 61f7218fc09748e15779f1436ef3d27896db3c1d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 25 Oct 2023 23:03:59 +0200 Subject: [PATCH 036/139] Add some QOL Simulator changes --- .../features/simulator2/SimulatorCursor.java | 30 ++++++++++------- .../features/simulator2/SimulatorStorage.java | 23 ++++++++++++- .../simulator2/SimulatorTestCommand.java | 10 ------ .../features/simulator2/SimulatorWatcher.java | 3 +- .../simulator2/data/SimulatorElement.java | 2 ++ .../data/redstone/RedstoneElement.java | 5 +++ .../simulator2/data/tnt/TNTElement.java | 5 +++ .../simulator2/gui/SimulatorGroupGui.java | 32 ++++++++++++++----- .../simulator2/gui/SimulatorRedstoneGui.java | 6 ++-- .../simulator2/gui/SimulatorTNTGui.java | 2 +- .../simulator2/gui/base/SimulatorPageGui.java | 2 +- 11 files changed, 83 insertions(+), 37 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java index 3f443d26..2b1f2f87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java @@ -59,10 +59,7 @@ import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; @@ -279,7 +276,11 @@ public class SimulatorCursor implements Listener { } pos.setX(pos.getBlockX() + 0.5); - pos.setY(pos.getBlockY()); + if (pos.getY() - pos.getBlockY() != 0 && face == BlockFace.UP) { + pos.setY(pos.getBlockY() + 1.0); + } else { + pos.setY(pos.getBlockY()); + } pos.setZ(pos.getBlockZ() + 0.5); return pos; } @@ -374,12 +375,19 @@ public class SimulatorCursor implements Listener { element.open(player, simulator, group1, back); break; default: - // Open multi element present in Simulator - SimulatorGroup group2 = new SimulatorGroup(); - group2.setMaterial(null); - group2.getElements().addAll(elements); - SimulatorGui simulatorGui = new SimulatorGui(player, simulator); - new SimulatorGroupGui(player, simulator, group2, simulatorGui).open(); + List parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList()); + if (parents.size() == 1) { + // Open multi element present in Simulator in existing group + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + new SimulatorGroupGui(player, simulator, parents.get(0), simulatorGui).open(); + } else { + // Open multi element present in Simulator in implicit group + SimulatorGroup group2 = new SimulatorGroup(); + group2.setMaterial(null); + group2.getElements().addAll(elements); + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + new SimulatorGroupGui(player, simulator, group2, simulatorGui).open(); + } break; } return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java index 0dca6740..c81b55f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulator2; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; @@ -27,6 +28,7 @@ import de.steamwar.inventory.SWItem; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.HashMap; @@ -76,7 +78,26 @@ public class SimulatorStorage { @Override public SWItem convert(Simulator simulator) { return simulator.toItem(player, clickType -> { - System.out.println(clickType); + ItemStack mainHand = player.getInventory().getItemInMainHand(); + ItemStack offHand = player.getInventory().getItemInOffHand(); + ItemStack itemStack; + if (SimulatorCursor.isSimulatorItem(mainHand)) { + itemStack = mainHand; + } else if (SimulatorCursor.isSimulatorItem(offHand)) { + itemStack = offHand; + } else { + itemStack = null; + } + if (itemStack == null) { + return; + } + + // TODO: Dynamic Item Lore, and remove if simulator does not exist anymore (On Join for every Player Inventory Slot with Simulator...) + ItemUtils.setTag(itemStack, simulatorSelection, simulator.getName()); + ItemMeta itemMeta = itemStack.getItemMeta(); + itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, simulator.getName())); + itemStack.setItemMeta(itemMeta); + player.closeInventory(); }); } }; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java index be44ee99..b3f668cb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java @@ -50,14 +50,4 @@ public class SimulatorTestCommand extends SWCommand { SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(-484, 47, 307)).add(new RedstonePhase())); SIMULATOR.getElements().add(group3); } - - @Register("open") - public void openCommand(Player player) { - new SimulatorGui(player, SIMULATOR).open(); - } - - @Register("run") - public void runCommand(Player player) { - SimulatorExecutor.run(SIMULATOR); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java index 470f9f12..eb888615 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -88,13 +88,12 @@ public class SimulatorWatcher { Map>> positionCache = new HashMap<>(); simulator.getElements().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> { SimulatorGroup group = pair.getKey(); - // TODO: Disabled material SimulatorElement element = pair.getValue(); boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>()) .add(element.getClass()); if (!wasNotPresent) return; - Material material = element.getWorldMaterial(); + Material material = group.isDisabled() || element.isDisabled() ? element.getWorldDisabledMaterial() : element.getWorldMaterial(); Location location = element.getWorldPos().toLocation(WORLD); RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material); rFallingBlockEntity.setNoGravity(true); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index b3c2b934..e01ef88c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -79,6 +79,8 @@ public abstract class SimulatorElement { public abstract Material getWorldMaterial(); + public abstract Material getWorldDisabledMaterial(); + public Vector getWorldPos() { return position; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index 158dfef4..4ba337a8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -44,6 +44,11 @@ public class RedstoneElement extends SimulatorElement { return Material.REDSTONE_BLOCK; } + @Override + public Material getWorldDisabledMaterial() { + return Material.WHITE_STAINED_GLASS; + } + @Override public Vector getWorldPos() { return position.clone().add(new Vector(0.5, 0, 0.5)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index 2a3037e0..62982a22 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -82,6 +82,11 @@ public class TNTElement extends SimulatorElement { return Material.TNT; } + @Override + public Material getWorldDisabledMaterial() { + return Material.RED_STAINED_GLASS; + } + @Override public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) { new SimulatorTNTGui(player, simulator, this, group, back).open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index 4360bcef..33d87d76 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -31,9 +31,12 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; +import java.util.List; +import java.util.stream.Collectors; + public class SimulatorGroupGui extends SimulatorPageGui> { - private final SimulatorGroup simulatorGroup; + private SimulatorGroup simulatorGroup; private final SimulatorBaseGui back; public SimulatorGroupGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) { @@ -49,6 +52,14 @@ public class SimulatorGroupGui extends SimulatorPageGui> { @Override public void headerAndFooter() { + if (simulatorGroup.getMaterial() == null) { + List parents = data.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList()); + if (parents.size() == 1) { + simulatorGroup = parents.get(0); + data = simulatorGroup.getElements(); + } + } + if (simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty())) { SimulatorWatcher.update(simulator); } @@ -69,15 +80,20 @@ public class SimulatorGroupGui extends SimulatorPageGui> { }, clickType -> { })); - inventory.setItem(simulatorGroup.getMaterial() != null ? 48 : 49, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); })); - if (simulatorGroup.getMaterial() != null) { - inventory.setItem(50, new SWItem(simulatorGroup.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { - simulatorGroup.setDisabled(!simulatorGroup.isDisabled()); - SimulatorWatcher.update(simulator); - })); - } + boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled) : simulatorGroup.isDisabled(); + inventory.setItem(50, new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + if (simulatorGroup.getMaterial() == null) { + simulatorGroup.getElements().forEach(simulatorElement -> { + simulatorElement.setDisabled(!disabled); + }); + } else { + simulatorGroup.setDisabled(!disabled); + } + SimulatorWatcher.update(simulator); + })); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java index 81c58b4e..bc2b36c5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java @@ -85,14 +85,14 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); })); - //Settings + // Settings inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open(); })); - //Group chooser + // Group chooser inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { - new SimulatorGroupChooserGui(player, simulator, redstone, parent, this).open(); + new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open(); })); //Enable/Disable diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java index c046a756..f4c80ebe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java @@ -89,7 +89,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { - new SimulatorGroupChooserGui(player, simulator, tnt, parent, this).open(); + new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); })); inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java index 42eb1e17..14c2d786 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java @@ -29,7 +29,7 @@ import java.util.List; public abstract class SimulatorPageGui extends SimulatorBaseGui { protected int page = 0; - protected final List data; + protected List data; protected SimulatorPageGui(Player player, Simulator simulator, int size, List data) { super(player, simulator, size); From 61d1f0bd4552257aaf0c89e4d668c3b6076b0a76 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 26 Oct 2023 18:07:25 +0200 Subject: [PATCH 037/139] Add loading and saving methods and fix many QOL things --- .../features/simulator2/SimulatorCursor.java | 8 +- .../features/simulator2/SimulatorStorage.java | 48 ++++--- .../features/simulator2/data/Simulator.java | 7 +- .../simulator2/data/SimulatorElement.java | 9 +- .../simulator2/data/SimulatorGroup.java | 4 +- .../simulator2/data/SimulatorPhase.java | 3 + .../data/redstone/RedstoneElement.java | 9 +- .../data/redstone/RedstonePhase.java | 3 +- .../simulator2/data/tnt/TNTElement.java | 10 +- .../simulator2/data/tnt/TNTPhase.java | 19 ++- .../gui/SimulatorGroupChooserGui.java | 8 ++ .../simulator2/gui/SimulatorGroupGui.java | 2 - .../simulator2/gui/base/SimulatorBaseGui.java | 5 +- .../storage/SimFormatSimulatorLoader.java | 130 +++++++++++++++++ .../SimulatorFormatSimulatorLoader.java | 136 ++++++++++++++++++ .../simulator2/storage/SimulatorLoader.java | 31 ++++ .../simulator2/storage/SimulatorSaver.java | 81 +++++++++++ .../storage/YAPIONFormatSimulatorLoader.java | 90 ++++++++++++ 18 files changed, 564 insertions(+), 39 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimFormatSimulatorLoader.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorLoader.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/YAPIONFormatSimulatorLoader.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java index 2b1f2f87..90feb161 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java @@ -34,14 +34,12 @@ import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGroupGui; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import lombok.AllArgsConstructor; import lombok.Getter; @@ -59,7 +57,10 @@ import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; @@ -343,6 +344,7 @@ public class SimulatorCursor implements Listener { sim = new Simulator(s); SimulatorStorage.addSimulator(s, sim); createElement(player, rayTraceResult, sim); + SimulatorStorage.setSimulator(player, sim); }); anvilInv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java index c81b55f2..8c49a66a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator2; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWItem; @@ -53,11 +54,11 @@ public class SimulatorStorage { if (selection == null) { return null; } - return simulatorMap.computeIfAbsent(selection, SimulatorStorage::loadSimulator); + return simulatorMap.get(selection); } public static Simulator getSimulator(String name) { - return simulatorMap.computeIfAbsent(name, SimulatorStorage::loadSimulator); + return simulatorMap.get(name); } public static void addSimulator(String name, Simulator simulator) { @@ -69,7 +70,7 @@ public class SimulatorStorage { } public static void openSimulatorSelector(Player player) { - SimulatorPageGui simulatorPageGui = new SimulatorPageGui(player, null, 6*9, new ArrayList<>(simulatorMap.values())) { + SimulatorPageGui simulatorPageGui = new SimulatorPageGui(player, null, 6 * 9, new ArrayList<>(simulatorMap.values())) { @Override public String baseTitle() { return "Simulators"; @@ -78,29 +79,32 @@ public class SimulatorStorage { @Override public SWItem convert(Simulator simulator) { return simulator.toItem(player, clickType -> { - ItemStack mainHand = player.getInventory().getItemInMainHand(); - ItemStack offHand = player.getInventory().getItemInOffHand(); - ItemStack itemStack; - if (SimulatorCursor.isSimulatorItem(mainHand)) { - itemStack = mainHand; - } else if (SimulatorCursor.isSimulatorItem(offHand)) { - itemStack = offHand; - } else { - itemStack = null; - } - if (itemStack == null) { - return; - } - - // TODO: Dynamic Item Lore, and remove if simulator does not exist anymore (On Join for every Player Inventory Slot with Simulator...) - ItemUtils.setTag(itemStack, simulatorSelection, simulator.getName()); - ItemMeta itemMeta = itemStack.getItemMeta(); - itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, simulator.getName())); - itemStack.setItemMeta(itemMeta); + setSimulator(player, simulator); player.closeInventory(); }); } }; simulatorPageGui.open(); } + + public static void setSimulator(Player player, Simulator simulator) { + ItemStack mainHand = player.getInventory().getItemInMainHand(); + ItemStack offHand = player.getInventory().getItemInOffHand(); + ItemStack itemStack; + if (SimulatorCursor.isSimulatorItem(mainHand)) { + itemStack = mainHand; + } else if (SimulatorCursor.isSimulatorItem(offHand)) { + itemStack = offHand; + } else { + itemStack = null; + } + if (itemStack == null) { + return; + } + + ItemUtils.setTag(itemStack, simulatorSelection, simulator.getName()); + ItemMeta itemMeta = itemStack.getItemMeta(); + itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, simulator.getName())); + itemStack.setItemMeta(itemMeta); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java index 73f0ab1d..b1f6c6f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java @@ -35,7 +35,7 @@ import java.util.Map; @Getter @Setter @RequiredArgsConstructor -public class Simulator { +public final class Simulator { private Material material = Material.BARREL; private final String name; private boolean autoTrace = false; @@ -56,4 +56,9 @@ public class Simulator { simulatorGroup.toSimulatorActions(actions); }); } + + public Simulator add(SimulatorGroup group) { + elements.add(group); + return this; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java index e01ef88c..aeb99c42 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java @@ -28,6 +28,7 @@ import lombok.Setter; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import yapion.hierarchy.types.YAPIONObject; import java.util.ArrayList; import java.util.Comparator; @@ -56,7 +57,7 @@ public abstract class SimulatorElement { phases.sort(Comparator.comparingInt(SimulatorPhase::getTickOffset)); } - public abstract String getName(); + public abstract String getName(Player player); public int getBaseTick() { return phases.stream() @@ -97,7 +98,7 @@ public abstract class SimulatorElement { lore.add(""); lore.add("§cDisabled"); } - return new SWItem(material, "§e" + getName(), lore, disabled, invCallback); + return new SWItem(material, "§e" + getName(player), lore, disabled, invCallback); } public void toSimulatorActions(Map> actions) { @@ -115,4 +116,8 @@ public abstract class SimulatorElement { .findFirst() .orElse(null); } + + public abstract String getType(); + public void saveExtra(YAPIONObject elementObject) {} + public void loadExtra(YAPIONObject elementObject) {} } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java index 4e643fda..a4b6d031 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java @@ -34,9 +34,9 @@ import java.util.Map; @Getter @Setter -public class SimulatorGroup { +public final class SimulatorGroup { private Material material = Material.CHEST; - protected boolean disabled = false; + private boolean disabled = false; private final List> elements = new ArrayList<>(); public SimulatorGroup add(SimulatorElement element) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java index d70acee5..09e174fd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; import lombok.Getter; import lombok.Setter; import org.bukkit.util.Vector; +import yapion.hierarchy.types.YAPIONObject; import java.util.List; import java.util.Map; @@ -37,4 +38,6 @@ public abstract class SimulatorPhase { protected int order = 0; public abstract void toSimulatorActions(Map> actions, Vector position); + public void saveExtra(YAPIONObject phaseObject) {} + public void loadExtra(YAPIONObject phaseObject) {} } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java index 4ba337a8..4394f27f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java @@ -28,14 +28,14 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -public class RedstoneElement extends SimulatorElement { +public final class RedstoneElement extends SimulatorElement { public RedstoneElement(Vector position) { super(Material.REDSTONE_BLOCK, position); } @Override - public String getName() { + public String getName(Player player) { return "Redstone"; } @@ -58,4 +58,9 @@ public class RedstoneElement extends SimulatorElement { public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) { new SimulatorRedstoneGui(player, simulator, group, this, back).open(); } + + @Override + public String getType() { + return "Redstone"; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java index df2e06e2..0972c4ca 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java @@ -1,3 +1,4 @@ + /* * This file is a part of the SteamWar software. * @@ -34,7 +35,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @NoArgsConstructor -public class RedstonePhase extends SimulatorPhase { +public final class RedstonePhase extends SimulatorPhase { public RedstonePhase(int tickOffset) { this.tickOffset = tickOffset; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java index 62982a22..69b7c67f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java @@ -30,14 +30,14 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -public class TNTElement extends SimulatorElement { +public final class TNTElement extends SimulatorElement { public TNTElement(Vector position) { super(Material.TNT, position); } @Override - public String getName() { + public String getName(Player player) { return "TNT"; } @@ -74,6 +74,7 @@ public class TNTElement extends SimulatorElement { long sum = phases.stream().mapToInt(TNTPhase::getCount).sum(); SWItem swItem = super.toItem(player, invCallback); swItem.getItemStack().setAmount((int) Math.min(64, Math.max(1, sum))); + swItem.setName("§e" + getName(player) + "§8:§7 " + sum); return swItem; } @@ -91,4 +92,9 @@ public class TNTElement extends SimulatorElement { public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) { new SimulatorTNTGui(player, simulator, this, group, back).open(); } + + @Override + public String getType() { + return "TNT"; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java index 36c2d2f6..7becfec9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java @@ -27,6 +27,7 @@ import lombok.Setter; import org.bukkit.World; import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; +import yapion.hierarchy.types.YAPIONObject; import java.util.ArrayList; import java.util.List; @@ -35,7 +36,7 @@ import java.util.Map; @Getter @Setter @NoArgsConstructor -public class TNTPhase extends SimulatorPhase { +public final class TNTPhase extends SimulatorPhase { private int count = 1; private boolean xJump = false; private boolean yJump = false; @@ -68,4 +69,20 @@ public class TNTPhase extends SimulatorPhase { } }); } + + @Override + public void saveExtra(YAPIONObject phaseObject) { + phaseObject.add("count", count); + phaseObject.add("xJump", xJump); + phaseObject.add("yJump", yJump); + phaseObject.add("zJump", zJump); + } + + @Override + public void loadExtra(YAPIONObject phaseObject) { + count = phaseObject.getPlainValue("count"); + xJump = phaseObject.getPlainValue("xJump"); + yJump = phaseObject.getPlainValue("yJump"); + zJump = phaseObject.getPlainValue("zJump"); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java index 503feb86..f71e7f4c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java @@ -57,6 +57,10 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { parent.getElements().remove(subject); back.open(); SimulatorWatcher.update(simulator); + if (parent.getElements().size() == 1) { + parent.setDisabled(false); + parent.setMaterial(Material.BARREL); + } })); } } @@ -71,6 +75,10 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { InvCallback invCallback = clickType -> { simulatorGroup.add(subject); parent.getElements().remove(subject); + if (parent.getElements().size() == 1) { + parent.setDisabled(false); + parent.setMaterial(Material.BARREL); + } back.open(); SimulatorWatcher.update(simulator); }; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java index 33d87d76..7fe8e6b4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java @@ -23,8 +23,6 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java index b15ba629..326425de 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java @@ -49,7 +49,10 @@ public abstract class SimulatorBaseGui { String originalTitle = player.getOpenInventory().getTitle(); if (inv != null && (Core.getVersion() > 19 || newTitle.equals(originalTitle))) { - inv.clear(); + // TODO: Flickering is better but not gone! + for (int i = 9; i < size - 9; i++) { + inv.setItem(i, null); + } setup(); if (player.getOpenInventory().getTopInventory() != inv) { inventory.open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimFormatSimulatorLoader.java new file mode 100644 index 00000000..4082850f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimFormatSimulatorLoader.java @@ -0,0 +1,130 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.storage; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; +import org.bukkit.Material; +import org.bukkit.util.Vector; +import yapion.exceptions.YAPIONException; +import yapion.hierarchy.types.YAPIONArray; +import yapion.hierarchy.types.YAPIONObject; +import yapion.parser.YAPIONParser; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +public class SimFormatSimulatorLoader implements SimulatorLoader { + + @Override + public Optional> load(File file) { + if (!file.getName().endsWith(".sim")) { + return Optional.empty(); + } + + YAPIONObject yapionObject; + try { + yapionObject = YAPIONParser.parse(file); + } catch (YAPIONException | IOException e) { + return Optional.empty(); + } + + String name = file.getName().substring(0, file.getName().length() - ".sim".length()); + + Simulator simulator = new Simulator(name); + loadSimulator(yapionObject, simulator); + return Optional.of(Collections.singletonList(simulator)); + } + + private void loadSimulator(YAPIONObject simulatorObject, Simulator simulator) { + simulator.setMaterial(Material.valueOf(simulatorObject.getPlainValue("material"))); + simulator.setAutoTrace(simulatorObject.getPlainValue("autoTrace")); + + YAPIONArray groups = simulatorObject.getArray("groups"); + groups.streamObject().forEach(groupObject -> { + SimulatorGroup simulatorGroup = new SimulatorGroup(); + loadGroup(groupObject, simulatorGroup); + simulator.add(simulatorGroup); + }); + } + + private void loadGroup(YAPIONObject groupObject, SimulatorGroup group) { + group.setMaterial(Material.valueOf(groupObject.getPlainValue("material"))); + group.setDisabled(groupObject.getPlainValue("disabled")); + + YAPIONArray elements = groupObject.getArray("elements"); + elements.streamObject().forEach(elementObject -> { + SimulatorElement element; + Supplier phaseConstructor; + Vector position = new Vector(groupObject.getDouble("x"), groupObject.getDouble("y"), groupObject.getDouble("z")); + String type = groupObject.getPlainValue("type"); + switch (type) { + case "TNT": + element = new TNTElement(position); + phaseConstructor = TNTPhase::new; + break; + case "Redstone": + element = new RedstoneElement(position); + phaseConstructor = RedstonePhase::new; + break; + default: + element = null; + phaseConstructor = null; + break; + } + if (element == null) { + return; + } + loadElement(elementObject, element, phaseConstructor); + group.add(element); + }); + } + + private void loadElement(YAPIONObject elementObject, SimulatorElement element, Supplier phaseConstructor) { + element.setMaterial(Material.valueOf(elementObject.getPlainValue("material"))); + element.setDisabled(elementObject.getPlainValue("disabled")); + element.loadExtra(elementObject); + + YAPIONArray phases = elementObject.getArray("phases"); + phases.streamObject().forEach(phaseObject -> { + SimulatorPhase phase = phaseConstructor.get(); + loadPhase(phaseObject, phase); + ((SimulatorElement) element).add(phase); + }); + } + + private void loadPhase(YAPIONObject phaseObject, SimulatorPhase phase) { + phase.setTickOffset(phaseObject.getPlainValue("tickOffset")); + phase.setLifetime(phaseObject.getPlainValue("lifetime")); + phase.setOrder(phaseObject.getPlainValue("order")); + phase.loadExtra(phaseObject); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java new file mode 100644 index 00000000..86bc406e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java @@ -0,0 +1,136 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.storage; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; +import org.bukkit.Material; +import org.bukkit.util.Vector; +import yapion.exceptions.YAPIONException; +import yapion.hierarchy.types.YAPIONArray; +import yapion.hierarchy.types.YAPIONObject; +import yapion.parser.YAPIONParser; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +public class SimulatorFormatSimulatorLoader implements SimulatorLoader { + + @Override + public Optional> load(File file) { + if (!file.getName().endsWith(".simulator")) { + return Optional.empty(); + } + + YAPIONObject yapionObject; + try { + yapionObject = YAPIONParser.parse(file); + } catch (YAPIONException | IOException e) { + return Optional.empty(); + } + + String name = file.getName().substring(0, file.getName().length() - ".simulator".length()); + + Simulator simulator = new Simulator(name); + simulator.setMaterial(Material.valueOf(yapionObject.getStringOrDefault("material", "BARREL"))); + + YAPIONArray tntElements = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray()); + for (YAPIONObject element : tntElements.streamObject().collect(Collectors.toList())) { + if (element.containsKey("elements")) { + simulator.add(loadGroup(element)); + } else { + simulator.add(loadElement(element)); + } + } + + file.delete(); + return Optional.of(Collections.singletonList(simulator)); + } + + private SimulatorGroup loadGroup(YAPIONObject element) { + double x = element.getDoubleOrDefault("x", 0); + double y = element.getDoubleOrDefault("y", 0); + double z = element.getDoubleOrDefault("z", 0); + int tickOffset = element.getIntOrDefault("tickOffset", 0); + + SimulatorGroup simulatorGroup = new SimulatorGroup(); + simulatorGroup.setDisabled(element.getBooleanOrDefault("disabled", false)); + + YAPIONArray elements = element.getArrayOrDefault("elements", new YAPIONArray()); + for (YAPIONObject e : elements.streamObject().collect(Collectors.toList())) { + simulatorGroup.add(loadElement(e, x, y, z, tickOffset)); + } + + return simulatorGroup; + } + + private TNTElement loadElement(YAPIONObject element, double dx, double dy, double dz, int dTickOffset) { + TNTElement tntElement = new TNTElement(new Vector(element.getDouble("x") + dx, element.getDouble("y") + dy, element.getDouble("z") + dz)); + tntElement.setDisabled(element.getBooleanOrDefault("disabled", false)); + tntElement.setMaterial(Material.valueOf(element.getStringOrDefault("material", "TNT"))); + + TNTPhase tntPhase = loadPhase(element); + tntPhase.setTickOffset(tntPhase.getTickOffset() + dTickOffset); + tntElement.add(tntPhase); + + return tntElement; + } + + private SimulatorGroup loadElement(YAPIONObject element) { + SimulatorGroup simulatorGroup = new SimulatorGroup(); + + TNTElement tntElement = new TNTElement(new Vector(element.getDouble("x"), element.getDouble("y"), element.getDouble("z"))); + tntElement.setDisabled(element.getBooleanOrDefault("disabled", false)); + tntElement.setMaterial(Material.valueOf(element.getStringOrDefault("material", "TNT"))); + simulatorGroup.add(tntElement); + + tntElement.add(loadPhase(element)); + + return simulatorGroup; + } + + private TNTPhase loadPhase(YAPIONObject element) { + TNTPhase tntPhase = new TNTPhase(); + tntPhase.setLifetime(element.getIntOrDefault("fuseTicks", 80)); + tntPhase.setCount(element.getIntOrDefault("count", 1)); + tntPhase.setTickOffset(element.getIntOrDefault("tickOffset", 0)); + tntPhase.setXJump(element.getBooleanOrDefault("xVelocity", false)); + tntPhase.setYJump(element.getBooleanOrDefault("yVelocity", false)); + tntPhase.setZJump(element.getBooleanOrDefault("zVelocity", false)); + switch (element.getStringOrDefault("order", "REPEATER")) { + case "REPEATER": + tntPhase.setOrder(0); + break; + case "OBSERVER": + tntPhase.setOrder(1); + break; + case "COMPARATOR": + tntPhase.setOrder(2); + break; + } + return tntPhase; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorLoader.java new file mode 100644 index 00000000..70659936 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorLoader.java @@ -0,0 +1,31 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.storage; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; + +import java.io.File; +import java.util.List; +import java.util.Optional; + +public interface SimulatorLoader { + + Optional> load(File file); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java new file mode 100644 index 00000000..bb19c48d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java @@ -0,0 +1,81 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.storage; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import lombok.experimental.UtilityClass; +import yapion.hierarchy.output.FileOutput; +import yapion.hierarchy.types.YAPIONArray; +import yapion.hierarchy.types.YAPIONObject; + +import java.io.File; +import java.io.IOException; + +@UtilityClass +public class SimulatorSaver { + + public void saveSimulator(File directory, Simulator simulator) { + YAPIONObject simulatorObject = new YAPIONObject(); + simulatorObject.add("material", simulator.getMaterial().name()); + simulatorObject.add("autoTrace", simulator.isAutoTrace()); + + YAPIONArray groups = new YAPIONArray(); + simulator.getElements().forEach(group -> { + YAPIONObject groupObject = new YAPIONObject(); + groupObject.add("material", group.getMaterial().name()); + groupObject.add("disabled", group.isDisabled()); + groups.add(groupObject); + + YAPIONArray elements = new YAPIONArray(); + group.getElements().forEach(element -> { + YAPIONObject elementObject = new YAPIONObject(); + elementObject.add("type", element.getType()); + elementObject.add("material", element.getMaterial()); + elementObject.add("disabled", element.isDisabled()); + elementObject.add("x", element.getPosition().getX()); + elementObject.add("y", element.getPosition().getY()); + elementObject.add("z", element.getPosition().getZ()); + element.saveExtra(elementObject); + + YAPIONArray phases = new YAPIONArray(); + element.getPhases().forEach(phase -> { + YAPIONObject phaseObject = new YAPIONObject(); + phaseObject.add("tickOffset", phase.getTickOffset()); + phaseObject.add("lifetime", phase.getLifetime()); + phaseObject.add("order", phase.getOrder()); + phase.saveExtra(phaseObject); + phases.add(phaseObject); + }); + elementObject.add("phases", phases); + elements.add(elementObject); + }); + groupObject.add("elements", elements); + groups.add(groupObject); + }); + simulatorObject.add("groups", groups); + + File file = new File(directory, simulator.getName() + ".sim"); + try { + simulatorObject.toJSON(new FileOutput(file)).close(); + } catch (IOException e) { + // Ignore + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/YAPIONFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/YAPIONFormatSimulatorLoader.java new file mode 100644 index 00000000..6434fcc0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/YAPIONFormatSimulatorLoader.java @@ -0,0 +1,90 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator2.storage; + +import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Material; +import org.bukkit.util.Vector; +import yapion.exceptions.YAPIONException; +import yapion.hierarchy.types.YAPIONArray; +import yapion.hierarchy.types.YAPIONObject; +import yapion.parser.YAPIONParser; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +public class YAPIONFormatSimulatorLoader implements SimulatorLoader { + + @Override + public Optional> load(File file) { + if (!file.getName().endsWith(".yapion")) { + return Optional.empty(); + } + + YAPIONObject yapionObject; + try { + yapionObject = YAPIONParser.parse(file); + } catch (YAPIONException | IOException e) { + return Optional.empty(); + } + + String name = file.getName().substring(0, file.getName().length() - 7); + SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(name)); + + List simulators = new ArrayList<>(); + for (String s : yapionObject.getKeys()) { + String newName = steamwarUser.getUserName() + (s.isEmpty() ? "" : "_" + s); + YAPIONArray content = yapionObject.getArray(s); + if (content.isEmpty()) continue; + Simulator simulator = new Simulator(newName); + for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) { + SimulatorGroup simulatorGroup = new SimulatorGroup(); + simulator.add(simulatorGroup); + + TNTElement tntElement = new TNTElement(new Vector(element.getDouble("positionX"), element.getDouble("positionY"), element.getDouble("positionZ"))); + tntElement.setDisabled(element.getBooleanOrDefault("disabled", false)); // IDK if this existed back then? + tntElement.setMaterial(Material.valueOf(element.getStringOrDefault("material", "TNT"))); + simulatorGroup.add(tntElement); + + TNTPhase tntPhase = new TNTPhase(); + tntPhase.setLifetime(element.getIntOrDefault("fuseTicks", 80)); + tntPhase.setCount(element.getIntOrDefault("count", 1)); + tntPhase.setTickOffset(element.getIntOrDefault("tickOffset", 0)); + tntPhase.setXJump(element.getBooleanOrDefault("xVelocity", false)); + tntPhase.setYJump(element.getBooleanOrDefault("yVelocity", false)); + tntPhase.setZJump(element.getBooleanOrDefault("zVelocity", false)); + tntPhase.setOrder(element.getBooleanOrDefault("comparator", false) ? 2 : 0); + tntElement.add(tntPhase); + } + simulators.add(simulator); + } + + file.delete(); + return Optional.of(simulators); + } +} From b49c75d6bd6520394fc2dae00c2fa9920c174cf6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 26 Oct 2023 22:31:30 +0200 Subject: [PATCH 038/139] Add storage api and implement SimulatorStorage --- BauSystem_15/build.gradle | 4 +- BauSystem_18/build.gradle | 4 +- BauSystem_19/build.gradle | 4 +- BauSystem_20/build.gradle | 4 +- BauSystem_Linkage/build.gradle | 4 +- BauSystem_Main/build.gradle | 4 +- .../features/simulator/SimulatorStorage.java | 2 +- .../features/simulator2/SimulatorStorage.java | 66 +++++++++++++++++-- .../features/simulator2/SimulatorWatcher.java | 2 + .../SimulatorFormatSimulatorLoader.java | 2 +- .../simulator2/storage/SimulatorSaver.java | 5 +- 11 files changed, 77 insertions(+), 24 deletions(-) diff --git a/BauSystem_15/build.gradle b/BauSystem_15/build.gradle index 87ae1928..180c7022 100644 --- a/BauSystem_15/build.gradle +++ b/BauSystem_15/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 sourceSets { main { diff --git a/BauSystem_18/build.gradle b/BauSystem_18/build.gradle index 8deb57fd..8fb54099 100644 --- a/BauSystem_18/build.gradle +++ b/BauSystem_18/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 sourceSets { main { diff --git a/BauSystem_19/build.gradle b/BauSystem_19/build.gradle index fb86e3ac..e7be349d 100644 --- a/BauSystem_19/build.gradle +++ b/BauSystem_19/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 sourceSets { main { diff --git a/BauSystem_20/build.gradle b/BauSystem_20/build.gradle index bfb7c724..be167e64 100644 --- a/BauSystem_20/build.gradle +++ b/BauSystem_20/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 sourceSets { main { diff --git a/BauSystem_Linkage/build.gradle b/BauSystem_Linkage/build.gradle index 2169557f..de3818a5 100644 --- a/BauSystem_Linkage/build.gradle +++ b/BauSystem_Linkage/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 sourceSets { main { diff --git a/BauSystem_Main/build.gradle b/BauSystem_Main/build.gradle index 62d604cf..bf61d861 100644 --- a/BauSystem_Main/build.gradle +++ b/BauSystem_Main/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 sourceSets { main { 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 a549e0a2..5103136a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -48,7 +48,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -@Linked +// @Linked public class SimulatorStorage implements Enable, Disable { public static final World WORLD = Bukkit.getWorlds().get(0); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java index 8c49a66a..7bae9ba9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java @@ -22,21 +22,28 @@ package de.steamwar.bausystem.features.simulator2; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator2.storage.SimFormatSimulatorLoader; +import de.steamwar.bausystem.features.simulator2.storage.SimulatorFormatSimulatorLoader; +import de.steamwar.bausystem.features.simulator2.storage.SimulatorSaver; +import de.steamwar.bausystem.features.simulator2.storage.YAPIONFormatSimulatorLoader; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWItem; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.api.Enable; +import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import java.io.File; +import java.util.*; -public class SimulatorStorage { +@Linked +public class SimulatorStorage implements Enable { + public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators"); private static Map simulatorMap = new HashMap<>(); private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection"); @@ -65,8 +72,53 @@ public class SimulatorStorage { simulatorMap.putIfAbsent(name, simulator); } - private static Simulator loadSimulator(String name) { - return SimulatorTestCommand.SIMULATOR; // TODO: Implement Loading and legacy Loading + @Override + public void enable() { + SimFormatSimulatorLoader simFormatSimulatorLoader = new SimFormatSimulatorLoader(); + SimulatorFormatSimulatorLoader simulatorFormatSimulatorLoader = new SimulatorFormatSimulatorLoader(); + YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader(); + + for (File file : simulatorsDir.listFiles()) { + try { + List simulators = simFormatSimulatorLoader.load(file) + .orElse(null); + if (simulators != null) { + simulators.forEach(simulator -> { + simulatorMap.put(simulator.getName(), simulator); + }); + continue; + } + } catch (Exception e) { + // Ignore + } + + try { + List simulators = simulatorFormatSimulatorLoader.load(file) + .orElse(null); + if (simulators != null) { + simulators.forEach(simulator -> { + simulatorMap.put(simulator.getName(), simulator); + SimulatorSaver.saveSimulator(simulatorsDir, simulator); + }); + continue; + } + } catch (Exception e) { + // Ignore + } + + try { + List simulators = yapionFormatSimulatorLoader.load(file) + .orElse(null); + if (simulators != null) { + simulators.forEach(simulator -> { + simulatorMap.put(simulator.getName(), simulator); + SimulatorSaver.saveSimulator(simulatorsDir, simulator); + }); + } + } catch (Exception e) { + // Ignore + } + } } public static void openSimulatorSelector(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java index eb888615..edb97005 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator2.storage.SimulatorSaver; import de.steamwar.bausystem.shared.Pair; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; @@ -69,6 +70,7 @@ public class SimulatorWatcher { simulatorRunnablePair.getValue().run(); } }); + SimulatorSaver.saveSimulator(SimulatorStorage.simulatorsDir, simulator); } @Linked diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java index 86bc406e..3783f833 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java @@ -66,7 +66,7 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader { } } - file.delete(); + // file.delete(); return Optional.of(Collections.singletonList(simulator)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java index bb19c48d..9f1fadb1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java @@ -41,13 +41,12 @@ public class SimulatorSaver { YAPIONObject groupObject = new YAPIONObject(); groupObject.add("material", group.getMaterial().name()); groupObject.add("disabled", group.isDisabled()); - groups.add(groupObject); YAPIONArray elements = new YAPIONArray(); group.getElements().forEach(element -> { YAPIONObject elementObject = new YAPIONObject(); elementObject.add("type", element.getType()); - elementObject.add("material", element.getMaterial()); + elementObject.add("material", element.getMaterial().name()); elementObject.add("disabled", element.isDisabled()); elementObject.add("x", element.getPosition().getX()); elementObject.add("y", element.getPosition().getY()); @@ -73,7 +72,7 @@ public class SimulatorSaver { File file = new File(directory, simulator.getName() + ".sim"); try { - simulatorObject.toJSON(new FileOutput(file)).close(); + simulatorObject.toJSONLossy(new FileOutput(file)).close(); } catch (IOException e) { // Ignore } From c050046820ffd2687fd9291839f536202e69ed6e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 11:55:47 +0200 Subject: [PATCH 039/139] Remove old and move new --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../features/simulator/OrderUtils.java | 92 ---- .../simulator/SimulatorBauGuiItem.java | 60 --- .../features/simulator/SimulatorCommand.java | 121 ++--- .../features/simulator/SimulatorCursor.java | 417 +++++++++++++++--- .../features/simulator/SimulatorStorage.java | 269 +++++------ .../SimulatorWatcher.java | 11 +- .../features/simulator/TNTSimulator.java | 270 ------------ .../simulator/TNTSimulatorListener.java | 130 ------ .../data/Simulator.java | 4 +- .../data/SimulatorElement.java | 6 +- .../data/SimulatorGroup.java | 4 +- .../data/SimulatorPhase.java | 4 +- .../data/redstone/RedstoneElement.java | 12 +- .../data/redstone/RedstonePhase.java | 6 +- .../data/tnt/TNTElement.java | 12 +- .../data/tnt/TNTPhase.java | 6 +- .../execute/SimulatorAction.java | 2 +- .../execute/SimulatorExecutor.java | 4 +- .../features/simulator/gui/ItemUtils.java | 39 -- .../gui/SimulatorGroupChooserGui.java | 14 +- .../gui/SimulatorGroupGui.java | 14 +- .../gui/SimulatorGroupSettingsGui.java | 10 +- .../gui/SimulatorGui.java | 14 +- .../gui/SimulatorMaterialGui.java | 10 +- .../gui/SimulatorRedstoneGui.java | 16 +- .../SimulatorRedstonePhaseSettingsGui.java | 12 +- .../gui/SimulatorRedstoneSettingsGui.java | 10 +- .../simulator/gui/SimulatorSelectionGUI.java | 79 ---- .../gui/SimulatorSettingsGui.java | 8 +- .../gui/SimulatorTNTGui.java | 16 +- .../gui/SimulatorTNTPhaseSettingsGui.java | 14 +- .../gui/SimulatorTNTSettingsGui.java | 10 +- .../features/simulator/gui/TNTElementGUI.java | 390 ---------------- .../simulator/gui/TNTGroupEditGUI.java | 198 --------- .../simulator/gui/TNTSimulatorGui.java | 216 --------- .../gui/base/SimulatorBaseGui.java | 6 +- .../gui/base/SimulatorPageGui.java | 4 +- .../gui/base/SimulatorScrollGui.java | 4 +- .../gui/components/ChangeMaterial.java | 66 --- .../gui/components/ChangePosition.java | 163 ------- .../simulator/gui/components/Disabled.java | 42 -- .../storage/SimFormatSimulatorLoader.java | 19 +- .../SimulatorFormatSimulatorLoader.java | 12 +- .../storage/SimulatorLoader.java | 4 +- .../storage/SimulatorSaver.java | 4 +- .../storage/YAPIONFormatSimulatorLoader.java | 10 +- .../simulator/tnt/SimulatorElement.java | 90 ---- .../features/simulator/tnt/TNTElement.java | 318 ------------- .../features/simulator/tnt/TNTGroup.java | 186 -------- .../features/simulator2/SimulatorCursor.java | 416 ----------------- .../features/simulator2/SimulatorStorage.java | 162 ------- .../simulator2/SimulatorTestCommand.java | 53 --- 54 files changed, 670 insertions(+), 3391 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/OrderUtils.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/SimulatorWatcher.java (92%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/data/Simulator.java (93%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/data/SimulatorElement.java (94%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/data/SimulatorGroup.java (95%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/data/SimulatorPhase.java (91%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/data/redstone/RedstoneElement.java (80%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/data/redstone/RedstonePhase.java (92%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/data/tnt/TNTElement.java (88%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/data/tnt/TNTPhase.java (93%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/execute/SimulatorAction.java (94%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/execute/SimulatorExecutor.java (96%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/ItemUtils.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorGroupChooserGui.java (86%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorGroupGui.java (88%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorGroupSettingsGui.java (93%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorGui.java (80%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorMaterialGui.java (88%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorRedstoneGui.java (91%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorRedstonePhaseSettingsGui.java (92%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorRedstoneSettingsGui.java (93%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorSettingsGui.java (93%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorTNTGui.java (91%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorTNTPhaseSettingsGui.java (93%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/SimulatorTNTSettingsGui.java (94%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/base/SimulatorBaseGui.java (94%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/base/SimulatorPageGui.java (95%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/gui/base/SimulatorScrollGui.java (96%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangeMaterial.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/storage/SimFormatSimulatorLoader.java (87%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/storage/SimulatorFormatSimulatorLoader.java (93%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/storage/SimulatorLoader.java (88%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/storage/SimulatorSaver.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{simulator2 => simulator}/storage/YAPIONFormatSimulatorLoader.java (91%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 0037825c..ff127af6 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -313,6 +313,7 @@ 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_ERROR_COPY = §cCopy failed SIMULATOR_NOT_EXISTS = §cSimulator does not exist SIMULATOR_CREATE = §aSimulator created SIMULATOR_EDIT_LOCATION = §7Edit position diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index e5da397d..de6de310 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -305,6 +305,7 @@ 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_ERROR_COPY = §cFehler beim kopieren SIMULATOR_NOT_EXISTS = §cSimulator existiert nicht SIMULATOR_CREATE = §aSimulator erstellt SIMULATOR_EDIT_LOCATION = §7Editiere Positionen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/OrderUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/OrderUtils.java deleted file mode 100644 index 2c377cea..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/OrderUtils.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.BauSystem; -import lombok.experimental.UtilityClass; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@UtilityClass -public class OrderUtils { - - private final List activationOrder = new ArrayList<>(); - - private final Map nameMap = new HashMap<>(); - - static { - add(Material.REPEATER, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER"); - add(Material.OBSERVER, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_OBSERVER"); - add(Material.COMPARATOR, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR"); - } - - public Material next(Material material) { - int index = activationOrder.indexOf(material); - if (index == -1) { - return activationOrder.get(0); - } - if (index + 1 >= activationOrder.size()) { - return activationOrder.get(0); - } - return activationOrder.get(index + 1); - } - - public Material previous(Material material) { - int index = activationOrder.indexOf(material); - if (index == -1) { - return activationOrder.get(0); - } - if (index - 1 < 0) { - return activationOrder.get(activationOrder.size() - 1); - } - return activationOrder.get(index - 1); - } - - public List orderList(Material material, Player player) { - List lore = new ArrayList<>(); - for (Material m : activationOrder) { - String element = BauSystem.MESSAGE.parse(name(m), player); - if (m == material) { - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVE", player, element)); - } else { - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_INACTIVE", player, element)); - } - } - return lore; - } - - public int order(Material material) { - return activationOrder.indexOf(material); - } - - public String name(Material material) { - return nameMap.getOrDefault(material, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_UNKNOWN"); - } - - private void add(Material material, String name) { - activationOrder.add(material); - nameMap.put(material, name); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java deleted file mode 100644 index baae7add..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 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.BauSystem; -import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.linkage.specific.BauGuiItem; -import de.steamwar.inventory.SWItem; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -@Linked -public class SimulatorBauGuiItem extends BauGuiItem { - - public SimulatorBauGuiItem() { - super(20); - } - - @Override - public ItemStack getItem(Player player) { - ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_GUI_ITEM_NAME", player)).getItemStack(); - ItemMeta itemMeta = itemStack.getItemMeta(); - itemMeta.setCustomModelData(1); - itemStack.setItemMeta(itemMeta); - return itemStack; - } - - @Override - public boolean click(ClickType click, Player p) { - p.closeInventory(); - p.performCommand("sim"); - return false; - } - - @Override - public Permission permission() { - return Permission.WORLD; - } -} 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 640d0360..5f320fc5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -1,20 +1,20 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2022 SteamWar.de-Serverteam + * Copyright (C) 2023 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 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. + * 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 . + * 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; @@ -22,105 +22,76 @@ package de.steamwar.bausystem.features.simulator; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI; -import de.steamwar.bausystem.utils.ItemUtils; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; import java.util.Collection; @Linked public class SimulatorCommand extends SWCommand { + @LinkedInstance + public SimulatorCursor simulatorCursor; + public SimulatorCommand() { - super("simulator", "sim"); + super("sim", "simulator"); } @Register(description = "SIMULATOR_HELP") public void genericCommand(@Validator Player p) { - SimulatorCursor.hide(p, null); SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p)); + simulatorCursor.calcCursor(p); } @Register(value = "change", description = "SIMULATOR_CHANGE_HELP") public void change(@Validator Player p) { - ItemStack itemStack = p.getInventory().getItemInMainHand(); - if (!ItemUtils.isItem(itemStack, "simulator")) { + if (!SimulatorCursor.isSimulatorItem(p.getInventory().getItemInMainHand()) && !SimulatorCursor.isSimulatorItem(p.getInventory().getItemInOffHand())) { BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p); return; } - SimulatorSelectionGUI.open(p, itemStack); - } - - @Register(value = "create", description = "SIMULATOR_CREATE_HELP") - public void create(@Validator 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 false; - } - if (!name.matches("[a-zA-Z_0-9-]+")) { - BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p); - return false; - } - SimulatorStorage.createNewSimulator(name); - BauSystem.MESSAGE.send("SIMULATOR_CREATE", p); - return true; - } - - @Register(value = "delete", description = "SIMULATOR_DELETE_HELP") - public void delete(@Validator 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(@Validator Player p, @Mapper("simulators") String name) { - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(name); - if (tntSimulator == null) { - BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p); - return; - } - tntSimulator.start(p); + SimulatorStorage.openSimulatorSelector(p); } @Register(value = "copy", description = "SIMULATOR_COPY_HELP") - public void copy(@Validator Player p, @Mapper("simulators") String toCopy, String name) { - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(toCopy); - if (tntSimulator == null) { - BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p); - return; - } + public void copy(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, String name) { if (SimulatorStorage.getSimulator(name) != null) { BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p); return; } - SimulatorStorage.copySimulator(tntSimulator, name); + if (!name.matches("[a-zA-Z_0-9-]+")) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p); + return; + } + if (!SimulatorStorage.copy(simulator, name)) { + BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p); + } } - @Mapper("simulators") - public TypeMapper allSimulators() { - return new TypeMapper() { + @Register(value = "delete", description = "SIMULATOR_DELETE_HELP") + public void delete(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator) { + SimulatorStorage.delete(simulator); + BauSystem.MESSAGE.send("SIMULATOR_DELETED", p); + } + + @Register(value = "start", description = "SIMULATOR_START_HELP") + public void start(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator) { + SimulatorExecutor.run(simulator); + } + + @ClassMapper(value = Simulator.class, local = true) + public TypeMapper allSimulators() { + return new TypeMapper<>() { @Override - public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { - if (SimulatorStorage.getSimulatorNames().contains(s)) { - return s; - } else { - return null; - } + public Simulator map(CommandSender commandSender, PreviousArguments previousArguments, String s) { + return SimulatorStorage.getSimulator(s); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index eede5d32..39564fa6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -1,108 +1,219 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2022 SteamWar.de-Serverteam + * Copyright (C) 2023 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 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. + * 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 . + * 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 com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor; +import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui; +import de.steamwar.bausystem.features.simulator.gui.SimulatorGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; +import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; -import lombok.experimental.UtilityClass; -import net.md_5.bungee.api.ChatMessageType; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.linkage.Linked; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.*; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Collectors; -@UtilityClass -public class SimulatorCursor { +@Linked +public class SimulatorCursor implements Listener { - private static final World WORLD = Bukkit.getWorlds().get(0); - private Map rEntityServerMap = new HashMap<>(); + private final World WORLD = Bukkit.getWorlds().get(0); + private Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); + private Class look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook"); + private Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); - public void show(Player player, TNTSimulator tntSimulator, RayTraceUtils.RRayTraceResult result) { - if (true) return; - REntityServer cursor = rEntityServerMap.get(player); + private Map cursorType = Collections.synchronizedMap(new HashMap<>()); + private Map cursors = Collections.synchronizedMap(new HashMap<>()); - if (cursor != null) - cursor.close(); - - tntSimulator.show(player); - - if (result == null) - return; - - if (result.getHitEntity() != null) { - List elements = tntSimulator.getEntity(result.getHitEntity()); - - cursor = new REntityServer(); - RFallingBlockEntity entity = new RFallingBlockEntity(cursor, (elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition()).toLocation(WORLD), Material.TNT); - entity.setNoGravity(true); - entity.setGlowing(true); - cursor.addPlayer(player); - rEntityServerMap.put(player, cursor); - BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_EDIT", player, ChatMessageType.ACTION_BAR); - return; - } - - if (SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()) != null && result.getHitPosition().distanceSquared(player.getLocation().toVector()) < 25) { - return; - } - - cursor = new REntityServer(); - RFallingBlockEntity entity = new RFallingBlockEntity(cursor, getPos(player, result).toLocation(WORLD), Material.TNT); - entity.setNoGravity(true); - cursor.addPlayer(player); - rEntityServerMap.put(player, cursor); - BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_ADD", player, ChatMessageType.ACTION_BAR); + public static boolean isSimulatorItem(ItemStack itemStack) { + return ItemUtils.isItem(itemStack, "simulator"); } - public void hide(Player player) { - REntityServer cursor = rEntityServerMap.get(player); - if (cursor == null) return; + public SimulatorCursor() { + BiFunction function = (player, object) -> { + calcCursor(player); + return object; + }; + TinyProtocol.instance.addFilter(position, function); + TinyProtocol.instance.addFilter(look, function); + TinyProtocol.instance.addFilter(positionLook, function); + } - cursor.close(); - SimulatorStorage.getSimulatorNames().forEach(s -> { - SimulatorStorage.getSimulator(s).hide(player); + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + calcCursor(event.getPlayer()); + } + + @EventHandler + public void onPlayerDropItem(PlayerDropItemEvent event) { + calcCursor(event.getPlayer()); + } + + @EventHandler + public void onPlayerItemHeld(PlayerItemHeldEvent event) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + calcCursor(event.getPlayer()); + }, 1); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + cursorType.remove(event.getPlayer()); + cursors.remove(event.getPlayer()); + } + + private static final Map LAST_SNEAKS = new HashMap<>(); + + static { + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + long millis = System.currentTimeMillis(); + LAST_SNEAKS.entrySet().removeIf(entry -> millis - entry.getValue() > 200); + }, 1, 1); + } + + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { + if (!event.isSneaking()) return; + Player player = event.getPlayer(); + if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + return; + } + if (LAST_SNEAKS.containsKey(player)) { + cursorType.put(player, cursorType.getOrDefault(player, CursorType.TNT).switchType()); + calcCursor(player); + } else { + LAST_SNEAKS.put(player, System.currentTimeMillis()); + } + } + + public synchronized void calcCursor(Player player) { + if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + if (removeCursor(player)) { + SimulatorWatcher.show(null, player); + SWUtils.sendToActionbar(player, ""); + } + return; + } + Simulator simulator = SimulatorStorage.getSimulator(player); + SimulatorWatcher.show(simulator, player); + + List entities = SimulatorWatcher.getEntitiesOfSimulator(simulator); + RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities); + if (rayTraceResult == null) { + removeCursor(player); + if (simulator == null) { + SWUtils.sendToActionbar(player, "§eSelect Simulator"); + } else { + SWUtils.sendToActionbar(player, "§eOpen Simulator"); + } + return; + } + + showCursor(player, rayTraceResult, simulator != null); + } + + private synchronized boolean removeCursor(Player player) { + REntityServer entityServer = cursors.get(player); + boolean hadCursor = entityServer != null && !entityServer.getEntities().isEmpty(); + if (entityServer != null) { + entityServer.getEntities().forEach(REntity::die); + } + return hadCursor; + } + + private synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, boolean hasSimulatorSelected) { + REntityServer entityServer = cursors.computeIfAbsent(player, __ -> { + REntityServer rEntityServer = new REntityServer(); + rEntityServer.addPlayer(player); + return rEntityServer; }); - } - public void hide(Player player, TNTSimulator tntSimulator) { - REntityServer cursor = rEntityServerMap.get(player); + CursorType type = cursorType.getOrDefault(player, CursorType.TNT); + REntity hitEntity = rayTraceResult.getHitEntity(); + Location location = hitEntity != null ? new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD) : + type.position.apply(player, rayTraceResult).toLocation(WORLD); - if (cursor != null) - cursor.close(); - - if (tntSimulator != null) { - tntSimulator.hide(player); + Material material = hitEntity != null ? Material.GLASS : type.getMaterial(); + List entities = entityServer.getEntitiesByType(RFallingBlockEntity.class); + entities.removeIf(rFallingBlockEntity -> { + if (rFallingBlockEntity.getMaterial() != material) { + rFallingBlockEntity.die(); + return true; + } + rFallingBlockEntity.move(location); + return false; + }); + if (entities.isEmpty()) { + RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, location, material); + rFallingBlockEntity.setNoGravity(true); + if (material == Material.GLASS) { + rFallingBlockEntity.setGlowing(true); + } + } + + if (hasSimulatorSelected) { + if (hitEntity != null) { + SWUtils.sendToActionbar(player, "§eEdit Position"); + } else { + SWUtils.sendToActionbar(player, "§eAdd new " + type.name); + } + } else { + SWUtils.sendToActionbar(player, "§eCreate new Simulator"); } - rEntityServerMap.remove(player); } - public static Vector getPos(Player player, RayTraceUtils.RRayTraceResult result) { + public static Vector getPosTNT(Player player, RayTraceUtils.RRayTraceResult result) { Vector pos = result.getHitPosition(); BlockFace face = result.getHitBlockFace(); @@ -141,4 +252,172 @@ public class SimulatorCursor { return pos; } + + private static Vector getPosRedstoneBlock(Player player, RayTraceUtils.RRayTraceResult result) { + Vector pos = result.getHitPosition(); + + BlockFace face = result.getHitBlockFace(); + if (face != null) { + switch (face) { + case DOWN: + pos.setY(pos.getY() - 0.98); + break; + case EAST: + pos.setX(pos.getX() + 0.49); + break; + case WEST: + pos.setX(pos.getX() - 0.49); + break; + case NORTH: + pos.setZ(pos.getZ() - 0.49); + break; + case SOUTH: + pos.setZ(pos.getZ() + 0.49); + break; + default: + break; + } + } + + pos.setX(pos.getBlockX() + 0.5); + if (pos.getY() - pos.getBlockY() != 0 && face == BlockFace.UP) { + pos.setY(pos.getBlockY() + 1.0); + } else { + pos.setY(pos.getBlockY()); + } + pos.setZ(pos.getBlockZ() + 0.5); + return pos; + } + + @Getter + @AllArgsConstructor + public enum CursorType { + TNT(Material.TNT, SimulatorCursor::getPosTNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())), + REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())), + ; + + private Material material; + private BiFunction position; + private String name; + private Function> elementFunction; + + public CursorType switchType() { + if (this == TNT) { + return REDSTONE_BLOCK; + } + return TNT; + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (!ItemUtils.isItem(event.getItem(), "simulator")) { + return; + } + + event.setCancelled(true); + Player player = event.getPlayer(); + Simulator simulator = SimulatorStorage.getSimulator(player); + + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { + if (simulator == null) { + return; + } + SimulatorExecutor.run(simulator); + return; + } + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) { + return; + } + + + RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator)); + if (simulator == null) { + if (rayTraceResult == null) { + SimulatorStorage.openSimulatorSelector(player); + } else { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Name"); + anvilInv.setCallback(s -> { + Simulator sim = SimulatorStorage.getSimulator(s); + if (sim != null) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", player); + return; + } + if (!s.matches("[a-zA-Z_0-9-]+")) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", player); + return; + } + sim = new Simulator(s); + SimulatorStorage.addSimulator(s, sim); + createElement(player, rayTraceResult, sim); + SimulatorStorage.setSimulator(player, sim); + }); + anvilInv.open(); + } + return; + } + + if (rayTraceResult == null) { + new SimulatorGui(player, simulator).open(); + return; + } + + if (rayTraceResult.getHitEntity() != null) { + REntity hitEntity = rayTraceResult.getHitEntity(); + Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()); + List> elements = simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> { + return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0); + }).collect(Collectors.toList()); + + switch (elements.size()) { + case 0: + return; + case 1: + // Open single element present in Simulator + SimulatorElement element = elements.get(0); + SimulatorGroup group1 = element.getGroup(simulator); + SimulatorBaseGui back = new SimulatorGui(player, simulator); + if (group1.getElements().size() > 1) { + back = new SimulatorGroupGui(player, simulator, group1, back); + } + element.open(player, simulator, group1, back); + break; + default: + List parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList()); + if (parents.size() == 1) { + // Open multi element present in Simulator in existing group + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + new SimulatorGroupGui(player, simulator, parents.get(0), simulatorGui).open(); + } else { + // Open multi element present in Simulator in implicit group + SimulatorGroup group2 = new SimulatorGroup(); + group2.setMaterial(null); + group2.getElements().addAll(elements); + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + new SimulatorGroupGui(player, simulator, group2, simulatorGui).open(); + } + break; + } + return; + } + + // Add new Element to current simulator + createElement(player, rayTraceResult, simulator); + } + + private void createElement(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, Simulator simulator) { + CursorType type = cursorType.getOrDefault(player, CursorType.TNT); + Vector vector = type.position.apply(player, rayTraceResult); + if (type == CursorType.REDSTONE_BLOCK) { + vector.subtract(new Vector(0.5, 0, 0.5)); + } + SimulatorElement element = type.elementFunction.apply(vector); + SimulatorGroup group = new SimulatorGroup().add(element); + simulator.getElements().add(group); + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + element.open(player, simulator, group, simulatorGui); + SimulatorWatcher.update(simulator); + calcCursor(player); + } } 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 5103136a..071a2acd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -1,124 +1,145 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2022 SteamWar.de-Serverteam + * Copyright (C) 2023 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 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. + * 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 . + * 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 com.google.common.io.Files; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.simulator.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator.storage.SimFormatSimulatorLoader; +import de.steamwar.bausystem.features.simulator.storage.SimulatorFormatSimulatorLoader; +import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver; +import de.steamwar.bausystem.features.simulator.storage.YAPIONFormatSimulatorLoader; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.api.Disable; import de.steamwar.linkage.api.Enable; -import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import yapion.exceptions.YAPIONException; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONObject; -import yapion.parser.YAPIONParser; import java.io.File; import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; +import java.util.*; -// @Linked -public class SimulatorStorage implements Enable, Disable { - - public static final World WORLD = Bukkit.getWorlds().get(0); - private static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators"); +@Linked +public class SimulatorStorage implements Enable { + public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators"); + private static Map simulatorMap = new HashMap<>(); private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection"); - private static Map tntSimulators = new HashMap<>(); - - public static void createNewSimulator(String name) { - tntSimulators.put(name, new TNTSimulator()); - } - - public static Set getSimulatorNames() { - return tntSimulators.keySet(); - } - - public static TNTSimulator getSimulator(String name) { - return tntSimulators.get(name); - } - - public static TNTSimulator getSimulator(Player player) { - TNTSimulator current = getSimulator(player.getInventory().getItemInMainHand()); - if (current != null) return current; + public static Simulator getSimulator(Player player) { + Simulator simulator = getSimulator(player.getInventory().getItemInMainHand()); + if (simulator != null) return simulator; return getSimulator(player.getInventory().getItemInOffHand()); } - public static TNTSimulator getSimulator(ItemStack itemStack) { - if (itemStack == null) { - return null; - } - if (!ItemUtils.isItem(itemStack, "simulator")) { + public static Simulator getSimulator(ItemStack itemStack) { + if (!SimulatorCursor.isSimulatorItem(itemStack)) { return null; } String selection = ItemUtils.getTag(itemStack, simulatorSelection); if (selection == null) { return null; } - return tntSimulators.get(selection); + return simulatorMap.get(selection); } - public static void setSimulator(Player player, ItemStack itemStack, TNTSimulator simulator) { - for (Map.Entry entry : tntSimulators.entrySet()) { - if (entry.getValue() == simulator) { - ItemUtils.setTag(itemStack, simulatorSelection, entry.getKey()); - ItemMeta itemMeta = itemStack.getItemMeta(); - itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, entry.getKey())); - itemStack.setItemMeta(itemMeta); - return; + public static Simulator getSimulator(String name) { + return simulatorMap.get(name); + } + + public static void addSimulator(String name, Simulator simulator) { + simulatorMap.putIfAbsent(name, simulator); + } + + @Override + public void enable() { + SimFormatSimulatorLoader simFormatSimulatorLoader = new SimFormatSimulatorLoader(); + SimulatorFormatSimulatorLoader simulatorFormatSimulatorLoader = new SimulatorFormatSimulatorLoader(); + YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader(); + + for (File file : simulatorsDir.listFiles()) { + try { + List simulators = simFormatSimulatorLoader.load(file) + .orElse(null); + if (simulators != null) { + simulators.forEach(simulator -> { + simulatorMap.put(simulator.getName(), simulator); + }); + continue; + } + } catch (Exception e) { + // Ignore + } + + try { + List simulators = simulatorFormatSimulatorLoader.load(file) + .orElse(null); + if (simulators != null) { + simulators.forEach(simulator -> { + simulatorMap.put(simulator.getName(), simulator); + SimulatorSaver.saveSimulator(simulatorsDir, simulator); + }); + continue; + } + } catch (Exception e) { + // Ignore + } + + try { + List simulators = yapionFormatSimulatorLoader.load(file) + .orElse(null); + if (simulators != null) { + simulators.forEach(simulator -> { + simulatorMap.put(simulator.getName(), simulator); + SimulatorSaver.saveSimulator(simulatorsDir, simulator); + }); + } + } catch (Exception e) { + // Ignore } } } - public static void delete(String name) { - TNTSimulator tntSimulator = tntSimulators.remove(name); - if (tntSimulator != null) { - tntSimulator.close(); - } - new File(simulatorsDir, name + ".simulator").delete(); - } + public static void openSimulatorSelector(Player player) { + SimulatorPageGui simulatorPageGui = new SimulatorPageGui(player, null, 6 * 9, new ArrayList<>(simulatorMap.values())) { + @Override + public String baseTitle() { + return "Simulators"; + } - public static void copySimulator(TNTSimulator tntSimulator, String name) { - tntSimulators.put(name, new TNTSimulator(tntSimulator.toYAPION())); - } - - public static void removeSimulator(ItemStack itemStack) { - if (!ItemUtils.isItem(itemStack, "simulator")) { - return; - } - ItemUtils.setTag(itemStack, simulatorSelection, null); + @Override + public SWItem convert(Simulator simulator) { + return simulator.toItem(player, clickType -> { + setSimulator(player, simulator); + player.closeInventory(); + }); + } + }; + simulatorPageGui.open(); } public static ItemStack getWand(Player p) { @@ -130,68 +151,48 @@ public class SimulatorStorage implements Enable, Disable { return itemStack; } - @Override - public void enable() { - if (!simulatorsDir.exists()) { - simulatorsDir.mkdir(); + public static void setSimulator(Player player, Simulator simulator) { + ItemStack mainHand = player.getInventory().getItemInMainHand(); + ItemStack offHand = player.getInventory().getItemInOffHand(); + ItemStack itemStack; + if (SimulatorCursor.isSimulatorItem(mainHand)) { + itemStack = mainHand; + } else if (SimulatorCursor.isSimulatorItem(offHand)) { + itemStack = offHand; + } else { + itemStack = null; } - File[] files = simulatorsDir.listFiles(); - if (files == null) return; - - for (File file : files) { - YAPIONObject yapionObject; - try { - yapionObject = YAPIONParser.parse(file); - } catch (YAPIONException | IOException e) { - continue; - } - if (file.getName().endsWith(".yapion")) { - String name = file.getName().substring(0, file.getName().length() - 7); - try { - SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(name)); - convert(file, steamwarUser); - } catch (Exception e) { - file.delete(); - } - } else { - String name = file.getName().substring(0, file.getName().length() - ".simulator".length()); - tntSimulators.put(name, new TNTSimulator(yapionObject)); - } - } - } - - private static void convert(File file, SteamwarUser steamwarUser) { - YAPIONObject yapionObject; - try { - yapionObject = YAPIONParser.parse(file); - } catch (YAPIONException | IOException e) { + if (itemStack == null) { return; } - try { - file.delete(); - } catch (Exception e) { - e.printStackTrace(); - } - for (String s : yapionObject.getKeys()) { - String newName = steamwarUser.getUserName() + (s.isEmpty() ? "" : "_" + s); - YAPIONArray content = yapionObject.getArray(s); - if (content.isEmpty()) continue; - TNTSimulator tntSimulator = new TNTSimulator(); - for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) { - tntSimulator.getTntElementList().add(new TNTElement(element, null, tntSimulator.getEntityServer())); - } - tntSimulators.put(newName, tntSimulator); - } + + ItemUtils.setTag(itemStack, simulatorSelection, simulator.getName()); + ItemMeta itemMeta = itemStack.getItemMeta(); + itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, simulator.getName())); + itemStack.setItemMeta(itemMeta); } - @Override - public void disable() { - for (Map.Entry entry : tntSimulators.entrySet()) { - try { - entry.getValue().toYAPION().toFile(new File(simulatorsDir, entry.getKey() + ".simulator")); - } catch (Exception e) { - e.printStackTrace(); - } + public static List getSimulatorNames() { + return new ArrayList<>(simulatorMap.keySet()); + } + + public static void delete(Simulator simulator) { + simulatorMap.remove(simulator.getName()); + new File(simulatorsDir, simulator.getName() + ".sim").delete(); + } + + public static boolean copy(Simulator simulator, String name) { + try { + File file = new File(simulatorsDir, name + ".sim"); + Files.copy(new File(simulatorsDir, simulator.getName() + ".sim"), file); + new SimFormatSimulatorLoader().load(file).ifPresent(simulators -> { + simulators.forEach(sim -> { + simulatorMap.put(sim.getName(), sim); + }); + }); + return true; + } catch (IOException e) { + return false; } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java similarity index 92% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java index edb97005..1a3f3987 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java @@ -17,13 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2; +package de.steamwar.bausystem.features.simulator; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.storage.SimulatorSaver; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver; import de.steamwar.bausystem.shared.Pair; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java deleted file mode 100644 index d1a71b95..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * 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.BauSystem; -import de.steamwar.bausystem.configplayer.Config; -import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI; -import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui; -import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; -import de.steamwar.bausystem.features.simulator.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator.tnt.TNTGroup; -import de.steamwar.bausystem.features.tracer.record.Recorder; -import de.steamwar.bausystem.features.tracer.record.SingleTraceRecorder; -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.shared.Pair; -import de.steamwar.bausystem.utils.RayTraceUtils; -import de.steamwar.entity.REntity; -import de.steamwar.entity.REntityServer; -import lombok.Getter; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONObject; -import yapion.hierarchy.types.YAPIONType; - -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -@Getter -public class TNTSimulator { - - private Set players = new HashSet<>(); - private REntityServer entityServer = new REntityServer(); - - private Material material = Material.TNT; - - private List tntElementList = new ArrayList<>(); - - public TNTSimulator() { - - } - - public TNTSimulator(YAPIONObject yapionObject) { - material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name())); - YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray()); - for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) { - if (element.containsKey("elements", YAPIONType.ARRAY)) { - tntElementList.add(new TNTGroup(element, entityServer)); - } else { - tntElementList.add(new TNTElement(element, null, entityServer)); - } - } - } - - public YAPIONObject toYAPION() { - YAPIONObject yapionObject = new YAPIONObject(); - yapionObject.add("material", material.name()); - YAPIONArray yapionArray = new YAPIONArray(); - for (SimulatorElement element : tntElementList) { - yapionArray.add(element.toYAPION()); - } - yapionObject.add("tntElements", yapionArray); - return yapionObject; - } - - public void close() { - entityServer.close(); - } - - public void show(Player player) { - if (!players.contains(player)) { - entityServer.addPlayer(player); - players.add(player); - } - } - - public void hide(Player player) { - if (players.contains(player)) { - entityServer.removePlayer(player); - players.remove(player); - } - } - - void _hide(Player player) { - players.remove(player); - } - - public List getEntities() { - return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList()); - } - - public List getEntity(REntity entity) { - List tntSpawns = new ArrayList<>(); - for (SimulatorElement spawn : tntElementList) { - spawn.getEntity(tntSpawns, entity); - } - return tntSpawns; - } - - public void clear() { - new ArrayList<>(tntElementList).forEach(this::remove); - } - - public void remove(SimulatorElement element) { - if (element instanceof TNTElement) { - TNTElement tntElement = (TNTElement) element; - if (tntElement.hasParent()) { - tntElement.getParent().remove(tntElement); - if (tntElement.getParent().getElements().isEmpty()) { - remove(tntElement.getParent()); - } - } else { - element.remove(tntElement); - } - } else if (element instanceof TNTGroup) { - TNTGroup tntGroup = (TNTGroup) element; - tntGroup.getElements().forEach(tntElement -> { - tntElement.remove(tntElement); - }); - tntGroup.getElements().clear(); - } - element.close(); - tntElementList.remove(element); - } - - public void change() { - tntElementList.forEach(simulatorElement -> { - simulatorElement.change(); - if (simulatorElement instanceof TNTGroup) { - ((TNTGroup) simulatorElement).getElements().forEach(SimulatorElement::change); - } - }); - } - - public void edit(Player player, RayTraceUtils.RRayTraceResult result) { - if (result == null) { - TNTSimulatorGui.open(player, this, null, this::getTntElementList, null); - return; - } - - SimulatorCursor.show(player, this, result); - - if (result.getHitEntity() != null) { - List elements = getEntity(result.getHitEntity()); - if (elements.isEmpty()) return; - - if (elements.size() == 1) { - TNTElementGUI.open(player, (TNTElement) elements.get(0), null); - } else { - List tntGroups = tntElementList.stream().filter(TNTGroup.class::isInstance).map(TNTGroup.class::cast).collect(Collectors.toList()); - List newElementList = new ArrayList<>(); - for (TNTGroup tntGroup : tntGroups) { - if (new HashSet<>(elements).containsAll(tntGroup.getElements())) { - newElementList.add(tntGroup); - elements.removeAll(tntGroup.getElements()); - } - } - newElementList.addAll(elements); - if (newElementList.size() == 1) { - SimulatorElement element = newElementList.get(0); - if (element instanceof TNTGroup) { - TNTGroup tntGroup = (TNTGroup) element; - TNTSimulatorGui.open(player, null, tntGroup, () -> { - List elementList = new ArrayList<>(); - elementList.addAll(tntGroup.getElements()); - return elementList; - }, null); - } else { - TNTElementGUI.open(player, (TNTElement) elements.get(0), null); - } - } else { - TNTSimulatorGui.open(player, null, null, () -> newElementList, null); - } - } - return; - } - - if (SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()) != null && result.getHitPosition().distanceSquared(player.getLocation().toVector()) < 25) { - return; - } - - TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result), null, entityServer); - tntElementList.add(tntElement); - TNTElementGUI.open(player, tntElement, null); - } - - public void start(Player p) { - Region region = Region.getRegion(p.getLocation()); - Map>>> result = new HashMap<>(); - boolean regionFrozen = false; - for (SimulatorElement element : tntElementList) { - regionFrozen |= element.locations(result, region, p.getLocation()); - } - if (regionFrozen) { - BauSystem.MESSAGE.send("SIMULATOR_REGION_FROZEN", p); - return; - } - - AtomicBoolean needsAutoTrace = new AtomicBoolean(); - players.forEach(player -> { - boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); - if (simulatorAutoTrace) { - needsAutoTrace.set(true); - player.performCommand("trace show"); - } - }); - if (needsAutoTrace.get()) { - Recorder.INSTANCE.set(region, new SingleTraceRecorder(region)); - } - - AtomicInteger maxTick = new AtomicInteger(0); - Map>>> toSpawn = new HashMap<>(); - result.forEach((integer, integerSetMap) -> { - List>>> internal = new ArrayList<>(); - integerSetMap.forEach((integer1, pairs) -> { - internal.add(new Pair<>(integer1, pairs)); - }); - internal.sort(Comparator.comparingInt(Pair::getKey)); - - toSpawn.put(integer, internal.stream().map(Pair::getValue).map(ArrayList::new).peek(Collections::shuffle).collect(Collectors.toList())); - - if (maxTick.get() < integer) { - maxTick.set(integer); - } - }); - - AtomicInteger currentTick = new AtomicInteger(0); - BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> { - int tick = currentTick.get(); - if (tick > maxTick.get()) bukkitTask.cancel(); - currentTick.incrementAndGet(); - - List>> toSpawnInTick = toSpawn.get(tick); - if (toSpawnInTick == null) return; - toSpawnInTick.forEach(pairs -> { - AtomicBoolean hasSomeLeft = new AtomicBoolean(true); - while(hasSomeLeft.get()) { - hasSomeLeft.set(false); - pairs.forEach(pair -> { - if (pair.getValue() > 0) { - hasSomeLeft.set(true); - pair.getKey().run(); - pair.setValue(pair.getValue() - 1); - } - }); - } - }); - }, 1, 1); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java deleted file mode 100644 index bfead637..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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.BauSystem; -import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI; -import de.steamwar.bausystem.utils.ItemUtils; -import de.steamwar.bausystem.utils.RayTraceUtils; -import de.steamwar.linkage.Linked; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.*; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; - -import java.util.function.Function; - -// @Linked -public class TNTSimulatorListener implements Listener { - - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLD)) { - BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player); - return false; - } - return true; - } - - static RayTraceUtils.RRayTraceResult trace(Player player, Location to, TNTSimulator simulator) { - return RayTraceUtils.traceREntity(player, to, simulator.getEntities()); - } - - @EventHandler - public void onPlayerMove(PlayerMoveEvent e) { - if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) { - simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getTo()); - } else { - SimulatorCursor.hide(e.getPlayer()); - } - } - - @EventHandler - public void onPlayerItemHeld(PlayerItemHeldEvent e) { - 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 TNTSimulator simulatorShowHide(Player player, Function oldItemFunction, Function newItemFunction, Location location) { - TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory())); - SimulatorCursor.hide(player, oldSimulator); - - TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory())); - if (simulator == null) return null; - - SimulatorCursor.show(player, simulator, trace(player, location, simulator)); - return simulator; - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) { - simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getPlayer().getLocation()); - } - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - SimulatorCursor.hide(event.getPlayer(), null); - SimulatorStorage.getSimulatorNames().forEach(s -> { - SimulatorStorage.getSimulator(s)._hide(event.getPlayer()); - }); - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (!ItemUtils.isItem(event.getItem(), "simulator")) { - return; - } - - event.setCancelled(true); - if (!permissionCheck(event.getPlayer())) { - return; - } - TNTSimulator simulator = SimulatorStorage.getSimulator(event.getItem()); - - switch (event.getAction()) { - case LEFT_CLICK_BLOCK: - case LEFT_CLICK_AIR: - if (simulator == null) { - return; - } - simulator.start(event.getPlayer()); - break; - case RIGHT_CLICK_BLOCK: - case RIGHT_CLICK_AIR: - if (simulator == null) { - SimulatorSelectionGUI.open(event.getPlayer(), event.getItem()); - } else { - simulator.edit(event.getPlayer(), trace(event.getPlayer(), event.getPlayer().getLocation(), simulator)); - } - break; - default: - break; - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java similarity index 93% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java index b1f6c6f6..75e79765 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java @@ -17,9 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.data; +package de.steamwar.bausystem.features.simulator.data; -import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; +import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import lombok.Getter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java similarity index 94% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java index aeb99c42..a79a7dad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.data; +package de.steamwar.bausystem.features.simulator.data; -import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import lombok.Getter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java similarity index 95% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java index a4b6d031..3b09e8b3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java @@ -17,9 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.data; +package de.steamwar.bausystem.features.simulator.data; -import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; +import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import lombok.Getter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorPhase.java similarity index 91% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorPhase.java index 09e174fd..33009044 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorPhase.java @@ -17,9 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.data; +package de.steamwar.bausystem.features.simulator.data; -import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; +import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import lombok.Getter; import lombok.Setter; import org.bukkit.util.Vector; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java similarity index 80% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java index 4394f27f..ac130e03 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java @@ -17,13 +17,13 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.data.redstone; +package de.steamwar.bausystem.features.simulator.data.redstone; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.gui.SimulatorRedstoneGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.gui.SimulatorRedstoneGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.util.Vector; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java similarity index 92% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java index 0972c4ca..f67dfb45 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java @@ -18,10 +18,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.data.redstone; +package de.steamwar.bausystem.features.simulator.data.redstone; -import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; -import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; +import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.World; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java similarity index 88% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java index 69b7c67f..36b10130 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java @@ -17,13 +17,13 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.data.tnt; +package de.steamwar.bausystem.features.simulator.data.tnt; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.gui.SimulatorTNTGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.gui.SimulatorTNTGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import org.bukkit.Material; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java similarity index 93% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java index 7becfec9..d776edb8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.data.tnt; +package de.steamwar.bausystem.features.simulator.data.tnt; -import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; -import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction; +import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorAction.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorAction.java similarity index 94% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorAction.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorAction.java index bacc0ffd..c6c9f1da 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorAction.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorAction.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.execute; +package de.steamwar.bausystem.features.simulator.execute; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorExecutor.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java index 0f755aa6..65f15009 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/execute/SimulatorExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.execute; +package de.steamwar.bausystem.features.simulator.execute; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.Simulator; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.World; 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 deleted file mode 100644 index 8a4bceb5..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/ItemUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/simulator2/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java similarity index 86% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java index f71e7f4c..c431420c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; import org.bukkit.Material; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java similarity index 88% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java index 7fe8e6b4..06df5e5e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java similarity index 93% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index eb27c8b2..2aa11e98 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java similarity index 80% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java index 192d239c..dfc612ec 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java @@ -17,15 +17,13 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorMaterialGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java similarity index 88% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorMaterialGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java index 9e8e6081..84f1e682 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorMaterialGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorMaterialGui.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java similarity index 91% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index bc2b36c5..d934df37 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -17,15 +17,15 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java similarity index 92% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index 7b93f595..3a03deed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -17,13 +17,13 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java similarity index 93% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java index 25db707e..eb0ea99e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; 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 deleted file mode 100644 index 2ca90d2a..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.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; - -import java.util.ArrayList; -import java.util.List; - -@UtilityClass -public class SimulatorSelectionGUI { - - public void open(Player player, ItemStack hand) { - List> swListEntryList = new ArrayList<>(); - - for (String name : SimulatorStorage.getSimulatorNames()) { - TNTSimulator simulator = SimulatorStorage.getSimulator(name); - SWItem swItem = new SWItem(simulator.getMaterial(), "§f" + name, new ArrayList<>(), false, null); - swListEntryList.add(new SWListInv.SWListEntry<>(swItem, simulator)); - } - - SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> { - TNTSimulator current = SimulatorStorage.getSimulator(hand); - if (current != null) { - current.hide(player); - } - SimulatorStorage.setSimulator(player, hand, tntSimulator); - player.getInventory().setItemInMainHand(hand); - 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.hide(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/simulator2/gui/SimulatorSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java similarity index 93% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java index 8ed72b0e..45b2e22a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java similarity index 91% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index f4c80ebe..7b9fc71a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -17,15 +17,15 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java similarity index 93% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index 613f1dc7..149fb599 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; import org.bukkit.Material; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java similarity index 94% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index f93cc648..e1698c6f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui; +package de.steamwar.bausystem.features.simulator.gui; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; 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 deleted file mode 100644 index 93181f90..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java +++ /dev/null @@ -1,390 +0,0 @@ -/* - * 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.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.OrderUtils; -import de.steamwar.bausystem.features.simulator.SimulatorStorage; -import de.steamwar.bausystem.features.simulator.TNTSimulator; -import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial; -import de.steamwar.bausystem.features.simulator.gui.components.ChangePosition; -import de.steamwar.bausystem.features.simulator.gui.components.Disabled; -import de.steamwar.bausystem.features.simulator.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator.tnt.TNTGroup; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.inventory.SWInventory; -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; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; - -@UtilityClass -public class TNTElementGUI { - - private SWInventory open(Player player, String name) { - SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_GUI_NAME", player, name)); - SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {}); - for (int i = 0; i < 9; i++) { - inv.setItem(i, gray); - inv.setItem(i + 36, gray); - } - return inv; - } - - public void open(Player player, TNTElement tntElement, Runnable back) { - SWInventory inv = open(player, ""); - if (back != null) { - inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); - } - - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - Runnable editObserver = () -> { - List locationLore = new ArrayList<>(); - locationLore.add(""); - locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, tntElement.getPosition().getX())); - locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, tntElement.getPosition().getY())); - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - editLocation(player, tntElement, () -> open(player, tntElement, back)); - })); - - List propertiesLore = new ArrayList<>(); - propertiesLore.add(""); - propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, tntElement.getCount())); - propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntElement.getTickOffset())); - propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, tntElement.getFuseTicks())); - propertiesLore.add(""); - propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, active(player, tntElement.isXVelocity()))); - propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, active(player, tntElement.isYVelocity()))); - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - editProperties(player, tntElement, () -> open(player, tntElement, back)); - })); - - List otherLore = new ArrayList<>(); - otherLore.add(""); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_WITH", player, BauSystem.MESSAGE.parse(OrderUtils.name(tntElement.getOrder()), player))); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, tntElement.getMaterial().name())); - if (tntElement.isDisabled()) { - otherLore.add(""); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player)); - } - inv.setItem(24, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - editOther(player, tntElement, () -> open(player, tntElement, back)); - })); - - // Delete tnt - inv.setItem(44, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_REMOVE_TNT", player), clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.remove(tntElement); - player.closeInventory(); - })); - }; - editObserver.run(); - tntElement.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> { - tntElement.unregister(editObserver); - }); - - inv.open(); - } - - private void editLocation(Player player, TNTElement tntElement, Runnable back) { - SWInventory inv = open(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_EDIT_LOCATION", player)); - if (back != null) { - inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); - } - - Runnable editObserver = () -> { - ChangePosition.show(inv, player, tntElement, vectorUnaryOperator -> { - if (tntElement.getParent() == null) { - tntElement.setPosition(vectorUnaryOperator.apply(tntElement.getPosition())); - } else { - tntElement.setPosition(vectorUnaryOperator.apply(tntElement.getPosition()).subtract(tntElement.getParent().getPosition())); - } - }, () -> editLocation(player, tntElement, back)); - - // Alignment - inv.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_Z", player), clickType -> { // Z negative - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0, 0, 0.49)); - tntElement.change(); - })); - inv.setItem(25, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_Z", player), clickType -> { // Z positive - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0, 0, 0.51)); - tntElement.change(); - })); - inv.setItem(15, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_X", player), clickType -> { // X positive - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0.51, 0, 0)); - tntElement.change(); - })); - inv.setItem(33, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_X", player), clickType -> { // X negative - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0.49, 0, 0)); - tntElement.change(); - })); - inv.setItem(24, new SWItem(Material.SUNFLOWER, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_CENTER", player), clickType -> { // CENTER - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0.5, 0, 0.5)); - tntElement.change(); - })); - }; - editObserver.run(); - tntElement.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> { - tntElement.unregister(editObserver); - }); - - inv.open(); - } - - private void editProperties(Player player, TNTElement tntElement, Runnable back) { - SWInventory inv = open(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_EDIT_PROPERTIES", player)); - if (back != null) { - inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); - } - - String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player); - String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player); - List plusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_FIVE_SHIFT", player)); - 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); - Runnable editObserver = () -> { - // Change Count of spawned TNT - inv.setItem(10, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.setCount(c); - tntElement.change(); - editProperties(player, tntElement, back); - }, () -> editProperties(player, tntElement, back))); - countItem.getItemStack().setAmount(tntElement.getCount()); - inv.setItem(19, countItem); - inv.setItem(28, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.setCount(tntElement.getCount() - ((clickType.isShiftClick()) ? 5 : 1)); - tntElement.change(); - }))); - - // Change TickOffset - inv.setItem(11, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.setTickOffset(tick - tntElement.getParentTickOffset()); - tntElement.change(); - editProperties(player, tntElement, back); - }, () -> editProperties(player, tntElement, back))); - tickItem.getItemStack().setAmount(Math.max(tntElement.getTickOffset(), 1)); - inv.setItem(20, tickItem); - inv.setItem(29, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.setTickOffset(tntElement.getOwnTickOffset() - (clickType.isShiftClick() ? 5 : 1)); - tntElement.change(); - }))); - - // Change FuseTicks - inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.setFuseTicks(tick); - tntElement.change(); - editProperties(player, tntElement, back); - }, () -> editProperties(player, tntElement, back))); - fuseTickItem.getItemStack().setAmount(Math.max(tntElement.getFuseTicks(), 1)); - inv.setItem(21, fuseTickItem); - inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - if (tntElement.isXVelocity() || tntElement.isYVelocity() || tntElement.isZVelocity()) { - tntElement.setXVelocity(false); - tntElement.setYVelocity(false); - tntElement.setZVelocity(false); - } else { - tntElement.setXVelocity(true); - tntElement.setYVelocity(true); - tntElement.setZVelocity(true); - } - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.setZVelocity(!tntElement.isZVelocity()); - tntElement.change(); - })); - }; - editObserver.run(); - tntElement.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> { - tntElement.unregister(editObserver); - }); - - inv.open(); - } - - private void editOther(Player player, TNTElement tntElement, Runnable back) { - SWInventory inv = open(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_EDIT_OTHER", player)); - if (back != null) { - inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); - } - - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - Runnable editObserver = () -> { - inv.setItem(19, new SWItem(tntElement.getOrder(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_NAME", player), OrderUtils.orderList(tntElement.getOrder(), player), false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - if (clickType.isShiftClick()) { - tntElement.setOrder(OrderUtils.previous(tntElement.getOrder())); - } else { - tntElement.setOrder(OrderUtils.next(tntElement.getOrder())); - } - tntElement.change(); - })); - - ChangeMaterial.show(inv, player, 21, tntElement, Material.BARREL, () -> editOther(player, tntElement, back)); - Disabled.show(inv, player, 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - // Create TNTGroup - tntSimulator.getTntElementList().remove(tntElement); - Vector vector = tntElement.getOwnPosition().clone(); - int tickOffset = tntElement.getOwnTickOffset(); - TNTGroup tntGroup = new TNTGroup(vector); - tntGroup.setTickOffset(tickOffset); - tntGroup.add(tntElement); - tntElement.setTickOffset(0); - tntElement.setPosition(new Vector(0, 0, 0)); - tntSimulator.getTntElementList().add(tntGroup); - - // Add new TNT - TNTElement newElement = new TNTElement(new Vector(0, 0, 0), tntGroup, tntSimulator.getEntityServer()); - newElement.setTickOffset(1); - tntGroup.add(newElement); - - tntElement.change(); - open(player, newElement, () -> TNTSimulatorGui.open(player, null, tntGroup, () -> new ArrayList<>(tntGroup.getElements()), () -> { - TNTSimulatorGui.open(player, tntSimulator, null, () -> new ArrayList<>(tntSimulator.getTntElementList()), null); - })); - })); - } else { - inv.setItem(24, new SWItem()); - } - - inv.setItem(25, new SWItem(Material.DISPENSER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_TNT", player), clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - Vector vector = tntElement.getOwnPosition().clone(); - TNTElement newElement = new TNTElement(vector, null, tntSimulator.getEntityServer()); - if (tntElement.hasParent()) { - newElement.setTickOffset(tntElement.getOwnTickOffset() + 1); - tntElement.getParent().add(newElement); - open(player, newElement, () -> TNTSimulatorGui.open(player, null, tntElement.getParent(), () -> new ArrayList<>(tntElement.getParent().getElements()), () -> { - TNTSimulatorGui.open(player, tntSimulator, null, () -> new ArrayList<>(tntSimulator.getTntElementList()), null); - })); - } else { - tntSimulator.getTntElementList().add(newElement); - open(player, newElement, () -> TNTSimulatorGui.open(player, tntSimulator, null, tntSimulator::getTntElementList, null)); - } - })); - - // Delete tnt - inv.setItem(44, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_REMOVE_TNT", player), clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.remove(tntElement); - player.closeInventory(); - })); - }; - editObserver.run(); - tntElement.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> { - tntElement.unregister(editObserver); - }); - - inv.open(); - } - - private String active(Player p, boolean active) { - return active ? BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_ON", p) : BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_OFF", p); - } - - private Material getWool(boolean b) { - return b ? Material.LIME_WOOL : Material.RED_WOOL; - } - - private byte getColor(boolean b) { - return (byte) (b ? 10 : 1); - } - - private void changeCount(Player player, String name, int defaultValue, Consumer result, Runnable failure) { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, name, defaultValue + ""); - swAnvilInv.setItem(Material.PAPER); - swAnvilInv.setCallback(s -> { - try { - result.accept(Integer.parseInt(s)); - } catch (NumberFormatException e) { - failure.run(); - } - }); - swAnvilInv.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 deleted file mode 100644 index 9c4aa70a..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.SimulatorStorage; -import de.steamwar.bausystem.features.simulator.TNTSimulator; -import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial; -import de.steamwar.bausystem.features.simulator.gui.components.ChangePosition; -import de.steamwar.bausystem.features.simulator.gui.components.Disabled; -import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; -import de.steamwar.bausystem.features.simulator.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator.tnt.TNTGroup; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.inventory.SWInventory; -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; - -import java.util.Arrays; -import java.util.List; -import java.util.function.UnaryOperator; - -import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; - -@UtilityClass -public class TNTGroupEditGUI { - - private static final Vector X_VECTOR = new Vector(0.0625, 0, 0); - private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0); - private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625); - - private static final Vector FX_VECTOR = new Vector(1, 0, 0); - private static final Vector FY_VECTOR = new Vector(0, 1, 0); - private static final Vector FZ_VECTOR = new Vector(0, 0, 1); - - public void open(Player player, TNTSimulator tntSimulator, List simulatorElements, Runnable back) { - SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_MOVE_ALL_GUI_NAME", player)); - SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {}); - for (int i = 0; i < 9; i++) { - inv.setItem(i, gray); - inv.setItem(i + 36, gray); - } - - if (back != null) { - inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); - } - - 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)); - List minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player)); - List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); - - Vector vector = simulatorElements.get(0).getPosition(); - - // X Position - inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(simulatorElements, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); - tntSimulator.change(); - }))); - inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, vector.getX()), lore, false, clickType -> {})); - inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(simulatorElements, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1)); - tntSimulator.change(); - }))); - - // Y Position - inv.setItem(13, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(simulatorElements, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); - tntSimulator.change(); - }))); - inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, vector.getY()), lore, false, clickType -> {})); - inv.setItem(31, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(simulatorElements, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1)); - tntSimulator.change(); - }))); - - // Z Position - inv.setItem(14, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(simulatorElements, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); - tntSimulator.change(); - }))); - inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, vector.getZ()), lore, false, clickType -> {})); - inv.setItem(32, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(simulatorElements, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1)); - }))); - - inv.open(); - } - - public void moveAll(List simulatorElements, Vector vector) { - for (SimulatorElement element : simulatorElements) { - if (element instanceof TNTGroup) { - TNTGroup group = (TNTGroup) element; - group.setPosition(group.getPosition().add(vector)); - } else if (element instanceof TNTElement) { - TNTElement tntElement = (TNTElement) element; - tntElement.setPosition(tntElement.getOwnPosition().add(vector)); - } - } - } - - public void open(Player player, TNTGroup tntGroup, Runnable back) { - SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP_MENU", player)); - SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {}); - for (int i = 0; i < 9; i++) { - inv.setItem(i, gray); - inv.setItem(i + 36, gray); - } - - if (back != null) { - inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); - } - - String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player); - String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player); - List plusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_FIVE_SHIFT", player)); - 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); - Runnable editObserver = () -> { - ChangePosition.show(inv, player, tntGroup, vectorUnaryOperator -> { - tntGroup.setPosition(vectorUnaryOperator.apply(tntGroup.getPosition())); - }, () -> open(player, tntGroup, back)); - ChangeMaterial.show(inv, player, 14, tntGroup, Material.BARREL, () -> open(player, tntGroup, back)); - Disabled.show(inv, player, 32, tntSimulator, tntGroup); - - // Change TickOffset - inv.setItem(16, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - 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 -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntGroup.setTickOffset(tick); - tntGroup.change(); - open(player, tntGroup, back); - }, () -> open(player, tntGroup, back))); - tickItem.getItemStack().setAmount(Math.max(tntGroup.getTickOffset(), 1)); - inv.setItem(25, tickItem); - inv.setItem(34, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - tntGroup.setTickOffset(tntGroup.getTickOffset() - (clickType.isShiftClick() ? 5 : 1)); - tntGroup.change(); - })); - }; - editObserver.run(); - tntGroup.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> { - tntGroup.unregister(editObserver); - }); - - inv.open(); - } - - private void changeCount(Player player, String name, int defaultValue, Consumer result, Runnable failure) { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, name, defaultValue + ""); - swAnvilInv.setItem(Material.PAPER); - swAnvilInv.setCallback(s -> { - try { - result.accept(Integer.parseInt(s)); - } catch (NumberFormatException e) { - failure.run(); - } - }); - swAnvilInv.open(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java deleted file mode 100644 index e813580a..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * 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.bausystem.BauSystem; -import de.steamwar.bausystem.configplayer.Config; -import de.steamwar.bausystem.features.simulator.SimulatorStorage; -import de.steamwar.bausystem.features.simulator.TNTSimulator; -import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; -import de.steamwar.bausystem.features.simulator.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator.tnt.TNTGroup; -import de.steamwar.inventory.SWInventory; -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.event.inventory.ClickType; -import org.bukkit.util.Vector; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.function.Supplier; - -import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; - -@UtilityClass -public class TNTSimulatorGui { - - private static final Vector X_VECTOR = new Vector(0.0625, 0, 0); - private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0); - private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625); - - private static final Vector FX_VECTOR = new Vector(1, 0, 0); - private static final Vector FY_VECTOR = new Vector(0, 1, 0); - private static final Vector FZ_VECTOR = new Vector(0, 0, 1); - - public void open(Player player, TNTSimulator currentTntSimulator, TNTGroup currentTntGroup, Supplier> simulatorElements, Runnable back) { - List> swListEntryList = new ArrayList<>(); - - int totalTNTCount = 0; - for (SimulatorElement element : simulatorElements.get()) { - swListEntryList.add(new SWListInv.SWListEntry<>(element.menu(player), element)); - totalTNTCount += element.tntCount(); - } - swListEntryList.sort(Comparator.comparing(o -> o.getObject().tick())); - - SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_NAME", player), false, swListEntryList, (clickType, simulatorElement) -> { - if (simulatorElement instanceof TNTGroup) { - TNTGroup tntGroup = (TNTGroup) simulatorElement; - open(player, null, tntGroup, () -> new ArrayList<>(tntGroup.getElements()), () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); - } else { - TNTElementGUI.open(player, (TNTElement) simulatorElement, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); - } - }); - if (back != null) { - inv.setItem(47, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); - } - SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TOTAL_TNT", player, totalTNTCount), clickType -> { - }); - swItem.getItemStack().setAmount(totalTNTCount); - List elements = simulatorElements.get(); - inv.setItem(elements.isEmpty() ? 49 : 50, swItem); - if (currentTntGroup != null) { - Runnable editObserver = () -> { - List otherLore = new ArrayList<>(); - otherLore.add(""); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, currentTntGroup.getPosition().getX())); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, currentTntGroup.getPosition().getY())); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, currentTntGroup.getPosition().getZ())); - otherLore.add(""); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, currentTntGroup.getMaterial().name())); - otherLore.add(""); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, currentTntGroup.getTickOffset())); - if (currentTntGroup.isDisabled()) { - otherLore.add(""); - otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player)); - } - inv.setItem(48, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), otherLore, false, clickType -> { - TNTGroupEditGUI.open(player, currentTntGroup, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); - })); - }; - editObserver.run(); - currentTntGroup.register(editObserver, player::closeInventory); - inv.addCloseRunnable(() -> { - currentTntGroup.unregister(editObserver); - }); - } else { - if (!elements.isEmpty()) { - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - inv.setItem(48, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), new ArrayList<>(), false, clickType -> { - TNTGroupEditGUI.open(player, tntSimulator, elements, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); - })); - } - } - if (currentTntSimulator != null) { - if (totalTNTCount > 0) { - inv.setItem(48, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> { - moveAll(player, currentTntSimulator, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); - })); - } - - boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); - inv.setItem(47, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, BauSystem.MESSAGE.parse("SIMULATOR_GUI_AUTO_TRACE", player, simulatorAutoTrace), clickType -> { - Config.getInstance().get(player).put("simulatorAutoTrace", !simulatorAutoTrace); - open(player, currentTntSimulator, currentTntGroup, simulatorElements, back); - })); - } - - if (currentTntSimulator != null || currentTntGroup != null) { - inv.setItem(51, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_GUI_DELETE", player), clickType -> { - if (currentTntSimulator != null) { - currentTntSimulator.getTntElementList().forEach(SimulatorElement::close); - currentTntSimulator.clear(); - player.closeInventory(); - } else { - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - tntSimulator.remove(currentTntGroup); - } - })); - } - - inv.open(); - } - - public void moveAll(Player player, TNTSimulator tntSimulator, Runnable back) { - SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_MOVE_ALL_GUI_NAME", player)); - SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {}); - for (int i = 0; i < 9; i++) { - inv.setItem(i, gray); - inv.setItem(i + 36, gray); - } - - if (back != null) { - inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); - } - - 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)); - List minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player)); - List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); - - // X Position - inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(tntSimulator, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); - tntSimulator.change(); - }))); - inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_X", player), lore, false, clickType -> {})); - inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(tntSimulator, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1)); - tntSimulator.change(); - }))); - - // Y Position - inv.setItem(13, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(tntSimulator, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); - tntSimulator.change(); - }))); - inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Y", player), lore, false, clickType -> {})); - inv.setItem(31, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(tntSimulator, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1)); - tntSimulator.change(); - }))); - - // Z Position - inv.setItem(14, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(tntSimulator, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); - tntSimulator.change(); - }))); - inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Z", player), lore, false, clickType -> {})); - inv.setItem(32, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - moveAll(tntSimulator, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1)); - tntSimulator.change(); - }))); - - inv.open(); - } - - public void moveAll(TNTSimulator tntSimulator, Vector vector) { - for (SimulatorElement element : tntSimulator.getTntElementList()) { - if (element instanceof TNTGroup) { - TNTGroup group = (TNTGroup) element; - group.setPosition(group.getPosition().add(vector)); - } else if (element instanceof TNTElement) { - TNTElement tntElement = (TNTElement) element; - tntElement.setPosition(tntElement.getOwnPosition().add(vector)); - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java similarity index 94% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java index 326425de..9f79a613 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorBaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui.base; +package de.steamwar.bausystem.features.simulator.gui.base; -import de.steamwar.bausystem.features.simulator2.SimulatorWatcher; -import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.core.Core; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java similarity index 95% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java index 14c2d786..e3c3ccbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorPageGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorPageGui.java @@ -17,9 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui.base; +package de.steamwar.bausystem.features.simulator.gui.base; -import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java index 4a4fb128..1c6d30e5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/base/SimulatorScrollGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.gui.base; +package de.steamwar.bausystem.features.simulator.gui.base; -import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangeMaterial.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangeMaterial.java deleted file mode 100644 index 5c6750fc..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangeMaterial.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.components; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWItem; -import de.steamwar.inventory.SWListInv; -import lombok.experimental.UtilityClass; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@UtilityClass -public class ChangeMaterial { - - private static final List MATERIALS = new ArrayList<>(); - static { - Arrays.stream(Material.values()) - .filter(Material::isItem) - .filter(material -> !material.isLegacy()) - .forEach(MATERIALS::add); - } - - public void show(SWInventory inv, Player player, int position, SimulatorElement simulatorElement, Material defaultMaterial, Runnable back) { - inv.setItem(position, new SWItem(simulatorElement.getMaterial(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL", player), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1", player, simulatorElement.getMaterial().name().toLowerCase()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2", player), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_3", player)), false, clickType -> { - if (clickType.isLeftClick()) { - List> swListEntries = new ArrayList<>(); - MATERIALS.forEach(current -> { - swListEntries.add(new SWListInv.SWListEntry<>(new SWItem(current, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME", player, current.name().toLowerCase()), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_CLICK", player)), false, ignored -> { - }), current)); - }); - SWListInv swListInv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_GUI_NAME", player), false, swListEntries, (invClickType, material) -> { - simulatorElement.setMaterial(material); - simulatorElement.change(); - back.run(); - }); - swListInv.open(); - } else { - simulatorElement.setMaterial(defaultMaterial); - simulatorElement.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 deleted file mode 100644 index 16f1090c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * 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.components; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.TNTSimulator; -import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.inventory.SWInventory; -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; - -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; - -import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; - -@UtilityClass -public class ChangePosition { - - private static final Vector X_VECTOR = new Vector(0.0625, 0, 0); - private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0); - private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625); - - private static final Vector FX_VECTOR = new Vector(1, 0, 0); - 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, SimulatorElement simulatorElement, Consumer> toChangeVector, 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)); - List minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player)); - List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); - - // X Position - inv.setItem(10, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - toChangeVector.accept(vector -> { - vector.add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); - return vector; - }); - 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 -> { - toChangeVector.accept(vector -> { - vector.setX(clamp(x)); - return vector; - }); - simulatorElement.change(); - back.run(); - }, back); - })); - inv.setItem(28, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - toChangeVector.accept(vector -> { - vector.subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); - return vector; - }); - simulatorElement.change(); - }))); - - // Y Position - inv.setItem(11, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - toChangeVector.accept(vector -> { - vector.add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); - return vector; - }); - 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 -> { - toChangeVector.accept(vector -> { - vector.setY(clamp(y)); - return vector; - }); - simulatorElement.change(); - back.run(); - }, back); - })); - inv.setItem(29, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - toChangeVector.accept(vector -> { - vector.subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); - return vector; - }); - simulatorElement.change(); - }))); - - // Z Position - inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - toChangeVector.accept(vector -> { - vector.add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); - return vector; - }); - 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 -> { - toChangeVector.accept(vector -> { - vector.setZ(clamp(z)); - return vector; - }); - simulatorElement.change(); - back.run(); - }, back); - })); - inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { - if (clickType == ClickType.DOUBLE_CLICK) return; - toChangeVector.accept(vector -> { - vector.subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); - return vector; - }); - simulatorElement.change(); - }))); - } - - private double clamp(double d) { - return (int) (d * 10000) * 0.0001; - } - - private void changePosition(Player player, double defaultValue, Consumer result, Runnable failure) { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_ANVIL_GUI_NAME", player), defaultValue + ""); - swAnvilInv.setItem(Material.PAPER); - swAnvilInv.setCallback(s -> { - try { - result.accept(Double.parseDouble(s.replace(',', '.'))); - } catch (NumberFormatException e) { - failure.run(); - } - }); - swAnvilInv.open(); - } -} 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 deleted file mode 100644 index a6798165..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.components; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.TNTSimulator; -import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWItem; -import lombok.experimental.UtilityClass; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.ArrayList; - -@UtilityClass -public class Disabled { - - public void show(SWInventory inv, Player player, 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 -> { - simulatorElement.setDisabled(!simulatorElement.isDisabled()); - simulatorElement.change(); - })); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java similarity index 87% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimFormatSimulatorLoader.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java index 4082850f..18089002 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimFormatSimulatorLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java @@ -17,16 +17,16 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.storage; +package de.steamwar.bausystem.features.simulator.storage; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import org.bukkit.Material; import org.bukkit.util.Vector; import yapion.exceptions.YAPIONException; @@ -40,7 +40,6 @@ import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Supplier; -import java.util.stream.Collectors; public class SimFormatSimulatorLoader implements SimulatorLoader { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorFormatSimulatorLoader.java similarity index 93% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorFormatSimulatorLoader.java index 3783f833..a386f86d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorFormatSimulatorLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorFormatSimulatorLoader.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.storage; +package de.steamwar.bausystem.features.simulator.storage; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import org.bukkit.Material; import org.bukkit.util.Vector; import yapion.exceptions.YAPIONException; @@ -66,7 +66,7 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader { } } - // file.delete(); + file.delete(); return Optional.of(Collections.singletonList(simulator)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorLoader.java similarity index 88% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorLoader.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorLoader.java index 70659936..4c9e3f92 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorLoader.java @@ -17,9 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.storage; +package de.steamwar.bausystem.features.simulator.storage; -import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.Simulator; import java.io.File; import java.util.List; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java index 9f1fadb1..67260e4f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/SimulatorSaver.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java @@ -17,9 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.storage; +package de.steamwar.bausystem.features.simulator.storage; -import de.steamwar.bausystem.features.simulator2.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.Simulator; import lombok.experimental.UtilityClass; import yapion.hierarchy.output.FileOutput; import yapion.hierarchy.types.YAPIONArray; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/YAPIONFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/YAPIONFormatSimulatorLoader.java similarity index 91% rename from BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/YAPIONFormatSimulatorLoader.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/YAPIONFormatSimulatorLoader.java index 6434fcc0..0c715443 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/storage/YAPIONFormatSimulatorLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/YAPIONFormatSimulatorLoader.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator2.storage; +package de.steamwar.bausystem.features.simulator.storage; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import de.steamwar.sql.SteamwarUser; import org.bukkit.Material; import org.bukkit.util.Vector; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java deleted file mode 100644 index 181e3389..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.tnt; - -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.shared.Pair; -import de.steamwar.entity.REntity; -import de.steamwar.inventory.SWItem; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; -import yapion.hierarchy.types.YAPIONObject; - -import java.util.*; - -public interface SimulatorElement { - - Map> observer = new HashMap<>(); - Map closeObserver = new HashMap<>(); - - YAPIONObject toYAPION(); - List getEntities(); - void getEntity(List elements, REntity entity); - - Vector getPosition(); - void setPosition(Vector position); - - void remove(TNTElement tntElement); - - SWItem menu(Player p); - boolean locations(Map>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations - int tntCount(); - int tick(); - - // Observer - default void change() { - observer.getOrDefault(this, new HashSet<>()).forEach(Runnable::run); - if (this instanceof TNTGroup) { - ((TNTGroup) this).getElements().forEach(SimulatorElement::change); - } - } - default void register(Runnable observer, Runnable close) { - SimulatorElement.observer.computeIfAbsent(this, k -> new HashSet<>()).add(observer); - SimulatorElement.closeObserver.put(observer, close); - } - default void unregister(Runnable observer) { - SimulatorElement.observer.computeIfPresent(this, (k, v) -> { - v.remove(observer); - return v.isEmpty() ? null : v; - }); - SimulatorElement.closeObserver.remove(observer); - } - default void close() { - Set allRunnables = observer.remove(this); - if (allRunnables == null) return; - allRunnables.forEach(runnable -> { - Runnable closeRunnable = closeObserver.remove(runnable); - if (closeRunnable == null) return; - closeRunnable.run(); - }); - if (this instanceof TNTGroup) { - ((TNTGroup) this).getElements().forEach(SimulatorElement::close); - } - } - - // API - Material getMaterial(); - void setMaterial(Material material); - - boolean isDisabled(); - void setDisabled(boolean disabled); -} 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 deleted file mode 100644 index 666c3359..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * 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.tnt; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.OrderUtils; -import de.steamwar.bausystem.features.simulator.SimulatorStorage; -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.bausystem.shared.Pair; -import de.steamwar.entity.REntity; -import de.steamwar.entity.REntityServer; -import de.steamwar.entity.RFallingBlockEntity; -import de.steamwar.inventory.SWItem; -import lombok.Getter; -import lombok.Setter; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.util.Vector; -import yapion.hierarchy.types.YAPIONObject; - -import java.util.*; - -@Getter -public class TNTElement implements SimulatorElement { - - private static final World WORLD = Bukkit.getWorlds().get(0); - - private final REntityServer entityServer; - private RFallingBlockEntity entity; - TNTGroup tntGroup = null; - - private final Vector position; - private int fuseTicks = 80; - private int count = 1; - private int tickOffset = 0; - - @Setter - private boolean xVelocity = false; - - @Setter - private boolean yVelocity = false; - - @Setter - private boolean zVelocity = false; - private Material order = Material.REPEATER; - private Material material = Material.TNT; - private boolean disabled = false; - - public TNTElement(Vector position, TNTGroup tntGroup, REntityServer entityServer) { - this.entityServer = entityServer; - this.tntGroup = tntGroup; - this.position = position; - initEntity(); - } - - public TNTElement(YAPIONObject yapionObject, TNTGroup tntGroup, REntityServer entityServer) { - this.entityServer = entityServer; - this.tntGroup = tntGroup; - this.position = new Vector(yapionObject.getDoubleOrDefault("x", yapionObject.getDoubleOrDefault("positionX", 0)), yapionObject.getDoubleOrDefault("y", yapionObject.getDoubleOrDefault("positionY", 0)), yapionObject.getDoubleOrDefault("z", yapionObject.getDoubleOrDefault("positionZ", 0))); - this.disabled = yapionObject.getBooleanOrDefault("disabled", false); - this.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80); - this.count = yapionObject.getIntOrDefault("count", 1); - this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0); - this.xVelocity = yapionObject.getBooleanOrDefault("xVelocity", false); - this.yVelocity = yapionObject.getBooleanOrDefault("yVelocity", false); - this.zVelocity = yapionObject.getBooleanOrDefault("zVelocity", false); - this.order = Material.valueOf(yapionObject.getStringOrDefault("order", yapionObject.getBooleanOrDefault("comparator", false) ? Material.COMPARATOR.name() : Material.REPEATER.name())); - this.material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name())); - initEntity(); - } - - private void initEntity() { - this.entity = new RFallingBlockEntity(entityServer, getPosition().toLocation(WORLD), Material.TNT); - this.entity.setNoGravity(true); - _updatePosition(); - } - - @Override - public YAPIONObject toYAPION() { - YAPIONObject yapionObject = new YAPIONObject(); - yapionObject.add("x", position.getX()); - yapionObject.add("y", position.getY()); - yapionObject.add("z", position.getZ()); - yapionObject.add("fuseTicks", fuseTicks); - yapionObject.add("count", count); - yapionObject.add("tickOffset", tickOffset); - yapionObject.add("xVelocity", xVelocity); - yapionObject.add("yVelocity", yVelocity); - yapionObject.add("zVelocity", zVelocity); - yapionObject.add("order", order.name()); - yapionObject.add("material", material.name()); - yapionObject.add("disabled", disabled); - return yapionObject; - } - - @Override - public List getEntities() { - if (disabled) return new ArrayList<>(); - return Arrays.asList(entity); - } - - @Override - public void getEntity(List elements, REntity entity) { - if (disabled) return; - if (this.entity.getEntityId() == entity.getEntityId() || getPosition().distanceSquared(new Vector(entity.getX(), entity.getY(), entity.getZ())) < 0.01) { - elements.add(this); - } - } - - @Override - public Vector getPosition() { - if (tntGroup != null) { - return tntGroup.getPosition().clone().add(position); - } - return position.clone(); - } - - @Override - public void setPosition(Vector position) { - this.position.setX(position.getX()); - this.position.setY(position.getY()); - this.position.setZ(position.getZ()); - _updatePosition(); - } - - void _updatePosition() { - if (disabled || (getParent() != null && getParent().isDisabled())) { - entity.move(-200000, 0, -200000, 0F, 0F, (byte) 0); - } else { - Vector position = getPosition(); - entity.move(position.getX(), position.getY(), position.getZ(), 0F, 0F, (byte) 0); - } - } - - public int getTickOffset() { - if (tntGroup != null) { - return tntGroup.getTickOffset() + tickOffset; - } - return tickOffset; - } - - @Override - public void remove(TNTElement tntElement) { - entity.die(); - } - - @Override - public SWItem menu(Player p) { - List lore = new ArrayList<>(); - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_1", p, count)); - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_2", p, getTickOffset())); - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_3", p, getFuseTicks())); - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_4", p)); - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_5", p, getPosition().getX())); - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_6", p, getPosition().getY())); - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_7", p, getPosition().getZ())); - if (disabled) { - lore.add(""); - lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); - } - SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_NAME", p), lore, disabled, null); - if (!disabled) swItem.getItemStack().setAmount(Math.max(tntCount(), 1)); - return swItem; - } - - @Override - public boolean locations(Map>>> result, Region region, Location radius) { - if (disabled) return false; - Location location = getPosition().toLocation(SimulatorStorage.WORLD); - if (region.isGlobal() && location.distanceSquared(radius) > 10000) { - return false; - } - if (!region.inRegion(location, RegionType.NORMAL, RegionExtensionType.NORMAL)) { - return false; - } - Region thisRegion = Region.getRegion(location); - if (thisRegion.getFlagStorage().get(Flag.FREEZE) == FreezeMode.ACTIVE) { - return true; - } - - result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) - .computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>()) - .add(new Pair<>(() -> { - SimulatorStorage.WORLD.spawn(location, TNTPrimed.class, tntPrimed -> { - tntPrimed.setFuseTicks(fuseTicks); - if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); - if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); - if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); - }); - }, count)); - return false; - } - - @Override - public int tntCount() { - return disabled ? 0 : count; - } - - @Override - public int tick() { - return getTickOffset(); - } - - public void setCount(int count) { - if (count < 0) count = 0; - if (count > 400) count = 400; - this.count = count; - } - - public int getOwnTickOffset() { - return tickOffset; - } - - public int getParentTickOffset() { - if (tntGroup != null) { - return tntGroup.getTickOffset(); - } - return 0; - } - - public void setTickOffset(int tickOffset) { - 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; - } - - public void setFuseTicks(int fuseTicks) { - if (fuseTicks < 0) fuseTicks = 0; - if (fuseTicks > 160) fuseTicks = 160; - this.fuseTicks = fuseTicks; - } - - public Vector getOwnPosition() { - return position.clone(); - } - - public void setOrder(Material material) { - this.order = material; - } - - public void setMaterial(Material material) { - this.material = material; - } - - public boolean hasParent() { - return tntGroup != null; - } - - public TNTGroup getParent() { - return tntGroup; - } - - public void setDisabled(boolean disabled) { - this.disabled = disabled; - _updatePosition(); - } - - public void align(Vector offset) { - Vector vector = getPosition(); - Vector parentVector = new Vector(0, 0, 0); - if (tntGroup != null) { - parentVector = tntGroup.getPosition(); - } - - if (offset.getX() != 0) { - if (vector.getX() - (int) vector.getX() == 0.49) { - vector.setX(vector.getX() + 0.02); - } - if (vector.getX() - (int) vector.getX() == -0.49) { - vector.setX(vector.getX() - 0.02); - } - vector.setX(vector.getBlockX() + offset.getX()); - } - - if (offset.getZ() != 0) { - if (vector.getZ() - (int) vector.getZ() == 0.49) { - vector.setZ(vector.getZ() + 0.02); - } - if (vector.getZ() - (int) vector.getZ() == -0.49) { - vector.setZ(vector.getZ() - 0.02); - } - vector.setZ(vector.getBlockZ() + offset.getZ()); - } - - setPosition(vector.subtract(parentVector)); - } -} 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 deleted file mode 100644 index f3327578..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * 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.tnt; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.shared.Pair; -import de.steamwar.entity.REntity; -import de.steamwar.entity.REntityServer; -import de.steamwar.inventory.SWItem; -import lombok.Getter; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONObject; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -@Getter -public class TNTGroup implements SimulatorElement { - - private final Vector position; - private int tickOffset = 0; - private Material material = Material.BARREL; - private boolean disabled = false; - private List elements = new ArrayList<>(); - - public TNTGroup(Vector position) { - this.position = position; - } - - public TNTGroup(YAPIONObject yapionObject, REntityServer entityServer) { - this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0)); - this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0); - this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL")); - this.disabled = yapionObject.getBooleanOrDefault("disabled", false); - YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray()); - for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) { - TNTElement tntElement = new TNTElement(element, this, entityServer); - this.elements.add(tntElement); - tntElement._updatePosition(); - } - } - - @Override - public YAPIONObject toYAPION() { - YAPIONObject yapionObject = new YAPIONObject(); - yapionObject.add("x", position.getX()); - yapionObject.add("y", position.getY()); - yapionObject.add("z", position.getZ()); - yapionObject.add("tickOffset", tickOffset); - yapionObject.add("material", material.name()); - yapionObject.add("disabled", disabled); - YAPIONArray yapionArray = new YAPIONArray(); - for (TNTElement element : elements) { - yapionArray.add(element.toYAPION()); - } - yapionObject.add("elements", yapionArray); - return yapionObject; - } - - public void add(TNTElement tntElement) { - tntElement.tntGroup = this; - elements.add(tntElement); - } - - @Override - public List getEntities() { - if (disabled) new ArrayList<>(); - return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList()); - } - - @Override - public void getEntity(List elements, REntity entity) { - if (disabled) return; - for (TNTElement tntElement : this.elements) { - tntElement.getEntity(elements, entity); - } - } - - @Override - public Vector getPosition() { - return position.clone(); - } - - @Override - public void setPosition(Vector position) { - this.position.setX(position.getX()); - this.position.setY(position.getY()); - this.position.setZ(position.getZ()); - elements.forEach(TNTElement::_updatePosition); - } - - @Override - public void remove(TNTElement tntElement) { - if (elements.remove(tntElement)) { - tntElement.remove(tntElement); - } - } - - @Override - 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)); - } - SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_NAME", p), lore, disabled, null); - if (!disabled) swItem.getItemStack().setAmount(Math.max(tntCount(), 1)); - return swItem; - } - - @Override - public boolean locations(Map>>> result, Region region, Location location) { - if (disabled) return false; - for (TNTElement element : elements) { - if (element.locations(result, region, location)) { - return true; - } - } - return false; - } - - @Override - public int tntCount() { - if (disabled) return 0; - return elements.stream().mapToInt(TNTElement::tntCount).sum(); - } - - @Override - public int tick() { - return getTickOffset(); - } - - 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; - } - - public void setMaterial(Material material) { - this.material = material; - } - - public void setDisabled(boolean disabled) { - this.disabled = disabled; - elements.forEach(TNTElement::_updatePosition); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java deleted file mode 100644 index 90feb161..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorCursor.java +++ /dev/null @@ -1,416 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 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.simulator2; - -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; -import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor; -import de.steamwar.bausystem.features.simulator2.gui.SimulatorGroupGui; -import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; -import de.steamwar.bausystem.utils.ItemUtils; -import de.steamwar.bausystem.utils.RayTraceUtils; -import de.steamwar.entity.REntity; -import de.steamwar.entity.REntityServer; -import de.steamwar.entity.RFallingBlockEntity; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.linkage.Linked; -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.*; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.stream.Collectors; - -@Linked -public class SimulatorCursor implements Listener { - - private final World WORLD = Bukkit.getWorlds().get(0); - private Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private Class look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook"); - private Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); - - private Map cursorType = Collections.synchronizedMap(new HashMap<>()); - private Map cursors = Collections.synchronizedMap(new HashMap<>()); - - public static boolean isSimulatorItem(ItemStack itemStack) { - return ItemUtils.isItem(itemStack, "simulator"); - } - - public SimulatorCursor() { - BiFunction function = (player, object) -> { - calcCursor(player); - return object; - }; - TinyProtocol.instance.addFilter(position, function); - TinyProtocol.instance.addFilter(look, function); - TinyProtocol.instance.addFilter(positionLook, function); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - calcCursor(event.getPlayer()); - } - - @EventHandler - public void onPlayerDropItem(PlayerDropItemEvent event) { - calcCursor(event.getPlayer()); - } - - @EventHandler - public void onPlayerItemHeld(PlayerItemHeldEvent event) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - calcCursor(event.getPlayer()); - }, 1); - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - cursorType.remove(event.getPlayer()); - cursors.remove(event.getPlayer()); - } - - private static final Map LAST_SNEAKS = new HashMap<>(); - - static { - Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { - long millis = System.currentTimeMillis(); - LAST_SNEAKS.entrySet().removeIf(entry -> millis - entry.getValue() > 200); - }, 1, 1); - } - - @EventHandler(priority = EventPriority.HIGH) - public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { - if (!event.isSneaking()) return; - Player player = event.getPlayer(); - if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { - return; - } - if (LAST_SNEAKS.containsKey(player)) { - cursorType.put(player, cursorType.getOrDefault(player, CursorType.TNT).switchType()); - calcCursor(player); - } else { - LAST_SNEAKS.put(player, System.currentTimeMillis()); - } - } - - private synchronized void calcCursor(Player player) { - if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { - removeCursor(player); - SimulatorWatcher.show(null, player); - SWUtils.sendToActionbar(player, ""); - return; - } - Simulator simulator = SimulatorStorage.getSimulator(player); - SimulatorWatcher.show(simulator, player); - - List entities = SimulatorWatcher.getEntitiesOfSimulator(simulator); - RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities); - if (rayTraceResult == null) { - removeCursor(player); - if (simulator == null) { - SWUtils.sendToActionbar(player, "§eSelect Simulator"); - } else { - SWUtils.sendToActionbar(player, "§eOpen Simulator"); - } - return; - } - - showCursor(player, rayTraceResult, simulator != null); - } - - private synchronized void removeCursor(Player player) { - REntityServer entityServer = cursors.get(player); - if (entityServer != null) { - entityServer.getEntities().forEach(REntity::die); - } - } - - private synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, boolean hasSimulatorSelected) { - REntityServer entityServer = cursors.computeIfAbsent(player, __ -> { - REntityServer rEntityServer = new REntityServer(); - rEntityServer.addPlayer(player); - return rEntityServer; - }); - - CursorType type = cursorType.getOrDefault(player, CursorType.TNT); - REntity hitEntity = rayTraceResult.getHitEntity(); - Location location = hitEntity != null ? new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD) : - type.position.apply(player, rayTraceResult).toLocation(WORLD); - - Material material = hitEntity != null ? Material.GLASS : type.getMaterial(); - List entities = entityServer.getEntitiesByType(RFallingBlockEntity.class); - entities.removeIf(rFallingBlockEntity -> { - if (rFallingBlockEntity.getMaterial() != material) { - rFallingBlockEntity.die(); - return true; - } - rFallingBlockEntity.move(location); - return false; - }); - if (entities.isEmpty()) { - RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, location, material); - rFallingBlockEntity.setNoGravity(true); - if (material == Material.GLASS) { - rFallingBlockEntity.setGlowing(true); - } - } - - if (hasSimulatorSelected) { - if (hitEntity != null) { - SWUtils.sendToActionbar(player, "§eEdit Position"); - } else { - SWUtils.sendToActionbar(player, "§eAdd new " + type.name); - } - } else { - SWUtils.sendToActionbar(player, "§eCreate new Simulator"); - } - } - - public static Vector getPosTNT(Player player, RayTraceUtils.RRayTraceResult result) { - Vector pos = result.getHitPosition(); - - BlockFace face = result.getHitBlockFace(); - if (face != null) { - switch (face) { - case DOWN: - pos.setY(pos.getY() - 0.98); - break; - case EAST: - pos.setX(pos.getX() + 0.49); - break; - case WEST: - pos.setX(pos.getX() - 0.49); - break; - case NORTH: - pos.setZ(pos.getZ() - 0.49); - break; - case SOUTH: - pos.setZ(pos.getZ() + 0.49); - break; - default: - break; - } - - if (face.getModY() == 0 && player.isSneaking()) { - pos.setY(pos.getY() - 0.49); - } - } - - if (!player.isSneaking()) { - pos.setX(pos.getBlockX() + 0.5); - if (face == null || face.getModY() == 0) - pos.setY(pos.getBlockY() + 0.0); - pos.setZ(pos.getBlockZ() + 0.5); - } - - return pos; - } - - private static Vector getPosRedstoneBlock(Player player, RayTraceUtils.RRayTraceResult result) { - Vector pos = result.getHitPosition(); - - BlockFace face = result.getHitBlockFace(); - if (face != null) { - switch (face) { - case DOWN: - pos.setY(pos.getY() - 0.98); - break; - case EAST: - pos.setX(pos.getX() + 0.49); - break; - case WEST: - pos.setX(pos.getX() - 0.49); - break; - case NORTH: - pos.setZ(pos.getZ() - 0.49); - break; - case SOUTH: - pos.setZ(pos.getZ() + 0.49); - break; - default: - break; - } - } - - pos.setX(pos.getBlockX() + 0.5); - if (pos.getY() - pos.getBlockY() != 0 && face == BlockFace.UP) { - pos.setY(pos.getBlockY() + 1.0); - } else { - pos.setY(pos.getBlockY()); - } - pos.setZ(pos.getBlockZ() + 0.5); - return pos; - } - - @Getter - @AllArgsConstructor - public enum CursorType { - TNT(Material.TNT, SimulatorCursor::getPosTNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())), - REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())), - ; - - private Material material; - private BiFunction position; - private String name; - private Function> elementFunction; - - public CursorType switchType() { - if (this == TNT) { - return REDSTONE_BLOCK; - } - return TNT; - } - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (!ItemUtils.isItem(event.getItem(), "simulator")) { - return; - } - - event.setCancelled(true); - Player player = event.getPlayer(); - Simulator simulator = SimulatorStorage.getSimulator(player); - - if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { - if (simulator == null) { - return; - } - SimulatorExecutor.run(simulator); - return; - } - - if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) { - return; - } - - - RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator)); - if (simulator == null) { - if (rayTraceResult == null) { - SimulatorStorage.openSimulatorSelector(player); - } else { - SWAnvilInv anvilInv = new SWAnvilInv(player, "Name"); - anvilInv.setCallback(s -> { - Simulator sim = SimulatorStorage.getSimulator(s); - if (sim != null) { - player.sendMessage("§cThe simulator " + s + " already exists"); - return; - } - sim = new Simulator(s); - SimulatorStorage.addSimulator(s, sim); - createElement(player, rayTraceResult, sim); - SimulatorStorage.setSimulator(player, sim); - }); - anvilInv.open(); - } - return; - } - - if (rayTraceResult == null) { - new SimulatorGui(player, simulator).open(); - return; - } - - if (rayTraceResult.getHitEntity() != null) { - REntity hitEntity = rayTraceResult.getHitEntity(); - Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()); - List> elements = simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> { - return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0); - }).collect(Collectors.toList()); - - switch (elements.size()) { - case 0: - return; - case 1: - // Open single element present in Simulator - SimulatorElement element = elements.get(0); - SimulatorGroup group1 = element.getGroup(simulator); - SimulatorBaseGui back = new SimulatorGui(player, simulator); - if (group1.getElements().size() > 1) { - back = new SimulatorGroupGui(player, simulator, group1, back); - } - element.open(player, simulator, group1, back); - break; - default: - List parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList()); - if (parents.size() == 1) { - // Open multi element present in Simulator in existing group - SimulatorGui simulatorGui = new SimulatorGui(player, simulator); - new SimulatorGroupGui(player, simulator, parents.get(0), simulatorGui).open(); - } else { - // Open multi element present in Simulator in implicit group - SimulatorGroup group2 = new SimulatorGroup(); - group2.setMaterial(null); - group2.getElements().addAll(elements); - SimulatorGui simulatorGui = new SimulatorGui(player, simulator); - new SimulatorGroupGui(player, simulator, group2, simulatorGui).open(); - } - break; - } - return; - } - - // Add new Element to current simulator - createElement(player, rayTraceResult, simulator); - } - - private void createElement(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, Simulator simulator) { - CursorType type = cursorType.getOrDefault(player, CursorType.TNT); - Vector vector = type.position.apply(player, rayTraceResult); - if (type == CursorType.REDSTONE_BLOCK) { - vector.subtract(new Vector(0.5, 0, 0.5)); - } - SimulatorElement element = type.elementFunction.apply(vector); - SimulatorGroup group = new SimulatorGroup().add(element); - simulator.getElements().add(group); - SimulatorGui simulatorGui = new SimulatorGui(player, simulator); - element.open(player, simulator, group, simulatorGui); - SimulatorWatcher.update(simulator); - calcCursor(player); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java deleted file mode 100644 index 7bae9ba9..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorStorage.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 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.simulator2; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui; -import de.steamwar.bausystem.features.simulator2.storage.SimFormatSimulatorLoader; -import de.steamwar.bausystem.features.simulator2.storage.SimulatorFormatSimulatorLoader; -import de.steamwar.bausystem.features.simulator2.storage.SimulatorSaver; -import de.steamwar.bausystem.features.simulator2.storage.YAPIONFormatSimulatorLoader; -import de.steamwar.bausystem.utils.ItemUtils; -import de.steamwar.inventory.SWItem; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.api.Enable; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.io.File; -import java.util.*; - -@Linked -public class SimulatorStorage implements Enable { - - public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators"); - private static Map simulatorMap = new HashMap<>(); - private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection"); - - public static Simulator getSimulator(Player player) { - Simulator simulator = getSimulator(player.getInventory().getItemInMainHand()); - if (simulator != null) return simulator; - return getSimulator(player.getInventory().getItemInOffHand()); - } - - public static Simulator getSimulator(ItemStack itemStack) { - if (!SimulatorCursor.isSimulatorItem(itemStack)) { - return null; - } - String selection = ItemUtils.getTag(itemStack, simulatorSelection); - if (selection == null) { - return null; - } - return simulatorMap.get(selection); - } - - public static Simulator getSimulator(String name) { - return simulatorMap.get(name); - } - - public static void addSimulator(String name, Simulator simulator) { - simulatorMap.putIfAbsent(name, simulator); - } - - @Override - public void enable() { - SimFormatSimulatorLoader simFormatSimulatorLoader = new SimFormatSimulatorLoader(); - SimulatorFormatSimulatorLoader simulatorFormatSimulatorLoader = new SimulatorFormatSimulatorLoader(); - YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader(); - - for (File file : simulatorsDir.listFiles()) { - try { - List simulators = simFormatSimulatorLoader.load(file) - .orElse(null); - if (simulators != null) { - simulators.forEach(simulator -> { - simulatorMap.put(simulator.getName(), simulator); - }); - continue; - } - } catch (Exception e) { - // Ignore - } - - try { - List simulators = simulatorFormatSimulatorLoader.load(file) - .orElse(null); - if (simulators != null) { - simulators.forEach(simulator -> { - simulatorMap.put(simulator.getName(), simulator); - SimulatorSaver.saveSimulator(simulatorsDir, simulator); - }); - continue; - } - } catch (Exception e) { - // Ignore - } - - try { - List simulators = yapionFormatSimulatorLoader.load(file) - .orElse(null); - if (simulators != null) { - simulators.forEach(simulator -> { - simulatorMap.put(simulator.getName(), simulator); - SimulatorSaver.saveSimulator(simulatorsDir, simulator); - }); - } - } catch (Exception e) { - // Ignore - } - } - } - - public static void openSimulatorSelector(Player player) { - SimulatorPageGui simulatorPageGui = new SimulatorPageGui(player, null, 6 * 9, new ArrayList<>(simulatorMap.values())) { - @Override - public String baseTitle() { - return "Simulators"; - } - - @Override - public SWItem convert(Simulator simulator) { - return simulator.toItem(player, clickType -> { - setSimulator(player, simulator); - player.closeInventory(); - }); - } - }; - simulatorPageGui.open(); - } - - public static void setSimulator(Player player, Simulator simulator) { - ItemStack mainHand = player.getInventory().getItemInMainHand(); - ItemStack offHand = player.getInventory().getItemInOffHand(); - ItemStack itemStack; - if (SimulatorCursor.isSimulatorItem(mainHand)) { - itemStack = mainHand; - } else if (SimulatorCursor.isSimulatorItem(offHand)) { - itemStack = offHand; - } else { - itemStack = null; - } - if (itemStack == null) { - return; - } - - ItemUtils.setTag(itemStack, simulatorSelection, simulator.getName()); - ItemMeta itemMeta = itemStack.getItemMeta(); - itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, simulator.getName())); - itemStack.setItemMeta(itemMeta); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java deleted file mode 100644 index b3f668cb..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/SimulatorTestCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 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.simulator2; - -import de.steamwar.bausystem.features.simulator2.data.Simulator; -import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement; -import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; -import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase; -import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor; -import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; -import de.steamwar.command.SWCommand; -import de.steamwar.linkage.Linked; -import jdk.jfr.Registered; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -@Linked -public class SimulatorTestCommand extends SWCommand { - - static final Simulator SIMULATOR = new Simulator("TestSim"); - - public SimulatorTestCommand() { - super("simtest"); - - SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(-477.5, 46, 311.5)).add(new TNTPhase())); - SIMULATOR.getElements().add(group1); - - SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(-477.5, 47, 312.5)).add(new TNTPhase())); - SIMULATOR.getElements().add(group2); - - SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(-484, 47, 307)).add(new RedstonePhase())); - SIMULATOR.getElements().add(group3); - } -} From c05724efda4d2a802a8c4e0905b6142a50aaa47f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 16:34:54 +0200 Subject: [PATCH 040/139] Update SimulatorExecutor and fix many bugs --- .../bausystem/utils/TickListener15.java | 23 ++++ BauSystem_19/build.gradle | 1 + .../bausystem/utils/TickListener19.java | 51 ++++++++ .../src/de/steamwar/bausystem/BauSystem.java | 2 + .../features/simulator/SimulatorCommand.java | 2 + .../features/simulator/SimulatorCursor.java | 6 +- .../features/simulator/SimulatorStorage.java | 2 + .../features/simulator/SimulatorWatcher.java | 4 +- .../features/simulator/data/Simulator.java | 13 ++- .../simulator/data/SimulatorElement.java | 7 +- .../simulator/data/SimulatorGroup.java | 9 +- .../simulator/data/SimulatorPhase.java | 3 +- .../data/redstone/RedstonePhase.java | 50 ++++---- .../features/simulator/data/tnt/TNTPhase.java | 5 +- .../simulator/execute/SimulatorExecutor.java | 109 +++++++++++------- .../gui/SimulatorGroupChooserGui.java | 4 +- .../features/simulator/gui/SimulatorGui.java | 4 +- .../gui/SimulatorTNTSettingsGui.java | 2 +- .../storage/SimFormatSimulatorLoader.java | 4 +- .../simulator/storage/SimulatorSaver.java | 2 +- .../bausystem/utils/TickEndEvent.java | 36 ++++++ .../bausystem/utils/TickListener.java | 31 +++++ .../bausystem/utils/TickStartEvent.java | 36 ++++++ build.gradle | 4 + 24 files changed, 316 insertions(+), 94 deletions(-) create mode 100644 BauSystem_15/src/de/steamwar/bausystem/utils/TickListener15.java create mode 100644 BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/TickEndEvent.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/TickListener.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/TickStartEvent.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/TickListener15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/TickListener15.java new file mode 100644 index 00000000..f2b604ac --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/TickListener15.java @@ -0,0 +1,23 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.utils; + +public class TickListener15 implements TickListener { +} diff --git a/BauSystem_19/build.gradle b/BauSystem_19/build.gradle index e7be349d..b1c37d01 100644 --- a/BauSystem_19/build.gradle +++ b/BauSystem_19/build.gradle @@ -51,6 +51,7 @@ dependencies { implementation project(":BauSystem_Main") compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT' + compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT' compileOnly 'it.unimi.dsi:fastutil:8.5.6' compileOnly 'com.mojang:datafixerupper:4.0.26' compileOnly 'io.netty:netty-all:4.1.68.Final' diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java new file mode 100644 index 00000000..5191b38b --- /dev/null +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java @@ -0,0 +1,51 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.utils; + +import com.destroystokyo.paper.event.server.ServerTickEndEvent; +import com.destroystokyo.paper.event.server.ServerTickStartEvent; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class TickListener19 implements TickListener, Listener { + + private boolean tickStartRan = false; + + public TickListener19() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + @EventHandler + public void onServerTickStart(ServerTickStartEvent event) { + if (TPSFreezeUtils.isFrozen()) return; + Bukkit.getPluginManager().callEvent(new TickStartEvent()); + tickStartRan = true; + } + + @EventHandler + public void onServerTickEnd(ServerTickEndEvent event) { + if (!tickStartRan) return; + Bukkit.getPluginManager().callEvent(new TickEndEvent()); + tickStartRan = false; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index bb60156f..10b36297 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.linkage.LinkageUtils; import de.steamwar.bausystem.region.loader.PrototypeLoader; import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.Updater; +import de.steamwar.bausystem.utils.TickListener; import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.message.Message; import lombok.Getter; @@ -76,6 +77,7 @@ public class BauSystem extends JavaPlugin implements Listener { LinkageUtils.link(); RamUsage.init(); + TickListener.impl.init(); // This could disable any watchdog stuff. We need to investigate if this is a problem. /* 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 5f320fc5..56991431 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -30,12 +30,14 @@ import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; +import de.steamwar.linkage.MinVersion; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.Collection; @Linked +@MinVersion(19) public class SimulatorCommand extends SWCommand { @LinkedInstance diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 39564fa6..ff545a86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -41,6 +41,7 @@ import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; import lombok.AllArgsConstructor; import lombok.Getter; import org.bukkit.Bukkit; @@ -66,6 +67,7 @@ import java.util.function.Function; import java.util.stream.Collectors; @Linked +@MinVersion(19) public class SimulatorCursor implements Listener { private final World WORLD = Bukkit.getWorlds().get(0); @@ -366,7 +368,7 @@ public class SimulatorCursor implements Listener { if (rayTraceResult.getHitEntity() != null) { REntity hitEntity = rayTraceResult.getHitEntity(); Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()); - List> elements = simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> { + List> elements = simulator.getGroups().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> { return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0); }).collect(Collectors.toList()); @@ -414,7 +416,7 @@ public class SimulatorCursor implements Listener { } SimulatorElement element = type.elementFunction.apply(vector); SimulatorGroup group = new SimulatorGroup().add(element); - simulator.getElements().add(group); + simulator.getGroups().add(group); SimulatorGui simulatorGui = new SimulatorGui(player, simulator); element.open(player, simulator, group, simulatorGui); SimulatorWatcher.update(simulator); 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 071a2acd..9ad4701d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -31,6 +31,7 @@ import de.steamwar.bausystem.features.simulator.storage.YAPIONFormatSimulatorLoa import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; import de.steamwar.linkage.api.Enable; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -44,6 +45,7 @@ import java.io.IOException; import java.util.*; @Linked +@MinVersion(19) public class SimulatorStorage implements Enable { public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java index 1a3f3987..4ea413d8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java @@ -28,6 +28,7 @@ import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -73,6 +74,7 @@ public class SimulatorWatcher { } @Linked + @MinVersion(19) public static class QuitListener implements Listener { @EventHandler @@ -87,7 +89,7 @@ public class SimulatorWatcher { return null; } Map>> positionCache = new HashMap<>(); - simulator.getElements().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> { + simulator.getGroups().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> { SimulatorGroup group = pair.getKey(); SimulatorElement element = pair.getValue(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java index 75e79765..91b7a8e1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/Simulator.java @@ -31,6 +31,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; @Getter @Setter @@ -39,10 +40,10 @@ public final class Simulator { private Material material = Material.BARREL; private final String name; private boolean autoTrace = false; - private final List elements = new ArrayList<>(); + private final List groups = new ArrayList<>(); public void move(int x, int y, int z) { - elements.forEach(simulatorGroup -> { + groups.forEach(simulatorGroup -> { simulatorGroup.move(x, y, z); }); } @@ -51,14 +52,14 @@ public final class Simulator { return new SWItem(material, "§e" + name, invCallback); } - public void toSimulatorActions(Map> actions) { - elements.forEach(simulatorGroup -> { - simulatorGroup.toSimulatorActions(actions); + public void toSimulatorActions(BiConsumer tickStart, BiConsumer tickEnd) { + groups.forEach(simulatorGroup -> { + simulatorGroup.toSimulatorActions(tickStart, tickEnd); }); } public Simulator add(SimulatorGroup group) { - elements.add(group); + groups.add(group); return this; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java index a79a7dad..df5b13a4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; @Getter @Setter @@ -101,17 +102,17 @@ public abstract class SimulatorElement { return new SWItem(material, "§e" + getName(player), lore, disabled, invCallback); } - public void toSimulatorActions(Map> actions) { + public void toSimulatorActions(BiConsumer tickStart, BiConsumer tickEnd) { if (disabled) return; phases.forEach(phase -> { - phase.toSimulatorActions(actions, position.clone()); + phase.toSimulatorActions(position.clone(), tickStart, tickEnd); }); } public abstract void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back); public SimulatorGroup getGroup(Simulator simulator) { - return simulator.getElements().stream() + return simulator.getGroups().stream() .filter(simulatorGroup -> simulatorGroup.getElements().contains(this)) .findFirst() .orElse(null); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java index 3b09e8b3..0e90903c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; @Getter @Setter @@ -40,7 +41,9 @@ public final class SimulatorGroup { private final List> elements = new ArrayList<>(); public SimulatorGroup add(SimulatorElement element) { - elements.add(element); + if (!elements.contains(element)) { + elements.add(element); + } return this; } @@ -82,10 +85,10 @@ public final class SimulatorGroup { } } - public void toSimulatorActions(Map> actions) { + public void toSimulatorActions(BiConsumer tickStart, BiConsumer tickEnd) { if (disabled) return; elements.forEach(simulatorElement -> { - simulatorElement.toSimulatorActions(actions); + simulatorElement.toSimulatorActions(tickStart, tickEnd); }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorPhase.java index 33009044..b226d124 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorPhase.java @@ -27,6 +27,7 @@ import yapion.hierarchy.types.YAPIONObject; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; @Getter @Setter @@ -37,7 +38,7 @@ public abstract class SimulatorPhase { protected int lifetime = 80; protected int order = 0; - public abstract void toSimulatorActions(Map> actions, Vector position); + public abstract void toSimulatorActions(Vector position, BiConsumer tickStart, BiConsumer tickEnd); public void saveExtra(YAPIONObject phaseObject) {} public void loadExtra(YAPIONObject phaseObject) {} } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java index f67dfb45..e54abf62 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.simulator.data.redstone; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import lombok.NoArgsConstructor; @@ -33,6 +34,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiConsumer; @NoArgsConstructor public final class RedstonePhase extends SimulatorPhase { @@ -46,31 +48,27 @@ public final class RedstonePhase extends SimulatorPhase { } @Override - public void toSimulatorActions(Map> actions, Vector position) { - AtomicReference previousBlockState = new AtomicReference<>(); - actions.computeIfAbsent(tickOffset, __ -> new ArrayList<>()) - .add(new SimulatorAction(0, 1) { - @Override - public void accept(World world) { - // TODO: 0 Tick Pistons not working - Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - previousBlockState.set(block.getState()); - block.setType(Material.REDSTONE_BLOCK); - if (lifetime == 0) { - previousBlockState.get().update(true, true); - } - } - }); - - if (lifetime == 0) { - return; - } - actions.computeIfAbsent(tickOffset + lifetime, __ -> new ArrayList<>()) - .add(new SimulatorAction(0, 1) { - @Override - public void accept(World world) { - previousBlockState.get().update(true, true); - } - }); + public void toSimulatorActions(Vector position, BiConsumer tickStart, BiConsumer tickEnd) { + AtomicReference blockState = new AtomicReference<>(); + tickStart.accept(tickOffset, new SimulatorAction(order, 1) { + @Override + public void accept(World world) { + Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + blockState.set(block.getState()); + block.setType(Material.REDSTONE_BLOCK); + } + }); + tickEnd.accept(tickOffset + lifetime, new SimulatorAction(0, 1) { + @Override + public void accept(World world) { + BlockState state = blockState.get(); + if (state != null) { + state.update(true, true); + } else { + Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + block.setType(Material.AIR); + } + } + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java index d776edb8..7583834b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java @@ -32,6 +32,7 @@ import yapion.hierarchy.types.YAPIONObject; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; @Getter @Setter @@ -57,8 +58,8 @@ public final class TNTPhase extends SimulatorPhase { } @Override - public void toSimulatorActions(Map> actions, Vector position) { - actions.computeIfAbsent(tickOffset, __ -> new ArrayList<>()).add(new SimulatorAction(order, count) { + public void toSimulatorActions(Vector position, BiConsumer tickStart, BiConsumer tickEnd) { + tickStart.accept(tickOffset, new SimulatorAction(order, count) { @Override public void accept(World world) { TNTPrimed tnt = world.spawn(position.toLocation(world), TNTPrimed.class); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java index 65f15009..cbc848e4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java @@ -19,63 +19,88 @@ package de.steamwar.bausystem.features.simulator.execute; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.simulator.data.Simulator; -import lombok.experimental.UtilityClass; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.utils.TickEndEvent; +import de.steamwar.bausystem.utils.TickStartEvent; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; -@UtilityClass -public class SimulatorExecutor { +@Linked +@MinVersion(19) +public class SimulatorExecutor implements Listener { private static final World WORLD = Bukkit.getWorlds().get(0); private static Set currentlyRunning = new HashSet<>(); + private static Map>> tickStartActions = new HashMap<>(); + private static Map> tickEndActions = new HashMap<>(); - public boolean run(Simulator simulator) { + public static boolean run(Simulator simulator) { if (currentlyRunning.contains(simulator)) return false; + currentlyRunning.add(simulator); - Map> map = new HashMap<>(); - simulator.toSimulatorActions(map); - - Map>> actions = new HashMap<>(); - map.forEach((integer, simulatorActions) -> { - simulatorActions.forEach(simulatorAction -> { - actions.computeIfAbsent(integer, __ -> new HashMap<>()).computeIfAbsent(simulatorAction.getOrder(), __ -> new ArrayList<>()).add(simulatorAction); - }); + long currentTick = TPSUtils.currentRealTick.get(); + AtomicLong lastTick = new AtomicLong(); + simulator.toSimulatorActions((tickOffset, simulatorAction) -> { + lastTick.set(Math.max(lastTick.get(), tickOffset)); + tickStartActions.computeIfAbsent(currentTick + tickOffset, __ -> new HashMap<>()) + .computeIfAbsent(simulatorAction.getOrder(), __ -> new ArrayList<>()) + .add(simulatorAction); + }, (tickOffset, simulatorAction) -> { + lastTick.set(Math.max(lastTick.get(), tickOffset)); + tickEndActions.computeIfAbsent(currentTick + tickOffset, __ -> new ArrayList<>()) + .add(simulatorAction); }); - AtomicInteger tick = new AtomicInteger(); - BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> { - if (actions.isEmpty()) { - bukkitTask.cancel(); - currentlyRunning.remove(simulator); - return; - } - - int currentTick = tick.getAndIncrement(); - Map> actionsToRun = actions.remove(currentTick); - if (actionsToRun == null) return; - List keys = new ArrayList<>(actionsToRun.keySet()); - keys.sort(null); - - for (int actionKey : keys) { - List keyedActions = actionsToRun.get(actionKey); - while (!keyedActions.isEmpty()) { - Collections.shuffle(keyedActions); - for (int i = keyedActions.size() - 1 ; i >= 0; i--) { - SimulatorAction action = keyedActions.get(i); - action.accept(WORLD); - action.setCount(action.getCount() - 1); - if (action.getCount() == 0) { - keyedActions.remove(i); - } + tickEndActions.computeIfAbsent(currentTick + lastTick.get() + 4, __ -> new ArrayList<>()) + .add(new SimulatorAction(0, 1) { + @Override + public void accept(World world) { + currentlyRunning.remove(simulator); } - } - } - }, 0, 1); + }); return true; } + + @EventHandler + public void onTickStart(TickStartEvent event) { + long currentTick = TPSUtils.currentRealTick.get(); + Map> actionsToRun = tickStartActions.remove(currentTick); + if (actionsToRun == null) return; + + List keys = new ArrayList<>(actionsToRun.keySet()); + keys.sort(null); + for (int actionKey : keys) { + runActions(actionsToRun.get(actionKey)); + } + } + + @EventHandler + public void onTickEnd(TickEndEvent event) { + long currentTick = TPSUtils.currentRealTick.get() - 1; + List actionsToRun = tickEndActions.remove(currentTick); + if (actionsToRun == null) return; + runActions(actionsToRun); + } + + private void runActions(List actionsToRun) { + while (!actionsToRun.isEmpty()) { + Collections.shuffle(actionsToRun); + for (int i = actionsToRun.size() - 1 ; i >= 0; i--) { + SimulatorAction action = actionsToRun.get(i); + action.accept(WORLD); + action.setCount(action.getCount() - 1); + if (action.getCount() == 0) { + actionsToRun.remove(i); + } + } + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java index c431420c..9778c6c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java @@ -39,7 +39,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { private final SimulatorBaseGui back; public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement subject, SimulatorGroup parent, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, simulator.getElements().stream().filter(e -> e != parent).collect(Collectors.toList())); + super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).collect(Collectors.toList())); this.subject = subject; this.parent = parent; this.back = back; @@ -53,7 +53,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { inventory.setItem(49, new SWItem(Material.BARRIER, "§cRemove from Group", clickType -> { SimulatorGroup newParent = new SimulatorGroup(); newParent.add(subject); - simulator.getElements().add(newParent); + simulator.getGroups().add(newParent); parent.getElements().remove(subject); back.open(); SimulatorWatcher.update(simulator); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java index dfc612ec..e35f0eaa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java @@ -31,7 +31,7 @@ import org.bukkit.entity.Player; public class SimulatorGui extends SimulatorPageGui { public SimulatorGui(Player player, Simulator simulator) { - super(player, simulator, 6 * 9, simulator.getElements()); + super(player, simulator, 6 * 9, simulator.getGroups()); } @Override @@ -41,7 +41,7 @@ public class SimulatorGui extends SimulatorPageGui { @Override public void headerAndFooter() { - if (simulator.getElements().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) { + if (simulator.getGroups().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) { SimulatorWatcher.update(simulator); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index e1698c6f..d880ca5e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -32,7 +32,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class SimulatorTNTSettingsGui extends SimulatorBaseGui { +public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // TODO: Anvil GUI's! private final TNTElement tnt; private final SimulatorBaseGui back; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java index 18089002..15af2e4a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java @@ -83,8 +83,8 @@ public class SimFormatSimulatorLoader implements SimulatorLoader { elements.streamObject().forEach(elementObject -> { SimulatorElement element; Supplier phaseConstructor; - Vector position = new Vector(groupObject.getDouble("x"), groupObject.getDouble("y"), groupObject.getDouble("z")); - String type = groupObject.getPlainValue("type"); + Vector position = new Vector(elementObject.getDouble("x"), elementObject.getDouble("y"), elementObject.getDouble("z")); + String type = elementObject.getPlainValue("type"); switch (type) { case "TNT": element = new TNTElement(position); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java index 67260e4f..285be22f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java @@ -37,7 +37,7 @@ public class SimulatorSaver { simulatorObject.add("autoTrace", simulator.isAutoTrace()); YAPIONArray groups = new YAPIONArray(); - simulator.getElements().forEach(group -> { + simulator.getGroups().forEach(group -> { YAPIONObject groupObject = new YAPIONObject(); groupObject.add("material", group.getMaterial().name()); groupObject.add("disabled", group.isDisabled()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/TickEndEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/TickEndEvent.java new file mode 100644 index 00000000..11b90f80 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/TickEndEvent.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.utils; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class TickEndEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/TickListener.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/TickListener.java new file mode 100644 index 00000000..029a2e5c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/TickListener.java @@ -0,0 +1,31 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.utils; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.VersionDependent; + +public interface TickListener { + + TickListener impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); + + default void init() { + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/TickStartEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/TickStartEvent.java new file mode 100644 index 00000000..1134a832 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/TickStartEvent.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.utils; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class TickStartEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/build.gradle b/build.gradle index 48c8df51..5ce3ebaf 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,10 @@ allprojects { maven { url = uri('https://libraries.minecraft.net') } + + maven { + url = uri("https://repo.papermc.io/repository/maven-public/") + } } } From 402de21c4722a3858438acda2e7fd18c91bc5bf6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 16:43:03 +0200 Subject: [PATCH 041/139] Add order to SimulatorRedstonePhaseSettingsGui --- .../gui/SimulatorRedstonePhaseSettingsGui.java | 17 +++++++++-------- .../gui/SimulatorTNTPhaseSettingsGui.java | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index 3a03deed..7103cb59 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -21,9 +21,11 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -106,22 +108,21 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { }); //Order - /* int order = redstone.getOrder(); - inventory.setItem(14, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(13, SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); - SWItem orderItem = new SWItem(Material.COMPASS, "§eOrder§8:§7 " + order, clickType -> { + Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); + SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { }); - orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); - inventory.setItem(23, orderItem); + orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); + inventory.setItem(22, orderItem); - inventory.setItem(32, SWItem.getDye(order > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - redstone.setOrder(Math.max(1, order - (clickType.isShiftClick() ? 5 : 1))); + inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + redstone.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); - */ } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index 149fb599..4022c82b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -138,7 +138,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(22, orderItem); inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - tnt.setOrder(Math.max(-30, order - (clickType.isShiftClick() ? 5 : 1))); + tnt.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); From b379f8457de1f18d44eae829323f74c3c4916345 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 16:46:56 +0200 Subject: [PATCH 042/139] Fix simulator double activation while tnt still present --- .../bausystem/features/simulator/data/tnt/TNTPhase.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java index 7583834b..34ae0572 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java @@ -69,6 +69,11 @@ public final class TNTPhase extends SimulatorPhase { tnt.setFuseTicks(lifetime); } }); + tickEnd.accept(tickOffset + lifetime, new SimulatorAction(0, 1) { + @Override + public void accept(World world) { + } + }); } @Override From a0859923f01ea10f842cd09e1d24fe07f529b046 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 17:41:10 +0200 Subject: [PATCH 043/139] Add SimulatorAnvilGui and add anvil gui's to everything --- .../simulator/execute/SimulatorExecutor.java | 21 ++++++ .../gui/SimulatorGroupSettingsGui.java | 7 ++ .../SimulatorRedstonePhaseSettingsGui.java | 20 +++++ .../gui/SimulatorRedstoneSettingsGui.java | 22 ++++++ .../gui/SimulatorTNTPhaseSettingsGui.java | 26 +++++++ .../gui/SimulatorTNTSettingsGui.java | 22 ++++++ .../simulator/gui/base/SimulatorAnvilGui.java | 73 +++++++++++++++++++ .../features/tracer/record/Recorder.java | 4 + .../tracer/record/SingleTraceRecorder.java | 2 +- 9 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java index cbc848e4..893161f4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/execute/SimulatorExecutor.java @@ -20,7 +20,12 @@ package de.steamwar.bausystem.features.simulator.execute; import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.record.SingleTraceRecorder; +import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.TickEndEvent; import de.steamwar.bausystem.utils.TickStartEvent; import de.steamwar.linkage.Linked; @@ -66,6 +71,22 @@ public class SimulatorExecutor implements Listener { currentlyRunning.remove(simulator); } }); + + if (simulator.isAutoTrace()) { + simulator.getGroups() + .stream() + .map(SimulatorGroup::getElements) + .flatMap(List::stream) + .map(SimulatorElement::getPosition) + .map(pos -> pos.toLocation(WORLD)) + .map(Region::getRegion) + .distinct() + .forEach(region -> { + if (Recorder.INSTANCE.isDisabled(region)) { + Recorder.INSTANCE.set(region, new SingleTraceRecorder(region)); + } + }); + } return true; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index 2aa11e98..4c1e8d74 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; @@ -70,6 +71,12 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { + new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + simulatorGroup.changeBaseTicks(integer - baseTicks); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.REPEATER).open(); }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index 7103cb59..07f55a73 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; @@ -81,6 +82,12 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { }); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { + new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + redstone.setTickOffset(integer); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.REPEATER).open(); }); offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(20, offsetItem); @@ -98,6 +105,12 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { }); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> { + new SimulatorAnvilGui<>(player, "Activation Time", lifetime + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + redstone.setLifetime(integer); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.CLOCK).open(); }); lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(21, lifetimeItem); @@ -116,6 +129,13 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { + new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> { + if (integer < -SimulatorPhase.ORDER_LIMIT) return false; + if (integer > SimulatorPhase.ORDER_LIMIT) return false; + redstone.setOrder(integer); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open(); }); orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); inventory.setItem(22, orderItem); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java index eb0ea99e..184d73a1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneSettingsGui.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; @@ -68,6 +69,12 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { + new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + redstone.changeBaseTicks(integer - baseTicks); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.REPEATER).open(); }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); @@ -86,6 +93,11 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + redstone.getPosition().getBlockX(), clickType -> { + new SimulatorAnvilGui<>(player, "X", redstone.getPosition().getBlockX() + "", Integer::parseInt, i -> { + redstone.getPosition().setX(i); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); })); inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0); @@ -98,6 +110,11 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + redstone.getPosition().getBlockY(), clickType -> { + new SimulatorAnvilGui<>(player, "Y", redstone.getPosition().getBlockY() + "", Integer::parseInt, i -> { + redstone.getPosition().setY(i); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); })); inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0); @@ -110,6 +127,11 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + redstone.getPosition().getBlockZ(), clickType -> { + new SimulatorAnvilGui<>(player, "Z", redstone.getPosition().getBlockZ() + "", Integer::parseInt, i -> { + redstone.getPosition().setZ(i); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); })); inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index 4022c82b..6541c112 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; @@ -81,6 +82,12 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { }); SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> { + new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + tnt.setCount(integer); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.TNT).open(); }); countItem.getItemStack().setAmount(Math.max(1, Math.min(count, 64))); inventory.setItem(18, countItem); @@ -98,6 +105,12 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { }); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { + new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + tnt.setTickOffset(integer); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.REPEATER).open(); }); offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(19, offsetItem); @@ -115,6 +128,12 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { }); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> { + new SimulatorAnvilGui<>(player, "Lifetime", lifetime + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + tnt.setLifetime(integer); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.CLOCK).open(); }); lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(20, lifetimeItem); @@ -133,6 +152,13 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eCalculation Order§8:§7 " + order, clickType -> { + new SimulatorAnvilGui<>(player, "Calculation Order", order + "", Integer::parseInt, integer -> { + if (integer < -SimulatorPhase.ORDER_LIMIT) return false; + if (integer > SimulatorPhase.ORDER_LIMIT) return false; + tnt.setOrder(integer); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open(); }); orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); inventory.setItem(22, orderItem); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index d880ca5e..20f695e4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; @@ -78,6 +79,12 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // TODO: Anvil G SimulatorWatcher.update(simulator); }); SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { + new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + tnt.changeBaseTicks(integer - baseTicks); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.REPEATER).open(); }); baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); inventory.setItem(18, baseTick); @@ -124,6 +131,11 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // TODO: Anvil G SimulatorWatcher.update(simulator); }); inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + tnt.getPosition().getX(), clickType -> { + new SimulatorAnvilGui<>(player, "X", tnt.getPosition().getX() + "", Double::parseDouble, d -> { + tnt.getPosition().setX(d); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); })); inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0); @@ -136,6 +148,11 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // TODO: Anvil G SimulatorWatcher.update(simulator); }); inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + tnt.getPosition().getY(), clickType -> { + new SimulatorAnvilGui<>(player, "Y", tnt.getPosition().getY() + "", Double::parseDouble, d -> { + tnt.getPosition().setY(d); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); })); inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0); @@ -148,6 +165,11 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // TODO: Anvil G SimulatorWatcher.update(simulator); }); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + tnt.getPosition().getZ(), clickType -> { + new SimulatorAnvilGui<>(player, "Z", tnt.getPosition().getZ() + "", Double::parseDouble, d -> { + tnt.getPosition().setZ(d); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); })); inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java new file mode 100644 index 00000000..e492a304 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java @@ -0,0 +1,73 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.base; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.inventory.SWAnvilInv; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Objects; +import java.util.function.Consumer; +import java.util.function.Function; + +public class SimulatorAnvilGui { + + private SWAnvilInv anvilInv; + + public SimulatorAnvilGui(Player player, String title, String defaultText, Function mapper, Function value, SimulatorBaseGui back) { + if (defaultText == null) { + anvilInv = new SWAnvilInv(player, title); + } else { + anvilInv = new SWAnvilInv(player, title, defaultText); + } + anvilInv.addCloseCallback(() -> { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + back.open(); + }, 0); + }); + anvilInv.setCallback(s -> { + T t; + try { + t = mapper.apply(s); + } catch (NumberFormatException e) { + new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open(); + return; + } + try { + if (!value.apply(t)) { + new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open(); + } + } finally { + back.open(); + } + }); + } + + public SimulatorAnvilGui setItem(Material material) { + anvilInv.setItem(material); + return this; + } + + public void open() { + anvilInv.open(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 1bd04377..1a310d35 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -86,6 +86,10 @@ public class Recorder implements Listener { return get(tntTraceRecorderMap.computeIfAbsent(tntPrimed, e -> Region.getRegion(e.getLocation()))); } + public boolean isDisabled(Region region) { + return !regionTraceRecorderMap.containsKey(region); + } + public TraceRecorder get(Region region) { return regionTraceRecorderMap.getOrDefault(region, DISABLED); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SingleTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SingleTraceRecorder.java index 6eae0b06..046f0368 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SingleTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SingleTraceRecorder.java @@ -36,7 +36,7 @@ public class SingleTraceRecorder extends AutoTraceRecorder { @Override protected boolean shouldStartRecording(StartType startType) { - return startType == StartType.EXPLODE; + return startType == StartType.IGNITE; } @Override From 08839343c36e80ff155b0efddf400a6333d21d40 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 17:43:59 +0200 Subject: [PATCH 044/139] Fix SimulatorSettingsGui click on XYZ --- .../features/simulator/gui/SimulatorSettingsGui.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java index 45b2e22a..ccb00412 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSettingsGui.java @@ -65,7 +65,8 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { + })); inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0); SimulatorWatcher.update(simulator); @@ -76,7 +77,8 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { + })); inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0); SimulatorWatcher.update(simulator); @@ -87,7 +89,8 @@ public class SimulatorSettingsGui extends SimulatorBaseGui { simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1); SimulatorWatcher.update(simulator); }); - inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { + })); inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1); SimulatorWatcher.update(simulator); From 98455a29cefd785b79ff08053c74c86271a3623f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 17:48:02 +0200 Subject: [PATCH 045/139] Fix source/target compatibility --- BauSystem_19/build.gradle | 4 ++-- BauSystem_20/build.gradle | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BauSystem_19/build.gradle b/BauSystem_19/build.gradle index b1c37d01..7973f1b0 100644 --- a/BauSystem_19/build.gradle +++ b/BauSystem_19/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = 17 +targetCompatibility = 17 sourceSets { main { diff --git a/BauSystem_20/build.gradle b/BauSystem_20/build.gradle index be167e64..17121b8d 100644 --- a/BauSystem_20/build.gradle +++ b/BauSystem_20/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = 17 +targetCompatibility = 17 sourceSets { main { From 5686b6bc4030711f87946bfbba51fcf6a35cebb2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 17:50:33 +0200 Subject: [PATCH 046/139] Fix source/target compatibility --- BauSystem_19/build.gradle | 2 +- BauSystem_20/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_19/build.gradle b/BauSystem_19/build.gradle index 7973f1b0..900fce9d 100644 --- a/BauSystem_19/build.gradle +++ b/BauSystem_19/build.gradle @@ -28,7 +28,7 @@ version '1.0' compileJava.options.encoding = 'UTF-8' sourceCompatibility = 17 -targetCompatibility = 17 +targetCompatibility = 11 sourceSets { main { diff --git a/BauSystem_20/build.gradle b/BauSystem_20/build.gradle index 17121b8d..b2620127 100644 --- a/BauSystem_20/build.gradle +++ b/BauSystem_20/build.gradle @@ -28,7 +28,7 @@ version '1.0' compileJava.options.encoding = 'UTF-8' sourceCompatibility = 17 -targetCompatibility = 17 +targetCompatibility = 11 sourceSets { main { From 8fb4a4669ad12f0ec2b9a47f132fae1438597cf9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 17:55:13 +0200 Subject: [PATCH 047/139] Fix source/target compatibility --- BauSystem_15/build.gradle | 4 ++-- BauSystem_18/build.gradle | 4 ++-- BauSystem_19/build.gradle | 2 +- BauSystem_20/build.gradle | 2 +- BauSystem_Linkage/build.gradle | 4 ++-- BauSystem_Main/build.gradle | 4 ++-- build.gradle | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/BauSystem_15/build.gradle b/BauSystem_15/build.gradle index 180c7022..d0acd9b2 100644 --- a/BauSystem_15/build.gradle +++ b/BauSystem_15/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = 17 +targetCompatibility = 17 sourceSets { main { diff --git a/BauSystem_18/build.gradle b/BauSystem_18/build.gradle index 8fb54099..4ac724e0 100644 --- a/BauSystem_18/build.gradle +++ b/BauSystem_18/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = 17 +targetCompatibility = 17 sourceSets { main { diff --git a/BauSystem_19/build.gradle b/BauSystem_19/build.gradle index 900fce9d..7973f1b0 100644 --- a/BauSystem_19/build.gradle +++ b/BauSystem_19/build.gradle @@ -28,7 +28,7 @@ version '1.0' compileJava.options.encoding = 'UTF-8' sourceCompatibility = 17 -targetCompatibility = 11 +targetCompatibility = 17 sourceSets { main { diff --git a/BauSystem_20/build.gradle b/BauSystem_20/build.gradle index b2620127..17121b8d 100644 --- a/BauSystem_20/build.gradle +++ b/BauSystem_20/build.gradle @@ -28,7 +28,7 @@ version '1.0' compileJava.options.encoding = 'UTF-8' sourceCompatibility = 17 -targetCompatibility = 11 +targetCompatibility = 17 sourceSets { main { diff --git a/BauSystem_Linkage/build.gradle b/BauSystem_Linkage/build.gradle index de3818a5..7b54641a 100644 --- a/BauSystem_Linkage/build.gradle +++ b/BauSystem_Linkage/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = 17 +targetCompatibility = 17 sourceSets { main { diff --git a/BauSystem_Main/build.gradle b/BauSystem_Main/build.gradle index bf61d861..38432993 100644 --- a/BauSystem_Main/build.gradle +++ b/BauSystem_Main/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = 17 +targetCompatibility = 17 sourceSets { main { diff --git a/build.gradle b/build.gradle index 5ce3ebaf..5b8a3f12 100644 --- a/build.gradle +++ b/build.gradle @@ -37,8 +37,8 @@ version '' compileJava.options.encoding = 'UTF-8' compileJava.options.compilerArgs << '-parameter' -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = 17 +targetCompatibility = 17 mainClassName = '' From 11fdd08f799f6565e9935a51c4778fb2143e22a1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 27 Oct 2023 21:08:02 +0200 Subject: [PATCH 048/139] Fix some stuff and layout --- .../features/simulator/SimulatorCursor.java | 3 +-- .../features/simulator/SimulatorWatcher.java | 8 ++++++-- .../gui/SimulatorRedstonePhaseSettingsGui.java | 12 ++++++------ .../simulator/gui/SimulatorTNTPhaseSettingsGui.java | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index ff545a86..2f4b0f8b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -141,8 +141,7 @@ public class SimulatorCursor implements Listener { public synchronized void calcCursor(Player player) { if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { - if (removeCursor(player)) { - SimulatorWatcher.show(null, player); + if (removeCursor(player) || SimulatorWatcher.show(null, player)) { SWUtils.sendToActionbar(player, ""); } return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java index 4ea413d8..d5f98986 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorWatcher.java @@ -41,6 +41,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.util.Vector; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @UtilityClass @@ -104,15 +105,18 @@ public class SimulatorWatcher { return server; } - public synchronized void show(Simulator sim, Player player) { + public synchronized boolean show(Simulator sim, Player player) { + AtomicBoolean removed = new AtomicBoolean(); entityServers.forEach((simulator, rEntityServer) -> { if (rEntityServer == null) return; if (rEntityServer.getPlayers().contains(player) && sim != simulator) { rEntityServer.removePlayer(player); + removed.set(true); } }); - if (sim == null) return; + if (sim == null) return removed.get(); entityServers.computeIfAbsent(sim, __ -> createSim(new REntityServer(), sim)).addPlayer(player); + return removed.get(); } synchronized List getEntitiesOfSimulator(Simulator simulator) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index 07f55a73..70a1bf9c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -76,7 +76,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { //Tick Offset int offset = redstone.getTickOffset(); - inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(10, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); @@ -90,16 +90,16 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { }, this).setItem(Material.REPEATER).open(); }); offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); - inventory.setItem(20, offsetItem); + inventory.setItem(19, offsetItem); - inventory.setItem(29, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(28, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); //Lifetime int lifetime = redstone.getLifetime(); - inventory.setItem(12, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { redstone.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); @@ -113,9 +113,9 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { }, this).setItem(Material.CLOCK).open(); }); lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); - inventory.setItem(21, lifetimeItem); + inventory.setItem(20, lifetimeItem); - inventory.setItem(30, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + inventory.setItem(29, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { redstone.setLifetime(Math.max(0, lifetime - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index 6541c112..01ec8b04 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -116,7 +116,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { inventory.setItem(19, offsetItem); inventory.setItem(28, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - tnt.setTickOffset(Math.max(1, offset - (clickType.isShiftClick() ? 5 : 1))); + tnt.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); @@ -129,7 +129,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> { new SimulatorAnvilGui<>(player, "Lifetime", lifetime + "", Integer::parseInt, integer -> { - if (integer < 0) return false; + if (integer < 1) return false; tnt.setLifetime(integer); SimulatorWatcher.update(simulator); return true; From 06a68a70040237c11bd352add18a8af0466abd2a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 28 Oct 2023 09:56:24 +0200 Subject: [PATCH 049/139] Fix lore of sim item --- BauSystem_Main/src/BauSystem.properties | 2 +- BauSystem_Main/src/BauSystem_de.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index ff127af6..27ca6f67 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -329,7 +329,7 @@ SIMULATOR_WAND_LORE_1 = §eRight click §8- §7Adds a position SIMULATOR_WAND_LORE_2 = §eSneaking §8- §7Free movement SIMULATOR_WAND_LORE_3 = §eLeft click §8- §7Start the simulation SIMULATOR_WAND_LORE_4 = §eRight click in air §8- §7Opens the gui -SIMULATOR_WAND_LORE_5 = §eOffhand §8- §7Simulator preview +SIMULATOR_WAND_LORE_5 = §eDouble Sneak §8- §7Swap between TNT and Redstone Block SIMULATOR_REGION_FROZEN = §cSimulator cannot be used inside frozen regions diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index de6de310..439267cf 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -321,7 +321,7 @@ SIMULATOR_WAND_LORE_1 = §eRechtsklick §8- §7Füge eine Position hinzu SIMULATOR_WAND_LORE_2 = §eSneaken §8- §7Freie Bewegung SIMULATOR_WAND_LORE_3 = §eLinksklick §8- §7Starte die Simulation SIMULATOR_WAND_LORE_4 = §eRechtsklick Luft §8- §7Öffne die GUI -SIMULATOR_WAND_LORE_5 = §eOffhand §8- §7Simulator Vorschau +SIMULATOR_WAND_LORE_5 = §eDoppel Shift §8- §7Wechsel zwischen TNT und Redstone Block SIMULATOR_REGION_FROZEN = §cSimulator kann nicht in eingefrorenen Regionen genutzt werden From fdc201e99d657d8a3715df350156ef4e33e05d3f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 28 Oct 2023 23:14:35 +0200 Subject: [PATCH 050/139] Add only similar elements inside of groups Add delete to group gui and redstone and tnt Rework SimulatorRedstoneGui Add 'Make Group' option to SimulatorTNTGui Fix Player Join server crash Add 'Create Sim' to Select Simulator Gui --- .../features/simulator/SimulatorCursor.java | 4 +- .../features/simulator/SimulatorStorage.java | 23 ++++ .../simulator/data/SimulatorElement.java | 4 +- .../simulator/data/SimulatorGroup.java | 3 +- .../data/redstone/RedstoneElement.java | 5 + .../simulator/data/tnt/TNTElement.java | 5 + .../gui/SimulatorGroupChooserGui.java | 2 +- .../simulator/gui/SimulatorGroupGui.java | 5 + .../gui/SimulatorGroupSettingsGui.java | 83 +++++++++--- .../simulator/gui/SimulatorRedstoneGui.java | 122 +++++++++++++++--- .../simulator/gui/SimulatorTNTGui.java | 32 +++-- .../simulator/gui/base/SimulatorAnvilGui.java | 21 +-- .../gui/base/SimulatorScrollGui.java | 4 +- 13 files changed, 254 insertions(+), 59 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 2f4b0f8b..6ff78e19 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -94,7 +94,9 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - calcCursor(event.getPlayer()); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + calcCursor(event.getPlayer()); + }, 0); } @EventHandler 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 9ad4701d..9ac84989 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.features.simulator.storage.SimulatorFormatSimulator import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver; import de.steamwar.bausystem.features.simulator.storage.YAPIONFormatSimulatorLoader; import de.steamwar.bausystem.utils.ItemUtils; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; @@ -133,6 +134,28 @@ public class SimulatorStorage implements Enable { return "Simulators"; } + @Override + public void headerAndFooter() { + inventory.setItem(49, new SWItem(Material.NAME_TAG, "§eCreate", clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Name"); + anvilInv.setCallback(s -> { + Simulator sim = SimulatorStorage.getSimulator(s); + if (sim != null) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", player); + return; + } + if (!s.matches("[a-zA-Z_0-9-]+")) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", player); + return; + } + sim = new Simulator(s); + SimulatorStorage.addSimulator(s, sim); + SimulatorStorage.setSimulator(player, sim); + }); + anvilInv.open(); + })); + } + @Override public SWItem convert(Simulator simulator) { return simulator.toItem(player, clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java index df5b13a4..119143db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorElement.java @@ -73,7 +73,7 @@ public abstract class SimulatorElement { }); } - public void move(int x, int y, int z) { + public void move(double x, double y, double z) { position.setX(position.getX() + x); position.setY(position.getY() + y); position.setZ(position.getZ() + z); @@ -83,6 +83,8 @@ public abstract class SimulatorElement { public abstract Material getWorldDisabledMaterial(); + public abstract boolean canBeInGroup(SimulatorGroup simulatorGroup); + public Vector getWorldPos() { return position; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java index 0e90903c..8031dd1c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorGroup.java @@ -30,7 +30,6 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.Map; import java.util.function.BiConsumer; @Getter @@ -64,7 +63,7 @@ public final class SimulatorGroup { }); } - public void move(int x, int y, int z) { + public void move(double x, double y, double z) { elements.forEach(simulatorElement -> { simulatorElement.move(x, y, z); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java index ac130e03..2eb7aca2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java @@ -49,6 +49,11 @@ public final class RedstoneElement extends SimulatorElement { return Material.WHITE_STAINED_GLASS; } + @Override + public boolean canBeInGroup(SimulatorGroup simulatorGroup) { + return simulatorGroup.getElements().stream().allMatch(RedstoneElement.class::isInstance); + } + @Override public Vector getWorldPos() { return position.clone().add(new Vector(0.5, 0, 0.5)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java index 36b10130..29e90d83 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java @@ -88,6 +88,11 @@ public final class TNTElement extends SimulatorElement { return Material.RED_STAINED_GLASS; } + @Override + public boolean canBeInGroup(SimulatorGroup simulatorGroup) { + return simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance); + } + @Override public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) { new SimulatorTNTGui(player, simulator, this, group, back).open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java index 9778c6c6..fabbfac3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java @@ -39,7 +39,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { private final SimulatorBaseGui back; public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement subject, SimulatorGroup parent, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).collect(Collectors.toList())); + super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).filter(e -> subject.canBeInGroup(e)).collect(Collectors.toList())); this.subject = subject; this.parent = parent; this.back = back; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java index 06df5e5e..c3b8ee1a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupGui.java @@ -72,6 +72,11 @@ public class SimulatorGroupGui extends SimulatorPageGui> { back.open(); })); + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + simulatorGroup.getElements().clear(); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { if (simulatorGroup.getMaterial() == null) return; new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index 4c1e8d74..873011f9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -22,11 +22,13 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import java.util.Arrays; @@ -62,7 +64,8 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { if (simulatorGroup.getMaterial() == null) return; new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); - }, clickType -> {})); + }, clickType -> { + })); // Base Tick int baseTicks = simulatorGroup.getBaseTick(); @@ -89,36 +92,84 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); + boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance); + + if (allTNT) { + // Subpixel Alignment + inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0.5, 0, 0.5)); + }); + SimulatorWatcher.update(simulator); + })); + + // Z + inventory.setItem(20, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0, 0, 0.49)); + }); + SimulatorWatcher.update(simulator); + })); + + inventory.setItem(22, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0, 0, 0.51)); + }); + SimulatorWatcher.update(simulator); + })); + + // X + inventory.setItem(12, new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0.49, 0, 0)); + }); + SimulatorWatcher.update(simulator); + })); + + inventory.setItem(30, new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { + simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { + tnt.align(new Vector(0.51, 0, 0)); + }); + SimulatorWatcher.update(simulator); + })); + } + //Pos X - inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - simulatorGroup.move(clickType.isShiftClick() ? 5 : 1, 0, 0); + inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(24, new SWItem(Material.PAPER, "§eX")); - inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - simulatorGroup.move(clickType.isShiftClick() ? -5 : -1, 0, 0); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { + // TODO: Change X Anvil GUI + })); + inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0); SimulatorWatcher.update(simulator); }); //Pos Y - inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - simulatorGroup.move(0, clickType.isShiftClick() ? 5 : 1, 0); + inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0); SimulatorWatcher.update(simulator); }); - inventory.setItem(25, new SWItem(Material.PAPER, "§eY")); - inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - simulatorGroup.move(0, clickType.isShiftClick() ? -5 : -1, 0); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { + // TODO: Change Y Anvil GUI + })); + inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0); SimulatorWatcher.update(simulator); }); //Pos Z - inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - simulatorGroup.move(0, 0, clickType.isShiftClick() ? 5 : 1); + inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { + simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1); SimulatorWatcher.update(simulator); }); - inventory.setItem(26, new SWItem(Material.PAPER, "§eZ")); - inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - simulatorGroup.move(0, 0, clickType.isShiftClick() ? -5 : -1); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { + // TODO: Change Z Anvil GUI + })); + inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { + simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1); SimulatorWatcher.update(simulator); }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index d934df37..81cc7f4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -27,20 +27,25 @@ import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; import de.steamwar.inventory.SWItem; +import lombok.AllArgsConstructor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; -public class SimulatorRedstoneGui extends SimulatorScrollGui { +public class SimulatorRedstoneGui extends SimulatorScrollGui { private final SimulatorGroup parent; private final RedstoneElement redstone; private final SimulatorBaseGui back; public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup parent, RedstoneElement redstone, SimulatorBaseGui back) { - super(player, simulator, 6 * 9, redstone.getPhases()); + super(player, simulator, 6 * 9, new ArrayList<>()); this.parent = parent; this.redstone = redstone; this.back = back; @@ -59,7 +64,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { return; } - redstone.sort(); + data.clear(); + redstone.getPhases().forEach(redstonePhase -> { + data.add(new RedstoneSubPhase(true, redstonePhase)); + data.add(new RedstoneSubPhase(false, redstonePhase)); + }); + data.sort(null); // Back Arrow inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { @@ -80,6 +90,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { } })); + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + redstone.getPhases().clear(); + SimulatorWatcher.update(simulator); + })); + // Material Chooser inventory.setItem(4, redstone.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open(); @@ -91,11 +106,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { })); // Group chooser - inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { + inventory.setItem(49, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open(); })); - //Enable/Disable + // Enable/Disable inventory.setItem(50, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { redstone.setDisabled(!redstone.isDisabled()); SimulatorWatcher.update(simulator); @@ -103,25 +118,63 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { } @Override - public SWItem[] column(RedstonePhase redstoneSetting) { - SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Activation Time§8:§e " + redstoneSetting.getLifetime(), "", "§7Middle-Click§8:§e Remove"), false, clickType -> { - if (clickType == ClickType.MIDDLE) this.redstone.getPhases().remove(redstoneSetting); - SimulatorWatcher.update(simulator); - }); - redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64))); + public SWItem[] column(RedstoneSubPhase redstoneSubPhase, int index) { + // TODO: Add to the phase edit menus and split those to better reflect the scroll gui state + int min; + if (index % 2 == 0 && index > 0) { + RedstoneSubPhase subPhase = data.get(index - 1); + min = subPhase.phase.getTickOffset() + subPhase.phase.getLifetime() + 1; + } else { + min = 0; + } - return new SWItem[]{ - new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { - redstoneSetting.setTickOffset(redstoneSetting.getTickOffset() + (clickType.isShiftClick() ? 5 : 1)); + int max; + if (index % 2 == 0 && index < data.size() - 2) { + RedstoneSubPhase subPhase = data.get(index + 2); + max = subPhase.phase.getTickOffset() - redstoneSubPhase.phase.getLifetime() - 1; + } else if (index % 2 != 0 && index < data.size() - 1) { + RedstoneSubPhase subPhase = data.get(index + 1); + max = subPhase.phase.getTickOffset() - redstoneSubPhase.phase.getTickOffset() - 1; + } else { + max = Integer.MAX_VALUE - 5; + } + + List lore = new ArrayList<>(); + int time = redstoneSubPhase.phase.getTickOffset() + (redstoneSubPhase.place ? 0 : redstoneSubPhase.phase.getLifetime()); + if (redstoneSubPhase.place) { + lore.add("§7Time§8:§e " + time); + lore.add("§7Order§8:§e " + redstoneSubPhase.phase.getOrder()); + } else { + lore.add("§7Time§8:§e " + time); + lore.add("§7Activation Time§8:§e " + redstoneSubPhase.phase.getLifetime()); + } + lore.add(""); + lore.add("§7Click§8:§e Edit"); + lore.add("§7Middle-Click§8:§e Remove"); + SWItem redstone = new SWItem(redstoneSubPhase.place ? Material.REDSTONE_BLOCK : Material.STONE, redstoneSubPhase.place ? "§eActivate" : "§eDeactivate", lore, false, clickType -> { + if (clickType == ClickType.MIDDLE) { + this.redstone.getPhases().remove(redstoneSubPhase.phase); + SimulatorWatcher.update(simulator); + } else { + new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); + } + }); + redstone.getItemStack().setAmount(Math.max(1, Math.min(time, 64))); + + Supplier getter = redstoneSubPhase.place ? redstoneSubPhase.phase::getTickOffset : redstoneSubPhase.phase::getLifetime; + Consumer setter = redstoneSubPhase.place ? redstoneSubPhase.phase::setTickOffset : redstoneSubPhase.phase::setLifetime; + return new SWItem[] { + new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }), redstone, - new SWItem(SWItem.getDye(redstoneSetting.getTickOffset() > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { - redstoneSetting.setTickOffset(Math.max(0, redstoneSetting.getTickOffset() - (clickType.isShiftClick() ? 5 : 1))); + new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { + setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { - new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSetting, this).open(); + new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); }), }; } @@ -132,7 +185,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); }), - new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§a New Phase", clickType -> { + new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> { addNewPhase(false); }), new SWItem(SWItem.getDye(8), "§7", clickType -> { @@ -142,10 +195,39 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { private void addNewPhase(boolean shift) { RedstonePhase lastElement = redstone.getPhases().get(redstone.getPhases().size() - 1); - RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + 1); + RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + lastElement.getLifetime() + 1); if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5); - scroll++; + scroll += 2; redstone.add(newPhase); SimulatorWatcher.update(simulator); } + + @AllArgsConstructor + public static class RedstoneSubPhase implements Comparable { + private boolean place; + private RedstonePhase phase; + + @Override + public int compareTo(RedstoneSubPhase o) { + int thisTick = phase.getTickOffset() + (place ? 0 : phase.getLifetime()); + int otherTick = o.phase.getTickOffset() + (o.place ? 0 : o.phase.getLifetime()); + + int compare = Integer.compare(thisTick, otherTick); + if (compare != 0) { + return compare; + } + + if (place && !o.place) { + return -1; + } + if (!place && o.place) { + return 1; + } + if (!place) { + return 0; + } + + return Integer.compare(phase.getOrder(), o.phase.getOrder()); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index 7b9fc71a..a6d6c944 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -80,28 +80,44 @@ public class SimulatorTNTGui extends SimulatorScrollGui { } })); + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + tnt.getPhases().clear(); + SimulatorWatcher.update(simulator); + })); + // Material Chooser inventory.setItem(4, tnt.toItem(player, clickType -> { new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open(); })); - inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); - inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> { + inventory.setItem(48, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); })); - inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + inventory.setItem(50, new SWItem(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> { + TNTElement tntElement = new TNTElement(tnt.getPosition().clone()); + tntElement.add(new TNTPhase()); + parent.add(tntElement); + new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open(); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(51, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { tnt.setDisabled(!tnt.isDisabled()); SimulatorWatcher.update(simulator); })); } @Override - public SWItem[] column(TNTPhase tntSetting) { - SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "", "§7Middle-Click§8:§e Remove"), false, clickType -> { - if (clickType == ClickType.MIDDLE) this.tnt.getPhases().remove(tntSetting); - SimulatorWatcher.update(simulator); + public SWItem[] column(TNTPhase tntSetting, int index) { + SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "", "§7Click§8:§e Edit", "§7Middle-Click§8:§e Remove"), false, clickType -> { + if (clickType == ClickType.MIDDLE) { + this.tnt.getPhases().remove(tntSetting); + SimulatorWatcher.update(simulator); + } else { + new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open(); + } }); tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64)); @@ -127,7 +143,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick()); }), - new SWItem(Material.TNT, "§eTNT§8:§a New Phase", clickType -> { + new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> { addNewPhase(false); }), new SWItem(SWItem.getDye(8), "§7", clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java index e492a304..380dc618 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorAnvilGui.java @@ -25,8 +25,7 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.Objects; -import java.util.function.Consumer; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; public class SimulatorAnvilGui { @@ -37,11 +36,17 @@ public class SimulatorAnvilGui { if (defaultText == null) { anvilInv = new SWAnvilInv(player, title); } else { - anvilInv = new SWAnvilInv(player, title, defaultText); + anvilInv = new SWAnvilInv(player, title + ": " + defaultText); } + AtomicBoolean error = new AtomicBoolean(); anvilInv.addCloseCallback(() -> { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - back.open(); + if (error.get()) { + anvilInv.open(); + } else { + back.open(); + } + error.set(false); }, 0); }); anvilInv.setCallback(s -> { @@ -49,15 +54,15 @@ public class SimulatorAnvilGui { try { t = mapper.apply(s); } catch (NumberFormatException e) { - new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open(); + error.set(true); return; } try { if (!value.apply(t)) { - new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open(); + error.set(true); } - } finally { - back.open(); + } catch (Exception e) { + // Ignore } }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java index 1c6d30e5..a4cfbb5d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorScrollGui.java @@ -67,7 +67,7 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { for (int i = 0; i < 9; i++) { if (scroll + i < data.size()) { T element = data.get(scroll + i); - SWItem[] column = column(element); + SWItem[] column = column(element, scroll + i); populateColumn(column, i); } else { SWItem[] column = lastColumn(); @@ -88,7 +88,7 @@ public abstract class SimulatorScrollGui extends SimulatorBaseGui { } } - public abstract SWItem[] column(T t); + public abstract SWItem[] column(T t, int index); public abstract SWItem[] lastColumn(); } From bdeb7da4c64f7710914cec53abaeece6a666df42 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Nov 2023 18:14:16 +0100 Subject: [PATCH 051/139] Add a few RegionLib getters Add storage saving and loading --- .../script/lua/SteamWarLuaPlugin.java | 2 +- .../features/script/lua/libs/LuaLib.java | 9 + .../features/script/lua/libs/PlayerLib.java | 5 +- .../features/script/lua/libs/RegionLib.java | 11 ++ .../features/script/lua/libs/StorageLib.java | 173 +++++++++++++++++- sw.def.lua | 31 ++++ 6 files changed, 224 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index 1e8ec13a..f6b0da69 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -192,7 +192,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction { class Print extends VarArgFunction { @Override public Varargs invoke(Varargs args) { - player.sendMessage(varArgsToString(args)); + player.sendMessage(varArgsToString(args).replaceAll("&([a-z0-9klmnor])", "§\1")); return LuaValue.NIL; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java index b88ee9d0..03ceb3ba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.script.lua.libs; +import de.steamwar.bausystem.region.Point; import lombok.AllArgsConstructor; import org.bukkit.entity.Player; import org.luaj.vm2.*; @@ -69,6 +70,14 @@ public interface LuaLib { return de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin.varArgsToString(varargs); } + default LuaTable toPos(Point point) { + return LuaValue.tableOf(new LuaValue[] { + LuaValue.valueOf("x"), LuaValue.valueOf(point.getX()), + LuaValue.valueOf("y"), LuaValue.valueOf(point.getY()), + LuaValue.valueOf("z"), LuaValue.valueOf(point.getZ()) + }); + } + default Class parent() { return null; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java index 6ce317b3..9a6441da 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.linkage.Linked; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.Player; import org.luaj.vm2.LuaTable; @@ -93,7 +94,7 @@ public class PlayerLib implements LuaLib { @Override public Varargs invoke(Varargs args) { - player.sendMessage(varArgsToString(args)); + player.sendMessage(varArgsToString(args).replaceAll("&([a-z0-9klmnor])", "§\1")); return LuaValue.NIL; } } @@ -107,7 +108,7 @@ public class PlayerLib implements LuaLib { @Override public Varargs invoke(Varargs args) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(varArgsToString(args))); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(varArgsToString(args).replaceAll("&([a-z0-9klmnor])", "§\1"))); return LuaValue.NIL; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java index f6c35f9f..07554a68 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java @@ -81,6 +81,17 @@ public class RegionLib implements LuaLib { Loader loader = Loader.getLoader(player); table.set("loader", getter(() -> loader == null ? "OFF" : loader.getStage().name())); + + table.set("copyPoint", getter(() -> toPos(region.get().getCopyPoint()))); + table.set("minPointBuild", getter(() -> toPos(region.get().getMinPointBuild()))); + table.set("maxPointBuild", getter(() -> toPos(region.get().getMaxPointBuild()))); + table.set("minPointBuildExtension", getter(() -> toPos(region.get().getMinPointBuildExtension()))); + table.set("maxPointBuildExtension", getter(() -> toPos(region.get().getMaxPointBuildExtension()))); + table.set("testblockPoint", getter(() -> toPos(region.get().getTestBlockPoint()))); + table.set("minPointTestblock", getter(() -> toPos(region.get().getMinPointTestblock()))); + table.set("maxPointTestblock", getter(() -> toPos(region.get().getMaxPointTestblock()))); + table.set("minPointTestblockExtension", getter(() -> toPos(region.get().getMinPointTestblockExtension()))); + table.set("maxPointTestblockExtension", getter(() -> toPos(region.get().getMaxPointTestblockExtension()))); return table; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java index 033c5f98..8967951d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java @@ -19,8 +19,13 @@ package de.steamwar.bausystem.features.script.lua.libs; +import com.google.gson.*; import de.steamwar.bausystem.region.Region; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.api.Disable; +import de.steamwar.linkage.api.Enable; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; @@ -29,15 +34,171 @@ import org.luaj.vm2.lib.OneArgFunction; import org.luaj.vm2.lib.TwoArgFunction; import org.luaj.vm2.lib.VarArgFunction; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @Linked -public class StorageLib implements LuaLib { +public class StorageLib implements LuaLib, Enable, Disable { + + private final Gson gson = new Gson(); + private final File storageDirectory = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "script_storage"); private static final HashMap GLOBAL_STORAGE = new HashMap<>(); - private static final HashMap> PLAYER_STORAGE = new HashMap<>(); + private static final HashMap> PLAYER_STORAGE = new HashMap<>(); private static final HashMap> REGION_STORAGE = new HashMap<>(); + @Override + public void enable() { + if (!storageDirectory.exists()) storageDirectory.mkdirs(); + + try { + JsonObject jsonObject = JsonParser.parseReader(new FileReader(new File(storageDirectory, "global.json"))).getAsJsonObject(); + jsonObject.keySet().forEach(key -> { + GLOBAL_STORAGE.put(key, fromJson(jsonObject.get(key))); + }); + } catch (Exception e) {} + + File regionStorageDirectory = new File(storageDirectory, "region"); + regionStorageDirectory.mkdirs(); + for (File regionStorage : regionStorageDirectory.listFiles()) { + try { + JsonObject jsonObject = JsonParser.parseReader(new FileReader(regionStorage)).getAsJsonObject(); + HashMap map = new HashMap<>(); + jsonObject.keySet().forEach(key -> { + map.put(key, fromJson(jsonObject.get(key))); + }); + Region region = Region.getREGION_MAP().get(regionStorage.getName().substring(0, regionStorage.getName().length() - ".json".length())); + REGION_STORAGE.put(region, map); + } catch (Exception e) {} + } + + File playerStorageDirectory = new File(storageDirectory, "player"); + playerStorageDirectory.mkdirs(); + for (File playerStorage : playerStorageDirectory.listFiles()) { + try { + JsonObject jsonObject = JsonParser.parseReader(new FileReader(playerStorage)).getAsJsonObject(); + HashMap map = new HashMap<>(); + jsonObject.keySet().forEach(key -> { + map.put(key, fromJson(jsonObject.get(key))); + }); + SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(playerStorage.getName().substring(0, playerStorage.getName().length() - ".json".length()))); + PLAYER_STORAGE.put(steamwarUser.getUUID(), map); + } catch (Exception e) {} + } + } + + private LuaValue fromJson(JsonElement jsonElement) { + if (jsonElement.isJsonNull()) { + return LuaValue.NIL; + } + if (jsonElement.isJsonPrimitive()) { + JsonPrimitive jsonPrimitive = jsonElement.getAsJsonPrimitive(); + if (jsonPrimitive.isBoolean()) { + return LuaValue.valueOf(jsonPrimitive.getAsBoolean()); + } + if (jsonPrimitive.isNumber()) { + try { + return LuaValue.valueOf(jsonPrimitive.getAsInt()); + } catch (NumberFormatException e) {} + try { + return LuaValue.valueOf(jsonPrimitive.getAsDouble()); + } catch (NumberFormatException e) {} + } + if (jsonPrimitive.isString()) { + return LuaValue.valueOf(jsonPrimitive.getAsString()); + } + return null; + } + if (jsonElement.isJsonObject()) { + JsonObject jsonObject = jsonElement.getAsJsonObject(); + LuaTable luaTable = new LuaTable(); + jsonObject.keySet().forEach(string -> { + LuaValue value = fromJson(jsonObject.get(string)); + if (value == null) return; + luaTable.set(string, value); + }); + return luaTable; + } + return null; + } + + @Override + public void disable() { + if (!storageDirectory.exists()) storageDirectory.mkdirs(); + try { + FileWriter fileWriter = new FileWriter(new File(storageDirectory, "global.json")); + gson.toJson(toJson(GLOBAL_STORAGE), fileWriter); + fileWriter.close(); + } catch (IOException e) {} + + File regionStorageDirectory = new File(storageDirectory, "region"); + regionStorageDirectory.mkdirs(); + for (Map.Entry> entry : REGION_STORAGE.entrySet()) { + try { + FileWriter fileWriter = new FileWriter(new File(regionStorageDirectory, entry.getKey().getName() + ".json")); + gson.toJson(toJson(entry.getValue()), fileWriter); + fileWriter.close(); + } catch (IOException e) {} + } + + File playerStorageDirectory = new File(storageDirectory, "player"); + playerStorageDirectory.mkdirs(); + for (Map.Entry> entry : PLAYER_STORAGE.entrySet()) { + try { + FileWriter fileWriter = new FileWriter(new File(playerStorageDirectory, SteamwarUser.get(entry.getKey()).getId() + ".json")); + gson.toJson(toJson(entry.getValue()), fileWriter); + fileWriter.close(); + } catch (IOException e) {} + } + } + + private JsonObject toJson(HashMap valueMap) { + JsonObject jsonObject = new JsonObject(); + valueMap.forEach((string, luaValue) -> { + JsonElement value = toJson(luaValue); + if (value == null) return; + jsonObject.add(string, value); + }); + return jsonObject; + } + + private JsonElement toJson(LuaValue luaValue) { + if (luaValue.isnil()) { + return JsonNull.INSTANCE; + } + try { + return new JsonPrimitive(luaValue.checkboolean()); + } catch (Exception e) {} + try { + return new JsonPrimitive(luaValue.checkint()); + } catch (Exception e) {} + try { + return new JsonPrimitive(luaValue.checkdouble()); + } catch (Exception e) {} + + if (luaValue.isstring()) { + return new JsonPrimitive(luaValue.tojstring()); + } + if (luaValue.istable()) { + LuaTable luaTable = luaValue.checktable(); + JsonObject jsonObject = new JsonObject(); + for (LuaValue key : luaTable.keys()) { + JsonElement value = toJson(luaTable.get(key)); + if (value == null) continue; + try { + jsonObject.add(key.checkjstring(), value); + } catch (Exception e) {} + } + return jsonObject; + } + return null; + } + @Override public String name() { return "storage"; @@ -92,7 +253,7 @@ public class StorageLib implements LuaLib { storageLib.set("global", global); LuaTable playerStorage = new LuaTable(); - HashMap playerStorageMap = PLAYER_STORAGE.computeIfAbsent(player, k -> new HashMap<>()); + HashMap playerStorageMap = PLAYER_STORAGE.computeIfAbsent(player.getUniqueId(), k -> new HashMap<>()); playerStorage.set("get", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { @@ -137,34 +298,38 @@ public class StorageLib implements LuaLib { storageLib.set("player", playerStorage); LuaTable regionStorage = new LuaTable(); - HashMap regionStorageMap = REGION_STORAGE.computeIfAbsent(Region.getRegion(player.getLocation()), k -> new HashMap<>()); regionStorage.set("get", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { + HashMap regionStorageMap = REGION_STORAGE.computeIfAbsent(Region.getRegion(player.getLocation()), k -> new HashMap<>()); return regionStorageMap.getOrDefault(arg.checkjstring(), NIL); } }); regionStorage.set("set", new TwoArgFunction() { @Override public LuaValue call(LuaValue arg1, LuaValue arg2) { + HashMap regionStorageMap = REGION_STORAGE.computeIfAbsent(Region.getRegion(player.getLocation()), k -> new HashMap<>()); return regionStorageMap.put(arg1.checkjstring(), arg2); } }); regionStorage.set("has", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { + HashMap regionStorageMap = REGION_STORAGE.computeIfAbsent(Region.getRegion(player.getLocation()), k -> new HashMap<>()); return valueOf(regionStorageMap.containsKey(arg.checkjstring())); } }); regionStorage.set("remove", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { + HashMap regionStorageMap = REGION_STORAGE.computeIfAbsent(Region.getRegion(player.getLocation()), k -> new HashMap<>()); return regionStorageMap.remove(arg.checkjstring()); } }); regionStorage.set("accessor", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { + HashMap regionStorageMap = REGION_STORAGE.computeIfAbsent(Region.getRegion(player.getLocation()), k -> new HashMap<>()); String key = arg.checkjstring(); return new VarArgFunction() { @Override diff --git a/sw.def.lua b/sw.def.lua index d56a134e..613437a1 100644 --- a/sw.def.lua +++ b/sw.def.lua @@ -153,6 +153,36 @@ function iregion.protect() return nil end ---@return string function iregion.loader() return nil end +---@return Position +function iregion.copyPoint() return nil end + +---@return Position +function iregion.minPointBuild() return nil end + +---@return Position +function iregion.maxPointBuild() return nil end + +---@return Position +function iregion.minPointBuildExtension() return nil end + +---@return Position +function iregion.maxPointBuildExtension() return nil end + +---@return Position +function iregion.testblockPoint() return nil end + +---@return Position +function iregion.minPointTestblock() return nil end + +---@return Position +function iregion.maxPointTestblock() return nil end + +---@return Position +function iregion.minPointTestblockExtension() return nil end + +---@return Position +function iregion.maxPointTestblockExtension() return nil end + ---@alias TNTMode 'ALLOW' | 'DENY' | 'ONLY_TB' ---@class tnt @@ -247,6 +277,7 @@ function tps.limit() return nil end storage = {} ---@class storageLib +---Any Primitive, Array or Table will be saved across restarts, everything else will be discarded local storageLib = {} ---@param key string From 36e0c4c910c972bd07b87d57907a67a776727e3e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Nov 2023 18:18:55 +0100 Subject: [PATCH 052/139] Fix NPE for Point convertion to Pos --- .../de/steamwar/bausystem/features/script/lua/libs/LuaLib.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java index 03ceb3ba..a4af0d3a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java @@ -71,6 +71,7 @@ public interface LuaLib { } default LuaTable toPos(Point point) { + if (point == null) return LuaTable.tableOf(); return LuaValue.tableOf(new LuaValue[] { LuaValue.valueOf("x"), LuaValue.valueOf(point.getX()), LuaValue.valueOf("y"), LuaValue.valueOf(point.getY()), From 4c7f56be7c570788aef42fba38fc45b2ba858487 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 18 Nov 2023 20:29:41 +0100 Subject: [PATCH 053/139] Fix ColorCodes --- .../bausystem/features/script/lua/SteamWarLuaPlugin.java | 3 ++- .../bausystem/features/script/lua/libs/PlayerLib.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index f6b0da69..b2bf51cc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -31,6 +31,7 @@ import de.steamwar.bausystem.features.world.WorldEditListener; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.inventory.SWAnvilInv; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -192,7 +193,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction { class Print extends VarArgFunction { @Override public Varargs invoke(Varargs args) { - player.sendMessage(varArgsToString(args).replaceAll("&([a-z0-9klmnor])", "§\1")); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', varArgsToString(args))); return LuaValue.NIL; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java index 9a6441da..d4895693 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.linkage.Linked; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Color; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; import org.luaj.vm2.LuaTable; @@ -94,7 +94,7 @@ public class PlayerLib implements LuaLib { @Override public Varargs invoke(Varargs args) { - player.sendMessage(varArgsToString(args).replaceAll("&([a-z0-9klmnor])", "§\1")); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', varArgsToString(args))); return LuaValue.NIL; } } @@ -108,7 +108,7 @@ public class PlayerLib implements LuaLib { @Override public Varargs invoke(Varargs args) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(varArgsToString(args).replaceAll("&([a-z0-9klmnor])", "§\1"))); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', varArgsToString(args)))); return LuaValue.NIL; } } From 1ed10c8c865b7b81cd36b9cd5cd96deae5f7f36d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 2 Dec 2023 12:58:31 +0100 Subject: [PATCH 054/139] Fix SmartPlaceListener click on Comparator --- .../bausystem/features/smartplace/SmartPlaceListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 07748a98..f3ab68bf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -67,6 +67,7 @@ public class SmartPlaceListener implements Plain, Listener { } } CONTAINERS.add(Material.GRINDSTONE); + CONTAINERS.remove(Material.COMPARATOR); state.update(true, false); IGNORED.add(Material.TNT); From 61282c0f846d2c9c3541ae53f979c8f68fa247c2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 3 Dec 2023 15:19:19 +0100 Subject: [PATCH 055/139] Fix MaterialCommand triggering WorldEditListener --- .../steamwar/bausystem/features/util/MaterialCommand.java | 2 ++ .../bausystem/features/world/WorldEditListener.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java index 6f7a92c7..7893b8c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.features.world.WorldEditListener; import de.steamwar.bausystem.shared.EnumDisplay; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; @@ -51,6 +52,7 @@ public class MaterialCommand extends SWCommand implements Listener { public MaterialCommand() { super("material", "baumaterial"); + WorldEditListener.addCommandExclusion("material"); } private Map searchMap = new HashMap<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java index 19dc6e09..ba9d6d9e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java @@ -51,7 +51,12 @@ public class WorldEditListener implements Listener { commands.add(s); } + public static void addCommandExclusion(String s) { + commandExclusions.add(s); + } + private static final Set commands = new HashSet<>(); + private static final Set commandExclusions = new HashSet<>(); private static final String[] shortcutCommands = {"//1", "//2", "//90", "//-90", "//180", "//p", "//c", "//flopy", "//floppy", "//flopyp", "//floppyp", "//u", "//r"}; public static boolean isWorldEditCommand(String command) { @@ -61,6 +66,9 @@ public class WorldEditListener implements Listener { for (String s : commands) { if (command.startsWith(s)) return true; } + for (String s : commandExclusions) { + if (command.startsWith(s)) return false; + } return FlatteningWrapper.impl.isWorldEditCommand(command); } From a0ff726fb4b40a6a86bcedfaefccd2d4c9124c70 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 15 Dec 2023 19:56:59 +0100 Subject: [PATCH 056/139] Add several Anvil Guis Fix some lifetime and offset contraints for RedstonePhases --- .../gui/SimulatorGroupChooserGui.java | 3 ++ .../gui/SimulatorGroupSettingsGui.java | 3 -- .../simulator/gui/SimulatorRedstoneGui.java | 1 - .../SimulatorRedstonePhaseSettingsGui.java | 36 ++++++++++++++----- .../gui/SimulatorTNTSettingsGui.java | 2 +- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java index fabbfac3..10396677 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupChooserGui.java @@ -63,6 +63,9 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui { } })); } + inventory.addCloseCallback(clickType -> { + back.open(); + }); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index 873011f9..e9439ce9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -140,7 +140,6 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { - // TODO: Change X Anvil GUI })); inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0); @@ -153,7 +152,6 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { - // TODO: Change Y Anvil GUI })); inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0); @@ -166,7 +164,6 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); }); inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { - // TODO: Change Z Anvil GUI })); inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index 81cc7f4e..1475cee4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -119,7 +119,6 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui 0) { RedstoneSubPhase subPhase = data.get(index - 1); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java index 70a1bf9c..27901b09 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstonePhaseSettingsGui.java @@ -74,17 +74,37 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { SimulatorWatcher.update(simulator); })); + int index = redstoneElement.getPhases().indexOf(redstone); + int min; + if (index > 0) { + RedstonePhase previous = redstoneElement.getPhases().get(index - 1); + min = previous.getTickOffset() + previous.getLifetime() + 1; + } else { + min = 0; + } + + int maxLifetime; + int maxOffset; + if (index < redstoneElement.getPhases().size() - 1) { + RedstonePhase next = redstoneElement.getPhases().get(index + 1); + maxLifetime = next.getTickOffset() - redstone.getTickOffset() - 1; + maxOffset = next.getTickOffset() - redstone.getLifetime() - 1; + } else { + maxLifetime = Integer.MAX_VALUE - 5; + maxOffset = Integer.MAX_VALUE - 5; + } + //Tick Offset int offset = redstone.getTickOffset(); - inventory.setItem(10, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); + inventory.setItem(10, SWItem.getDye(offset < maxOffset ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.setTickOffset(Math.min(maxOffset, offset + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { if (integer < 0) return false; - redstone.setTickOffset(integer); + redstone.setTickOffset(Math.min(Math.max(integer, min), maxOffset)); SimulatorWatcher.update(simulator); return true; }, this).setItem(Material.REPEATER).open(); @@ -92,22 +112,22 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui { offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(19, offsetItem); - inventory.setItem(28, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - redstone.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1))); + inventory.setItem(28, SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + redstone.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); //Lifetime int lifetime = redstone.getLifetime(); - inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); + inventory.setItem(11, SWItem.getDye(lifetime < maxLifetime ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + redstone.setLifetime(Math.min(maxLifetime, lifetime + (clickType.isShiftClick() ? 5 : 1))); SimulatorWatcher.update(simulator); }); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> { new SimulatorAnvilGui<>(player, "Activation Time", lifetime + "", Integer::parseInt, integer -> { if (integer < 0) return false; - redstone.setLifetime(integer); + redstone.setLifetime(Math.min(integer, maxLifetime)); SimulatorWatcher.update(simulator); return true; }, this).setItem(Material.CLOCK).open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index 20f695e4..1dcf005c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -33,7 +33,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // TODO: Anvil GUI's! +public class SimulatorTNTSettingsGui extends SimulatorBaseGui { private final TNTElement tnt; private final SimulatorBaseGui back; From 52fcb69e1e781bc3e89284889893949ee9853033 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 12:27:33 +0100 Subject: [PATCH 057/139] Optimize imports --- .../features/simulator/data/redstone/RedstonePhase.java | 4 ---- .../bausystem/features/simulator/data/tnt/TNTPhase.java | 3 --- 2 files changed, 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java index e54abf62..f2b99d36 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.features.simulator.data.redstone; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import lombok.NoArgsConstructor; @@ -30,9 +29,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java index 34ae0572..4af3dc15 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java @@ -29,9 +29,6 @@ import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONObject; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; import java.util.function.BiConsumer; @Getter From b73af3e2ec11f8e14a9e138a648860bbb845c1c7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 12:48:52 +0100 Subject: [PATCH 058/139] Hotfix SimulatorStorage --- .../bausystem/features/simulator/SimulatorStorage.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 9ac84989..b3fbcba8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -84,7 +84,9 @@ public class SimulatorStorage implements Enable { SimulatorFormatSimulatorLoader simulatorFormatSimulatorLoader = new SimulatorFormatSimulatorLoader(); YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader(); - for (File file : simulatorsDir.listFiles()) { + File[] files = simulatorsDir.listFiles(); + if (files == null) return; + for (File file : files) { try { List simulators = simFormatSimulatorLoader.load(file) .orElse(null); From 1a6c0de502df750703406fd256799867f6114d53 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 14:01:42 +0100 Subject: [PATCH 059/139] Update Permission --- .../src/de/steamwar/bausystem/Permission.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index b2f14e4f..6d9dbf96 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -36,27 +36,21 @@ import java.util.function.Predicate; @AllArgsConstructor public enum Permission { - WORLD(BauweltMember::isWorld), - WORLDEDIT(BauweltMember::isWorldEdit), - MEMBER(bauweltMember -> true), - OWNER(bauweltMember -> false); + OWNER(bauweltMember -> { + return bauweltMember.getBauweltID() == BauServer.getInstance().getOwnerID(); + }), + SUPERVISOR(bauweltMember -> { + return OWNER.permissionPredicate.test(bauweltMember); // TODO: Needs to be changed later on + }), + BUILD(bauweltMember -> { + return bauweltMember.isWorld() || bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember); + }); private final Predicate permissionPredicate; public boolean hasPermission(Player member) { - if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) { - return true; - } - BauweltMember bauMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); - if (bauMember == null) { - return false; - } - + if (bauMember == null) return false; return permissionPredicate.test(bauMember); } - - public static boolean hasPermission(Player member, Permission permission) { - return permission.hasPermission(member); - } } \ No newline at end of file From ec93dfd8ec7162376e48a13436221151a4789f7e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 14:04:46 +0100 Subject: [PATCH 060/139] Add Permission.SPECTATOR --- BauSystem_Main/src/de/steamwar/bausystem/Permission.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 6d9dbf96..009e51a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -44,6 +44,9 @@ public enum Permission { }), BUILD(bauweltMember -> { return bauweltMember.isWorld() || bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember); + }), + SPECTATOR(bauweltMember -> { + return !BUILD.permissionPredicate.test(bauweltMember); }); private final Predicate permissionPredicate; From 0b70bdfe97dc58d09e78816e4dd40b57854318c5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 14:05:58 +0100 Subject: [PATCH 061/139] Fix Permission.SPECTATOR --- BauSystem_Main/src/de/steamwar/bausystem/Permission.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 009e51a5..3e25ced6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -52,8 +52,8 @@ public enum Permission { private final Predicate permissionPredicate; public boolean hasPermission(Player member) { - BauweltMember bauMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); - if (bauMember == null) return false; - return permissionPredicate.test(bauMember); + BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); + if (bauweltMember == null) return this != SPECTATOR; + return permissionPredicate.test(bauweltMember); } } \ No newline at end of file From 0cec90c55cfa92a18105a4c01b179b540690e001 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 14:19:30 +0100 Subject: [PATCH 062/139] Add validator for player and commandsender for checking build Permission --- BauSystem_Main/src/BauSystem.properties | 3 +++ BauSystem_Main/src/BauSystem_de.properties | 3 +++ .../src/de/steamwar/bausystem/BauSystem.java | 21 +++++++++++++++++++ .../src/de/steamwar/bausystem/Permission.java | 7 ------- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 27ca6f67..0231d101 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -27,6 +27,9 @@ PAGE_LIST=§e Page ({0}/{1}) »» LIST_PREVIOUS_PAGE=§ePrevious page LIST_NEXT_PAGE=§eNext page +# Permissions +NO_PERMISSION = You are not allowed to use that here + # Scoreboard SCOREBOARD_TIME = Time SCOREBOARD_REGION = Region diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 439267cf..f81caadd 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -27,6 +27,9 @@ PAGE_LIST=§e Seite ({0}/{1}) »» LIST_PREVIOUS_PAGE=§eVorherige Seite LIST_NEXT_PAGE=§eNächste Seite +# Permission +NO_PERMISSION = Du darfst dies hier nicht nutzen + # Scoreboard SCOREBOARD_TIME = Uhrzeit SCOREBOARD_REGION = Region diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 10b36297..ad5790a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -29,9 +29,12 @@ import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.Updater; import de.steamwar.bausystem.utils.TickListener; import de.steamwar.bausystem.worlddata.WorldData; +import de.steamwar.command.SWCommandUtils; import de.steamwar.message.Message; import lombok.Getter; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -75,6 +78,24 @@ public class BauSystem extends JavaPlugin implements Listener { new Updater(PrototypeLoader.file, PrototypeLoader::load); new Updater(RegionLoader.file, RegionLoader::load); + SWCommandUtils.addValidator(Player.class, (player, object, messageSender) -> { + if (Permission.BUILD.hasPermission(player)) { + return true; + } + messageSender.send("NO_PERMISSION"); + return false; + }); + SWCommandUtils.addValidator(CommandSender.class, (commandSender, object, messageSender) -> { + if (commandSender instanceof Player) { + if (Permission.BUILD.hasPermission((Player) commandSender)) { + return true; + } + messageSender.send("NO_PERMISSION"); + return false; + } + return true; + }); + LinkageUtils.link(); RamUsage.init(); TickListener.impl.init(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 3e25ced6..68900972 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -20,17 +20,10 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.config.BauServer; -import de.steamwar.command.CommandMetaData; -import de.steamwar.command.TypeValidator; import de.steamwar.sql.BauweltMember; import lombok.AllArgsConstructor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import java.util.function.Predicate; @AllArgsConstructor From 20af36a4a2f32b8cee75f15f3c1a4faaaa6b8c45 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 14:42:01 +0100 Subject: [PATCH 063/139] Add SpectatorListener --- .../features/world/SpectatorListener.java | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java new file mode 100644 index 00000000..ffc45f90 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -0,0 +1,110 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.world; + +import de.steamwar.bausystem.Permission; +import de.steamwar.linkage.Linked; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockCanBuildEvent; +import org.bukkit.event.block.BlockMultiPlaceEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.*; + +@Linked +public class SpectatorListener implements Listener { + + private boolean anySupervisorOnline(Player player) { + return Bukkit.getOnlinePlayers().stream().filter(p -> p != player).anyMatch(Permission.SUPERVISOR::hasPermission); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + if (!anySupervisorOnline(null)) { + event.getPlayer().kickPlayer(""); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if (!anySupervisorOnline(event.getPlayer())) { + Bukkit.getOnlinePlayers().forEach(player -> { + player.kickPlayer(""); + }); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + if (event.getMessage().startsWith("/schem save") || event.getMessage().startsWith("//schem save") || event.getMessage().startsWith("/schematic save") || event.getMessage().startsWith("//schematic save")) { + if (!Permission.SUPERVISOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + event.setMessage("/"); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onBlockMultiPlace(BlockMultiPlaceEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onBlockCanBuild(BlockCanBuildEvent event) { + if (event.getPlayer() == null) return; + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setBuildable(false); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onBlockBreak(BlockBreakEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerInteract(PlayerInteractEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerBucket(PlayerBucketEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } +} From 7802a03f48faaf2ffdfab19de58ded3988a4f110 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sat, 16 Dec 2023 14:47:33 +0100 Subject: [PATCH 064/139] Addjusted permissions --- .../bausystem/features/warp/WarpCommand.java | 7 ------- .../de/steamwar/bausystem/features/warp/WarpGui.java | 2 +- .../features/world/AxiomPermissionCheck.java | 2 +- .../bausystem/features/world/ClipboardListener.java | 5 +++++ .../bausystem/features/world/ItemFrameListener.java | 4 ++++ .../bausystem/features/world/KickallCommand.java | 12 ++++-------- .../bausystem/features/world/StopCommand.java | 2 +- .../bausystem/features/world/WorldEditListener.java | 2 +- .../features/worldedit/ColorReplaceCommand.java | 2 +- .../features/worldedit/TypeReplaceCommand.java | 2 +- .../bausystem/features/xray/XrayCommand.java | 2 +- 11 files changed, 20 insertions(+), 22 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java index 8fa832a7..aad07fcb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -122,13 +122,6 @@ public class WarpCommand extends SWCommand implements Disable, Enable { BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.getLocation().distance(player.getLocation())); } - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "WARP_DISALLOWED"); - }; - } - @Linked public static class WarpsLink extends SWCommand { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java index 7c5c87a6..30fd21e3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java @@ -55,7 +55,7 @@ public class WarpGui { ), warp))); SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("WARP_GUI_NAME", player), false, entries, (clickType, warp) -> { - if (clickType.isRightClick() && Permission.hasPermission(player, Permission.WORLD)) { + if (clickType.isRightClick() && Permission.BUILD.hasPermission(player)) { openWarpGui(player, warp); } else { warp.teleport(player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java index 5ee07dae..e006e184 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java @@ -32,7 +32,7 @@ public class AxiomPermissionCheck implements Listener { @EventHandler public void onAxiomHandshake(AxiomHandshakeEvent event) { - if (Permission.WORLDEDIT.hasPermission(event.getPlayer())) return; + if (Permission.BUILD.hasPermission(event.getPlayer())) return; event.setCancelled(true); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java index 3d3ca140..04c95e5c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.world; +import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; @@ -35,6 +36,8 @@ public class ClipboardListener implements Listener { @EventHandler public void onLogin(PlayerJoinEvent e) { + if(!Permission.BUILD.hasPermission(e.getPlayer())) return; + try { SchematicNode schematic = SchematicNode.getSchematicNode(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, (Integer) null); if (schematic != null) { @@ -47,6 +50,8 @@ public class ClipboardListener implements Listener { @EventHandler public void onLogout(PlayerQuitEvent e) { + if(!Permission.SUPERVISOR.hasPermission(e.getPlayer())) return; + SchematicNode schematic = SchematicNode.getSchematicNode(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, (Integer) null); boolean newSchem = false; if (schematic == null) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java index 9a294708..535551ab 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.world; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.linkage.Linked; import org.bukkit.Material; @@ -40,6 +41,9 @@ public class ItemFrameListener implements Listener { if (!(event.getEntity() instanceof ItemFrame)) { return; } + + if(!Permission.BUILD.hasPermission((Player) event.getDamager())) return; + event.setCancelled(true); ItemFrame itemFrame = (ItemFrame) event.getEntity(); ItemStack itemStack = itemFrame.getItem(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/KickallCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/KickallCommand.java index ee9ace1b..d4e5d3f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/KickallCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/KickallCommand.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.world; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.config.BauServer; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; @@ -38,16 +39,11 @@ public class KickallCommand extends SWCommand { } @Register(description = "KICKALL_HELP") - public void genericCommand(@Validator Player player) { + public void genericCommand(Player player) { + if(!Permission.OWNER.hasPermission(player)) return; + Bukkit.getOnlinePlayers().forEach(p -> { if (!bauServer.getOwner().equals(p.getUniqueId())) p.kickPlayer(""); }); } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!bauServer.getOwner().equals(player.getUniqueId()), "KICKALL_NO_PERM"); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/StopCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/StopCommand.java index 4017e548..479cd9ad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/StopCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/StopCommand.java @@ -51,7 +51,7 @@ public class StopCommand extends SWCommand { return true; } Player player = (Player) sender; - if (Permission.hasPermission(player, Permission.WORLD)) { + if (Permission.SUPERVISOR.hasPermission(player)) { return true; } SteamwarUser user = SteamwarUser.get(player.getUniqueId()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java index ba9d6d9e..6cda80be 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java @@ -40,7 +40,7 @@ public class WorldEditListener implements Listener { if (!isWorldEditCommand(e.getMessage().split(" ")[0])) return; Player p = e.getPlayer(); - if (!Permission.hasPermission(p, Permission.WORLDEDIT)) { + if (!Permission.BUILD.hasPermission(e.getPlayer())) { BauSystem.MESSAGE.send("WORLD_EDIT_NO_PERMS", p); e.setCancelled(true); e.setMessage("/"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java index 010498a8..6b6659ba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java @@ -63,7 +63,7 @@ public class ColorReplaceCommand extends SWCommand { @Register(description = "COLORREPLACE_HELP") @SneakyThrows - public void genericCommand(Player player, Pair from, Color to) { + public void genericCommand(@Validator Player player, Pair from, Color to) { if (from.getValue() == to) { BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)})); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java index 0cc939d6..8013c92b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java @@ -67,7 +67,7 @@ public class TypeReplaceCommand extends SWCommand { @Register(description = "TYPEREPLACE_HELP") @SneakyThrows - public void genericCommand(Player player, Pair from, Type to) { + public void genericCommand(@Validator Player player, Pair from, Type to) { if (from.getValue() == to) { BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)})); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index ef30fbcd..2e5d90a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -62,7 +62,7 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen public TechHiderCommand techHiderCommand; @Register(description = "XRAY_HELP") - public void toggleHider(Player player) { + public void toggleHider(@Validator Player player) { Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { BauSystem.MESSAGE.send("XRAY_GLOBAL", player); From bcb8b31ba99ab5b3b16d03c9f6ea3bc395792188 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 14:51:24 +0100 Subject: [PATCH 065/139] Add Permission.MEMBER --- BauSystem_Main/src/de/steamwar/bausystem/Permission.java | 3 +++ .../de/steamwar/bausystem/features/util/ClearCommand.java | 7 ------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 68900972..40978989 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -40,6 +40,9 @@ public enum Permission { }), SPECTATOR(bauweltMember -> { return !BUILD.permissionPredicate.test(bauweltMember); + }), + MEMBER(bauweltMember -> { + return true; }); private final Predicate permissionPredicate; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/ClearCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/ClearCommand.java index 3e8899d6..1df08e5d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/ClearCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/ClearCommand.java @@ -48,13 +48,6 @@ public class ClearCommand extends SWCommand { BauSystem.MESSAGE.send("OTHER_CLEAR_TO", p, target.getName()); } - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "OTHER_CLEAR_NO_PERMS"); - }; - } - private void clear(Player player) { player.getInventory().clear(); player.getInventory().setHelmet(new ItemStack(Material.AIR)); From 37e6628aaadb77e2f1c02c8407209b2a886f7761 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 15:12:16 +0100 Subject: [PATCH 066/139] Fix SpectatorListener --- .../features/world/SpectatorListener.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index ffc45f90..942d8eb7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -20,8 +20,10 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -30,7 +32,9 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockMultiPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.*; +import org.bukkit.inventory.ItemStack; @Linked public class SpectatorListener implements Listener { @@ -44,6 +48,38 @@ public class SpectatorListener implements Listener { if (!anySupervisorOnline(null)) { event.getPlayer().kickPlayer(""); } + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + Player p = event.getPlayer(); + ItemStack[] content = event.getPlayer().getInventory().getContents(); + for (int i = 0; i < content.length; i++) { + if (content[i] == null) continue; + if (checkItemStack(content[i])) { + p.getInventory().setItem(i, null); + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onInventoryClick(InventoryClickEvent event) { + ItemStack itemStack = event.getCurrentItem(); + if (itemStack == null || !itemStack.hasItemMeta()) { + return; + } + if (checkItemStack(itemStack)) { + event.setCancelled(true); + event.setCurrentItem(null); + } + } + + private boolean checkItemStack(ItemStack itemStack) { + switch (itemStack.getType()) { + case WOODEN_AXE: + case DEBUG_STICK: + return true; + default: + return false; + } } @EventHandler From 3dddb48d0ca4b475e954557436759f754811a7c8 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sat, 16 Dec 2023 15:53:02 +0100 Subject: [PATCH 067/139] Adjusted more permissions --- .../AttributeRemoveCommand.java | 4 +-- .../attributescopy/AttributesCopyCommand.java | 2 +- .../AttributesPlaceListener.java | 2 ++ .../features/autostart/AutoStartCommand.java | 2 +- .../features/autostart/AutoStartGuiItem.java | 2 +- .../features/autostart/AutostartListener.java | 3 +++ .../features/backup/BackupCommand.java | 7 ----- .../endstone/DesignEndStoneCommand.java | 2 +- .../detonator/DetonatorBauGuiItem.java | 2 +- .../features/detonator/DetonatorCommand.java | 4 +-- .../features/detonator/DetonatorListener.java | 6 +++++ .../features/hotbar/HotbarCommand.java | 2 +- .../features/hotbar/HotbarListener.java | 2 ++ .../inventoryfiller/InventoryFiller.java | 3 +++ .../killchecker/KillcheckerCommand.java | 2 +- .../bausystem/features/loader/Loader.java | 2 ++ .../features/loader/LoaderCommand.java | 7 ----- .../loader/LoaderScoreboardElement.java | 2 ++ .../features/loadtimer/LoadtimerCommand.java | 6 ++--- .../observer/ObserverTracerCommand.java | 3 ++- .../observer/ObserverTracerListener.java | 2 ++ .../features/region/ColorCommand.java | 2 +- .../features/region/FireCommand.java | 11 -------- .../features/region/FreezeCommand.java | 11 -------- .../features/region/ItemsCommand.java | 11 -------- .../features/region/ProtectCommand.java | 7 ----- .../features/region/RegionCommand.java | 26 +++++-------------- .../features/region/ResetCommand.java | 7 ----- .../bausystem/features/region/TNTCommand.java | 7 ----- .../features/region/TestblockCommand.java | 5 ---- .../features/region/items/FireBauGuiItem.java | 2 +- .../region/items/FreezeBauGuiItem.java | 2 +- .../region/items/ProtectBauGuiItem.java | 2 +- .../region/items/ResetBauGuiItem.java | 2 +- .../region/items/TestblockBauGuiItem.java | 2 +- .../features/region/items/TntBauGuiItem.java | 2 +- .../features/script/ScriptCommand.java | 2 +- .../features/script/ScriptListener.java | 4 +++ .../script/event/CommandListener.java | 2 ++ .../features/script/event/EventListener.java | 11 ++++++++ .../features/script/event/HotkeyListener.java | 2 ++ .../shieldprinting/ShieldPrintingCommand.java | 5 ++-- .../features/simulator/SimulatorCommand.java | 7 ----- .../features/simulator/SimulatorCursor.java | 2 ++ .../slaves/laufbau/LaufbauCommand.java | 7 ----- .../slaves/panzern/PanzernCommand.java | 7 ----- .../smartplace/SmartPlaceListener.java | 4 +++ .../features/techhider/TechHiderCommand.java | 2 +- .../testblock/blockcounter/BlockCounter.java | 3 +++ .../features/tpslimit/TPSSystem.java | 22 +--------------- .../features/tracer/TraceCommand.java | 11 -------- .../features/tracer/TracerBauGuiItem.java | 2 +- .../bausystem/features/util/BindCommand.java | 4 ++- .../features/util/BookReplaceCommand.java | 4 +-- .../features/util/DebugStickCommand.java | 2 +- .../features/util/KillAllCommand.java | 4 +-- .../features/util/SelectCommand.java | 7 ----- .../bausystem/features/util/SkullCommand.java | 2 +- .../features/util/StructureVoidCommand.java | 2 +- .../features/util/TNTClickListener.java | 7 ++--- .../bausystem/features/util/TimeCommand.java | 7 ----- .../util/items/DebugstickBauGuiItem.java | 2 +- .../util/items/KillAllBauGuiItem.java | 2 +- .../util/items/NavWandBauGuiItem.java | 2 +- .../features/util/items/SchemBauGuiItem.java | 2 +- .../features/util/items/SelectBauGuiItem.java | 2 +- .../features/util/items/SkullBauGuiItem.java | 2 +- .../util/items/WorldEditBauGuiItem.java | 2 +- 68 files changed, 107 insertions(+), 205 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java index 11cacde1..689be980 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java @@ -44,7 +44,7 @@ public class AttributeRemoveCommand extends SWCommand { @Register({"all"}) @Register({"*"}) - public void genericCommand(Player player) { + public void genericCommand(@Validator Player player) { ItemStack itemStack = player.getInventory().getItemInMainHand(); ItemMeta itemMeta = itemStack.getItemMeta(); itemMeta.setLore(new ArrayList<>()); @@ -53,7 +53,7 @@ public class AttributeRemoveCommand extends SWCommand { } @Register(description = "ATTRIBUTE_REMOVE_COMMAND_HELP") - public void genericCommand(Player player, @Mapper("attribute") String attribute) { + public void genericCommand(@Validator Player player, @Mapper("attribute") String attribute) { ItemStack itemStack = player.getInventory().getItemInMainHand(); ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta == null) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java index 01d652b4..808ca339 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java @@ -41,7 +41,7 @@ public class AttributesCopyCommand extends SWCommand { } @Register - public void genericCommand(Player player) { + public void genericCommand(@Validator Player player) { Block block = player.getTargetBlockExact(8, FluidCollisionMode.ALWAYS); if (block == null) return; ItemStack mainHand = player.getInventory().getItemInMainHand(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java index de4b192a..965d8bad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.attributescopy; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -40,6 +41,7 @@ public class AttributesPlaceListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; ItemStack itemStack = event.getItemInHand(); ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta == null) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java index 8e2b8c1a..3401267e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java @@ -32,7 +32,7 @@ public class AutoStartCommand extends SWCommand { } @Register(description = "AUTOSTART_COMMAND_HELP") - public void genericCommand(Player p) { + public void genericCommand(@Validator Player p) { SWUtils.giveItemToPlayer(p, AutostartListener.getWandItem(p)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartGuiItem.java index a66e3785..f622d70b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartGuiItem.java @@ -50,6 +50,6 @@ public class AutoStartGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.MEMBER; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 7da0fea1..28fb7f94 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.autostart; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; @@ -66,6 +67,7 @@ public class AutostartListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!ItemUtils.isItem(event.getItem(), "autostart")) { return; } @@ -83,6 +85,7 @@ public class AutostartListener implements Listener { if (!(event.getPlayer() instanceof Player)) { return; } + if(!Permission.BUILD.hasPermission((Player) event.getPlayer())) return; if (!ItemUtils.isItem(event.getPlayer().getInventory().getItemInMainHand(), "autostart")) { return; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java index ba7035dc..f4194a4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java @@ -140,13 +140,6 @@ public class BackupCommand extends SWCommand { return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listBackup((Player) commandSender)); } - @ClassValidator(value = Player.class, local = true) - public TypeValidator backupValidator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "BACKUP_NO_PERMS"); - }; - } - private List listBackup(Player p) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java index bafa3206..35a7fa7a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java @@ -45,7 +45,7 @@ public class DesignEndStoneCommand extends SWCommand implements Listener { private Map designEndStoneMap = new HashMap<>(); @Register(description = "DESIGN_ENDSTONE_COMMAND_HELP") - public void genericCommand(Player player) { + public void genericCommand(@Validator Player player) { Region region = Region.getRegion(player.getLocation()); if (!region.hasType(RegionType.BUILD)) { BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorBauGuiItem.java index 2207ce45..3f633663 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorBauGuiItem.java @@ -47,6 +47,6 @@ public class DetonatorBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.MEMBER; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java index bb71245d..c8d493bd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java @@ -58,12 +58,12 @@ public class DetonatorCommand extends SWCommand { } @Register(value = "wand", description = "DETONATOR_HELP_WAND") - public void giveWand(Player p) { + public void giveWand(@Validator Player p) { SWUtils.giveItemToPlayer(p, getWAND(p)); } @Register(value = "click", description = "DETONATOR_HELP_CLICK") - public void clickDetonator(Player p) { + public void clickDetonator(@Validator Player p) { Detonator.activateDetonator(new ItemStorage(p)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java index be8e8ce9..0ea3c469 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.detonator; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage; import de.steamwar.bausystem.features.detonator.storage.ItemStorage; @@ -65,6 +66,7 @@ public class DetonatorListener implements Listener { @EventHandler public void onBlockBreak(BlockBreakEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; Player p = event.getPlayer(); if (Detonator.isDetonator(p.getInventory().getItemInMainHand())) { event.setCancelled(true); @@ -75,6 +77,7 @@ public class DetonatorListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!Detonator.isDetonator(event.getItem())) { return; } @@ -89,6 +92,7 @@ public class DetonatorListener implements Listener { @EventHandler(ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) { if (Detonator.hasActiveDetonatorShow(event.getPlayer())) { Detonator.hideDetonator(event.getPlayer()); @@ -110,6 +114,7 @@ public class DetonatorListener implements Listener { @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) { HAS_UPDATED.add(event.getPlayer()); } @@ -117,6 +122,7 @@ public class DetonatorListener implements Listener { @EventHandler public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (Detonator.isDetonator(event.getMainHandItem()) || Detonator.isDetonator(event.getOffHandItem())) { HAS_UPDATED.add(event.getPlayer()); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarCommand.java index 9b52890c..77a13716 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarCommand.java @@ -35,7 +35,7 @@ public class HotbarCommand extends SWCommand { } @Register(value = "load", description = "HOTBAR_HELP_LOAD") - public void loadHotbar(Player p) { + public void loadHotbar(@Validator Player p) { DefaultHotbar.setHotbar(p); BauSystem.MESSAGE.send("HOTBAR_LOADED", p); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java index de00331f..8a4c78de 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.hotbar; +import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -30,6 +31,7 @@ public class HotbarListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) { DefaultHotbar.setHotbar(event.getPlayer()); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFiller.java b/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFiller.java index f72d08f2..d69e3410 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFiller.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFiller.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.inventoryfiller; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.linkage.Linked; import net.md_5.bungee.api.ChatMessageType; @@ -38,6 +39,7 @@ public class InventoryFiller implements Listener { @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return; if (!event.getPlayer().isSneaking()) return; Block block = event.getPlayer().getTargetBlockExact(5); @@ -59,6 +61,7 @@ public class InventoryFiller implements Listener { */ @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return; if (!event.getPlayer().isSneaking()) return; ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index 1340f1c1..bbba61ea 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -54,7 +54,7 @@ public class KillcheckerCommand extends SWCommand implements Listener { } @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") - public void genericCommand(Player player, @OptionalValue("-outline") @StaticValue(value = {"-area", "-outline"}, allowISE = true) boolean onlyOutline) { + public void genericCommand(@Validator Player player, @OptionalValue("-outline") @StaticValue(value = {"-area", "-outline"}, allowISE = true) boolean onlyOutline) { Region region = Region.getRegion(player.getLocation()); KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, region1 -> new KillcheckerVisualizer(region1, bossBarService)); killcheckerVisualizer.recalc(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index 22e0df02..266cd65b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.loader.elements.LoaderElement; import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT; @@ -70,6 +71,7 @@ public class Loader implements Listener { BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { if (stage != Stage.RUNNING) return; + if(!Permission.BUILD.hasPermission(p)) return; if (waitTime > 0) { waitTime--; return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java index b065c3d2..55264ec2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -101,11 +101,4 @@ public class LoaderCommand extends SWCommand { BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay); loader.setTicksBetweenBlocks(delay); } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator loaderValidator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "LOADER_PERMS"); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java index b3e2ba2f..fdcda57a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; @@ -40,6 +41,7 @@ public class LoaderScoreboardElement implements ScoreboardElement { @Override public String get(Region region, Player p) { + if(!Permission.BUILD.hasPermission(p)) return null; Loader loader = Loader.getLoader(p); if (loader == null) return null; if (loader.getStage() == Loader.Stage.RUNNING) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadtimer/LoadtimerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadtimer/LoadtimerCommand.java index 42d5175c..503c1b47 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadtimer/LoadtimerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadtimer/LoadtimerCommand.java @@ -32,12 +32,12 @@ public class LoadtimerCommand extends SWCommand { } @Register(value = "start", description = "LOADTIMER_HELP_START_1") - public void start(Player p) { + public void start(@Validator Player p) { start(p, TimerMode.HALF); } @Register(value = "start", description = {"LOADTIMER_HELP_START_2", "LOADTIMER_HELP_START_3"}) - public void start(Player p, TimerMode mode) { + public void start(@Validator Player p, TimerMode mode) { Region r = Region.getRegion(p.getLocation()); if (r.isGlobal()) return; if (!Loadtimer.hasTimer(r)) @@ -45,7 +45,7 @@ public class LoadtimerCommand extends SWCommand { } @Register(value = "stop", description = "LOADTIMER_HELP_STOP") - public void stop(Player p) { + public void stop(@Validator Player p) { Region r = Region.getRegion(p.getLocation()); if (r.isGlobal()) return; if (Loadtimer.hasTimer(r)) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java index fd0df724..dbd3e48a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.observer; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; @@ -52,7 +53,7 @@ public class ObserverTracerCommand extends SWCommand { } @Register(value = "retrace", description = "OBSERVER_HELP_RETRACE") - public void retrace(Player p) { + public void retrace(@Validator Player p) { if (ObserverTracerListener.observerTracerMap.containsKey(p)) { BauSystem.MESSAGE.send("OBSERVER_RETRACE_NO_TRACE", p); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java index b841755b..801f9ce0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.observer; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -55,6 +56,7 @@ public class ObserverTracerListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!enabled.contains(event.getPlayer())) { return; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java index 543d8727..7c60aef2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java @@ -85,7 +85,7 @@ public class ColorCommand extends SWCommand { @ClassValidator(value = Player.class, local = true) public TypeValidator validator() { return (commandSender, player, messageSender) -> { - return !messageSender.send(!bauServer.getOwner().equals(player.getUniqueId()), "REGION_COLOR_NO_PERMS"); + return !messageSender.send(!bauServer.getOwner().equals(player.getUniqueId()), "NO_PERMISSION"); }; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireCommand.java index da5b2665..3a0d4403 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireCommand.java @@ -46,10 +46,6 @@ public class FireCommand extends SWCommand { } } - private String getNoPermMessage() { - return "REGION_FIRE_NO_PERMS"; - } - private String getEnableMessage() { return "REGION_FIRE_ENABLED"; } @@ -69,11 +65,4 @@ public class FireCommand extends SWCommand { return false; } } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), getNoPermMessage()); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java index 339ea122..d154ce66 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java @@ -46,10 +46,6 @@ public class FreezeCommand extends SWCommand { } } - private String getNoPermMessage() { - return "REGION_FREEZE_NO_PERMS"; - } - private String getEnableMessage(){ return "REGION_FREEZE_ENABLED"; } @@ -69,11 +65,4 @@ public class FreezeCommand extends SWCommand { return true; } } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), getNoPermMessage()); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java index d1709dc7..8c4452cb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -49,10 +49,6 @@ public class ItemsCommand extends SWCommand { } } - private String getNoPermMessage() { - return "REGION_ITEMS_NO_PERMS"; - } - private String getEnableMessage(){ return "REGION_ITEMS_ENABLED"; } @@ -72,11 +68,4 @@ public class ItemsCommand extends SWCommand { return true; } } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), getNoPermMessage()); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectCommand.java index 3793d3ec..4fc33cf0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectCommand.java @@ -54,13 +54,6 @@ public class ProtectCommand extends SWCommand { } } - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "REGION_PROTECT_NO_PERMS"); - }; - } - private Region regionCheck(Player player) { Region region = Region.getRegion(player.getLocation()); if (region.getFloorLevel() == 0) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index 5caf0af3..28da6094 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -71,7 +71,7 @@ public class RegionCommand extends SWCommand { } @Register(value = "undo", description = "REGION_REGION_HELP_UNDO") - public void undoCommand(@Validator("WORLD_EDIT") Player p) { + public void undoCommand(@Validator Player p) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) return; @@ -83,7 +83,7 @@ public class RegionCommand extends SWCommand { } @Register(value = "redo", description = "REGION_REGION_HELP_REDO") - public void redoCommand(@Validator("WORLD_EDIT") Player p) { + public void redoCommand(@Validator Player p) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; @@ -97,7 +97,7 @@ public class RegionCommand extends SWCommand { } @Register(value = "restore", description = "REGION_REGION_HELP_RESTORE") - public void genericRestoreCommand(@Validator("WORLD_EDIT") Player p) { + public void genericRestoreCommand(@Validator Player p) { Region region = Region.getRegion(p.getLocation()); if(checkGlobalRegion(region, p)) return; @@ -114,7 +114,7 @@ public class RegionCommand extends SWCommand { } @Register(value = "restore", description = "REGION_REGION_HELP_RESTORE_SCHEMATIC") - public void schematicRestoreCommand(@Validator("WORLD_EDIT") Player p, SchematicNode node) { + public void schematicRestoreCommand(@Validator Player p, SchematicNode node) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) return; @@ -176,7 +176,7 @@ public class RegionCommand extends SWCommand { @Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE") @Register("type") - public void changeTypeCommand(@Validator("WORLD") Player p, @Mapper("regionTypeMapper") String s) { + public void changeTypeCommand(@Validator Player p, @Mapper("regionTypeMapper") String s) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; @@ -210,7 +210,7 @@ public class RegionCommand extends SWCommand { @Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN") @Register("skin") - public void changeSkinCommand(@Validator("WORLD") Player p, @Mapper("skinTypeMapper") String s) { + public void changeSkinCommand(@Validator Player p, @Mapper("skinTypeMapper") String s) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; @@ -266,18 +266,4 @@ public class RegionCommand extends SWCommand { } }; } - - @Validator(value = "WORLD", local = true) - public TypeValidator worldValidator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_REGION_NO_PERMS"); - }; - } - - @Validator(value = "WORLD_EDIT", local = true) - public TypeValidator worldEditValidator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "REGION_REGION_NO_PERMS"); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index 03a22027..680224a7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -97,13 +97,6 @@ public class ResetCommand extends SWCommand { } } - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_RESET_NO_PERMS"); - }; - } - private Region regionCheck(Player player) { Region region = Region.getRegion(player.getLocation()); if (region == GlobalRegion.getInstance()) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java index af9f3837..27dcbe8f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java @@ -157,11 +157,4 @@ public class TNTCommand extends SWCommand { break; } } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_TNT_NO_PERMS"); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 3572cf71..6b319062 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -157,11 +157,6 @@ public class TestblockCommand extends SWCommand { }; } - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "REGION_TB_NO_PERMS"); - } - private Region regionCheck(Player player) { Region region = Region.getRegion(player.getLocation()); if (!region.hasType(RegionType.TESTBLOCK)) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FireBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FireBauGuiItem.java index 01714fba..79101ee9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FireBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FireBauGuiItem.java @@ -57,6 +57,6 @@ public class FireBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLD; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FreezeBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FreezeBauGuiItem.java index 43d1903f..1406638c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FreezeBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FreezeBauGuiItem.java @@ -57,6 +57,6 @@ public class FreezeBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLD; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ProtectBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ProtectBauGuiItem.java index 652c2fb2..a11e508d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ProtectBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ProtectBauGuiItem.java @@ -58,6 +58,6 @@ public class ProtectBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLDEDIT; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ResetBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ResetBauGuiItem.java index 79f6537a..e5295b2e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ResetBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ResetBauGuiItem.java @@ -65,6 +65,6 @@ public class ResetBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLDEDIT; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java index 7b0f25e0..355b5209 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java @@ -64,6 +64,6 @@ public class TestblockBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLDEDIT; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java index 673a9295..38f1b04a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java @@ -116,6 +116,6 @@ public class TntBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLD; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java index 9d640d52..0194514f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java @@ -31,7 +31,7 @@ public class ScriptCommand extends SWCommand { } @Register - public void genericCommand(Player player) { + public void genericCommand(@Validator Player player) { ScriptGUI.open(player); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java index 61b8862d..ed88d2ee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.script; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; @@ -42,6 +43,8 @@ public class ScriptListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onLeftClick(PlayerInteractEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; + ItemStack item = event.getItem(); if (item == null || FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) { return; @@ -68,6 +71,7 @@ public class ScriptListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; ScriptRunner.updateGlobalScript(event.getPlayer()); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java index 77bd991e..da5f1f21 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.script.event; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; @@ -41,6 +42,7 @@ public class CommandListener implements Listener { @EventHandler public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; String[] split = event.getMessage().split(" "); if (calledCommands.getOrDefault(event.getPlayer(), new HashSet<>()).contains(split[0])) { return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java index 89f9667e..9f38c219 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.script.event; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin; import de.steamwar.bausystem.features.script.lua.libs.StorageLib; @@ -64,17 +65,20 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL, event); } @EventHandler(priority = EventPriority.HIGH) public void onPlayerQuit(PlayerQuitEvent event) { StorageLib.removePlayer(event.getPlayer()); + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event); } @EventHandler(priority = EventPriority.HIGH) public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (LAST_FS.containsKey(event.getPlayer())) { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DoubleSwap, LuaValue.NIL, event); @@ -86,6 +90,7 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; LuaTable table = new LuaTable(); table.set("x", event.getBlock().getX()); table.set("y", event.getBlock().getY()); @@ -96,6 +101,7 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onBlockBreak(BlockBreakEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; LuaTable table = new LuaTable(); table.set("x", event.getBlock().getX()); table.set("y", event.getBlock().getY()); @@ -108,6 +114,7 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.LOW) public void onPlayerInteract(PlayerInteractEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (ignore.remove(event.getPlayer())) { return; } @@ -144,6 +151,7 @@ public class EventListener implements Listener { Region tntRegion = Region.getRegion(event.getLocation()); for (Player player : Bukkit.getOnlinePlayers()) { + if(!Permission.BUILD.hasPermission(player)) continue; if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTSpawn, LuaValue.NIL, event); } @@ -165,6 +173,7 @@ public class EventListener implements Listener { boolean inBuild = event.blockList().stream().anyMatch(block -> tntRegion.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); for (Player player : Bukkit.getOnlinePlayers()) { + if(!Permission.BUILD.hasPermission(player)) continue; if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table, event); if (inBuild) { @@ -176,6 +185,7 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onPlayerDropItem(PlayerDropItemEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; ignore.add(event.getPlayer()); LuaTable table = new LuaTable(); table.set("type", event.getItemDrop().getItemStack().getType().name()); @@ -185,6 +195,7 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onEntityDeath(EntityDeathEvent event) { for (Player player : Bukkit.getOnlinePlayers()) { + if(!Permission.BUILD.hasPermission(player)) continue; LuaTable table = new LuaTable(); table.set("type", event.getEntityType().name()); ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.EntityDeath, table, event); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java index d27a314e..52843f79 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.script.event; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.linkage.Linked; import de.steamwar.linkage.api.Plain; @@ -36,6 +37,7 @@ public class HotkeyListener implements PluginMessageListener, Plain { @Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { + if(!Permission.BUILD.hasPermission(player)) return; if (!channel.equals("sw:hotkeys")) return; if (message.length < 5) return; int action = message[4] & 0xFF; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java index d1b60349..20bbd8df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -108,8 +108,8 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { @ClassValidator(value = Player.class, local = true) public TypeValidator validator() { return (commandSender, player, messageSender) -> { - if (!Permission.hasPermission(player, Permission.WORLD)) { - messageSender.send("SHIELD_PRINTING_DISALLOWED", player); + if (!Permission.BUILD.hasPermission(player)) { + messageSender.send("NO_PERMISSION", player); return false; } Region region = Region.getRegion(player.getLocation()); @@ -123,6 +123,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (event.getClickedBlock() == null) { return; } 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 56991431..06af3e68 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -102,11 +102,4 @@ public class SimulatorCommand extends SWCommand { } }; } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "SIMULATOR_NO_PERMS"); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 6ff78e19..5dd31b6a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorElement; @@ -148,6 +149,7 @@ public class SimulatorCursor implements Listener { } return; } + if(!Permission.BUILD.hasPermission(player)) return; Simulator simulator = SimulatorStorage.getSimulator(player); SimulatorWatcher.show(simulator, player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java index 86585417..daff9d87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java @@ -78,11 +78,4 @@ public class LaufbauCommand extends SWCommand { public void laufbauSettings(@Validator Player player) { new LaufbauSettings(player); } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "LAUFBAU_NO_PERM"); - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java index 3bb2379e..8d83d3dd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java @@ -91,13 +91,6 @@ public class PanzernCommand extends SWCommand { }.runTaskTimer(BauSystem.getInstance(), 1, 1); } - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "PANZERN_NO_PERM"); - }; - } - @Mapper(value = "block", local = true) private TypeMapper blockMapper() { Set strings = new HashSet<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index f3ab68bf..ea6faa46 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.smartplace; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; @@ -90,6 +91,7 @@ public class SmartPlaceListener implements Plain, Listener { public SmartPlaceListener() { TinyProtocol.instance.addFilter(useItem, (player, packet) -> { + if(!Permission.BUILD.hasPermission(player)) return packet; if (!Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false)) return packet; Block block = player.getTargetBlockExact(6); boolean shouldSneak = !(block != null && (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) && !CONTAINERS.contains(block.getType()) && !IGNORED.contains(block.getType())); @@ -116,6 +118,7 @@ public class SmartPlaceListener implements Plain, Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return; WAS_EXECUTED.add(event.getPlayer()); if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; @@ -134,6 +137,7 @@ public class SmartPlaceListener implements Plain, Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return; if (!SMART_PLACING.contains(event.getPlayer())) { if (CONTAINERS.contains(event.getBlockAgainst().getType())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java index b6c6975e..731b583a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -55,7 +55,7 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE public XrayCommand xrayCommand; @Register(description = "TECHHIDER_HELP") - public void toggleHider(Player player) { + public void toggleHider(@Validator Player player) { Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { BauSystem.MESSAGE.send("TECHHIDER_GLOBAL", player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java index cf34f6f1..8b0796b8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.testblock.blockcounter; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.region.Region; import lombok.experimental.UtilityClass; @@ -49,6 +50,8 @@ public class BlockCounter { } public String getMessage(Player player, int count, int tntCount, long tick, long lastTick) { + if(!Permission.BUILD.hasPermission(player)) return null; + double countPerTNT = (double) count / tntCount; double countPerTick = (double) count / Math.max((lastTick - tick), 1); if (isActive(player)) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index 43eb40da..b801e324 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -143,16 +143,6 @@ public class TPSSystem implements Plain { }.runTaskTimer(BauSystem.getInstance(), 1, 1); } - public TypeValidator player() { - return (commandSender, player, messageSender) -> { - if (!Permission.hasPermission(player, Permission.WORLD)) { - messageSender.send("TPSLIMIT_NO_PERMS"); - return false; - } - return true; - }; - } - private class TPSBaseCommand extends SWCommand { private TPSBaseCommand() { @@ -160,11 +150,6 @@ public class TPSSystem implements Plain { setMessage(BauSystem.MESSAGE); addDefaultHelpMessage("TPSLIMIT_HELP"); } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator player() { - return TPSSystem.this.player(); - } } @AbstractSWCommand.PartOf(TPSBaseCommand.class) @@ -230,11 +215,6 @@ public class TPSSystem implements Plain { super("tick"); setMessage(BauSystem.MESSAGE); } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator player() { - return TPSSystem.this.player(); - } } @AbstractSWCommand.PartOf(TickBaseCommand.class) @@ -403,7 +383,7 @@ public class TPSSystem implements Plain { @Override public Permission permission() { - return Permission.WORLD; + return Permission.BUILD; } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 366cc7a3..004f841b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -243,15 +243,4 @@ public class TraceCommand extends SWCommand { } }; } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - if (!Permission.hasPermission(player, Permission.WORLD)) { - messageSender.send("TRACE_MESSAGE_DISALLOWED", player); - return false; - } - return true; - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TracerBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TracerBauGuiItem.java index 5df27f45..5df2ce7b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TracerBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TracerBauGuiItem.java @@ -96,6 +96,6 @@ public class TracerBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLD; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java index ab213c83..820b20b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java @@ -1,6 +1,7 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.script.ScriptCommand; import de.steamwar.bausystem.features.script.ScriptRunner; @@ -62,7 +63,7 @@ public class BindCommand extends SWCommand implements Listener { } @Register(description = "OTHER_BIND_HELP") - public void bind(Player player, @Mapper("command") @ErrorMessage("OTHER_BIND_ERROR") String... command) { + public void bind(@Validator Player player, @Mapper("command") @ErrorMessage("OTHER_BIND_ERROR") String... command) { bindInternal(player, command); } @@ -91,6 +92,7 @@ public class BindCommand extends SWCommand implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (!event.hasItem()) return; + if(!Permission.BUILD.hasPermission(event.getPlayer())) return; ItemStack itemStack = event.getItem(); ItemMeta meta = itemStack.getItemMeta(); if (meta == null) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BookReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BookReplaceCommand.java index 290223a2..c534e38d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BookReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BookReplaceCommand.java @@ -17,7 +17,7 @@ public class BookReplaceCommand extends SWCommand { } @Register("color") - public void color(Player player) { + public void color(@Validator Player player) { ItemStack itemStack = player.getInventory().getItemInMainHand(); ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta instanceof BookMeta) { @@ -29,7 +29,7 @@ public class BookReplaceCommand extends SWCommand { } @Register("uncolor") - public void uncolor(Player player) { + public void uncolor(@Validator Player player) { ItemStack itemStack = player.getInventory().getItemInMainHand(); ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta instanceof BookMeta) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/DebugStickCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/DebugStickCommand.java index e2de740f..5b87464c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/DebugStickCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/DebugStickCommand.java @@ -34,7 +34,7 @@ public class DebugStickCommand extends SWCommand { } @Register(description = "DEBUG_STICK_COMMAND_HELP") - public void genericCommand(Player p) { + public void genericCommand(@Validator Player p) { SWUtils.giveItemToPlayer(p, new ItemStack(Material.DEBUG_STICK)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/KillAllCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/KillAllCommand.java index 49654a05..e08b40c0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/KillAllCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/KillAllCommand.java @@ -45,12 +45,12 @@ public class KillAllCommand extends SWCommand { } @Register(description = "OTHER_KILLALL_HELP_SELF") - public void genericCommand(Player player) { + public void genericCommand(@Validator Player player) { genericCommand(player, RegionSelectionType.LOCAL); } @Register(description = "OTHER_KILLALL_HELP_ALL") - public void genericCommand(Player player, RegionSelectionType regionSelectionType) { + public void genericCommand(@Validator Player player, RegionSelectionType regionSelectionType) { Region region = Region.getRegion(player.getLocation()); AtomicLong count = new AtomicLong(0); if (regionSelectionType == RegionSelectionType.GLOBAL || GlobalRegion.getInstance() == region) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java index bd8566ea..e9c2c09a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java @@ -45,13 +45,6 @@ public class SelectCommand extends SWCommand { baurahmenCommand(p, RegionType.TESTBLOCK, regionExtensionType); } - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "SELECT_NO_PERMS"); - }; - } - private void setSelection(RegionType regionType, RegionExtensionType regionExtensionType, Region region, Player p) { Point minPoint = region.getMinPoint(regionType, regionExtensionType); Point maxPoint = region.getMaxPoint(regionType, regionExtensionType); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java index 9bb2331d..1f50a2ae 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java @@ -43,7 +43,7 @@ public class SkullCommand extends SWCommand { } @Register(description = "SKULL_HELP") - public void giveCommand(Player p, @Mapper("player") @ErrorMessage("SKULL_INVALID") String skull) { + public void giveCommand(@Validator Player p, @Mapper("player") @ErrorMessage("SKULL_INVALID") String skull) { ItemStack is = SWItem.getPlayerSkull(skull).getItemStack(); SkullMeta sm = (SkullMeta) is.getItemMeta(); assert sm != null; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/StructureVoidCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/StructureVoidCommand.java index 277eb59a..44bae130 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/StructureVoidCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/StructureVoidCommand.java @@ -34,7 +34,7 @@ public class StructureVoidCommand extends SWCommand { } @Register(description = "STRUCTURE_VOID_COMMAND_HELP") - public void genericCommand(Player p) { + public void genericCommand(@Validator Player p) { SWUtils.giveItemToPlayer(p, new ItemStack(Material.STRUCTURE_VOID, 1)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java index 9bb8368f..85f73e04 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; @@ -34,9 +35,9 @@ public class TNTClickListener implements Listener { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if (event.getHand() != EquipmentSlot.HAND) { - return; - } + if (event.getHand() != EquipmentSlot.HAND) return; + if (!Permission.BUILD.hasPermission(event.getPlayer())); + Entity entity = event.getRightClicked(); if (event.getRightClicked() instanceof TNTPrimed) { TNTPrimed tntPrimed = (TNTPrimed) entity; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TimeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TimeCommand.java index 15f48590..249f4072 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TimeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TimeCommand.java @@ -66,13 +66,6 @@ public class TimeCommand extends SWCommand { }, s -> tabCompletions); } - @ClassValidator(value = Player.class, local = true) - public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "OTHER_TIME_NO_PERM"); - }; - } - public enum Time { NIGHT(18000), DAY(6000), diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/DebugstickBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/DebugstickBauGuiItem.java index 725d75b1..c6341818 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/DebugstickBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/DebugstickBauGuiItem.java @@ -50,6 +50,6 @@ public class DebugstickBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.MEMBER; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/KillAllBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/KillAllBauGuiItem.java index 42a4588a..a5f76346 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/KillAllBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/KillAllBauGuiItem.java @@ -62,6 +62,6 @@ public class KillAllBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.MEMBER; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/NavWandBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/NavWandBauGuiItem.java index 30ac88a2..6b9b6775 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/NavWandBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/NavWandBauGuiItem.java @@ -39,7 +39,7 @@ public class NavWandBauGuiItem extends BauGuiItem { } @Override public Permission permission() { - return Permission.WORLDEDIT; + return Permission.MEMBER; } @Override public ItemStack getItem(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SchemBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SchemBauGuiItem.java index dc5569e4..027d6c9c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SchemBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SchemBauGuiItem.java @@ -18,7 +18,7 @@ public class SchemBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLDEDIT; + return Permission.BUILD; } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SelectBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SelectBauGuiItem.java index 2e90be13..b0feb305 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SelectBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SelectBauGuiItem.java @@ -88,7 +88,7 @@ public class SelectBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLDEDIT; + return Permission.BUILD; } @AllArgsConstructor diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SkullBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SkullBauGuiItem.java index f9ec57c8..c7e500db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SkullBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/SkullBauGuiItem.java @@ -54,6 +54,6 @@ public class SkullBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.MEMBER; + return Permission.BUILD; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/WorldEditBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/WorldEditBauGuiItem.java index ddfa66d7..9ef2400f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/WorldEditBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/WorldEditBauGuiItem.java @@ -40,7 +40,7 @@ public class WorldEditBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLDEDIT; + return Permission.BUILD; } @Override From 78f7e4262979b8ef744afbc4427af26a217840df Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 16:52:59 +0100 Subject: [PATCH 068/139] Fix Permission --- .../src/de/steamwar/bausystem/Permission.java | 17 ++++--- .../bausystem/features/bau/InfoCommand.java | 23 +++++----- .../countingwand/CountingwandGuiItem.java | 2 +- .../bausystem/features/gui/BauGUI.java | 17 +------ .../features/world/SpectatorListener.java | 44 +++++++++++++------ 5 files changed, 58 insertions(+), 45 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 40978989..b25e0fb1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.config.BauServer; import de.steamwar.sql.BauweltMember; +import de.steamwar.sql.SteamwarUser; import lombok.AllArgsConstructor; import org.bukkit.entity.Player; @@ -29,11 +30,9 @@ import java.util.function.Predicate; @AllArgsConstructor public enum Permission { - OWNER(bauweltMember -> { - return bauweltMember.getBauweltID() == BauServer.getInstance().getOwnerID(); - }), + OWNER(bauweltMember -> false), SUPERVISOR(bauweltMember -> { - return OWNER.permissionPredicate.test(bauweltMember); // TODO: Needs to be changed later on + return false; // TODO: Needs to be changed later on }), BUILD(bauweltMember -> { return bauweltMember.isWorld() || bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember); @@ -47,9 +46,17 @@ public enum Permission { private final Predicate permissionPredicate; + public boolean hasPermission(BauweltMember bauweltMember) { + if (bauweltMember == null) return false; + return permissionPredicate.test(bauweltMember); + } + public boolean hasPermission(Player member) { + if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) { + return this != SPECTATOR; + } BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); - if (bauweltMember == null) return this != SPECTATOR; + if (bauweltMember == null) return false; return permissionPredicate.test(bauweltMember); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index 345dc1b3..cdd481ea 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -1,6 +1,7 @@ package de.steamwar.bausystem.features.bau; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; @@ -24,12 +25,7 @@ public class InfoCommand extends SWCommand { super("bauinfo"); } - @Register(help = true) - public void genericHelp(Player p, String... args) { - BauSystem.MESSAGE.send("BAU_INFO_COMMAND_HELP", p); - } - - @Register + @Register(description = "BAU_INFO_COMMAND_HELP") public void genericCommand(Player p) { sendBauInfo(p); } @@ -52,11 +48,16 @@ public class InfoCommand extends SWCommand { membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size())); for (BauweltMember member : members) { - membermessage.append(BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_INFO", p, - SteamwarUser.get(member.getMemberID()).getUserName(), - member.isWorldEdit() ? BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WE_ALLOW", p) : BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WE_DISALLOW", p), - member.isWorld() ? BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WORLD_ALLOW", p) : BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WORLD_DISALLOW", p) - )); + if (!membermessage.isEmpty()) { + membermessage.append(", "); + } + if (Permission.SUPERVISOR.hasPermission(member)) { + membermessage.append("§c").append(SteamwarUser.get(member.getMemberID()).getUserName()); + } else if (Permission.BUILD.hasPermission(member)) { + membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName()); + } else { + membermessage.append("§7").append(SteamwarUser.get(member.getMemberID()).getUserName()); + } } p.sendMessage(membermessage.toString()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandGuiItem.java index 7772f9c7..dbeae70d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandGuiItem.java @@ -48,6 +48,6 @@ public class CountingwandGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLDEDIT; + return Permission.MEMBER; } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java index 74a915da..92289699 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java @@ -108,26 +108,13 @@ public class BauGUI { if (!permission.hasPermission(p)) { List lore = meta.getLore(); if (lore == null) { - lore = Collections.singletonList(BauSystem.MESSAGE.parse(permissionString(permission), p)); + lore = Collections.singletonList(BauSystem.MESSAGE.parse("NO_PERMISSION", p)); } else { - lore.add(BauSystem.MESSAGE.parse(permissionString(permission), p)); + lore.add(BauSystem.MESSAGE.parse("NO_PERMISSION", p)); } meta.setLore(lore); } itemStack.setItemMeta(meta); return itemStack; } - - private static String permissionString(Permission permission) { - switch (permission) { - case OWNER: - return "GUI_NO_OWNER"; - case WORLD: - return "GUI_NO_WORLD"; - case WORLDEDIT: - return "GUI_NO_WORLDEDIT"; - default: - return "GUI_NO_MEMBER"; - } - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index 942d8eb7..f80661aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -19,11 +19,10 @@ package de.steamwar.bausystem.features.world; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -45,8 +44,13 @@ public class SpectatorListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + if (Permission.SUPERVISOR.hasPermission(event.getPlayer())) { + return; + } if (!anySupervisorOnline(null)) { - event.getPlayer().kickPlayer(""); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + event.getPlayer().kickPlayer(""); + }, 1); } if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { Player p = event.getPlayer(); @@ -60,6 +64,15 @@ public class SpectatorListener implements Listener { } } + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if (!anySupervisorOnline(event.getPlayer())) { + Bukkit.getOnlinePlayers().forEach(player -> { + player.kickPlayer(""); + }); + } + } + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent event) { ItemStack itemStack = event.getCurrentItem(); @@ -82,15 +95,6 @@ public class SpectatorListener implements Listener { } } - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - if (!anySupervisorOnline(event.getPlayer())) { - Bukkit.getOnlinePlayers().forEach(player -> { - player.kickPlayer(""); - }); - } - } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { if (event.getMessage().startsWith("/schem save") || event.getMessage().startsWith("//schem save") || event.getMessage().startsWith("/schematic save") || event.getMessage().startsWith("//schematic save")) { @@ -138,7 +142,21 @@ public class SpectatorListener implements Listener { } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerBucket(PlayerBucketEvent event) { + public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerBucketEntity(PlayerBucketEntityEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerBucketFill(PlayerBucketFillEvent event) { if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { event.setCancelled(true); } From a61f1e2c8c6f002aacb401e0aee06dd0a9efa7a6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 18:08:48 +0100 Subject: [PATCH 069/139] Fix Permission for ServerLib.getBlockAt and setBlockAt and exec --- BauSystem_Main/src/de/steamwar/bausystem/Permission.java | 2 +- .../de/steamwar/bausystem/features/bau/InfoCommand.java | 5 +++-- .../bausystem/features/script/lua/SteamWarLuaPlugin.java | 1 + .../bausystem/features/script/lua/libs/ServerLib.java | 7 +++++++ .../bausystem/features/world/AxiomPermissionCheck.java | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index b25e0fb1..50251be3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -56,7 +56,7 @@ public enum Permission { return this != SPECTATOR; } BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); - if (bauweltMember == null) return false; + if (bauweltMember == null) return this == SPECTATOR; return permissionPredicate.test(bauweltMember); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index cdd481ea..1a7e1551 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -47,10 +47,11 @@ public class InfoCommand extends SWCommand { StringBuilder membermessage = new StringBuilder(); membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size())); - for (BauweltMember member : members) { - if (!membermessage.isEmpty()) { + for (int i = 0; i < members.size(); i++) { + if (i != 0) { membermessage.append(", "); } + BauweltMember member = members.get(i); if (Permission.SUPERVISOR.hasPermission(member)) { membermessage.append("§c").append(SteamwarUser.get(member.getMemberID()).getUserName()); } else if (Permission.BUILD.hasPermission(member)) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index b2bf51cc..4aefce8f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -123,6 +123,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction { return LuaValue.NIL; } + command = preprocessEvent.getMessage().substring(1); Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); String[] commandSplit = command.split(" "); if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java index 80134fba..be55dcdd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.inventory.SWItem; @@ -50,6 +51,9 @@ public class ServerLib implements LuaLib { serverLib.set("getBlockAt", new OneArgFunction() { @Override public LuaValue call(LuaValue arg1) { + if (!Permission.SUPERVISOR.hasPermission(player)) { + return LuaValue.NIL; + } LuaTable pos = arg1.checktable(); return valueOf(player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()).getType().name()); } @@ -57,6 +61,9 @@ public class ServerLib implements LuaLib { serverLib.set("setBlockAt", new TwoArgFunction() { @Override public LuaValue call(LuaValue arg1, LuaValue arg2) { + if (!Permission.SUPERVISOR.hasPermission(player)) { + return LuaValue.NIL; + } LuaTable pos = arg1.checktable(); LuaString material = arg2.checkstring(); Material mat = SWItem.getMaterial(material.tojstring()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java index e006e184..bdfe3d40 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java @@ -32,7 +32,7 @@ public class AxiomPermissionCheck implements Listener { @EventHandler public void onAxiomHandshake(AxiomHandshakeEvent event) { - if (Permission.BUILD.hasPermission(event.getPlayer())) return; + if (!Permission.BUILD.hasPermission(event.getPlayer())) return; event.setCancelled(true); } } From 6305453e1588e961334edd99b448c7f19493dac2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 21:34:29 +0100 Subject: [PATCH 070/139] Fix Permission for SignEdit and other stuff --- .../src/de/steamwar/bausystem/Permission.java | 4 +-- .../bausystem/features/bau/InfoCommand.java | 33 ++++++++++--------- .../features/world/SignEditFrom20.java | 2 ++ .../features/world/SignEditUntil19.java | 2 ++ .../features/world/SpectatorListener.java | 26 ++++++++++++--- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 50251be3..8e51d97d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -32,10 +32,10 @@ public enum Permission { OWNER(bauweltMember -> false), SUPERVISOR(bauweltMember -> { - return false; // TODO: Needs to be changed later on + return bauweltMember.isWorld(); }), BUILD(bauweltMember -> { - return bauweltMember.isWorld() || bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember); + return bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember); }), SPECTATOR(bauweltMember -> { return !BUILD.permissionPredicate.test(bauweltMember); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index 1a7e1551..9f53f563 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -43,24 +43,27 @@ public class InfoCommand extends SWCommand { } } - List members = BauweltMember.getMembers(bauServer.getOwnerID()); - StringBuilder membermessage = new StringBuilder(); - membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size())); + if (Permission.BUILD.hasPermission(p)) { + List members = BauweltMember.getMembers(bauServer.getOwnerID()); + StringBuilder membermessage = new StringBuilder(); + membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size())); - for (int i = 0; i < members.size(); i++) { - if (i != 0) { - membermessage.append(", "); - } - BauweltMember member = members.get(i); - if (Permission.SUPERVISOR.hasPermission(member)) { - membermessage.append("§c").append(SteamwarUser.get(member.getMemberID()).getUserName()); - } else if (Permission.BUILD.hasPermission(member)) { - membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName()); - } else { - membermessage.append("§7").append(SteamwarUser.get(member.getMemberID()).getUserName()); + for (int i = 0; i < members.size(); i++) { + if (i != 0) { + membermessage.append("§8, "); + } + BauweltMember member = members.get(i); + if (Permission.SUPERVISOR.hasPermission(member)) { + membermessage.append("§e"); + } else if (Permission.BUILD.hasPermission(member)) { + membermessage.append("§6"); + } else { + membermessage.append("§7"); + } + membermessage.append(SteamwarUser.get(member.getMemberID()).getUserName()); } + p.sendMessage(membermessage.toString()); } - p.sendMessage(membermessage.toString()); StringBuilder tpsMessage = new StringBuilder(); tpsMessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_TPS", p)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java index 7956a3ef..df4935dc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.world; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.utils.PlaceItemUtils; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; @@ -81,6 +82,7 @@ public class SignEditFrom20 implements Listener { } private void edit(Player player, Block block) { + if (Permission.SPECTATOR.hasPermission(player)) return; Sign sign = (Sign) block.getState(); Side side = signSide(player, block); SignSide signSide = sign.getSide(side); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java index 19184032..89a4120d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.world; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MaxVersion; import org.bukkit.Bukkit; @@ -68,6 +69,7 @@ public class SignEditUntil19 implements Listener { } private void edit(Player player, Block block) { + if (Permission.SPECTATOR.hasPermission(player)) return; Sign sign = (org.bukkit.block.Sign) block.getState(); String[] lines = sign.getLines(); for (int i = 0; i < lines.length; i++) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index f80661aa..a15c1e4f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -27,10 +27,11 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockCanBuildEvent; -import org.bukkit.event.block.BlockMultiPlaceEvent; -import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityEnterBlockEvent; +import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; @@ -73,7 +74,7 @@ public class SpectatorListener implements Listener { } } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + @EventHandler public void onInventoryClick(InventoryClickEvent event) { ItemStack itemStack = event.getCurrentItem(); if (itemStack == null || !itemStack.hasItemMeta()) { @@ -161,4 +162,19 @@ public class SpectatorListener implements Listener { event.setCancelled(true); } } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerDropItem(PlayerDropItemEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onEntityPickupItem(EntityPickupItemEvent event) { + if (!(event.getEntity() instanceof Player)) return; + if (Permission.SPECTATOR.hasPermission((Player) event.getEntity())) { + event.setCancelled(true); + } + } } From 006a0edef67380648db0c2540eb94944a6c73980 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 21:36:13 +0100 Subject: [PATCH 071/139] Add SimulatorBauGuiItem back --- .../simulator/SimulatorBauGuiItem.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java new file mode 100644 index 00000000..86476fe6 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java @@ -0,0 +1,60 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.linkage.specific.BauGuiItem; +import de.steamwar.inventory.SWItem; +import de.steamwar.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +@Linked +public class SimulatorBauGuiItem extends BauGuiItem { + + public SimulatorBauGuiItem() { + super(20); + } + + @Override + public ItemStack getItem(Player player) { + ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_GUI_ITEM_NAME", player)).getItemStack(); + ItemMeta itemMeta = itemStack.getItemMeta(); + itemMeta.setCustomModelData(1); + itemStack.setItemMeta(itemMeta); + return itemStack; + } + + @Override + public boolean click(ClickType click, Player p) { + p.closeInventory(); + p.performCommand("sim"); + return false; + } + + @Override + public Permission permission() { + return Permission.WORLD; + } +} From 5556bd7875548bc5210989cb1dacc006bf894b44 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 21:39:25 +0100 Subject: [PATCH 072/139] Update SimulatorBauGuiItem Permission --- .../bausystem/features/simulator/SimulatorBauGuiItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java index 86476fe6..d03dc55c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java @@ -55,6 +55,6 @@ public class SimulatorBauGuiItem extends BauGuiItem { @Override public Permission permission() { - return Permission.WORLD; + return Permission.BUILD; } } From 3d0ebbe74389bb32005014c527599c9a52c27baa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 22:22:53 +0100 Subject: [PATCH 073/139] Fix TNTPhase spawning in frozen Region --- .../bausystem/features/simulator/data/tnt/TNTPhase.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java index 4af3dc15..2e913bdd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java @@ -21,9 +21,14 @@ package de.steamwar.bausystem.features.simulator.data.tnt; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import de.steamwar.bausystem.region.tags.Tag; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; @@ -59,7 +64,9 @@ public final class TNTPhase extends SimulatorPhase { tickStart.accept(tickOffset, new SimulatorAction(order, count) { @Override public void accept(World world) { - TNTPrimed tnt = world.spawn(position.toLocation(world), TNTPrimed.class); + Location location = position.toLocation(world); + if (Region.getRegion(location).get(Flag.FREEZE) == FreezeMode.ACTIVE) return; + TNTPrimed tnt = world.spawn(location, TNTPrimed.class); if (!xJump) tnt.setVelocity(tnt.getVelocity().setX(0)); if (!yJump) tnt.setVelocity(tnt.getVelocity().setY(0)); if (!zJump) tnt.setVelocity(tnt.getVelocity().setZ(0)); From 4ff706e1ef9d0342a04eddc81a68757f81f3d901 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 17 Dec 2023 12:20:36 +0100 Subject: [PATCH 074/139] Fix Gui --- .../simulator/gui/SimulatorRedstoneGui.java | 14 +++++++------- .../features/simulator/gui/SimulatorTNTGui.java | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java index 1475cee4..2e288895 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorRedstoneGui.java @@ -101,20 +101,20 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui { + inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open(); })); - // Group chooser - inventory.setItem(49, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { - new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open(); - })); - // Enable/Disable - inventory.setItem(50, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + inventory.setItem(48, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { redstone.setDisabled(!redstone.isDisabled()); SimulatorWatcher.update(simulator); })); + + // Group chooser + inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { + new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open(); + })); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java index a6d6c944..a9c178ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTGui.java @@ -93,8 +93,9 @@ public class SimulatorTNTGui extends SimulatorScrollGui { inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); })); - inventory.setItem(48, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { - new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); + inventory.setItem(48, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + tnt.setDisabled(!tnt.isDisabled()); + SimulatorWatcher.update(simulator); })); inventory.setItem(50, new SWItem(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> { TNTElement tntElement = new TNTElement(tnt.getPosition().clone()); @@ -103,9 +104,8 @@ public class SimulatorTNTGui extends SimulatorScrollGui { new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open(); SimulatorWatcher.update(simulator); })); - inventory.setItem(51, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { - tnt.setDisabled(!tnt.isDisabled()); - SimulatorWatcher.update(simulator); + inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { + new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); })); } From f6644d8ad81550e16a02193c01bd6392c056b6be Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 17 Dec 2023 12:24:01 +0100 Subject: [PATCH 075/139] Fix Gui not populated on tpslimit 0 --- .../features/simulator/gui/base/SimulatorBaseGui.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java index 9f79a613..1be012f3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java @@ -62,6 +62,7 @@ public abstract class SimulatorBaseGui { player.getOpenInventory().setTitle(title()); } populate(); + inventory.open(); return; } @@ -76,9 +77,9 @@ public abstract class SimulatorBaseGui { SimulatorWatcher.watch(player, null, null); }); - inventory.open(); SimulatorWatcher.watch(player, simulator, this::open); populate(); + inventory.open(); } private void setup() { From 17c03f629a54570cd2a7137ea64b05396606c4de Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 17 Dec 2023 12:48:05 +0100 Subject: [PATCH 076/139] Fix SimulatorBaseGui open --- .../features/simulator/gui/base/SimulatorBaseGui.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java index 1be012f3..41f95a88 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/base/SimulatorBaseGui.java @@ -62,7 +62,10 @@ public abstract class SimulatorBaseGui { player.getOpenInventory().setTitle(title()); } populate(); - inventory.open(); + if (player.getOpenInventory().getTopInventory() == inv) { + inventory.open(); + SimulatorWatcher.watch(player, simulator, this::open); + } return; } From 19bb7cc73303e108e172cadad4a27cbab973ec1f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 17 Dec 2023 13:07:48 +0100 Subject: [PATCH 077/139] Fix synchronized errors --- .../features/simulator/SimulatorCursor.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 6ff78e19..911872ba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -58,10 +58,7 @@ import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; @@ -77,6 +74,7 @@ public class SimulatorCursor implements Listener { private Map cursorType = Collections.synchronizedMap(new HashMap<>()); private Map cursors = Collections.synchronizedMap(new HashMap<>()); + private final Set calculating = new HashSet<>(); public static boolean isSimulatorItem(ItemStack itemStack) { return ItemUtils.isItem(itemStack, "simulator"); @@ -115,6 +113,9 @@ public class SimulatorCursor implements Listener { public void onPlayerQuit(PlayerQuitEvent event) { cursorType.remove(event.getPlayer()); cursors.remove(event.getPlayer()); + synchronized (calculating) { + calculating.remove(event.getPlayer()); + } } private static final Map LAST_SNEAKS = new HashMap<>(); @@ -141,11 +142,18 @@ public class SimulatorCursor implements Listener { } } - public synchronized void calcCursor(Player player) { + public void calcCursor(Player player) { + synchronized (calculating) { + if (calculating.contains(player)) return; + calculating.add(player); + } if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { if (removeCursor(player) || SimulatorWatcher.show(null, player)) { SWUtils.sendToActionbar(player, ""); } + synchronized (calculating) { + calculating.remove(player); + } return; } Simulator simulator = SimulatorStorage.getSimulator(player); @@ -160,10 +168,16 @@ public class SimulatorCursor implements Listener { } else { SWUtils.sendToActionbar(player, "§eOpen Simulator"); } + synchronized (calculating) { + calculating.remove(player); + } return; } showCursor(player, rayTraceResult, simulator != null); + synchronized (calculating) { + calculating.remove(player); + } } private synchronized boolean removeCursor(Player player) { From 4f266a30abb46a1ee5fdb2306d6eae6b8aa8a064 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 20 Dec 2023 20:39:23 +0100 Subject: [PATCH 078/139] Fix StorageLib in 1.15 --- .../bausystem/features/script/lua/libs/StorageLib.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java index 8967951d..898b68a7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/StorageLib.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.script.lua.libs; import com.google.gson.*; import de.steamwar.bausystem.region.Region; +import de.steamwar.core.Core; import de.steamwar.linkage.Linked; import de.steamwar.linkage.api.Disable; import de.steamwar.linkage.api.Enable; @@ -54,6 +55,7 @@ public class StorageLib implements LuaLib, Enable, Disable { @Override public void enable() { + if (Core.getVersion() <= 15) return; if (!storageDirectory.exists()) storageDirectory.mkdirs(); try { @@ -129,6 +131,7 @@ public class StorageLib implements LuaLib, Enable, Disable { @Override public void disable() { + if (Core.getVersion() <= 15) return; if (!storageDirectory.exists()) storageDirectory.mkdirs(); try { FileWriter fileWriter = new FileWriter(new File(storageDirectory, "global.json")); From bff63482ef0139ef1843de931afb6a8a21c5fc3f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 08:44:54 +0100 Subject: [PATCH 079/139] Add BauLockStateScoreboard --- BauSystem_Main/src/BauSystem.properties | 5 ++ BauSystem_Main/src/BauSystem_de.properties | 5 ++ .../world/BauLockStateScoreboard.java | 68 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/BauLockStateScoreboard.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 27ca6f67..c7f98ce5 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -40,6 +40,11 @@ SCOREBOARD_TRACE_TICKS = Ticks SCOREBOARD_TECHHIDER = TechHider§8: §aOn SCOREBOARD_XRAY = XRay§8: §aOn +SCOREBOARD_LOCK_TEAM = Bau Lock§8: §eTeam +SCOREBOARD_LOCK_TEAM_AND_SERVERTEAM = Bau Lock§8: §e(Server) Team +SCOREBOARD_LOCK_SERVERTEAM = Bau Lock§8: §eServer Team +SCOREBOARD_LOCK_NOBODY = Bau Lock§8: §cNobody + # Flags FLAG_COLOR = Color FLAG_TNT = TNT diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 439267cf..2186282a 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -40,6 +40,11 @@ SCOREBOARD_TRACE_TICKS = Ticks SCOREBOARD_TECHHIDER = TechHider§8: §aAn SCOREBOARD_XRAY = XRay§8: §aAn +SCOREBOARD_LOCK_TEAM = Bau Lock§8: §eTeam +SCOREBOARD_LOCK_TEAM_AND_SERVERTEAM = Bau Lock§8: §e(Server-) Team +SCOREBOARD_LOCK_SERVERTEAM = Bau Lock§8: §eServerteam +SCOREBOARD_LOCK_NOBODY = Bau Lock§8: §cNiemand + # Flags FLAG_COLOR = Color FLAG_TNT = TNT diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauLockStateScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauLockStateScoreboard.java new file mode 100644 index 00000000..ab3630d4 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauLockStateScoreboard.java @@ -0,0 +1,68 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.world; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.config.BauServer; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import de.steamwar.sql.UserConfig; +import org.bukkit.entity.Player; + +@Linked +public class BauLockStateScoreboard implements ScoreboardElement { + + private static final String BAU_LOCK_CONFIG_NAME = "baulockstate"; + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.FOOTER; + } + + @Override + public int order() { + return -10; + } + + @Override + public String get(Region region, Player p) { + if (!BauServer.getInstance().getOwner().equals(p.getUniqueId())) { + return null; + } + String state = UserConfig.getConfig(p.getUniqueId(), BAU_LOCK_CONFIG_NAME); + switch (state == null ? BauLockState.OPEN : BauLockState.valueOf(state)) { + case OPEN: + return null; + default: + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOCK_" + state.toUpperCase(), p); + } + } + + public enum BauLockState { + + NOBODY, + SERVERTEAM, + TEAM_AND_SERVERTEAM, + TEAM, + OPEN + } + +} From ec10b0fe710d878c13d9374b29a93885cce69159 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 09:01:54 +0100 Subject: [PATCH 080/139] Add Observer to Simulator --- .../features/simulator/SimulatorCursor.java | 14 +- .../data/SimulatorBlockAlignedElement.java | 35 ++++ .../data/observer/ObserverElement.java | 103 ++++++++++ .../data/observer/ObserverPhase.java | 81 ++++++++ .../data/redstone/RedstoneElement.java | 9 +- .../simulator/gui/SimulatorObserverGui.java | 188 ++++++++++++++++++ .../SimulatorObserverPhaseSettingsGui.java | 172 ++++++++++++++++ .../gui/SimulatorObserverSettingsGui.java | 142 +++++++++++++ .../storage/SimFormatSimulatorLoader.java | 6 + 9 files changed, 739 insertions(+), 11 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorBlockAlignedElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverPhase.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 911872ba..83b373ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -26,6 +26,8 @@ import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorElement; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; @@ -230,7 +232,7 @@ public class SimulatorCursor implements Listener { } } - public static Vector getPosTNT(Player player, RayTraceUtils.RRayTraceResult result) { + public static Vector getPosFree(Player player, RayTraceUtils.RRayTraceResult result) { Vector pos = result.getHitPosition(); BlockFace face = result.getHitBlockFace(); @@ -270,7 +272,7 @@ public class SimulatorCursor implements Listener { return pos; } - private static Vector getPosRedstoneBlock(Player player, RayTraceUtils.RRayTraceResult result) { + private static Vector getPosBlockAligned(Player player, RayTraceUtils.RRayTraceResult result) { Vector pos = result.getHitPosition(); BlockFace face = result.getHitBlockFace(); @@ -309,8 +311,9 @@ public class SimulatorCursor implements Listener { @Getter @AllArgsConstructor public enum CursorType { - TNT(Material.TNT, SimulatorCursor::getPosTNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())), - REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())), + TNT(Material.TNT, SimulatorCursor::getPosFree, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())), + REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosBlockAligned, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())), + OBSERVER(Material.OBSERVER, SimulatorCursor::getPosBlockAligned, "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase())), ; private Material material; @@ -322,6 +325,9 @@ public class SimulatorCursor implements Listener { if (this == TNT) { return REDSTONE_BLOCK; } + if (this == REDSTONE_BLOCK) { + return OBSERVER; + } return TNT; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorBlockAlignedElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorBlockAlignedElement.java new file mode 100644 index 00000000..de0d2b69 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/SimulatorBlockAlignedElement.java @@ -0,0 +1,35 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.data; + +import org.bukkit.Material; +import org.bukkit.util.Vector; + +public abstract class SimulatorBlockAlignedElement extends SimulatorElement { + + protected SimulatorBlockAlignedElement(Material material, Vector position) { + super(material, position); + } + + @Override + public final boolean canBeInGroup(SimulatorGroup simulatorGroup) { + return simulatorGroup.getElements().stream().allMatch(SimulatorBlockAlignedElement.class::isInstance); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverElement.java new file mode 100644 index 00000000..9c7f36d5 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverElement.java @@ -0,0 +1,103 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.data.observer; + +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorBlockAlignedElement; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; +import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; +import de.steamwar.bausystem.features.simulator.gui.SimulatorObserverGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.inventory.InvCallback; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.util.Vector; + +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiConsumer; + +public final class ObserverElement extends SimulatorBlockAlignedElement { + + public ObserverElement(Vector position) { + super(Material.OBSERVER, position); + } + + @Override + public String getName(Player player) { + return "Observer"; + } + + @Override + public Material getWorldMaterial() { + return Material.OBSERVER; + } + + @Override + public Material getWorldDisabledMaterial() { + return Material.GRAY_STAINED_GLASS; + } + + public void toSimulatorActions(BiConsumer tickStart, BiConsumer tickEnd) { + if (disabled) return; + phases.forEach(phase -> { + phase.toSimulatorActions(position.clone(), tickStart, tickEnd); + }); + + int end = phases.stream().mapToInt(SimulatorPhase::getTickOffset).max().orElse(0) + 4; + AtomicReference blockState = new AtomicReference<>(); + tickStart.accept(0, new SimulatorAction(-100, 1) { + @Override + public void accept(World world) { + Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + blockState.set(block.getState()); + block.setType(Material.OBSERVER, false); + } + }); + tickEnd.accept(end, new SimulatorAction(0, 1) { + @Override + public void accept(World world) { + BlockState oldState = blockState.get(); + if (oldState != null) { + oldState.update(true, true); + } else { + Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + block.setType(Material.AIR); + } + } + }); + } + + @Override + public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) { + new SimulatorObserverGui(player, simulator, group, this, back).open(); + } + + @Override + public String getType() { + return "Observer"; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverPhase.java new file mode 100644 index 00000000..e3707c3e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverPhase.java @@ -0,0 +1,81 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.data.observer; + +import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.type.Observer; +import org.bukkit.util.Vector; +import yapion.hierarchy.types.YAPIONObject; + +import java.util.function.BiConsumer; + +@NoArgsConstructor +public final class ObserverPhase extends SimulatorPhase { + + @Getter + @Setter + private BlockFace orientation = BlockFace.UP; + + public ObserverPhase(int tickOffset) { + this.tickOffset = tickOffset; + } + + { + this.lifetime = 0; + } + + @Override + public void toSimulatorActions(Vector position, BiConsumer tickStart, BiConsumer tickEnd) { + Observer observer = (Observer) Material.OBSERVER.createBlockData(); + observer.setFacing(orientation.getOppositeFace()); + observer.setPowered(true); + + tickStart.accept(tickOffset, new SimulatorAction(order, 1) { + @Override + public void accept(World world) { + Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + Block updateBlock = block.getRelative(orientation); + BlockState state = updateBlock.getState(); + updateBlock.setType(Material.SPONGE, true); + block.setBlockData(observer, true); + state.update(true, true); + } + }); + } + + @Override + public void saveExtra(YAPIONObject phaseObject) { + phaseObject.add("orientation", orientation.name()); + } + + @Override + public void loadExtra(YAPIONObject phaseObject) { + orientation = BlockFace.valueOf(phaseObject.getPlainValue("orientation")); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java index 2eb7aca2..9a970526 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java @@ -19,8 +19,8 @@ package de.steamwar.bausystem.features.simulator.data.redstone; +import de.steamwar.bausystem.features.simulator.data.SimulatorBlockAlignedElement; import de.steamwar.bausystem.features.simulator.data.Simulator; -import de.steamwar.bausystem.features.simulator.data.SimulatorElement; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.gui.SimulatorRedstoneGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; @@ -28,7 +28,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -public final class RedstoneElement extends SimulatorElement { +public final class RedstoneElement extends SimulatorBlockAlignedElement { public RedstoneElement(Vector position) { super(Material.REDSTONE_BLOCK, position); @@ -49,11 +49,6 @@ public final class RedstoneElement extends SimulatorElement { return Material.WHITE_STAINED_GLASS; } - @Override - public boolean canBeInGroup(SimulatorGroup simulatorGroup) { - return simulatorGroup.getElements().stream().allMatch(RedstoneElement.class::isInstance); - } - @Override public Vector getWorldPos() { return position.clone().add(new Vector(0.5, 0, 0.5)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java new file mode 100644 index 00000000..42669387 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverGui.java @@ -0,0 +1,188 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class SimulatorObserverGui extends SimulatorScrollGui { + + private final SimulatorGroup parent; + private final ObserverElement observer; + private final SimulatorBaseGui back; + + public SimulatorObserverGui(Player player, Simulator simulator, SimulatorGroup parent, ObserverElement observer, SimulatorBaseGui back) { + super(player, simulator, 6 * 9, observer.getPhases()); + this.parent = parent; + this.observer = observer; + this.back = back; + } + + @Override + public String baseTitle() { + return "Observer"; + } + + @Override + public void headerAndFooter() { + if (observer.getPhases().isEmpty()) { + back.open(); + SimulatorWatcher.update(simulator); + return; + } + + observer.sort(); + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + if (parent.getElements().contains(observer)) { + back.open(); + } else { + SimulatorGroup newParent = observer.getGroup(simulator); + if (newParent == null) { + player.closeInventory(); + return; + } + SimulatorGui simulatorGui = new SimulatorGui(player, simulator); + if (newParent.getElements().size() == 1) { + simulatorGui.open(); + } else { + new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open(); + } + } + })); + + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + observer.getPhases().clear(); + SimulatorWatcher.update(simulator); + })); + + // Material Chooser + inventory.setItem(4, observer.toItem(player, clickType -> { + new SimulatorMaterialGui(player, simulator, observer::getMaterial, observer::setMaterial, this).open(); + })); + + // Settings + inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { + new SimulatorObserverSettingsGui(player, simulator, observer, this).open(); + })); + + // Enable/Disable + inventory.setItem(48, new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { + observer.setDisabled(!observer.isDisabled()); + SimulatorWatcher.update(simulator); + })); + + // Group chooser + inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { + new SimulatorGroupChooserGui(player, simulator, observer, observer.getGroup(simulator), this).open(); + })); + } + + @Override + public SWItem[] column(ObserverPhase observerPhase, int index) { + int min; + if (index > 0) { + min = data.get(index - 1).getTickOffset() + 4; + } else { + min = 0; + } + + int max; + if (index < data.size() - 1) { + max = data.get(index + 1).getTickOffset() - 4; + } else { + max = Integer.MAX_VALUE - 4; + } + + List lore = new ArrayList<>(); + lore.add("§7Time§8:§e " + observerPhase.getTickOffset()); + lore.add("§7Order§8:§e " + observerPhase.getOrder()); + lore.add(""); + lore.add("§7Orientation§8:§e " + observerPhase.getOrientation().name()); + lore.add(""); + lore.add("§7Click§8:§e Edit"); + lore.add("§7Middle-Click§8:§e Remove"); + SWItem observer = new SWItem(Material.OBSERVER, "§eObserver", lore, false, clickType -> { + if (clickType == ClickType.MIDDLE) { + this.observer.getPhases().remove(observerPhase); + SimulatorWatcher.update(simulator); + } else { + new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open(); + } + }); + observer.getItemStack().setAmount(Math.min(Math.max(observerPhase.getTickOffset(), 1), 64)); + + Supplier getter = observerPhase::getTickOffset; + Consumer setter = observerPhase::setTickOffset; + return new SWItem[] { + new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); + SimulatorWatcher.update(simulator); + }), + observer, + new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { + setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); + SimulatorWatcher.update(simulator); + }), + new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> { + new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open(); + }), + }; + } + + @Override + public SWItem[] lastColumn() { + return new SWItem[]{ + new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { + addNewPhase(clickType.isShiftClick()); + }), + new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> { + addNewPhase(false); + }), + new SWItem(SWItem.getDye(8), "§7", clickType -> { + }), + }; + } + + private void addNewPhase(boolean shift) { + ObserverPhase lastElement = observer.getPhases().get(observer.getPhases().size() - 1); + ObserverPhase newPhase = new ObserverPhase(lastElement.getTickOffset() + 4); + if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5); + scroll += 2; + observer.add(newPhase); + SimulatorWatcher.update(simulator); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java new file mode 100644 index 00000000..f7925c34 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverPhaseSettingsGui.java @@ -0,0 +1,172 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.core.Core; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; + +import java.util.Arrays; + +public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui { + + private final ObserverElement observerElement; + private final ObserverPhase observer; + private final SimulatorBaseGui back; + + public SimulatorObserverPhaseSettingsGui(Player player, Simulator simulator, ObserverElement observerElement, ObserverPhase observer, SimulatorBaseGui back) { + super(player, simulator, 5 * 9); + this.observerElement = observerElement; + this.observer = observer; + this.back = back; + } + + @Override + public String title() { + return "Observer"; + } + + @Override + public void populate() { + if (!observerElement.getPhases().contains(observer)) { + back.open(); + return; + } + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + inventory.setItem(4, observerElement.toItem(player, clickType -> { + new SimulatorMaterialGui(player, simulator, observerElement::getMaterial, observerElement::setMaterial, this).open(); + })); + + // Delete + inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { + observerElement.getPhases().remove(observer); + back.open(); + SimulatorWatcher.update(simulator); + })); + + int index = observerElement.getPhases().indexOf(observer); + int min; + if (index > 0) { + ObserverPhase previous = observerElement.getPhases().get(index - 1); + min = previous.getTickOffset() + 4; + } else { + min = 0; + } + + int max; + if (index < observerElement.getPhases().size() - 1) { + ObserverPhase next = observerElement.getPhases().get(index + 1); + max = next.getTickOffset() - 4; + } else { + max = Integer.MAX_VALUE - 4; + } + + //Tick Offset + int offset = observer.getTickOffset(); + inventory.setItem(10, SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + observer.setTickOffset(Math.min(max, offset + (clickType.isShiftClick() ? 5 : 1))); + SimulatorWatcher.update(simulator); + }); + + SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { + new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + observer.setTickOffset(Math.min(Math.max(integer, min), max)); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.REPEATER).open(); + }); + offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); + inventory.setItem(19, offsetItem); + + inventory.setItem(28, SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + observer.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); + SimulatorWatcher.update(simulator); + }); + + //Order + int order = observer.getOrder(); + inventory.setItem(13, SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); + SimulatorWatcher.update(simulator); + }); + + Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); + SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { + new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> { + if (integer < -SimulatorPhase.ORDER_LIMIT) return false; + if (integer > SimulatorPhase.ORDER_LIMIT) return false; + observer.setOrder(integer); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open(); + }); + orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); + inventory.setItem(22, orderItem); + + inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); + SimulatorWatcher.update(simulator); + }); + + // Update orientation + inventory.setItem(25, new SWItem(Material.SUNFLOWER, "§7", clickType -> { + })); + inventory.setItem(15, new SWItem(observer.getOrientation() == BlockFace.UP ? Material.LIME_CONCRETE : Material.GRAY_CONCRETE, "§eUp", clickType -> { + observer.setOrientation(BlockFace.UP); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(33, new SWItem(observer.getOrientation() == BlockFace.DOWN ? Material.RED_CONCRETE : Material.GRAY_CONCRETE, "§eDown", clickType -> { + observer.setOrientation(BlockFace.DOWN); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(16, new SWItem(observer.getOrientation() == BlockFace.NORTH ? Material.LIME_WOOL : Material.GRAY_WOOL, "§eNorth", clickType -> { + observer.setOrientation(BlockFace.NORTH); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(34, new SWItem(observer.getOrientation() == BlockFace.SOUTH ? Material.RED_WOOL : Material.GRAY_WOOL, "§eSouth", clickType -> { + observer.setOrientation(BlockFace.SOUTH); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(24, new SWItem(observer.getOrientation() == BlockFace.EAST ? Material.LIME_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eEast", clickType -> { + observer.setOrientation(BlockFace.EAST); + SimulatorWatcher.update(simulator); + })); + inventory.setItem(26, new SWItem(observer.getOrientation() == BlockFace.WEST ? Material.RED_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eWest", clickType -> { + observer.setOrientation(BlockFace.WEST); + SimulatorWatcher.update(simulator); + })); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java new file mode 100644 index 00000000..8084c7b1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorObserverSettingsGui.java @@ -0,0 +1,142 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.bausystem.features.simulator.SimulatorWatcher; +import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; +import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Arrays; + +public class SimulatorObserverSettingsGui extends SimulatorBaseGui { + + private final ObserverElement observer; + private final SimulatorBaseGui back; + + public SimulatorObserverSettingsGui(Player player, Simulator simulator, ObserverElement observer, SimulatorBaseGui back) { + super(player, simulator, 5 * 9); + this.observer = observer; + this.back = back; + } + + @Override + public String title() { + return "Observer"; + } + + @Override + public void populate() { + if (observer.getPhases().isEmpty()) { + back.open(); + return; + } + + // Back Arrow + inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> { + back.open(); + })); + + // Material Chooser + inventory.setItem(4, observer.toItem(player, clickType -> { + new SimulatorMaterialGui(player, simulator, observer::getMaterial, observer::setMaterial, this).open(); + })); + + // Base Tick + int baseTicks = observer.getBaseTick(); + inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + observer.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { + new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { + if (integer < 0) return false; + observer.changeBaseTicks(integer - baseTicks); + SimulatorWatcher.update(simulator); + return true; + }, this).setItem(Material.REPEATER).open(); + }); + baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64))); + inventory.setItem(18, baseTick); + inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) { + observer.changeBaseTicks(-baseTicks); + } else { + observer.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); + } + SimulatorWatcher.update(simulator); + }); + + //Pos X + inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + observer.move(clickType.isShiftClick() ? 5 : 1, 0, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + observer.getPosition().getBlockX(), clickType -> { + new SimulatorAnvilGui<>(player, "X", observer.getPosition().getBlockX() + "", Integer::parseInt, i -> { + observer.getPosition().setX(i); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); + })); + inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + observer.move(clickType.isShiftClick() ? -5 : -1, 0, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Y + inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + observer.move(0, clickType.isShiftClick() ? 5 : 1, 0); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + observer.getPosition().getBlockY(), clickType -> { + new SimulatorAnvilGui<>(player, "Y", observer.getPosition().getBlockY() + "", Integer::parseInt, i -> { + observer.getPosition().setY(i); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); + })); + inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + observer.move(0, clickType.isShiftClick() ? -5 : -1, 0); + SimulatorWatcher.update(simulator); + }); + + //Pos Z + inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { + observer.move(0, 0, clickType.isShiftClick() ? 5 : 1); + SimulatorWatcher.update(simulator); + }); + inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + observer.getPosition().getBlockZ(), clickType -> { + new SimulatorAnvilGui<>(player, "Z", observer.getPosition().getBlockZ() + "", Integer::parseInt, i -> { + observer.getPosition().setZ(i); + SimulatorWatcher.update(simulator); + return true; + }, this).open(); + })); + inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { + observer.move(0, 0, clickType.isShiftClick() ? -5 : -1); + SimulatorWatcher.update(simulator); + }); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java index 15af2e4a..218c89a4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimFormatSimulatorLoader.java @@ -23,6 +23,8 @@ import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorElement; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; +import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; @@ -94,6 +96,10 @@ public class SimFormatSimulatorLoader implements SimulatorLoader { element = new RedstoneElement(position); phaseConstructor = RedstonePhase::new; break; + case "Observer": + element = new ObserverElement(position); + phaseConstructor = ObserverPhase::new; + break; default: element = null; phaseConstructor = null; From 2cfed8b84d2cb59f497a3cd05d65a201251c9c97 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 09:24:49 +0100 Subject: [PATCH 081/139] Fix CancelPacketHandleException in SmartPlaceListener --- .../features/smartplace/SmartPlaceListener.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index f3ab68bf..61b69c31 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -103,9 +103,14 @@ public class SmartPlaceListener implements Plain, Listener { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { if (sneaking) SMART_PLACING.add(player); player.setSneaking(shouldSneak || sneaking); - packetExecutor.invoke(playerConnection.get(getHandle.invoke(player)), packet); - SMART_PLACING.remove(player); - player.setSneaking(sneaking); + try { + packetExecutor.invoke(playerConnection.get(getHandle.invoke(player)), packet); + } catch (Exception e) { + return; + } finally { + SMART_PLACING.remove(player); + player.setSneaking(sneaking); + } if (!WAS_EXECUTED.contains(player) && first) { run(player, packet, false, sneaking, shouldSneak); From 202e03c957a812532974fe5a7c52e6918e3f5f8e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 10:03:24 +0100 Subject: [PATCH 082/139] Fix SmartPlaceListener --- .../features/smartplace/SmartPlaceListener.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 61b69c31..b079d224 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -73,6 +73,7 @@ public class SmartPlaceListener implements Plain, Listener { IGNORED.add(Material.TNT); IGNORED.add(Material.REDSTONE_ORE); IGNORED.add(SWItem.getMaterial("BEEHIVE")); + IGNORED.add(SWItem.getMaterial("SEA_PICKLE")); IGNORED.remove(Material.STONE); IGNORED.remove(Material.BARRIER); } @@ -92,7 +93,18 @@ public class SmartPlaceListener implements Plain, Listener { TinyProtocol.instance.addFilter(useItem, (player, packet) -> { if (!Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false)) return packet; Block block = player.getTargetBlockExact(6); - boolean shouldSneak = !(block != null && (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) && !CONTAINERS.contains(block.getType()) && !IGNORED.contains(block.getType())); + boolean shouldSneak = false; + if (block != null) { + if (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) { + shouldSneak = true; + } + if (!CONTAINERS.contains(block.getType())) { + shouldSneak = false; + } + if (IGNORED.contains(block.getType())) { + shouldSneak = false; + } + } boolean sneaking = player.isSneaking(); run(player, packet, true, sneaking, shouldSneak); return null; From 0bf27db398eae5c18bc7813db4bc9c16604a53e5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 10:19:40 +0100 Subject: [PATCH 083/139] Fix SmartPlaceListener --- .../smartplace/SmartPlaceListener.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index b079d224..fc95224a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -112,23 +112,21 @@ public class SmartPlaceListener implements Plain, Listener { } private void run(Player player, Object packet, boolean first, boolean sneaking, boolean shouldSneak) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - if (sneaking) SMART_PLACING.add(player); - player.setSneaking(shouldSneak || sneaking); - try { - packetExecutor.invoke(playerConnection.get(getHandle.invoke(player)), packet); - } catch (Exception e) { - return; - } finally { - SMART_PLACING.remove(player); - player.setSneaking(sneaking); - } + if (sneaking) SMART_PLACING.add(player); + player.setSneaking(shouldSneak || sneaking); + try { + packetExecutor.invoke(playerConnection.get(getHandle.invoke(player)), packet); + } catch (Exception e) { + return; + } finally { + SMART_PLACING.remove(player); + player.setSneaking(sneaking); + } - if (!WAS_EXECUTED.contains(player) && first) { - run(player, packet, false, sneaking, shouldSneak); - } - WAS_EXECUTED.remove(player); - }, first ? 0 : 1); + if (!WAS_EXECUTED.contains(player) && first) { + run(player, packet, false, sneaking, shouldSneak); + } + WAS_EXECUTED.remove(player); } @EventHandler From 927ce1f49594827a24983010e2d843c1fa1012d9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 11:48:55 +0100 Subject: [PATCH 084/139] Fix SmartPlaceListener --- .../smartplace/SmartPlaceListener.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index fc95224a..3bc35100 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -40,6 +40,8 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.io.OutputStream; +import java.io.PrintStream; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -106,29 +108,16 @@ public class SmartPlaceListener implements Plain, Listener { } } boolean sneaking = player.isSneaking(); - run(player, packet, true, sneaking, shouldSneak); - return null; + if (sneaking) SMART_PLACING.add(player); + player.setSneaking(shouldSneak || sneaking); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + SMART_PLACING.remove(player); + player.setSneaking(sneaking); + }, 0); + return packet; }); } - private void run(Player player, Object packet, boolean first, boolean sneaking, boolean shouldSneak) { - if (sneaking) SMART_PLACING.add(player); - player.setSneaking(shouldSneak || sneaking); - try { - packetExecutor.invoke(playerConnection.get(getHandle.invoke(player)), packet); - } catch (Exception e) { - return; - } finally { - SMART_PLACING.remove(player); - player.setSneaking(sneaking); - } - - if (!WAS_EXECUTED.contains(player) && first) { - run(player, packet, false, sneaking, shouldSneak); - } - WAS_EXECUTED.remove(player); - } - @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return; From 8da1fdac58063a5d6825b7ebab2329569e175afe Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 14:57:54 +0100 Subject: [PATCH 085/139] Fix SmartPlaceListener --- .../features/smartplace/SmartPlaceListener.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 3bc35100..dad12d7e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -39,6 +39,7 @@ 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.inventory.ItemStack; import java.io.OutputStream; import java.io.PrintStream; @@ -100,7 +101,14 @@ public class SmartPlaceListener implements Plain, Listener { if (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) { shouldSneak = true; } - if (!CONTAINERS.contains(block.getType())) { + if (CONTAINERS.contains(block.getType())) { + ItemStack itemStack = player.getInventory().getItemInMainHand(); + if (itemStack.getType() == Material.TNT) { + if (block.getType() == Material.CHEST || block.getType() == Material.BARREL || block.getType().name().endsWith("SHULKER_BOX")) { + shouldSneak = false; + } + } + } else { shouldSneak = false; } if (IGNORED.contains(block.getType())) { From ca8a916042a05c82f580af20d385dc73bdf7a31d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 15:16:28 +0100 Subject: [PATCH 086/139] Optimize imports --- .../features/simulator/data/observer/ObserverElement.java | 4 ---- .../features/simulator/data/redstone/RedstoneElement.java | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverElement.java index 9c7f36d5..7fdff328 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/observer/ObserverElement.java @@ -23,18 +23,14 @@ import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorBlockAlignedElement; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; -import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import de.steamwar.bausystem.features.simulator.gui.SimulatorObserverGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; -import de.steamwar.inventory.InvCallback; -import de.steamwar.inventory.SWItem; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.Vector; import java.util.concurrent.atomic.AtomicReference; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java index 9a970526..3b949609 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstoneElement.java @@ -19,8 +19,8 @@ package de.steamwar.bausystem.features.simulator.data.redstone; -import de.steamwar.bausystem.features.simulator.data.SimulatorBlockAlignedElement; import de.steamwar.bausystem.features.simulator.data.Simulator; +import de.steamwar.bausystem.features.simulator.data.SimulatorBlockAlignedElement; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.gui.SimulatorRedstoneGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; From f5e4d725fe2ef6eac3d45d8755cf907588156324 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Dec 2023 16:55:41 +0100 Subject: [PATCH 087/139] Add BauMemberUpdate and BauMemberUpdateEvent --- .../features/world/BauMemberUpdate.java | 50 +++++++++++++++++++ .../bausystem/utils/BauMemberUpdateEvent.java | 36 +++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/BauMemberUpdateEvent.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java new file mode 100644 index 00000000..fe90be02 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java @@ -0,0 +1,50 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.world; + +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.server.BaumemberUpdatePacket; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +@Linked +public class BauMemberUpdate extends PacketHandler { + + @Handler + public void baumemberUpdate(BaumemberUpdatePacket baumemberUpdatePacket) { + Bukkit.getPluginManager().callEvent(new BauMemberUpdateEvent()); + } + + @Linked + public static class TestCommand extends SWCommand { // TODO: Remove before merge + + public TestCommand() { + super("test"); + } + + @Register + public void test(Player player) { + PacketHandler.handlePacket(new BaumemberUpdatePacket()); + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/BauMemberUpdateEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/BauMemberUpdateEvent.java new file mode 100644 index 00000000..4d26dc6f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/BauMemberUpdateEvent.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.utils; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class BauMemberUpdateEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} From b00babdcbd208a920c01b3d916df030916109e1b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Dec 2023 08:01:38 +0100 Subject: [PATCH 088/139] Fix permission messages --- BauSystem_Main/src/BauSystem.properties | 50 ------------------- BauSystem_Main/src/BauSystem_de.properties | 50 ------------------- .../bausystem/features/gui/BauGUI.java | 2 +- .../features/world/SpectatorListener.java | 50 +++++-------------- .../bausystem/features/world/StopCommand.java | 2 +- .../features/world/WorldEditListener.java | 2 +- 6 files changed, 16 insertions(+), 140 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 0231d101..3928e0f4 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -119,7 +119,6 @@ BACKUP_HELP_LOAD=§8/§ebackup load §8[§7BackupName§8] §8- §7Load a region BACKUP_HELP_LIST=§8/§ebackup list §8- §7List all region backups BACKUP_HELP_GUI=§8/§ebackup gui §8- §7Open the backup GUI BACKUP_REGION_NO_REGION=§cYou are not inside any region -BACKUP_NO_PERMS=§You do not have permission to use the backup system BACKUP_CREATE_SUCCESS=§7Backup created BACKUP_CREATE_FAILURE=§cBackup failed BACKUP_CREATE_NO_CHANGE=§7No changes to save @@ -133,11 +132,6 @@ BACKUP_LORE=§eClick to load # Bau BAU_COMMAND_HELP_INFO = §8/§ebau info §8- §7Alias for §8/§ebauinfo -BAU_COMMAND_HELP_TOGGLEWE = §8/§ebau togglewe §8[§7Player§8] §8- §7Edit the WorldEdit permissions of a player -BAU_COMMAND_HELP_TOGGLEWORLD = §8/§ebau toggleworld §8[§7Player§8] §8- §7Edit the World permissions of a player -BAU_UNKNOWN_PLAYER = §cUnknown Player -BAU_NO_PLAYER = §cThe player is no member of your world! -BAU_NO_WORLD = §cThis is not your world! BAU_INFO_ITEM_NAME = §eBau-Management ## This is used in BauInfoBauGuiItem.java @@ -151,11 +145,6 @@ BAU_INFO_ITEM_LORE_ITEMS = §7Items§8: §e{0} BAU_INFO_COMMAND_HELP = §8/§ebauinfo §8- §7Information regarding this build server BAU_INFO_COMMAND_OWNER = §7Owner§8: §e{0} BAU_INFO_COMMAND_MEMBER = §7Member §8[§7{0}§8]§8: §e -BAU_INFO_MEMBER_INFO = §e{0}§8[{1}§8,{2}§8] §8 -BAU_INFO_MEMBER_WE_ALLOW = §aWE -BAU_INFO_MEMBER_WE_DISALLOW = §cWE -BAU_INFO_MEMBER_WORLD_ALLOW = §aW -BAU_INFO_MEMBER_WORLD_DISALLOW = §cW BAU_INFO_COMMAND_FLAG = §7{0}§8: §7{1} BAU_INFO_COMMAND_TPS = §7TPS§8:§e @@ -214,11 +203,6 @@ HOTBAR_INVENTORY=Standard hotbar # GUI GUI_EDITOR_ITEM_NAME=§eGui editor GUI_NAME=Bau GUI -GUI_NO_PERMISSION=§cYou do not have enough permissions for this -GUI_NO_OWNER=§cYou are not the owner of this World -GUI_NO_WORLD=§cYou do not have permissions to change the World -GUI_NO_WORLDEDIT=§cYou do not have permissions to use WorldEdit -GUI_NO_MEMBER=§cYou need to be a member of this World GUI_ITEM_LORE1=§7Use this item to open the bau gui GUI_ITEM_LORE2=§7or press swap hands twice. GUI_EDITOR_TITLE=Bau GUI Editor @@ -269,7 +253,6 @@ SHIELD_PRINTING_HELP_STEP_7 = §87. §7Apply the shield printing with §8/§eshi SHIELD_PRINTING_NO_REGION = §cYou are not in a region. SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. -SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here. SHIELD_PRINTING_BOSSBAR = §fMovements: {0} SHIELD_PRINTING_BOSSBAR_COPIED = §fMovements: {0} Copied: {1} @@ -306,7 +289,6 @@ SIMULATOR_CHANGE_HELP = §8/§esimulator change §8-§7 Change your simulator wa 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_COPY_HELP = §8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Copy the simulator -SIMULATOR_NO_PERMS = §cYou are not allowed to use the simulator here SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator @@ -485,7 +467,6 @@ TPSLIMIT_GUI_ITEM_NAME = §eTPS limiter TPSLIMIT_GUI_ITEM_LORE = §7Currently: §e{0} TPSLIMIT_ANVIL_GUI = New TPS limit TPSLIMIT_CURRENT = §7Current TPS limit§8: §e{0} -TPSLIMIT_NO_PERMS = §cYou are not allowed to use the TPS-Limiter here TPSLIMIT_SET = §eSet TPS limit to {0} TPSLIMIT_FROZEN = §eTPS frozen @@ -511,7 +492,6 @@ TRACE_MESSAGE_DELETE = §cAll TNT-positions deleted TRACE_MESSAGE_SHOW = §aAll TNT-positions shown TRACE_MESSAGE_HIDE = §cAll TNT-positions hidden TRACE_MESSAGE_CLICK_ISOLATE = §eClick to §aisolate§8/§cunisolate -TRACE_MESSAGE_DISALLOWED = §cYou are not allowed to use the TNT-Tracer here TRACE_MESSAGE_SHOW_AT = §aTNT-positions shown with {0} at {1} TRACE_MESSAGE_SHOW_FROM = §aAll TNT-positions shown with {0} from {1} TRACE_MESSAGE_SHOW_FROM_TO = §aAll TNT-positions shown with {0} from {1} to {2} @@ -700,7 +680,6 @@ OTHER_CLEAR_HELP_PLAYER=§8/§eclear §8[§7Player§8] §8- §7Clears a player i OTHER_CLEAR_CLEARED=Your inventory was cleared. OTHER_CLEAR_FROM=Your invetnory was cleared by {0}. OTHER_CLEAR_TO=The inventory of {0} §7was cleared. -OTHER_CLEAR_NO_PERMS=§cYou are not allowed to clear other's inventory here. OTHER_DECLUTTER_HELP=§8/§edeclutter §8- §7Organise your inventory OTHER_DECLUTTER_DONE=§aYour inventory was organised. OTHER_GAMEMODE_UNKNOWN=§cUnknown gamemode. @@ -716,7 +695,6 @@ OTHER_TELEPORT_SELF_2=§cBlocks left to travel: 0; ETA: 0:00 OTHER_TELEPORT_SELF_3=§cA little Movement is important. OTHER_TELEPORT_SELF_4=§cFor such a distance? OTHER_TIME_HELP=§8/§etime §8<§7Time 0=Morining§8, §76000=Midday§8, §718000=Midnight§8> - §7Sets the time on the Build -OTHER_TIME_NO_PERM=§cYou are not allowed to change the time here OTHER_TIME_INVALID=§cPlease input a time between 0 and 24000 OTHER_TIME_RESULT=§7§oWhooosh OTHER_TPS_HEAD = §7TPS: 1s 10s 1m 5m 10m @@ -782,17 +760,6 @@ MATERIAL_FLAMMABLE=§8- §eFlammable block MATERIAL_BURNABLE=§8- §eBurnable block MATERIAL_WATERLOGGABLE=§8- §eWaterloggable block MATERIAL_UNMOVABLE=§8- §eUnmovable block -# Redstonetester -RT_HELP=§8/§eredstonetester §8-§7 Gives you the redstone tester -RT_GIVEN=§7Measure the time between activation of components -RT_ITEM_NAME=§eRedstonetester -RT_ITEM_LORE_1=§eLeftclick block §8-§7 Sets the 1. Position -RT_ITEM_LORE_2=§eRightclick block §8-§7 Sets the 2. Position -RT_ITEM_LORE_3=§eShift-rightclick in air §8-§7 Reset -RT_LOC=§8: §e{0} {1} {2} -RT_INVALID_LOC=§cUnknown Position -RT_RESULT=§7Difference§8: §e{0}§7 Ticks §8,§7 R-Ticks §e{1} -RT_ACTIVATE=§7Positions deleted§8. # Region Items REGION_ITEM_COLOR=§7Color: §e{0} REGION_ITEM_COLOR_CHOOSE=Choose color @@ -818,24 +785,18 @@ REGION_COLOR_HELP_COLOR=§8/§ecolor §8[§7Color§8] §8- §7Sets the color of REGION_COLOR_HELP_COLOR_TYPE=§8/§ecolor §8[§7Color§8] §8[§7Type§8] §8- §7Sets the color of the region or globally REGION_COLOR_GLOBAL=§7All regions color set to §e{0} REGION_COLOR_NO_REGION=§cYou are currently not in any region -REGION_COLOR_NO_PERMS=§cThis is not your world! REGION_FIRE_HELP=§8/§efire §8- §7Toggle fire damage -REGION_FIRE_NO_PERMS=§cYou are not allowed to toggle fire damage here REGION_FIRE_ENABLED=§cFire damage deactivated in this region REGION_FIRE_DISABLED=§aFire damage activated in this region REGION_FREEZE_HELP=§8/§efreeze §8- §7Toggle Freeze -REGION_FREEZE_NO_PERMS=§cYou are not allowed to freeze this world REGION_FREEZE_ENABLED=§cRegion frozen REGION_FREEZE_DISABLED=§aRegion thawed REGION_ITEMS_HELP=§8/§eitems §8- §7Toggle Items -REGION_ITEMS_NO_PERMS=§cYou are not allowed to toggle items in this world REGION_ITEMS_ENABLED=§aItems enabled in this region -REGION_ITEMS_DISABLED_GLOBAL=§cItems disabled in this world REGION_ITEMS_DISABLED=§cItems disabled in this region REGION_PROTECT_HELP=§8/§eprotect §8- §7Protect the region REGION_PROTECT_DISABLE=§cProtection disabled REGION_PROTECT_ENABLE=§aProtection enabled -REGION_PROTECT_NO_PERMS=§cYou are not allowed to protect the floor here REGION_PROTECT_FALSE_REGION=§cYou are not currently in a (M)WG-region REGION_REGION_HELP_UNDO=§8/§eregion undo §8- §7undo the last 20 /testblock or /reset REGION_REGION_HELP_REDO=§8/§eregion redo §8- §7redo the last 20 §8/§7rg undo @@ -860,7 +821,6 @@ REGION_REGION_TP_COPY=§7Teleported to the copy point REGION_REGION_TP_TEST_BLOCK=§7Teleported to the tesblock REGION_REGION_TP_UNKNOWN=§cUndefined teleport point REGION_REGION_NO_REGION=§cYou are not inside any region -REGION_REGION_NO_PERMS=§cYou are not allowed to change the region REGION_REGION_CHANGETYPE_INFO=§7RRegion type is §e{0} REGION_REGION_CHANGETYPE_UNKNOWN=§cRegion type is invalid REGION_REGION_CHANGETYPE_INVALID=§cRegion type is not allowed here @@ -878,7 +838,6 @@ REGION_RESET_HELP_RESET=§8/§ereset §8- §7Resets the region REGION_RESET_HELP_SCHEMATIC=§8/§ereset §8[§7Schematic§8] §8- §7Resets the region using a schematic REGION_RESET_RESETED=§7Region reset REGION_RESET_ERROR=§cError reseting the region -REGION_RESET_NO_PERMS=§cYou are not allowed to reset the region here REGION_RESET_NO_REGION=§cYou are currently not in any region REGION_TB_HELP_RESET=§8/§etestblock §8- §7Reset the dummy REGION_TB_HELP_RESET_EXTENSION=§8/§etestblock §8[§7ExtensionType§8] §8- §7Reset the dummy @@ -886,7 +845,6 @@ REGION_TB_HELP_SCHEMATIC=§8/§etestblock §8[§7Schematic§8] §8- §7Reset the REGION_TB_HELP_SCHEMATIC_EXTENSION=§8/§etestblock §8[§7Schematic§8] §8[§7ExtensionType§8] §8- §7Reset the dummy using a schematic REGION_TB_DONE=§7Dummy reset REGION_TB_ERROR=§cError resetting the dummy -REGION_TB_NO_PERMS=§cYou are not allowed to reset the dummy here REGION_TB_NO_REGION=§cYou are currently not in any region REGION_TB_NO_SCHEMSHARING=§cYou currently cannot share schematics until {0}. REGION_TB_NO_SCHEMRECEIVING=§cThe Owner of this build server cannot receive any schematics until {0}. @@ -896,7 +854,6 @@ REGION_TNT_ON=§aTNT-Damage activated REGION_TNT_OFF=§cTNT-Damage deactivated REGION_TNT_TB=§aTNT-Damage activated outside the building area REGION_TNT_BUILD=§aTNT-Damage activated outside the testblok area -REGION_TNT_NO_PERMS=§cYou are not allowed to toggle tnt damage here REGION_TNT_BUILD_DESTROY=§cAn explosion would have destroyed blocks in the building area REGION_TNT_TB_DESTROY=§cAn explosion would have destroyed blocks in the testblock area @@ -915,7 +872,6 @@ PANZERN_PREPARE1 = §71. Check, if barrels reach until border of armor. PANZERN_PREPARE2 = §72. Carpet on the floor in walkways helps with armoring. PANZERN_PREPARE3 = §73. Shieldtechnology should be encased. PANZERN_PREPARE4 = §74. Standing in the region that is being armored can improve armoring. -PANZERN_NO_PERM = §cYou are not allowed to use the armoring system here PANZERN_NO_WORLDEDIT = §cYou have no WorldEdit selcetion PANZERN_PROGRESS = §e{0} §7Blocks left, §e{1} §7Blocks per second, §e{2} §7block delta PANZERN_DONE = §aDone @@ -925,7 +881,6 @@ LAUFBAU_HELP = §8/§elaufbau §8[§7smallest§8|§7blastresistant§8] §8- §7B LAUFBAU_HELP_SETTINGS = §8/§elaufbau settings §8- §7Opens the settings GUI LAUFBAU_PREPARE1 = §71. Trace the cannons as often as necessary, in all modes. LAUFBAU_PREPARE2 = §72. Try to delete all fails from the traces. -LAUFBAU_NO_PERM = §cYou are not allowed to use the barrel building system here LAUFBAU_NO_WORLDEDIT = §cYou don't have a WorldEdit selection LAUFBAU_STATE_FILTERING_TRACES = Filtering traces LAUFBAU_STATE_PROCESSING_TRACES = Connnecting traces @@ -1037,7 +992,6 @@ LAUFBAU_TILT_PARTIAL = §8-§7 Tilt partial # UTILS SELECT_HELP = §8/§eselect §8[§7RegionsTyp§8] §8- §7Select a region type SELECT_EXTENSION_HELP = §8/§eselect §8[§7RegionsTyp§8] §8[§7Extension§8] §8- §7Select a region type with or without extension -SELECT_NO_PERMS = §cYou are not allowed to use the slection tool here SELECT_GLOBAL_REGION = §cThe global region cannot be selected SELECT_NO_TYPE = §cThis region has no {0} SELECT_NO_EXTENSION = §cThis region has no extension @@ -1091,7 +1045,6 @@ PISTON_HELP_3 = §7Count is yellow, if too many blocks are present. PISTON_INFO = §7Moved Blocks {0}{1}§8/§712 # Warp -WARP_DISALLOWED = §cYou are not allowed to use the warp here WARP_LOC_X = §7X§8: §e{0} WARP_LOC_Y = §7Y§8: §e{0} WARP_LOC_Z = §7Z§8: §e{0} @@ -1117,12 +1070,9 @@ WARP_HELP_LIST=§8/§ewarp list §8- §7List all warps # WORLD STOP_HELP = §8/§estop §8- §7Stops the server -STOP_NO_PERMS = §cYou do not have the permission to stop the server STOP_MESSAGE = §eServer is stopping -WORLD_EDIT_NO_PERMS = §cYou do not have the permission to use WorldEdit KICKALL_HELP = §8/§ekickall §8- §7Kick all players from the server except the owner -KICKALL_NO_PERM = §cThis is not your world! # Techhider TECHHIDER_HELP = §8/§etechhider §8- §7Toggle Techhider diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index f81caadd..ecb3deae 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -118,7 +118,6 @@ BACKUP_HELP_LOAD=§8/§ebackup load §8[§7BackupName§8] §8- §7 Lade ein Back BACKUP_HELP_LIST=§8/§ebackup list §8- §7Liste alle Backups der Region auf BACKUP_HELP_GUI=§8/§ebackup gui §8- §7Öffne die Backups in einer GUI BACKUP_REGION_NO_REGION=§cDu bist in keiner Region -BACKUP_NO_PERMS=§cDu darfst hier nicht das Backup System verwenden BACKUP_CREATE_SUCCESS=§7Das Backup wurde erstellt BACKUP_CREATE_FAILURE=§cDas Backup erstellen ist schiefgegangen BACKUP_CREATE_NO_CHANGE=§7Die Region hat keine Veränderung @@ -132,11 +131,6 @@ BACKUP_LORE=§eKlicken zum Laden # Bau BAU_COMMAND_HELP_INFO = §8/§ebau info §8- §7Alias für §8/§ebauinfo -BAU_COMMAND_HELP_TOGGLEWE = §8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers -BAU_COMMAND_HELP_TOGGLEWORLD = §8/§ebau toggleworld §8[§7Player§8] §8- §7Editiere die Welt Rechte eines Spielers -BAU_UNKNOWN_PLAYER = §cUnbekannter Spieler -BAU_NO_PLAYER = §cDer Spieler ist kein Mitglied deiner Welt! -BAU_NO_WORLD = §cDies ist nicht deine Welt! BAU_INFO_ITEM_NAME = §eBau-Management ## This is used in BauInfoBauGuiItem.java @@ -150,11 +144,6 @@ BAU_INFO_ITEM_LORE_PROTECT = §7Protect§8: §e{0} BAU_INFO_COMMAND_HELP = §8/§ebauinfo §8- §7Gibt Informationen über den Bau BAU_INFO_COMMAND_OWNER = §7Besitzer§8: §e{0} BAU_INFO_COMMAND_MEMBER = §7Mitglieder §8[§7{0}§8]§8: §e -BAU_INFO_MEMBER_INFO = §e{0}§8[{1}§8,{2}§8] §8 -BAU_INFO_MEMBER_WE_ALLOW = §aWE -BAU_INFO_MEMBER_WE_DISALLOW = §cWE -BAU_INFO_MEMBER_WORLD_ALLOW = §aW -BAU_INFO_MEMBER_WORLD_DISALLOW = §cW BAU_INFO_COMMAND_FLAG = §7{0}§8: §7{1} BAU_INFO_COMMAND_TPS = §7TPS§8:§e @@ -213,11 +202,6 @@ HOTBAR_INVENTORY=Standard Hotbar # GUI GUI_EDITOR_ITEM_NAME=§eGui Editor GUI_NAME=Bau GUI -GUI_NO_PERMISSION=§cDu hast nicht genug Rechte um dies zu tun -GUI_NO_OWNER=§cDas ist nicht deine Bauwelt -GUI_NO_WORLD=§cDu darfst hier die Welt nicht einstellen -GUI_NO_WORLDEDIT=§cDu darfst hier kein Worldedit benutzen -GUI_NO_MEMBER=§cDu musst ein Member der Bauwelt sein GUI_ITEM_LORE1=§7Du kannst dieses Item zum Öffnen der BauGUI nutzen GUI_ITEM_LORE2=§7oder Doppel F (Swap hands) drücken. GUI_EDITOR_TITLE=Bau GUI Editor @@ -261,7 +245,6 @@ SHIELD_PRINTING_HELP_STEP_7 = §87. §7Wende das gedruckte mit §8/§eshieldprin SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. -SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen. SHIELD_PRINTING_BOSSBAR = §fBewegungen: {0} SHIELD_PRINTING_BOSSBAR_COPIED = §fBewegungen: {0} Kopiert: {1} @@ -298,7 +281,6 @@ SIMULATOR_CHANGE_HELP = §8/§esimulator change §8-§7 Wechsel zu einem anderen 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_COPY_HELP = §8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Kopiert einen Simulator -SIMULATOR_NO_PERMS = §cDu darfst hier nicht den Simulator nutzen SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator @@ -454,7 +436,6 @@ TPSLIMIT_GUI_ITEM_NAME = §eTPS Limiter TPSLIMIT_GUI_ITEM_LORE = §7Aktuell: §e{0} TPSLIMIT_ANVIL_GUI = Neues TPS Limit TPSLIMIT_CURRENT = §7Jetziges TPS limit§8: §e{0} -TPSLIMIT_NO_PERMS = §cDu darfst hier nicht den TPS-Limiter nutzen TPSLIMIT_SET = §eTPS limit auf {0} gesetzt. TPSLIMIT_FROZEN = §eTPS eingefroren. @@ -480,7 +461,6 @@ TRACE_MESSAGE_DELETE = §cAlle TNT-Positionen gelöscht TRACE_MESSAGE_SHOW = §aAlle TNT-Positionen angezeigt TRACE_MESSAGE_HIDE = §cAlle TNT-Positionen ausgeblendet TRACE_MESSAGE_CLICK_ISOLATE = §eKlicken zum §aisolieren§8/§causblenden -TRACE_MESSAGE_DISALLOWED = §cDu darfst hier nicht den TNT-Tracer nutzen TRACE_MESSAGE_SHOW_AT = §aTNT-positions angezeigt mit {0} bei {1} TRACE_MESSAGE_SHOW_FROM = §aAll TNT-positions angezeigt mit {0} von {1} TRACE_MESSAGE_SHOW_FROM_TO = §aAll TNT-positions angezeigt mit {0} von {1} bis {2} @@ -667,7 +647,6 @@ OTHER_CLEAR_HELP_PLAYER=§8/§eclear §8[§7Player§8] §8- §7Leere ein Spieler OTHER_CLEAR_CLEARED=Dein Inventar wurde geleert. OTHER_CLEAR_FROM=Dein Inventar wurde von {0} §7geleert. OTHER_CLEAR_TO=Das Inventar von {0} §7wurde geleert. -OTHER_CLEAR_NO_PERMS=§cDu darfst hier keine fremden Inventare leeren. OTHER_DECLUTTER_HELP=§8/§edeclutter §8- §7Räume dein Inventar auf OTHER_DECLUTTER_DONE=§aDein Inventar wurde aufgeräumt. OTHER_GAMEMODE_UNKNOWN=§cUnbekannter Spielmodus. @@ -683,7 +662,6 @@ OTHER_TELEPORT_SELF_2=§cNoch zu reisende Blöcke: 0; ETA: 0:00 OTHER_TELEPORT_SELF_3=§cEin wenig bewegung muss ein. OTHER_TELEPORT_SELF_4=§cFür eine solche Distanz? OTHER_TIME_HELP=§8/§etime §8<§7Zeit 0=Morgen§8, §76000=Mittag§8, §718000=Mitternacht§8> - §7Setzt die Zeit auf dem Bau -OTHER_TIME_NO_PERM=§cDu darfst hier nicht die Zeit ändern OTHER_TIME_INVALID=§cBitte gib eine Zahl zwischen 0 und 24000 an OTHER_TIME_RESULT=§7§oWhooosh OTHER_TPS_HEAD = §7TPS: 1s 10s 1m 5m 10m @@ -745,17 +723,6 @@ MATERIAL_INTERACTABLE=§8- §eInterargierbarer Block MATERIAL_FLAMMABLE=§8- §eFlammbarer Block MATERIAL_BURNABLE=§8- §eBrennbarer Block MATERIAL_WATERLOGGABLE=§8- §eWasserspeicherbarer Block -# Redstonetester -RT_HELP=§8/§eredstonetester §8-§7 Gibt den RedstoneTester -RT_GIVEN=§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten -RT_ITEM_NAME=§eRedstonetester -RT_ITEM_LORE_1=§eLinksklick Block §8-§7 Setzt die 1. Position -RT_ITEM_LORE_2=§eRechtsklick Block §8-§7 Setzt die 2. Position -RT_ITEM_LORE_3=§eShift-Rechtsklick Luft §8-§7 Zurücksetzten -RT_LOC=§8: §e{0} {1} {2} -RT_INVALID_LOC=§cUnbekannte Position -RT_RESULT=§7Differenz§8: §e{0}§7 Ticks §8,§7 R-Ticks §e{1} -RT_ACTIVATE=§7Positionen gelöscht§8. # Region Items REGION_ITEM_COLOR=§7Color: §e{0} REGION_ITEM_COLOR_CHOOSE=Farbe Wählen @@ -781,24 +748,18 @@ REGION_COLOR_HELP_COLOR=§8/§ecolor §8[§7Color§8] §8- §7Setze die Farbe de REGION_COLOR_HELP_COLOR_TYPE=§8/§ecolor §8[§7Color§8] §8[§7Type§8] §8- §7Setze die Farbe der Region oder Global REGION_COLOR_GLOBAL=§7Alle Regions farben auf §e{0}§7 gesetzt REGION_COLOR_NO_REGION=§cDu befindest dich derzeit in keiner Region -REGION_COLOR_NO_PERMS=§cDies ist nicht deine Welt! REGION_FIRE_HELP=§8/§efire §8- §7Toggle Feuerschaden -REGION_FIRE_NO_PERMS=§cDu darfst hier nicht Feuerschaden (de-)aktivieren REGION_FIRE_ENABLED=§cRegions Feuerschaden deaktiviert REGION_FIRE_DISABLED=§aRegions Feuerschaden aktiviert REGION_FREEZE_HELP=§8/§efreeze §8- §7Toggle Freeze -REGION_FREEZE_NO_PERMS=§cDu darfst diese Welt nicht einfrieren REGION_FREEZE_ENABLED=§cRegion eingefroren REGION_FREEZE_DISABLED=§aRegion aufgetaut REGION_ITEMS_HELP=§8/§eitems §8- §7Toggle Items -REGION_ITEMS_NO_PERMS=§cDu darfst hier nicht Items (de-)aktivieren REGION_ITEMS_ENABLED=§aItems aktiviert in dieser Region REGION_ITEMS_DISABLED=§cItems deaktiviert in dieser Region -REGION_ITEMS_DISABLED_GLOBAL=§cItems sind auf dem Server deaktiviert. REGION_PROTECT_HELP=§8/§eprotect §8- §7Schütze die Region REGION_PROTECT_DISABLE=§cBoden Schutz aufgehoben REGION_PROTECT_ENABLE=§aBoden geschützt -REGION_PROTECT_NO_PERMS=§cDu darfst hier nicht den Boden schützen REGION_PROTECT_FALSE_REGION=§cDu befindest dich derzeit in keiner (M)WG-Region REGION_REGION_HELP_UNDO=§8/§eregion undo §8- §7Mache die letzten 20 /testblock oder /reset rückgängig REGION_REGION_HELP_REDO=§8/§eregion redo §8- §7Wiederhole die letzten 20 §8/§7rg undo @@ -823,7 +784,6 @@ REGION_REGION_TP_COPY=§7Zum Kopierpunkt teleportiert REGION_REGION_TP_TEST_BLOCK=§7Zum Testblock teleportiert REGION_REGION_TP_UNKNOWN=§cNicht definierter Teleportierpunkt REGION_REGION_NO_REGION=§cDu bist in keiner Region -REGION_REGION_NO_PERMS=§cDu darfst hier nicht die Region verändern REGION_REGION_CHANGETYPE_INFO=§7Regions Type ist §e{0} REGION_REGION_CHANGETYPE_UNKNOWN=§cRegions Type ist nicht valide REGION_REGION_CHANGETYPE_INVALID=§cRegions Type ist nicht erlaubt hier @@ -841,7 +801,6 @@ REGION_RESET_HELP_RESET=§8/§ereset §8- §7Setzte die Region zurück REGION_RESET_HELP_SCHEMATIC=§8/§ereset §8[§7Schematic§8] §8- §7Setzte die Region mit einer Schematic zurück REGION_RESET_RESETED=§7Region zurückgesetzt REGION_RESET_ERROR=§cFehler beim Zurücksetzen der Region -REGION_RESET_NO_PERMS=§cDu darfst hier nicht die Region zurücksetzen REGION_RESET_NO_REGION=§cDu befindest dich derzeit in keiner Region REGION_TB_HELP_RESET=§8/§etestblock §8- §7Setzte den Testblock zurück REGION_TB_HELP_RESET_EXTENSION=§8/§etestblock §8[§7ExtensionType§8] §8- §7Setzte den Testblock zurück @@ -849,7 +808,6 @@ REGION_TB_HELP_SCHEMATIC=§8/§etestblock §8[§7Schematic§8] §8- §7Setzte de REGION_TB_HELP_SCHEMATIC_EXTENSION=§8/§etestblock §8[§7Schematic§8] §8[§7ExtensionType§8] §8- §7Setzte den Testblock mit einer Schematic zurück REGION_TB_DONE=§7Testblock zurückgesetzt REGION_TB_ERROR=§cFehler beim Zurücksetzen des Testblocks -REGION_TB_NO_PERMS=§cDu darfst hier nicht den Testblock zurücksetzen REGION_TB_NO_REGION=§cDu befindest dich derzeit in keiner Region REGION_TB_NO_SCHEMSHARING=§cDu kannst aktuell keine Schematics teilen bis {0}. REGION_TB_NO_SCHEMRECEIVING=§cDer Besitzer dieses Bauservers kann keine Schematics erhalten bis {0}. @@ -858,7 +816,6 @@ REGION_TNT_HELP_MODE=§8/§etnt §8[§7Mode§8] §8- §7Setzte das TNT verhalten REGION_TNT_ON=§aTNT-Schaden aktiviert REGION_TNT_OFF=§cTNT-Schaden deaktiviert REGION_TNT_TB=§aTNT-Schaden außerhalb Baurahmen aktiviert -REGION_TNT_NO_PERMS=§cDu darfst hier nicht TNT-Schaden (de-)aktivieren REGION_TNT_BUILD_DESTROY=§cEine Explosion hätte Blöcke im Baubereich zerstört REGION_TNT_TB_DESTROY=§cEine Explosion hätte Blöcke im Testblockbereich zerstört AFK_KICK_MESSAGE=§cAuf diesem Server ist seit 5 Minuten nichts passiert. @@ -876,7 +833,6 @@ PANZERN_PREPARE1 = §71. Gucke nochmal nach, ob Läufe auch bis zur Panzergrenze PANZERN_PREPARE2 = §72. Teppich in Gänge auf dem Boden vereinfacht das panzern. PANZERN_PREPARE3 = §73. Schildtechnik sollte explizit eingeschlossen sein. PANZERN_PREPARE4 = §74. Innerhalb der zu panzernden Region zu stehen, beim Befehlausführen kann das Panzern verbessern. -PANZERN_NO_PERM = §cDu darfst hier nicht das Panzern System verwenden PANZERN_NO_WORLDEDIT = §cDu hast keine WorldEdit Selection PANZERN_PROGRESS = §e{0} §7Blöcke übrig, §e{1} §7Blöcke pro Sekunde, §e{2} §7Block Delta PANZERN_DONE = §aZuende gepanzert @@ -886,7 +842,6 @@ LAUFBAU_HELP = §8/§elaufbau §8[§7smallest§8|§7blastresistant§8] §8- §7B LAUFBAU_HELP_SETTINGS = §8/§elaufbau settings §8- §7Öffnet die Settings GUI LAUFBAU_PREPARE1 = §71. Trace die Kanonen so oft wie nötig, in allen Modi. LAUFBAU_PREPARE2 = §72. Versuche alle Fails aus dem Trace zu löschen. -LAUFBAU_NO_PERM = §cDu darfst hier nicht das Laufbau System verwenden LAUFBAU_NO_WORLDEDIT = §cDu hast keine WorldEdit Selection LAUFBAU_STATE_FILTERING_TRACES = Traces filtern LAUFBAU_STATE_PROCESSING_TRACES = Traces verbinden @@ -994,7 +949,6 @@ LAUFBAU_TILT_PARTIAL = §8-§7 Neigung teilweise # UTILS SELECT_HELP = §8/§eselect §8[§7RegionsTyp§8] §8- §7Wähle einen RegionsTyp aus SELECT_EXTENSION_HELP = §8/§eselect §8[§7RegionsTyp§8] §8[§7Extension§8] §8- §7Wähle einen RegionsTyp aus mit oder ohne Extension -SELECT_NO_PERMS = §cDu darfst hier nicht den Select Befehl verwenden SELECT_GLOBAL_REGION = §cDie globale Region kannst du nicht auswählen SELECT_NO_TYPE = §cDiese Region hat keinen {0} SELECT_NO_EXTENSION = §cDiese Region hat keine Ausfahrmaße @@ -1046,7 +1000,6 @@ PISTON_HELP_3 = §7Die Anzahl ist Gelb, wenn zu viele Blöcke vorhanden sind. PISTON_INFO = §7Bewegte Blöcke {0}{1}§8/§712 # Warp -WARP_DISALLOWED = §cDu darfst hier nicht das Warp System nutzen WARP_LOC_X = §7X§8: §e{0} WARP_LOC_Y = §7Y§8: §e{0} WARP_LOC_Z = §7Z§8: §e{0} @@ -1072,12 +1025,9 @@ WARP_HELP_LIST=§8/§ewarp list §8- §7Liste alle Warp-Punkt auf # WORLD STOP_HELP = §8/§estop §8- §7Stoppt den Server -STOP_NO_PERMS = §cDu hast keine Rechte den Server zu stoppen STOP_MESSAGE = §eDer Server wird gestoppt -WORLD_EDIT_NO_PERMS = §cDu darfst hier kein WorldEdit benutzen KICKALL_HELP = §8/§ekickall §8- §7Kickt alle Spieler vom Server außer den Owner -KICKALL_NO_PERM = §cDies ist nicht deine Welt! # Techhider TECHHIDER_HELP = §8/§etechhider §8- §7Techhider umschalten diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java index 92289699..3b8dc600 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java @@ -81,7 +81,7 @@ public class BauGUI { } } else { p.closeInventory(); - BauSystem.MESSAGE.send("GUI_NO_PERMISSION", p); + BauSystem.MESSAGE.send("NO_PERMISSION", p); } }); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index a15c1e4f..163bec3c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -21,20 +21,19 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.*; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityEnterBlockEvent; -import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockCanBuildEvent; +import org.bukkit.event.block.BlockMultiPlaceEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityPickupItemEvent; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.*; -import org.bukkit.inventory.ItemStack; @Linked public class SpectatorListener implements Listener { @@ -53,15 +52,14 @@ public class SpectatorListener implements Listener { event.getPlayer().kickPlayer(""); }, 1); } - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { - Player p = event.getPlayer(); - ItemStack[] content = event.getPlayer().getInventory().getContents(); - for (int i = 0; i < content.length; i++) { - if (content[i] == null) continue; - if (checkItemStack(content[i])) { - p.getInventory().setItem(i, null); - } - } + } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + if (!anySupervisorOnline(null)) { + Bukkit.getOnlinePlayers().forEach(player -> { + player.kickPlayer(""); + }); } } @@ -74,28 +72,6 @@ public class SpectatorListener implements Listener { } } - @EventHandler - public void onInventoryClick(InventoryClickEvent event) { - ItemStack itemStack = event.getCurrentItem(); - if (itemStack == null || !itemStack.hasItemMeta()) { - return; - } - if (checkItemStack(itemStack)) { - event.setCancelled(true); - event.setCurrentItem(null); - } - } - - private boolean checkItemStack(ItemStack itemStack) { - switch (itemStack.getType()) { - case WOODEN_AXE: - case DEBUG_STICK: - return true; - default: - return false; - } - } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { if (event.getMessage().startsWith("/schem save") || event.getMessage().startsWith("//schem save") || event.getMessage().startsWith("/schematic save") || event.getMessage().startsWith("//schematic save")) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/StopCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/StopCommand.java index 479cd9ad..68f618db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/StopCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/StopCommand.java @@ -58,7 +58,7 @@ public class StopCommand extends SWCommand { if (user.hasPerm(UserPerm.ADMINISTRATION)) { return true; } - messageSender.send("STOP_NO_PERMS"); + messageSender.send("NO_PERMISSION"); return false; }; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java index 6cda80be..a377db87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java @@ -41,7 +41,7 @@ public class WorldEditListener implements Listener { Player p = e.getPlayer(); if (!Permission.BUILD.hasPermission(e.getPlayer())) { - BauSystem.MESSAGE.send("WORLD_EDIT_NO_PERMS", p); + BauSystem.MESSAGE.send("NO_PERMISSION", p); e.setCancelled(true); e.setMessage("/"); } From 0ac735c30f936108c7bd99a51c8374729eb0c234 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Dec 2023 13:02:44 +0100 Subject: [PATCH 089/139] Add ForceSpectatorCommand Add TechHiderCommand.toggleHider for spectators --- .../src/de/steamwar/bausystem/BauSystem.java | 10 +++ .../src/de/steamwar/bausystem/Permission.java | 42 ++++++++- .../bausystem/features/bau/BauCommand.java | 41 --------- .../features/bau/ForceSpectatorCommand.java | 73 ++++++++++++++++ .../bausystem/features/bau/InfoCommand.java | 4 - .../features/techhider/TechHiderCommand.java | 33 +++++++ .../features/world/BauMemberUpdate.java | 86 ++++++++++++++++++- .../features/world/SpectatorListener.java | 44 ++++++++++ .../bausystem/utils/BauMemberUpdateEvent.java | 24 ++++++ 9 files changed, 305 insertions(+), 52 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/bau/ForceSpectatorCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index ad5790a0..2d2773b4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -95,6 +95,16 @@ public class BauSystem extends JavaPlugin implements Listener { } return true; }); + SWCommandUtils.addValidator("supervisor", (commandSender, object, messageSender) -> { + if (commandSender instanceof Player) { + if (Permission.SUPERVISOR.hasPermission((Player) commandSender)) { + return true; + } + messageSender.send("NO_PERMISSION"); + return false; + } + return true; + }); LinkageUtils.link(); RamUsage.init(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 8e51d97d..2d642ac1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -20,11 +20,16 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.config.BauServer; +import de.steamwar.bausystem.features.world.BauMemberUpdate; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; import lombok.AllArgsConstructor; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.HashSet; +import java.util.Set; import java.util.function.Predicate; @AllArgsConstructor @@ -32,10 +37,17 @@ public enum Permission { OWNER(bauweltMember -> false), SUPERVISOR(bauweltMember -> { - return bauweltMember.isWorld(); + return bauweltMember.isSupervisor(); }), BUILD(bauweltMember -> { - return bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember); + if (isTempOnlySpectator(bauweltMember)) return false; + return bauweltMember.isBuild() || SUPERVISOR.permissionPredicate.test(bauweltMember); + }), + /** + * Only used for {@link BauMemberUpdate} + */ + REAL_SPECTATOR(bauweltMember -> { + return !bauweltMember.isBuild() && !bauweltMember.isSupervisor(); }), SPECTATOR(bauweltMember -> { return !BUILD.permissionPredicate.test(bauweltMember); @@ -44,6 +56,28 @@ public enum Permission { return true; }); + private static final Set TEMP_ONLY_SPECTATOR = new HashSet<>(); + + private static boolean isTempOnlySpectator(BauweltMember bauweltMember) { + return TEMP_ONLY_SPECTATOR.contains(bauweltMember.getMemberID()); + } + + public static boolean isTempOnlySpectator(Player player) { + return TEMP_ONLY_SPECTATOR.contains(SteamwarUser.get(player.getUniqueId()).getId()); + } + + public static void forceOnlySpectator(Player player) { + TEMP_ONLY_SPECTATOR.add(SteamwarUser.get(player.getUniqueId()).getId()); + BauMemberUpdate.baumemberUpdate(); + } + + /** + * Only used by {@link BauMemberUpdate} + */ + public static void removeForceOnlySpectator(Player player) { + TEMP_ONLY_SPECTATOR.remove(SteamwarUser.get(player.getUniqueId()).getId()); + } + private final Predicate permissionPredicate; public boolean hasPermission(BauweltMember bauweltMember) { @@ -53,10 +87,10 @@ public enum Permission { public boolean hasPermission(Player member) { if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) { - return this != SPECTATOR; + return this != SPECTATOR && this != REAL_SPECTATOR; } BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); - if (bauweltMember == null) return this == SPECTATOR; + if (bauweltMember == null) return this == SPECTATOR || this == REAL_SPECTATOR; return permissionPredicate.test(bauweltMember); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java deleted file mode 100644 index 69ee7af8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 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.bau; - -import de.steamwar.command.SWCommand; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; -import org.bukkit.entity.Player; - -@Linked -public class BauCommand extends SWCommand { - - @LinkedInstance - public InfoCommand infoCommand; - - public BauCommand() { - super("bau", "b", "gs"); - } - - @Register(value = "info", description = "BAU_COMMAND_HELP_INFO") - public void infoCommand(Player p) { - infoCommand.sendBauInfo(p); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/ForceSpectatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/ForceSpectatorCommand.java new file mode 100644 index 00000000..7bef91df --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/ForceSpectatorCommand.java @@ -0,0 +1,73 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.bau; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.command.PreviousArguments; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import de.steamwar.linkage.Linked; +import de.steamwar.techhider.TechHider; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.stream.Collectors; + +@Linked +public class ForceSpectatorCommand extends SWCommand { + + public ForceSpectatorCommand() { + super("forcespectator"); + } + + @Register + public void forceSpectator(@Validator("supervisor") Player player, @Mapper("builder") Player other) { + Permission.forceOnlySpectator(other); + } + + @Mapper("builder") + public TypeMapper spectatorMapper() { + return new TypeMapper<>() { + @Override + public Player map(CommandSender commandSender, String[] previousArguments, String s) { + Player player = Bukkit.getPlayer(s); + if (player == null) { + return null; + } + if (Permission.BUILD.hasPermission(player) && !Permission.SUPERVISOR.hasPermission(player)) { + return player; + } + return null; + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return Bukkit.getOnlinePlayers().stream() + .filter(Permission.BUILD::hasPermission) + .filter(player -> !Permission.SUPERVISOR.hasPermission(player)) + .map(Player::getName) + .collect(Collectors.toList()); + } + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index 9f53f563..19d8aab5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -27,10 +27,6 @@ public class InfoCommand extends SWCommand { @Register(description = "BAU_INFO_COMMAND_HELP") public void genericCommand(Player p) { - sendBauInfo(p); - } - - public void sendBauInfo(Player p) { BauSystem.MESSAGE.send("BAU_INFO_COMMAND_OWNER", p, SteamwarUser.get(bauServer.getOwnerID()).getUserName()); Region region = Region.getRegion(p.getLocation()); for (Flag flag : Flag.getFlags()) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java index 731b583a..612cf8cb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -20,16 +20,22 @@ package de.steamwar.bausystem.features.techhider; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.features.world.SpectatorListener; import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import de.steamwar.techhider.TechHider; import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -104,6 +110,33 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE }); } + @Register + public void toggleHider(@Validator("supervisor") Player player, @Mapper("spectator") Player other) { + SpectatorListener.toggleNoTechHider(other); + } + + @Mapper("spectator") + public TypeMapper spectatorMapper() { + return new TypeMapper<>() { + @Override + public Player map(CommandSender commandSender, String[] previousArguments, String s) { + Player player = Bukkit.getPlayer(s); + if (player != null && Permission.REAL_SPECTATOR.hasPermission(player)) { + return player; + } + return null; + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return Bukkit.getOnlinePlayers().stream() + .filter(Permission.REAL_SPECTATOR::hasPermission) + .map(Player::getName) + .collect(Collectors.toList()); + } + }; + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { hidden.values().forEach(set -> set.remove(event.getPlayer())); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java index fe90be02..576b4fa1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java @@ -19,6 +19,8 @@ package de.steamwar.bausystem.features.world; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; @@ -26,15 +28,93 @@ import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerItemConsumeEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.HashSet; +import java.util.Set; @Linked -public class BauMemberUpdate extends PacketHandler { +public class BauMemberUpdate extends PacketHandler implements Listener { + + private static final Set SPECTATORS = new HashSet<>(); @Handler public void baumemberUpdate(BaumemberUpdatePacket baumemberUpdatePacket) { - Bukkit.getPluginManager().callEvent(new BauMemberUpdateEvent()); + baumemberUpdate(); } - + + public static void baumemberUpdate() { + Set newSpectator = new HashSet<>(); + Set newBuilder = new HashSet<>(); + Bukkit.getOnlinePlayers().forEach(player -> { + if (Permission.REAL_SPECTATOR.hasPermission(player)) { + if (!SPECTATORS.contains(player)) { + SPECTATORS.add(player); + Permission.removeForceOnlySpectator(player); + newSpectator.add(player); + player.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false)); + } + } else { + if (Permission.SUPERVISOR.hasPermission(player)) { + Permission.removeForceOnlySpectator(player); + } + if (SPECTATORS.contains(player)) { + SPECTATORS.remove(player); + newBuilder.add(player); + player.removePotionEffect(PotionEffectType.GLOWING); + } + } + }); + Bukkit.getPluginManager().callEvent(new BauMemberUpdateEvent(newSpectator, newBuilder)); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + SPECTATORS.add(event.getPlayer()); + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false)); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + SPECTATORS.remove(event.getPlayer()); + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent event) { + event.setDeathMessage(null); + if (SPECTATORS.contains(event.getEntity())) { + event.getDrops().clear(); + } + } + + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent event) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (SPECTATORS.contains(event.getPlayer())) { + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false, false, false)); + } + }, 1); + } + + @EventHandler + public void onPlayerItemConsume(PlayerItemConsumeEvent event) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (SPECTATORS.contains(event.getPlayer())) { + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false)); + } + }, 1); + } + @Linked public static class TestCommand extends SWCommand { // TODO: Remove before merge diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index 163bec3c..68bb465a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -22,8 +22,12 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; +import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; +import de.steamwar.techhider.TechHider; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -35,9 +39,41 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.player.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + @Linked public class SpectatorListener implements Listener { + private static final Set NO_TECHHIDER = new HashSet<>(); + + static { + TechHider techHider = new TechHider((player, i, i1) -> { + return Permission.BUILD.hasPermission(player) || Permission.isTempOnlySpectator(player) || NO_TECHHIDER.contains(player); + }, Material.END_STONE, new HashSet<>(Arrays.asList(Material.REDSTONE_WIRE)), new HashSet<>()); + techHider.enable(); + } + + public static void toggleNoTechHider(Player player) { + if (NO_TECHHIDER.contains(player)) { + NO_TECHHIDER.remove(player); + } else { + NO_TECHHIDER.add(player); + } + resendChunks(player); + } + + private static void resendChunks(Player player) { + int distance = player.getClientViewDistance(); + Location location = player.getLocation(); + for (int x = (int) Math.floor(location.getX() / 16.0) - distance; x <= (int) Math.ceil(location.getX() / 16.0) + distance; x++) { + for (int z = (int) Math.floor(location.getZ() / 16.0) - distance; z <= (int) Math.ceil(location.getZ() / 16.0) + distance; z++) { + CraftbukkitWrapper.impl.sendChunk(player, x, z); + } + } + } + private boolean anySupervisorOnline(Player player) { return Bukkit.getOnlinePlayers().stream().filter(p -> p != player).anyMatch(Permission.SUPERVISOR::hasPermission); } @@ -60,11 +96,19 @@ public class SpectatorListener implements Listener { Bukkit.getOnlinePlayers().forEach(player -> { player.kickPlayer(""); }); + return; } + + event.getChanged().forEach(player -> { + NO_TECHHIDER.remove(player); + if (Permission.isTempOnlySpectator(player)) return; + resendChunks(player); + }); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { + NO_TECHHIDER.remove(event.getPlayer()); if (!anySupervisorOnline(event.getPlayer())) { Bukkit.getOnlinePlayers().forEach(player -> { player.kickPlayer(""); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/BauMemberUpdateEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/BauMemberUpdateEvent.java index 4d26dc6f..77f2ba3e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/BauMemberUpdateEvent.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/BauMemberUpdateEvent.java @@ -19,11 +19,35 @@ package de.steamwar.bausystem.utils; +import lombok.Getter; +import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + public class BauMemberUpdateEvent extends Event { + @Getter + private final Set changed; + + @Getter + private final Set newSpectator; + + @Getter + private final Set newBuilder; + + public BauMemberUpdateEvent(Set newSpectator, Set newBuilder) { + this.newSpectator = Collections.unmodifiableSet(newSpectator); + this.newBuilder = Collections.unmodifiableSet(newBuilder); + Set changed = new HashSet<>(); + changed.addAll(newSpectator); + changed.addAll(newBuilder); + this.changed = Collections.unmodifiableSet(changed); + } + private static final HandlerList handlers = new HandlerList(); public HandlerList getHandlers() { From 2a55f607d31610ba2c2c71118638e16766bb7e88 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Dec 2023 14:18:32 +0100 Subject: [PATCH 090/139] Add dynamic spectator disable --- BauSystem_Main/src/BauSystem.properties | 8 --- BauSystem_Main/src/BauSystem_de.properties | 8 --- .../design/endstone/DesignEndStone.java | 9 ++-- .../endstone/DesignEndStoneCommand.java | 24 ++++++--- .../features/detonator/DetonatorListener.java | 3 +- .../killchecker/KillcheckerCommand.java | 19 ++++--- .../killchecker/KillcheckerVisualizer.java | 32 ++---------- .../features/loader/LoaderCommand.java | 14 +++++- .../observer/ObserverTracerCommand.java | 2 +- .../observer/ObserverTracerListener.java | 6 +++ .../features/region/RegionCommand.java | 50 ------------------- .../features/script/ScriptListener.java | 7 +++ .../shieldprinting/ShieldPrinting.java | 7 +++ .../features/simulator/SimulatorCursor.java | 13 ++++- .../tracer/show/TraceShowManager.java | 14 +++++- .../features/util/NoClipCommand.java | 13 ++++- .../features/util/PistonCalculator.java | 2 + .../util/PistonCalculatorCommand.java | 2 +- .../bausystem/features/util/SlotCommand.java | 6 +-- .../features/util/TNTClickListener.java | 2 +- .../features/world/BauMemberUpdate.java | 2 + .../features/world/ItemFrameListener.java | 2 +- .../features/world/WorldEditListener.java | 2 +- 23 files changed, 118 insertions(+), 129 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 3928e0f4..d34ae1ef 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -804,8 +804,6 @@ REGION_REGION_HELP_RESTORE=§8/§eregion restore §8- §7Resets the region, with REGION_REGION_HELP_RESTORE_SCHEMATIC=§8/§eregion restore §8[§7Schematic§8] §8- §7Resets the region, withoout removing your builds REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleport to the regions copy point REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleport to the regions dummy point -REGION_REGION_HELP_CHANGETYPE_INFO=§8/§eregion changetype §8- §7Returns the region type -REGION_REGION_HELP_CHANGETYPE=§8/§eregion changetype §8[§7Type§8] §8- §8Sets the region type REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Returns the region skin REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Sets the region skin REGION_REGION_NOTHING_UNDO=§cNothing left to undo @@ -821,12 +819,6 @@ REGION_REGION_TP_COPY=§7Teleported to the copy point REGION_REGION_TP_TEST_BLOCK=§7Teleported to the tesblock REGION_REGION_TP_UNKNOWN=§cUndefined teleport point REGION_REGION_NO_REGION=§cYou are not inside any region -REGION_REGION_CHANGETYPE_INFO=§7RRegion type is §e{0} -REGION_REGION_CHANGETYPE_UNKNOWN=§cRegion type is invalid -REGION_REGION_CHANGETYPE_INVALID=§cRegion type is not allowed here -REGION_REGION_CHANGETYPE_CHANGE=§7Region type changed to §e{0} -REGION_REGION_CHANGETYPE_CHANGE_UPDATE=§7Click §e§lHERE §7to change the region type -REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER=§8/§ereset REGION_REGION_CHANGESKIN_INFO=§7Region skin is §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0} REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index ecb3deae..535caa3f 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -767,8 +767,6 @@ REGION_REGION_HELP_RESTORE=§8/§eregion restore §8- §7Setzte die Region zurü REGION_REGION_HELP_RESTORE_SCHEMATIC=§8/§eregion restore §8[§7Schematic§8] §8- §7Setzte die Region zurück, ohne das Gebaute zu löschen REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleportiere dich zum Regions Kopierpunkt REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleportiere dich zum Regions Testblockpunkt -REGION_REGION_HELP_CHANGETYPE_INFO=§8/§eregion changetype §8- §7Gebe den Regions Type aus -REGION_REGION_HELP_CHANGETYPE=§8/§eregion changetype §8[§7Type§8] §8- §8Setzte den Regions Type REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Gebe den Regions Skin aus REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Setzte den Regions Skin REGION_REGION_NOTHING_UNDO=§cNichts zum rückgängig machen @@ -784,12 +782,6 @@ REGION_REGION_TP_COPY=§7Zum Kopierpunkt teleportiert REGION_REGION_TP_TEST_BLOCK=§7Zum Testblock teleportiert REGION_REGION_TP_UNKNOWN=§cNicht definierter Teleportierpunkt REGION_REGION_NO_REGION=§cDu bist in keiner Region -REGION_REGION_CHANGETYPE_INFO=§7Regions Type ist §e{0} -REGION_REGION_CHANGETYPE_UNKNOWN=§cRegions Type ist nicht valide -REGION_REGION_CHANGETYPE_INVALID=§cRegions Type ist nicht erlaubt hier -REGION_REGION_CHANGETYPE_CHANGE=§7Regions Type ist auf §e{0}§7 geändert -REGION_REGION_CHANGETYPE_CHANGE_UPDATE=§7Klicke §e§lHIER §7um den Type anzuwenden -REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER=§8/§ereset REGION_REGION_CHANGESKIN_INFO=§7Regions Skin ist §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0} REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java index fd9899f8..0fa990aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java @@ -44,7 +44,6 @@ public class DesignEndStone { private REntityServer entityServer = new REntityServer(); private List entities = new ArrayList<>(); private Set locations = new HashSet<>(); - private List players = new ArrayList<>(); public DesignEndStone(Region region) { this.minX = region.getMinPointBuild().getX(); @@ -95,12 +94,10 @@ public class DesignEndStone { } public void toggle(Player player) { - if (players.contains(player)) { - players.remove(player); + if (entityServer.getPlayers().contains(player)) { entityServer.removePlayer(player); BauSystem.MESSAGE.sendPrefixless("DESIGN_ENDSTONE_DISABLE", player, ChatMessageType.ACTION_BAR); } else { - players.add(player); entityServer.addPlayer(player); calc(); BauSystem.MESSAGE.sendPrefixless("DESIGN_ENDSTONE_ENABLE", player, ChatMessageType.ACTION_BAR); @@ -108,7 +105,7 @@ public class DesignEndStone { } public boolean removePlayer(Player player) { - players.remove(player); - return players.isEmpty(); + entityServer.removePlayer(player); + return entityServer.getPlayers().isEmpty(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java index 35a7fa7a..92934c23 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.design.endstone; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import org.bukkit.Location; @@ -33,6 +34,7 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; @Linked @@ -56,14 +58,20 @@ public class DesignEndStoneCommand extends SWCommand implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - Region region = Region.getRegion(event.getPlayer().getLocation()); - DesignEndStone designEndStone = designEndStoneMap.get(region); - if (designEndStone == null) { - return; - } - if (designEndStone.removePlayer(event.getPlayer())) { - designEndStoneMap.remove(region); - } + disableDesignEndStone(event.getPlayer()); + } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(this::disableDesignEndStone); + } + + private void disableDesignEndStone(Player player) { + new HashSet<>(designEndStoneMap.entrySet()).forEach(regionDesignEndStoneEntry -> { + if (regionDesignEndStoneEntry.getValue().removePlayer(player)) { + designEndStoneMap.remove(regionDesignEndStoneEntry.getKey()); + } + }); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java index 0ea3c469..cabe00c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -92,8 +92,7 @@ public class DetonatorListener implements Listener { @EventHandler(ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { - if(!Permission.BUILD.hasPermission(event.getPlayer())) return; - if (!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) { + if (!Permission.BUILD.hasPermission(event.getPlayer()) ||!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) { if (Detonator.hasActiveDetonatorShow(event.getPlayer())) { Detonator.hideDetonator(event.getPlayer()); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index bbba61ea..9ca7a480 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.killchecker; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; @@ -74,16 +75,22 @@ public class KillcheckerCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("KILLCHECKER_DISABLE", player); } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(this::hide); + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); - Set regions = new HashSet<>(); - visualizers.forEach((region, visualizer) -> { - if (visualizer.disconnect(player)) { - regions.add(region); + hide(event.getPlayer()); + } + + private void hide(Player player) { + new HashSet<>(visualizers.entrySet()).forEach(regionKillcheckerVisualizerEntry -> { + if (regionKillcheckerVisualizerEntry.getValue().hide(player)) { + visualizers.remove(regionKillcheckerVisualizerEntry.getKey()); } }); - regions.forEach(visualizers::remove); } private void recalc(Block block) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index d7c89254..c68ad901 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -57,9 +57,6 @@ public class KillcheckerVisualizer { private final int zArea; private final int xArea; - private final Set players = new HashSet<>(); - private final Set areaPlayers = new HashSet<>(); - private final Region region; private final BossBarService bossBarService; @@ -261,7 +258,7 @@ public class KillcheckerVisualizer { double zPercent = xCount / (double) zArea; percent = (xPercent + yPercent + zPercent) / 3; kills = zKills + yKills + xKills; - players.forEach(this::updateBossBar); + outline.getPlayers().forEach(this::updateBossBar); Set pointSet = new HashSet<>(killCount.keySet()); Set outlinePointsCacheLast = new HashSet<>(outlinePointsCache); @@ -356,40 +353,21 @@ public class KillcheckerVisualizer { return new Cuboid(minX, minY, minZ, maxX, maxY, maxZ); } - public boolean show(Player player, boolean onlyOutline) { + public void show(Player player, boolean onlyOutline) { outline.addPlayer(player); if (!onlyOutline) { inner.addPlayer(player); - areaPlayers.add(player); - } else if (areaPlayers.contains(player)) { + } else { inner.removePlayer(player); - areaPlayers.remove(player); } updateBossBar(player); - return players.add(player); } public boolean hide(Player player) { outline.removePlayer(player); - if (areaPlayers.contains(player)) { - inner.removePlayer(player); - } - players.remove(player); - areaPlayers.remove(player); + inner.removePlayer(player); bossBarService.remove(player, region, "killchecker"); - if (players.isEmpty()) { - outline.close(); - inner.close(); - return true; - } - return false; - } - - public boolean disconnect(Player player) { - players.remove(player); - areaPlayers.remove(player); - bossBarService.remove(player, region, "killchecker"); - if (players.isEmpty()) { + if (outline.getPlayers().isEmpty() && inner.getPlayers().isEmpty()) { outline.close(); inner.close(); return true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java index 55264ec2..ffe27e64 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -21,13 +21,16 @@ package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; @Linked -public class LoaderCommand extends SWCommand { +public class LoaderCommand extends SWCommand implements Listener { public LoaderCommand() { super("loader"); @@ -101,4 +104,13 @@ public class LoaderCommand extends SWCommand { BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay); loader.setTicksBetweenBlocks(delay); } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(player -> { + Loader loader = Loader.getLoader(player); + if (loader == null) return; + loader.stop(); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java index dbd3e48a..531eda68 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java @@ -47,7 +47,7 @@ public class ObserverTracerCommand extends SWCommand { } @Register(value = "delete", description = "OBSERVER_HELP_DELETE") - public void delete(Player p) { + public void delete(@Validator Player p) { ObserverTracerListener.observerTracerMap.remove(p); BauSystem.MESSAGE.send("OBSERVER_DELETE", p); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java index 801f9ce0..a2d9c991 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.observer; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -89,6 +90,11 @@ public class ObserverTracerListener implements Listener { } } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(observerTracerMap::remove); + } + @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { enabled.add(event.getPlayer()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index 28da6094..efad26fd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -164,36 +164,6 @@ public class RegionCommand extends SWCommand { BauSystem.MESSAGE.send("REGION_REGION_TP_TEST_BLOCK", p); } - @Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE_INFO") - @Register("type") - public void changeTypeCommand(Player p) { - Region region = Region.getRegion(p.getLocation()); - if (checkGlobalRegion(region, p)) { - return; - } - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INFO", p, region.getPrototype().getDisplayName()); - } - - @Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE") - @Register("type") - public void changeTypeCommand(@Validator Player p, @Mapper("regionTypeMapper") String s) { - Region region = Region.getRegion(p.getLocation()); - if (checkGlobalRegion(region, p)) { - return; - } - Prototype prototype = Prototype.getByDisplayName(s); - if (prototype == null) { - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_UNKNOWN", p); - } else { - if (region.setPrototype(prototype)) { - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE", p, s); - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset")); - } else { - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INVALID", p); - } - } - } - @Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN_INFO") @Register("skin") public void changeSkinCommand(Player p) { @@ -227,26 +197,6 @@ public class RegionCommand extends SWCommand { } } - @Mapper(value = "regionTypeMapper", local = true) - private TypeMapper regionTypeMapper() { - return new TypeMapper() { - @Override - public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { - Player p = (Player) commandSender; - Region region = Region.getRegion(p.getLocation()); - if (region.isGlobal()) { - return Collections.emptyList(); - } - return region.getPrototypes().stream().map(Prototype::getByName).map(Prototype::getDisplayName).map(c -> c.replace(' ', '_')).collect(Collectors.toList()); - } - - @Override - public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { - return s.replace('_', ' '); - } - }; - } - @Mapper(value = "skinTypeMapper", local = true) private TypeMapper skinTypeMapper() { return new TypeMapper() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java index ed88d2ee..14f8d983 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.script; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; @@ -74,4 +75,10 @@ public class ScriptListener implements Listener { if(!Permission.BUILD.hasPermission(event.getPlayer())) return; ScriptRunner.updateGlobalScript(event.getPlayer()); } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(ScriptRunner::remove); + event.getNewBuilder().forEach(ScriptRunner::updateGlobalScript); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 197300d0..1e3fd6e1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.shieldprinting; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.shieldprinting.impl.*; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.inventory.SWItem; @@ -273,6 +274,12 @@ public class ShieldPrinting implements Listener { updateBossbar(event.getPlayer()); } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(player -> BossBarService.instance.remove(player, region, "shieldprinting")); + event.getNewBuilder().forEach(this::updateBossbar); + } + private void updateBossbars() { for (Player player : Bukkit.getOnlinePlayers()) { updateBossbar(player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 5dd31b6a..bc09a7b3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -35,6 +35,7 @@ import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor; import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui; import de.steamwar.bausystem.features.simulator.gui.SimulatorGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.entity.REntity; @@ -95,6 +96,7 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { calcCursor(event.getPlayer()); }, 0); @@ -102,16 +104,23 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; calcCursor(event.getPlayer()); } @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { calcCursor(event.getPlayer()); }, 1); } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getChanged().forEach(this::calcCursor); + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { cursorType.remove(event.getPlayer()); @@ -143,13 +152,12 @@ public class SimulatorCursor implements Listener { } public synchronized void calcCursor(Player player) { - if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + if (Permission.SPECTATOR.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) { if (removeCursor(player) || SimulatorWatcher.show(null, player)) { SWUtils.sendToActionbar(player, ""); } return; } - if(!Permission.BUILD.hasPermission(player)) return; Simulator simulator = SimulatorStorage.getSimulator(player); SimulatorWatcher.show(simulator, player); @@ -316,6 +324,7 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; if (!ItemUtils.isItem(event.getItem(), "simulator")) { return; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java index 695c8115..7c335052 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -131,12 +132,21 @@ public class TraceShowManager implements Listener { @EventHandler public void onLeave(PlayerQuitEvent event) { + hideComplete(event.getPlayer()); + } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(this::hideComplete); + } + + private void hideComplete(Player player) { showModes.forEach((region, playerShowModeMap) -> { - ShowMode showMode = playerShowModeMap.remove(event.getPlayer()); + ShowMode showMode = playerShowModeMap.remove(player); if (showMode != null) showMode.hide(); }); showFilters.forEach((region, playerPredicateMap) -> { - playerPredicateMap.remove(event.getPlayer()); + playerPredicateMap.remove(player); }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index ba5d5000..867ad83d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -24,6 +24,7 @@ import com.comphenix.tinyprotocol.TinyProtocol; import com.mojang.authlib.GameProfile; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.command.SWCommand; import de.steamwar.core.ProtocolWrapper; @@ -97,7 +98,7 @@ public class NoClipCommand extends SWCommand implements Listener { } @Register(help = true) - public void genericCommand(Player player, String... args) { + public void genericCommand(@Validator Player player) { if (NOCLIPS.contains(player)) { NOCLIPS.remove(player); player.setGameMode(GameMode.CREATIVE); @@ -116,6 +117,16 @@ public class NoClipCommand extends SWCommand implements Listener { } } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(player -> { + if (NOCLIPS.contains(player)) { + NOCLIPS.remove(player); + player.setGameMode(GameMode.CREATIVE); + } + }); + } + @EventHandler(ignoreCancelled = true) public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) { if (NOCLIPS.contains(event.getPlayer())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java index 0f1cfe5e..6703bd5c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.linkage.Linked; @@ -49,6 +50,7 @@ public class PistonCalculator implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (!event.hasItem() || event.getItem().getType() != Material.SLIME_BALL) return; if (event.getClickedBlock() == null) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java index 8aef617f..71fefaa4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java @@ -32,7 +32,7 @@ public class PistonCalculatorCommand extends SWCommand { } @Register - public void help(Player player) { + public void help(@Validator Player player) { BauSystem.MESSAGE.send("PISTON_HELP_1", player); BauSystem.MESSAGE.send("PISTON_HELP_2", player); BauSystem.MESSAGE.send("PISTON_HELP_3", player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SlotCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SlotCommand.java index 4ea5d62b..37ff3b89 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SlotCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SlotCommand.java @@ -41,7 +41,7 @@ public class SlotCommand extends SWCommand { } @Register - public void slotCommand(Player player, Integer slot) { + public void slotCommand(@Validator Player player, Integer slot) { if (slot < 1 || slot > 9) { BauSystem.MESSAGE.send("OTHER_SLOT_INVALID_SLOT", player); return; @@ -50,7 +50,7 @@ public class SlotCommand extends SWCommand { } @Register(value = "pick", description = "OTHER_NOCLIP_SLOT_HELP_PICK") - public void eyedropBlock(Player player) { + public void eyedropBlock(@Validator Player player) { Block block = player.getTargetBlockExact(6); ItemStack itemStack; if (block == null) { @@ -61,7 +61,7 @@ public class SlotCommand extends SWCommand { } @Register(value = "drop", description = "OTHER_NOCLIP_SLOT_HELP_DROP") - public void dropBlock(Player player) { + public void dropBlock(@Validator Player player) { player.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java index 85f73e04..19cede21 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java @@ -35,8 +35,8 @@ public class TNTClickListener implements Listener { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; if (event.getHand() != EquipmentSlot.HAND) return; - if (!Permission.BUILD.hasPermission(event.getPlayer())); Entity entity = event.getRightClicked(); if (event.getRightClicked() instanceof TNTPrimed) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java index 576b4fa1..b48ccad5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java @@ -81,6 +81,8 @@ public class BauMemberUpdate extends PacketHandler implements Listener { if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { SPECTATORS.add(event.getPlayer()); event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false)); + } else { + event.getPlayer().removePotionEffect(PotionEffectType.GLOWING); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java index 535551ab..13cf0d0c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java @@ -42,7 +42,7 @@ public class ItemFrameListener implements Listener { return; } - if(!Permission.BUILD.hasPermission((Player) event.getDamager())) return; + if(Permission.SPECTATOR.hasPermission((Player) event.getDamager())) return; event.setCancelled(true); ItemFrame itemFrame = (ItemFrame) event.getEntity(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java index a377db87..40e32eda 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java @@ -40,7 +40,7 @@ public class WorldEditListener implements Listener { if (!isWorldEditCommand(e.getMessage().split(" ")[0])) return; Player p = e.getPlayer(); - if (!Permission.BUILD.hasPermission(e.getPlayer())) { + if (Permission.SPECTATOR.hasPermission(e.getPlayer())) { BauSystem.MESSAGE.send("NO_PERMISSION", p); e.setCancelled(true); e.setMessage("/"); From 6e9693d8384eca93160f11c175bebd55eb5dba47 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Dec 2023 15:06:49 +0100 Subject: [PATCH 091/139] Update Techhider of Spectators --- .../features/world/SpectatorListener.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index 68bb465a..10fd30ea 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.core.CraftbukkitWrapper; +import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import de.steamwar.techhider.TechHider; import org.bukkit.Bukkit; @@ -49,9 +50,56 @@ public class SpectatorListener implements Listener { private static final Set NO_TECHHIDER = new HashSet<>(); static { + Set materials = new HashSet<>(); + materials.add(Material.REDSTONE_WIRE); + materials.add(Material.REDSTONE_TORCH); + materials.add(Material.REDSTONE_BLOCK); + materials.add(Material.REPEATER); + materials.add(Material.COMPARATOR); + materials.add(Material.LEVER); + for (Material value : Material.values()) { + if (value.name().endsWith("_BUTTON")) { + materials.add(value); + } + if (value.name().endsWith("_PRESSURE_PLATE")) { + materials.add(value); + } + if (value.name().endsWith("_SIGN")) { + materials.add(value); + } + } + materials.add(SWItem.getMaterial("SCULK_SENSOR")); + materials.add(SWItem.getMaterial("CALIBRATED_SCULK_SENSOR")); + materials.add(SWItem.getMaterial("SCULK_SHRIEKER")); + materials.add(SWItem.getMaterial("AMETHYST_BLOCK")); + materials.add(SWItem.getMaterial("AMETHYST_CLUSTER")); + materials.add(SWItem.getMaterial("SMALL_AMETHYST_BUG")); + materials.add(SWItem.getMaterial("MEDIUM_AMETHYST_BUG")); + materials.add(SWItem.getMaterial("LARGE_AMETHYST_BUG")); + materials.add(Material.TRIPWIRE_HOOK); + materials.add(Material.TRIPWIRE); + materials.add(Material.DAYLIGHT_DETECTOR); + materials.add(SWItem.getMaterial("LIGHTNING_ROD")); + materials.add(Material.PISTON); + materials.add(Material.PISTON_HEAD); + materials.add(Material.MOVING_PISTON); + materials.add(Material.STICKY_PISTON); + materials.add(Material.SLIME_BLOCK); + materials.add(Material.HONEY_BLOCK); + materials.add(Material.OBSERVER); + materials.add(Material.RAIL); + materials.add(Material.POWERED_RAIL); + materials.add(Material.DETECTOR_RAIL); + materials.add(Material.ACTIVATOR_RAIL); + materials.add(Material.TNT); + materials.add(Material.REDSTONE_ORE); + materials.add(SWItem.getMaterial("SCAFFOLDING")); + materials.add(Material.WATER); + materials.remove(Material.BARRIER); + materials.remove(Material.STONE); TechHider techHider = new TechHider((player, i, i1) -> { return Permission.BUILD.hasPermission(player) || Permission.isTempOnlySpectator(player) || NO_TECHHIDER.contains(player); - }, Material.END_STONE, new HashSet<>(Arrays.asList(Material.REDSTONE_WIRE)), new HashSet<>()); + }, Material.END_STONE, materials, new HashSet<>()); techHider.enable(); } From 96b84a798b76b3f24b60eb7cfdd67c729230879c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Dec 2023 16:45:48 +0100 Subject: [PATCH 092/139] Update BauMemberUpdate --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../features/world/BauMemberUpdate.java | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index d34ae1ef..1878486b 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -29,6 +29,7 @@ LIST_NEXT_PAGE=§eNext page # Permissions NO_PERMISSION = You are not allowed to use that here +SPECTATOR = §fSpectator # Scoreboard SCOREBOARD_TIME = Time diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 535caa3f..ff2cfe89 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -29,6 +29,7 @@ LIST_NEXT_PAGE=§eNächste Seite # Permission NO_PERMISSION = Du darfst dies hier nicht nutzen +SPECTATOR = §fZuschauer # Scoreboard SCOREBOARD_TIME = Uhrzeit diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java index b48ccad5..86742974 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java @@ -21,12 +21,18 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.region.Color; +import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; +import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; +import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import org.bukkit.Bukkit; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -61,6 +67,7 @@ public class BauMemberUpdate extends PacketHandler implements Listener { Permission.removeForceOnlySpectator(player); newSpectator.add(player); player.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false)); + showSpectatorNotice(player); } } else { if (Permission.SUPERVISOR.hasPermission(player)) { @@ -70,6 +77,7 @@ public class BauMemberUpdate extends PacketHandler implements Listener { SPECTATORS.remove(player); newBuilder.add(player); player.removePotionEffect(PotionEffectType.GLOWING); + BossBarService.instance.remove(player, GlobalRegion.getInstance(), "spectator"); } } }); @@ -81,11 +89,20 @@ public class BauMemberUpdate extends PacketHandler implements Listener { if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { SPECTATORS.add(event.getPlayer()); event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false)); + showSpectatorNotice(event.getPlayer()); } else { event.getPlayer().removePotionEffect(PotionEffectType.GLOWING); } } + private static void showSpectatorNotice(Player player) { + BauSystemBossbar bossbar = BossBarService.instance.get(player, GlobalRegion.getInstance(), "spectator"); + bossbar.setTitle(BauSystem.MESSAGE.parse("SPECTATOR", player)); + bossbar.setColor(BarColor.WHITE); + bossbar.setStyle(BarStyle.SOLID); + bossbar.setProgress(1.0); + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { SPECTATORS.remove(event.getPlayer()); From 2c5a50bff3d17e22eeb7c09a3dd860a3e0c8fad6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Dec 2023 17:54:54 +0100 Subject: [PATCH 093/139] Update BauMemberUpdate --- .../de/steamwar/bausystem/features/world/BauMemberUpdate.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java index 86742974..be3bb44b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; From cdac4235f55ab3e7da89e7330590cf9e463b3631 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 25 Dec 2023 11:38:20 +0100 Subject: [PATCH 094/139] Fix SimulatorTNTPhaseSettingsGui --- .../features/simulator/gui/SimulatorTNTPhaseSettingsGui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java index 01ec8b04..9bfc4fe5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTPhaseSettingsGui.java @@ -83,7 +83,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui { SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> { new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> { - if (integer < 0) return false; + if (integer < 1) return false; tnt.setCount(integer); SimulatorWatcher.update(simulator); return true; From 21aa22d75fd65b4e47865500a0d41e550a9b967d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 27 Dec 2023 17:34:00 +0100 Subject: [PATCH 095/139] Fix SteamWarLuaPlugin WE permission for WorldEdit commands --- .../bausystem/features/script/lua/SteamWarLuaPlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index b2bf51cc..7b1fdee9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -25,6 +25,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.extension.platform.Actor; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.bausystem.features.script.lua.libs.LuaLib; import de.steamwar.bausystem.features.world.WorldEditListener; @@ -126,6 +127,9 @@ public class SteamWarLuaPlugin extends TwoArgFunction { Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); String[] commandSplit = command.split(" "); if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) { + if (!Permission.WORLDEDIT.hasPermission(player)) { + return NIL; + } EditSession editSession = WorldEditUtils.getEditSession(player); Actor actor = BukkitAdapter.adapt(player); WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); From ada8fefd624bce6d762083e7b352210c6eed5138 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 14 Jan 2024 11:52:20 +0100 Subject: [PATCH 096/139] Fix SimulatorSaver --- .../bausystem/features/simulator/storage/SimulatorSaver.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java index 285be22f..48ccfd7a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/storage/SimulatorSaver.java @@ -32,6 +32,10 @@ import java.io.IOException; public class SimulatorSaver { public void saveSimulator(File directory, Simulator simulator) { + if (!directory.exists()) { + directory.mkdirs(); + } + YAPIONObject simulatorObject = new YAPIONObject(); simulatorObject.add("material", simulator.getMaterial().name()); simulatorObject.add("autoTrace", simulator.isAutoTrace()); From c2bec980638ca5835df5a77a1ba40ad09c71e5fa Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 17 Jan 2024 16:20:24 +0100 Subject: [PATCH 097/139] Checkpoint idle server --- BauSystem_Main/src/BauSystem.properties | 2 +- BauSystem_Main/src/BauSystem_de.properties | 2 +- .../src/de/steamwar/bausystem/BauSystem.java | 19 --- .../features/world/AFKStopperListener.java | 41 +++--- .../bausystem/features/world/RamUsage.java | 120 ------------------ 5 files changed, 19 insertions(+), 165 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index c7f98ce5..f9c2afde 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -902,7 +902,7 @@ REGION_TNT_NO_PERMS=§cYou are not allowed to toggle tnt damage here REGION_TNT_BUILD_DESTROY=§cAn explosion would have destroyed blocks in the building area REGION_TNT_TB_DESTROY=§cAn explosion would have destroyed blocks in the testblock area -AFK_KICK_MESSAGE=§cNothing happened on this server for 5 minutes. +AFK_KICK_MESSAGE=§cNothing happened on this server for 15 minutes. AFK_WARNING_MESSAGE=§cThis server will stop in one minute if you remain inactive SKIN_HELP = §8/§eskin §8[§7Shortform§8] §8[§7Creator§8|§epublic§8] §8[§7Name...§8] §8- §7Creates the skin schematic. Use 'public' as creator to have no creator, then copy the message to YoyoNow by clicking diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 2186282a..871e66de 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -863,7 +863,7 @@ REGION_TNT_TB=§aTNT-Schaden außerhalb Baurahmen aktiviert REGION_TNT_NO_PERMS=§cDu darfst hier nicht TNT-Schaden (de-)aktivieren REGION_TNT_BUILD_DESTROY=§cEine Explosion hätte Blöcke im Baubereich zerstört REGION_TNT_TB_DESTROY=§cEine Explosion hätte Blöcke im Testblockbereich zerstört -AFK_KICK_MESSAGE=§cAuf diesem Server ist seit 5 Minuten nichts passiert. +AFK_KICK_MESSAGE=§cAuf diesem Server ist seit 15 Minuten nichts passiert. AFK_WARNING_MESSAGE=§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt SKIN_HELP = §8/§eskin §8[§7Kuerzel§8] §8[§7Creator§8|§epublic§8] §8[§7Name...§8] §8- §7Erstellt die Skin Schematics. 'public' als Creator nutzen für keinen Creator, danach die nachricht an YoyoNow kopieren (mit Click kopieren) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 10b36297..4b62243f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils; -import de.steamwar.bausystem.features.world.RamUsage; import de.steamwar.bausystem.linkage.LinkageUtils; import de.steamwar.bausystem.region.loader.PrototypeLoader; import de.steamwar.bausystem.region.loader.RegionLoader; @@ -76,25 +75,7 @@ public class BauSystem extends JavaPlugin implements Listener { new Updater(RegionLoader.file, RegionLoader::load); LinkageUtils.link(); - RamUsage.init(); TickListener.impl.init(); - - // This could disable any watchdog stuff. We need to investigate if this is a problem. - /* - Thread thread = new Thread(() -> { - while (true) { - WatchdogThread.tick(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - }); - thread.setName("WatchdogThread ticker"); - thread.setDaemon(true); - thread.start(); - */ } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index 52249a23..70434d25 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -20,63 +20,56 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.CheckpointUtils; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; @Linked public class AFKStopperListener implements Listener { - // CPU > 50% - // RAM > 60% - private int afkTicks = 0; public AFKStopperListener() { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { - // System.out.println("CPU: " + load + " RAM: " + usage); - if (Bukkit.getOnlinePlayers().isEmpty()) { - if (RamUsage.getLoad() >= 50.0 || RamUsage.getUsage() >= 0.6) { - Bukkit.shutdown(); - return; - } - } else if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) { - afkTicks = 0; - return; - } switch (afkTicks) { - case 90: - Bukkit.shutdown(); - break; case 15: for (Player p : Bukkit.getOnlinePlayers()) { p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p)); } - case 12: + case 14: BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE"); default: afkTicks++; } - }, 20*60, 20*60); //every minute + }, 1200, 1200); //every minute } @EventHandler public void onPlayerMove(PlayerMoveEvent event) { - if (event.getTo() == null) return; - if (event.getFrom().getPitch() != event.getTo().getPitch()) { + Location to = event.getTo(); + if (to == null) + return; + + Location from = event.getFrom(); + if (from.getPitch() != to.getPitch() || from.getYaw() != to.getYaw()) afkTicks = 0; - } - if (event.getFrom().getYaw() != event.getTo().getYaw()) { - afkTicks = 0; - } } @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { event.getPlayer().setOp(true); } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) + CheckpointUtils.freeze(); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java deleted file mode 100644 index 1d187444..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 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.world; - -import lombok.experimental.UtilityClass; - -import java.io.*; -import java.util.concurrent.locks.LockSupport; - -@UtilityClass -public class RamUsage { - - private File meminfo = new File("/proc/meminfo"); - private File stat = new File("/proc/stat"); - - private double usageSelf = 0D; - private double usage = 0D; - private double load = 0D; - - public static void init() { - } - - static { - Thread thread = new Thread(() -> { - while (true) { - long maxMemory = Runtime.getRuntime().maxMemory(); - long totalMemory = Runtime.getRuntime().totalMemory(); - long freeMemory = Runtime.getRuntime().freeMemory(); - long usedMemory = totalMemory - freeMemory; - usageSelf = usedMemory / (double) totalMemory; - double usageSelfByMax = usedMemory / (double) maxMemory; - // System.out.println("Self: " + usageSelf + "/" + usageSelfByMax + /* " " + maxMemory + " " + totalMemory + " " + freeMemory + " " + usedMemory + */ " Ram: " + usage + " CPU: " + load); - - usage = _getUsage(); - load = _getLoad(); - Thread.yield(); - LockSupport.parkNanos(1000000000L); - } - }); - thread.setDaemon(true); - thread.setName("RamUsage"); - thread.start(); - } - - public static double getUsage() { - return usage; - } - - private static double _getUsage() { - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) { - String memTotal = bufferedReader.readLine().replaceAll(" +", " "); - bufferedReader.readLine(); - String memAvailable = bufferedReader.readLine().replaceAll(" +", " "); - - long memTotalLong = getNumber(memTotal); - long memAvailableLong = getNumber(memAvailable); - return (memTotalLong - memAvailableLong) / (double) memTotalLong; - } catch (IOException e) { - return 1D; - } - } - - public static double getLoad() { - return load; - } - - private long lastCpuSecond = -1; - private long lastCpuForth = -1; - private long lastCpuFifth = -1; - - private static double _getLoad() { - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(stat)))) { - String[] strings = bufferedReader.readLine().split(" "); - - long cpuSecond = Long.parseLong(strings[2]); - long cpuForth = Long.parseLong(strings[4]); - long cpuFifth = Long.parseLong(strings[5]); - - if (lastCpuSecond == -1) { - lastCpuSecond = cpuSecond; - lastCpuForth = cpuForth; - lastCpuFifth = cpuFifth; - return 0D; - } - - long cpuSecondDiff = cpuSecond - lastCpuSecond; - long cpuForthDiff = cpuForth - lastCpuForth; - long cpuSixthDiff = cpuFifth - lastCpuFifth; - - lastCpuSecond = cpuSecond; - lastCpuForth = cpuForth; - lastCpuFifth = cpuFifth; - - return (cpuSecondDiff + cpuForthDiff) / (double) (cpuSecondDiff + cpuForthDiff + cpuSixthDiff); - } catch (IOException e) { - return 1D; - } - } - - private static long getNumber(String s) { - return Long.parseLong(s.split(" ")[1]); - } -} From ad9b0aeab0c854607ee2ed15d7af73f8264f2d53 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 19 Jan 2024 15:52:06 +0100 Subject: [PATCH 098/139] Fix freeze order. --- .../steamwar/bausystem/features/world/AFKStopperListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index 70434d25..263324c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -26,6 +26,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; @@ -67,7 +68,7 @@ public class AFKStopperListener implements Listener { event.getPlayer().setOp(true); } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) CheckpointUtils.freeze(); From da1ea27f610c3337eb931d2203f7740d51c00e12 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 19 Jan 2024 17:02:57 +0100 Subject: [PATCH 099/139] Remove Permission.SPECTATOR --- .../src/de/steamwar/bausystem/BauSystem.java | 44 +++++++------------ .../src/de/steamwar/bausystem/Permission.java | 10 ++--- .../features/simulator/SimulatorCursor.java | 10 ++--- .../features/util/PistonCalculator.java | 2 +- .../features/util/TNTClickListener.java | 2 +- .../features/world/BauMemberUpdate.java | 2 +- .../features/world/ItemFrameListener.java | 2 +- .../features/world/SignEditFrom20.java | 2 +- .../features/world/SignEditUntil19.java | 2 +- .../features/world/SpectatorListener.java | 20 ++++----- .../features/world/WorldEditListener.java | 2 +- 11 files changed, 44 insertions(+), 54 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index b0548ced..0bda77c1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -28,6 +28,7 @@ import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.Updater; import de.steamwar.bausystem.utils.TickListener; import de.steamwar.bausystem.worlddata.WorldData; +import de.steamwar.command.AbstractValidator; import de.steamwar.command.SWCommandUtils; import de.steamwar.message.Message; import lombok.Getter; @@ -77,38 +78,27 @@ public class BauSystem extends JavaPlugin implements Listener { new Updater(PrototypeLoader.file, PrototypeLoader::load); new Updater(RegionLoader.file, RegionLoader::load); - SWCommandUtils.addValidator(Player.class, (player, object, messageSender) -> { - if (Permission.BUILD.hasPermission(player)) { - return true; - } - messageSender.send("NO_PERMISSION"); - return false; - }); - SWCommandUtils.addValidator(CommandSender.class, (commandSender, object, messageSender) -> { - if (commandSender instanceof Player) { - if (Permission.BUILD.hasPermission((Player) commandSender)) { - return true; - } - messageSender.send("NO_PERMISSION"); - return false; - } - return true; - }); - SWCommandUtils.addValidator("supervisor", (commandSender, object, messageSender) -> { - if (commandSender instanceof Player) { - if (Permission.SUPERVISOR.hasPermission((Player) commandSender)) { - return true; - } - messageSender.send("NO_PERMISSION"); - return false; - } - return true; - }); + SWCommandUtils.addValidator(Player.class, validator(Permission.BUILD)); + SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD)); + SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR)); LinkageUtils.link(); TickListener.impl.init(); } + private AbstractValidator validator(Permission permission) { + return (commandSender, object, messageSender) -> { + if (commandSender instanceof Player) { + if (permission.hasPermission((Player) commandSender)) { + return true; + } + messageSender.send("NO_PERMISSION"); + return false; + } + return true; + }; + } + @Override public void onDisable() { LinkageUtils.unlink(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 2d642ac1..0985a62d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -49,9 +49,9 @@ public enum Permission { REAL_SPECTATOR(bauweltMember -> { return !bauweltMember.isBuild() && !bauweltMember.isSupervisor(); }), - SPECTATOR(bauweltMember -> { - return !BUILD.permissionPredicate.test(bauweltMember); - }), + /** + * Primarily used for {@link de.steamwar.bausystem.linkage.specific.GuiItem} + */ MEMBER(bauweltMember -> { return true; }); @@ -87,10 +87,10 @@ public enum Permission { public boolean hasPermission(Player member) { if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) { - return this != SPECTATOR && this != REAL_SPECTATOR; + return this != REAL_SPECTATOR; } BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); - if (bauweltMember == null) return this == SPECTATOR || this == REAL_SPECTATOR; + if (bauweltMember == null) return this == REAL_SPECTATOR; return permissionPredicate.test(bauweltMember); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 0c335c02..a7664158 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -96,7 +96,7 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; + if (!Permission.BUILD.hasPermission(event.getPlayer())) return; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { calcCursor(event.getPlayer()); }, 0); @@ -104,13 +104,13 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; + if (!Permission.BUILD.hasPermission(event.getPlayer())) return; calcCursor(event.getPlayer()); } @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; + if (!Permission.BUILD.hasPermission(event.getPlayer())) return; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { calcCursor(event.getPlayer()); }, 1); @@ -159,7 +159,7 @@ public class SimulatorCursor implements Listener { if (calculating.contains(player)) return; calculating.add(player); } - if (Permission.SPECTATOR.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) { + if (!Permission.BUILD.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) { if (removeCursor(player) || SimulatorWatcher.show(null, player)) { SWUtils.sendToActionbar(player, ""); } @@ -344,7 +344,7 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; + if (!Permission.BUILD.hasPermission(event.getPlayer())) return; if (!ItemUtils.isItem(event.getItem(), "simulator")) { return; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java index 6703bd5c..de9ea34a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java @@ -50,7 +50,7 @@ public class PistonCalculator implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; + if (!Permission.BUILD.hasPermission(event.getPlayer())) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (!event.hasItem() || event.getItem().getType() != Material.SLIME_BALL) return; if (event.getClickedBlock() == null) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java index 19cede21..3284876a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java @@ -35,7 +35,7 @@ public class TNTClickListener implements Listener { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; + if (!Permission.BUILD.hasPermission(event.getPlayer())) return; if (event.getHand() != EquipmentSlot.HAND) return; Entity entity = event.getRightClicked(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java index be3bb44b..46c10ef1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java @@ -85,7 +85,7 @@ public class BauMemberUpdate extends PacketHandler implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { SPECTATORS.add(event.getPlayer()); event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false)); showSpectatorNotice(event.getPlayer()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java index 13cf0d0c..535551ab 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java @@ -42,7 +42,7 @@ public class ItemFrameListener implements Listener { return; } - if(Permission.SPECTATOR.hasPermission((Player) event.getDamager())) return; + if(!Permission.BUILD.hasPermission((Player) event.getDamager())) return; event.setCancelled(true); ItemFrame itemFrame = (ItemFrame) event.getEntity(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java index df4935dc..1ccfb014 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java @@ -82,7 +82,7 @@ public class SignEditFrom20 implements Listener { } private void edit(Player player, Block block) { - if (Permission.SPECTATOR.hasPermission(player)) return; + if (!Permission.BUILD.hasPermission(player)) return; Sign sign = (Sign) block.getState(); Side side = signSide(player, block); SignSide signSide = sign.getSide(side); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java index 89a4120d..7aebd4e9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java @@ -69,7 +69,7 @@ public class SignEditUntil19 implements Listener { } private void edit(Player player, Block block) { - if (Permission.SPECTATOR.hasPermission(player)) return; + if (!Permission.BUILD.hasPermission(player)) return; Sign sign = (org.bukkit.block.Sign) block.getState(); String[] lines = sign.getLines(); for (int i = 0; i < lines.length; i++) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index 10fd30ea..43b04d2c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -176,7 +176,7 @@ public class SpectatorListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockMultiPlace(BlockMultiPlaceEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setCancelled(true); } } @@ -184,56 +184,56 @@ public class SpectatorListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockCanBuild(BlockCanBuildEvent event) { if (event.getPlayer() == null) return; - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setBuildable(false); } } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerBucketEntity(PlayerBucketEntityEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerBucketFill(PlayerBucketFillEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerDropItem(PlayerDropItemEvent event) { - if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + if (!Permission.BUILD.hasPermission(event.getPlayer())) { event.setCancelled(true); } } @@ -241,7 +241,7 @@ public class SpectatorListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityPickupItem(EntityPickupItemEvent event) { if (!(event.getEntity() instanceof Player)) return; - if (Permission.SPECTATOR.hasPermission((Player) event.getEntity())) { + if (!Permission.BUILD.hasPermission((Player) event.getEntity())) { event.setCancelled(true); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java index 40e32eda..a377db87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java @@ -40,7 +40,7 @@ public class WorldEditListener implements Listener { if (!isWorldEditCommand(e.getMessage().split(" ")[0])) return; Player p = e.getPlayer(); - if (Permission.SPECTATOR.hasPermission(e.getPlayer())) { + if (!Permission.BUILD.hasPermission(e.getPlayer())) { BauSystem.MESSAGE.send("NO_PERMISSION", p); e.setCancelled(true); e.setMessage("/"); From ea5df6cee37b848c5d96edff0f1204023209325b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 19 Jan 2024 17:08:11 +0100 Subject: [PATCH 100/139] Fix SteamWarLuaPlugin --- .../bausystem/features/script/lua/SteamWarLuaPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index 06a6334b..0105abad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -128,7 +128,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction { Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); String[] commandSplit = command.split(" "); if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) { - if (!Permission.WORLDEDIT.hasPermission(player)) { + if (!Permission.BUILD.hasPermission(player)) { return NIL; } EditSession editSession = WorldEditUtils.getEditSession(player); From 775d428671ed6eace044e93ed2519645a8dbadc9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 19 Jan 2024 20:33:27 +0100 Subject: [PATCH 101/139] Fix SpectatorListener --- .../bausystem/features/world/SpectatorListener.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index 43b04d2c..0fd30b13 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -21,10 +21,12 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; +import de.steamwar.sql.BauweltMember; import de.steamwar.techhider.TechHider; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -128,6 +130,11 @@ public class SpectatorListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), event.getPlayer().getUniqueId()); + if (bauweltMember == null) { + event.getPlayer().kickPlayer(""); + return; + } if (Permission.SUPERVISOR.hasPermission(event.getPlayer())) { return; } From 94bf2f3ae6ae96d80f42815e02b4db2a22040cfb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Jan 2024 20:35:19 +0100 Subject: [PATCH 102/139] Hotfix SpectatorListener --- .../steamwar/bausystem/features/world/SpectatorListener.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index 0fd30b13..51eb1fe5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -130,6 +130,9 @@ public class SpectatorListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) { + return; + } BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), event.getPlayer().getUniqueId()); if (bauweltMember == null) { event.getPlayer().kickPlayer(""); From e77680d25a283338d9f9d8a21f22fc42fa1ef592 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 23 Jan 2024 10:11:19 +0100 Subject: [PATCH 103/139] Fix AxiomPermissionCheck --- .../bausystem/features/simulator/data/tnt/TNTPhase.java | 1 - .../bausystem/features/world/AxiomPermissionCheck.java | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java index 2e913bdd..4c03ac9b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java @@ -24,7 +24,6 @@ import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; -import de.steamwar.bausystem.region.tags.Tag; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java index bdfe3d40..c6cecb2b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.world; import com.moulberry.axiom.event.AxiomHandshakeEvent; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.BauServer; import de.steamwar.linkage.Linked; import de.steamwar.linkage.PluginCheck; import org.bukkit.event.EventHandler; @@ -32,7 +33,7 @@ public class AxiomPermissionCheck implements Listener { @EventHandler public void onAxiomHandshake(AxiomHandshakeEvent event) { - if (!Permission.BUILD.hasPermission(event.getPlayer())) return; + if (Permission.BUILD.hasPermission(event.getPlayer()) || BauServer.getInstance().getOwner().equals(event.getPlayer().getUniqueId())) return; event.setCancelled(true); } } From d1afb344d9d7f4ca3bd5bba07654c12168e53742 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 30 Jan 2024 16:06:53 +0100 Subject: [PATCH 104/139] Fix SimulatorSaver --- .../data/redstone/RedstonePhase.java | 2 +- .../features/tpslimit/TPSSystem.java | 66 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java index f2b99d36..614be659 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java @@ -54,7 +54,7 @@ public final class RedstonePhase extends SimulatorPhase { block.setType(Material.REDSTONE_BLOCK); } }); - tickEnd.accept(tickOffset + lifetime, new SimulatorAction(0, 1) { + tickStart.accept(tickOffset + lifetime, new SimulatorAction(ORDER_LIMIT + 1, 1) { @Override public void accept(World world) { BlockState state = blockState.get(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index b801e324..aa25a433 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -26,33 +26,31 @@ import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.bausystem.utils.TickEndEvent; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; import de.steamwar.core.Core; import de.steamwar.core.TPSWarpUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.api.Plain; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.boss.BarColor; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; import java.util.Arrays; -import java.util.concurrent.atomic.AtomicInteger; @Linked -public class TPSSystem implements Plain { +public class TPSSystem implements Listener { @Getter private double currentTPSLimit = 20; @@ -87,12 +85,9 @@ public class TPSSystem implements Plain { instance = this; } - private BukkitTask stepper = null; - private void setTPS(double tps) { - if (stepper != null) { - stepper.cancel(); - stepper = null; + if (currentlyStepping) { + currentlyStepping = false; Bukkit.getOnlinePlayers().forEach(player -> { BossBarService.instance.remove(player, GlobalRegion.getInstance(), "TickStep"); }); @@ -120,27 +115,34 @@ public class TPSSystem implements Plain { }); } - private void setSkip(int steps, double tpsLimitToUse) { - double currentLimit = tpsLimitToUse == 20 ? 0 : currentTPSLimit; - setTPS(tpsLimitToUse); - stepper = new BukkitRunnable() { - AtomicInteger stepsLeft = new AtomicInteger(steps); + private boolean currentlyStepping = false; + private double currentLimit; + private int stepsTotal; + private int stepsLeft; - @Override - public void run() { - if (steps > 1) { - Bukkit.getOnlinePlayers().forEach(player -> { - BauSystemBossbar bossbar = BossBarService.instance.get(player, GlobalRegion.getInstance(), "TickStep"); - bossbar.setColor(BarColor.YELLOW); - bossbar.setTitle(BauSystem.MESSAGE.parse("TICK_BOSSBAR", player, (steps - stepsLeft.get()), steps)); - bossbar.setProgress((steps - stepsLeft.get()) / (double) steps); - }); - } - if (stepsLeft.decrementAndGet() < 0) { - setTPS(currentLimit); - } - } - }.runTaskTimer(BauSystem.getInstance(), 1, 1); + private void setSkip(int steps, double tpsLimitToUse) { + currentLimit = tpsLimitToUse == 20 ? 0 : currentTPSLimit; + setTPS(tpsLimitToUse); + stepsLeft = steps; + stepsTotal = steps; + currentlyStepping = true; + } + + @EventHandler + public void onTickEnd(TickEndEvent event) { + if (!currentlyStepping) return; + if (stepsTotal > 1) { + Bukkit.getOnlinePlayers().forEach(player -> { + BauSystemBossbar bossbar = BossBarService.instance.get(player, GlobalRegion.getInstance(), "TickStep"); + bossbar.setColor(BarColor.YELLOW); + bossbar.setTitle(BauSystem.MESSAGE.parse("TICK_BOSSBAR", player, (stepsTotal - stepsLeft), stepsTotal)); + bossbar.setProgress((stepsTotal - stepsLeft) / (double) stepsTotal); + }); + } + stepsLeft--; + if (stepsLeft <= 0) { + setTPS(currentLimit); + } } private class TPSBaseCommand extends SWCommand { @@ -321,7 +323,7 @@ public class TPSSystem implements Plain { @Override public String get(Region region, Player p) { - if (TPSSystem.getInstance().stepper != null) { + if (TPSSystem.getInstance().currentlyStepping) { long time = System.currentTimeMillis() % 1000; if (time < 250) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7•••"; From 78c0bc51b9fc6a79e9363bda054afc17fb06f7da Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 30 Jan 2024 16:06:53 +0100 Subject: [PATCH 105/139] Fix SimulatorSaver --- .../data/redstone/RedstonePhase.java | 2 +- .../features/tpslimit/TPSSystem.java | 66 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java index f2b99d36..614be659 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/redstone/RedstonePhase.java @@ -54,7 +54,7 @@ public final class RedstonePhase extends SimulatorPhase { block.setType(Material.REDSTONE_BLOCK); } }); - tickEnd.accept(tickOffset + lifetime, new SimulatorAction(0, 1) { + tickStart.accept(tickOffset + lifetime, new SimulatorAction(ORDER_LIMIT + 1, 1) { @Override public void accept(World world) { BlockState state = blockState.get(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index 43eb40da..4368966f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -26,33 +26,31 @@ import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.bausystem.utils.TickEndEvent; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; import de.steamwar.core.Core; import de.steamwar.core.TPSWarpUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.api.Plain; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.boss.BarColor; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; import java.util.Arrays; -import java.util.concurrent.atomic.AtomicInteger; @Linked -public class TPSSystem implements Plain { +public class TPSSystem implements Listener { @Getter private double currentTPSLimit = 20; @@ -87,12 +85,9 @@ public class TPSSystem implements Plain { instance = this; } - private BukkitTask stepper = null; - private void setTPS(double tps) { - if (stepper != null) { - stepper.cancel(); - stepper = null; + if (currentlyStepping) { + currentlyStepping = false; Bukkit.getOnlinePlayers().forEach(player -> { BossBarService.instance.remove(player, GlobalRegion.getInstance(), "TickStep"); }); @@ -120,27 +115,34 @@ public class TPSSystem implements Plain { }); } - private void setSkip(int steps, double tpsLimitToUse) { - double currentLimit = tpsLimitToUse == 20 ? 0 : currentTPSLimit; - setTPS(tpsLimitToUse); - stepper = new BukkitRunnable() { - AtomicInteger stepsLeft = new AtomicInteger(steps); + private boolean currentlyStepping = false; + private double currentLimit; + private int stepsTotal; + private int stepsLeft; - @Override - public void run() { - if (steps > 1) { - Bukkit.getOnlinePlayers().forEach(player -> { - BauSystemBossbar bossbar = BossBarService.instance.get(player, GlobalRegion.getInstance(), "TickStep"); - bossbar.setColor(BarColor.YELLOW); - bossbar.setTitle(BauSystem.MESSAGE.parse("TICK_BOSSBAR", player, (steps - stepsLeft.get()), steps)); - bossbar.setProgress((steps - stepsLeft.get()) / (double) steps); - }); - } - if (stepsLeft.decrementAndGet() < 0) { - setTPS(currentLimit); - } - } - }.runTaskTimer(BauSystem.getInstance(), 1, 1); + private void setSkip(int steps, double tpsLimitToUse) { + currentLimit = tpsLimitToUse == 20 ? 0 : currentTPSLimit; + setTPS(tpsLimitToUse); + stepsLeft = steps; + stepsTotal = steps; + currentlyStepping = true; + } + + @EventHandler + public void onTickEnd(TickEndEvent event) { + if (!currentlyStepping) return; + if (stepsTotal > 1) { + Bukkit.getOnlinePlayers().forEach(player -> { + BauSystemBossbar bossbar = BossBarService.instance.get(player, GlobalRegion.getInstance(), "TickStep"); + bossbar.setColor(BarColor.YELLOW); + bossbar.setTitle(BauSystem.MESSAGE.parse("TICK_BOSSBAR", player, (stepsTotal - stepsLeft), stepsTotal)); + bossbar.setProgress((stepsTotal - stepsLeft) / (double) stepsTotal); + }); + } + stepsLeft--; + if (stepsLeft <= 0) { + setTPS(currentLimit); + } } public TypeValidator player() { @@ -341,7 +343,7 @@ public class TPSSystem implements Plain { @Override public String get(Region region, Player p) { - if (TPSSystem.getInstance().stepper != null) { + if (TPSSystem.getInstance().currentlyStepping) { long time = System.currentTimeMillis() % 1000; if (time < 250) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7•••"; From b891c5adf111a4ace5072c52310ce138e620957d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 30 Jan 2024 19:48:43 +0100 Subject: [PATCH 106/139] Fix TPSSystem --- .../src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index 4368966f..388e0dbf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -31,6 +31,7 @@ import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; import de.steamwar.core.Core; import de.steamwar.core.TPSWarpUtils; import de.steamwar.core.TPSWatcher; From f83ba6ab964ae71c3297e97c60422bc2235c328e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Feb 2024 20:02:43 +0100 Subject: [PATCH 107/139] Fix AxiomPermissionCheck --- .../bausystem/features/world/AxiomPermissionCheck.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java index 5ee07dae..05faf23a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java @@ -32,7 +32,10 @@ public class AxiomPermissionCheck implements Listener { @EventHandler public void onAxiomHandshake(AxiomHandshakeEvent event) { - if (Permission.WORLDEDIT.hasPermission(event.getPlayer())) return; + if (Permission.WORLDEDIT.hasPermission(event.getPlayer())) { + event.setMaxBufferSize(Short.MAX_VALUE); + return; + } event.setCancelled(true); } } From 2ba51e66e01024f069ce6079f07bb7e1dad8474b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Feb 2024 21:48:14 +0100 Subject: [PATCH 108/139] Fix BindCommand --- .../bausystem/features/util/BindCommand.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java index ab213c83..c0190486 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java @@ -1,9 +1,17 @@ package de.steamwar.bausystem.features.util; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.event.platform.CommandEvent; +import com.sk89q.worldedit.extension.platform.Actor; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.script.ScriptCommand; import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.bausystem.features.world.WorldEditListener; +import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; @@ -20,14 +28,18 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; +import org.luaj.vm2.LuaValue; import java.lang.reflect.Field; import java.util.*; +import java.util.logging.Level; import java.util.stream.Collectors; @Linked public class BindCommand extends SWCommand implements Listener { + private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null; + @Linked public static class UnBindCommand extends SWCommand { @@ -107,7 +119,21 @@ public class BindCommand extends SWCommand implements Listener { PlayerCommandPreprocessEvent playerCommandPreprocessEvent = new PlayerCommandPreprocessEvent(event.getPlayer(), "/" + command); Bukkit.getPluginManager().callEvent(playerCommandPreprocessEvent); if (playerCommandPreprocessEvent.isCancelled()) return; - Bukkit.getServer().dispatchCommand(event.getPlayer(), command); + + Bukkit.getLogger().log(Level.INFO, event.getPlayer().getName() + " dispatched command: " + command); + String[] commandSplit = command.split(" "); + if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) { + if (!Permission.WORLDEDIT.hasPermission(event.getPlayer())) { + return; + } + EditSession editSession = WorldEditUtils.getEditSession(event.getPlayer()); + Actor actor = BukkitAdapter.adapt(event.getPlayer()); + WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); + editSession.flushSession(); + WorldEditUtils.addToPlayer(event.getPlayer(), editSession); + } else { + Bukkit.getServer().dispatchCommand(event.getPlayer(), command); + } }, 1); } From b211f9cf79ceb4176968102ad9541e3939013ebf Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 4 Feb 2024 01:18:50 +0100 Subject: [PATCH 109/139] Hot Hot Hot-fix Players on Bauserver without add --- .../features/world/AntiBauAddMemberFix.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java new file mode 100644 index 00000000..c406f5c7 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java @@ -0,0 +1,44 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.world; + +import de.steamwar.bausystem.config.BauServer; +import de.steamwar.linkage.Linked; +import de.steamwar.sql.BauweltMember; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +@Linked +public class AntiBauAddMemberFix implements Listener { + + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) { + return; + } + if (BauweltMember.getBauMember(BauServer.getInstance().getOwner(), event.getPlayer().getUniqueId()) == null) { + event.getPlayer().kickPlayer(""); + throw new SecurityException("The player " + event.getPlayer().getName() + " joined on the server of " + SteamwarUser.get(BauServer.getInstance().getOwnerID()).getUserName() + " without being added!"); + } + } +} From 7ded9eefa404aec6e9a48b3452b0072b7aee4537 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Feb 2024 22:39:33 +0100 Subject: [PATCH 110/139] Potential WE axe fix --- .../steamwar/bausystem/features/world/AFKStopperListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index 263324c3..81e2f4dd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -63,7 +63,7 @@ public class AFKStopperListener implements Listener { afkTicks = 0; } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) //Potential fix for potential race condition with WE axe spontaneously not working public void onPlayerJoin(PlayerJoinEvent event) { event.getPlayer().setOp(true); } From c2c686319db38f0af5f91cfc419c7d756241831c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 11 Feb 2024 15:17:07 +0100 Subject: [PATCH 111/139] Fix ServerLib --- .../bausystem/features/script/lua/libs/ServerLib.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java index 80134fba..2a28bf16 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -20,6 +20,8 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; +import de.steamwar.bausystem.features.tpslimit.TPSSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.inventory.SWItem; @@ -75,7 +77,7 @@ public class ServerLib implements LuaLib { tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES))); tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES))); tpsLib.set("current", getter(TPSWatcher::getTPS)); - // tpsLib.set("limit", getter(TPSLimitUtils::getCurrentTPSLimit)); + tpsLib.set("limit", getter(TPSSystem.getInstance()::getCurrentTPSLimit)); serverLib.set("tps", tpsLib); return serverLib; From 953db6942513bdf0b5156c714fed58cf4c086cd8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 16 Feb 2024 08:09:40 +0100 Subject: [PATCH 112/139] Fix BackupCommand --- .../steamwar/bausystem/features/backup/BackupCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java index f4194a4e..6e04d2a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java @@ -62,7 +62,7 @@ public class BackupCommand extends SWCommand { } @Register(value = "create", description = "BACKUP_HELP_CREATE") - public void backupCreate(@Validator Player p) { + public void backupCreate(@Validator("supervisor") Player p) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; @@ -79,7 +79,7 @@ public class BackupCommand extends SWCommand { } @Register(value = "load", description = "BACKUP_HELP_LOAD") - public void backupLoad(@Validator Player p, @Mapper("backupName") String backupName) { + public void backupLoad(@Validator("supervisor") Player p, @Mapper("backupName") String backupName) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; @@ -130,7 +130,7 @@ public class BackupCommand extends SWCommand { } SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> { p.getOpenInventory().close(); - backupLoad(p, s); + p.performCommand("backup load " + s); }); swListInv.open(); } From 21e7bd89afa75eb943e8c757f66ff643e81d5ba5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 16 Feb 2024 08:24:42 +0100 Subject: [PATCH 113/139] Fix BindCommand and SteamWarLuaPlugin --- .../features/script/lua/SteamWarLuaPlugin.java | 3 --- .../bausystem/features/util/BindCommand.java | 18 ++++++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index 0105abad..36cf05e3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -128,9 +128,6 @@ public class SteamWarLuaPlugin extends TwoArgFunction { Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); String[] commandSplit = command.split(" "); if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) { - if (!Permission.BUILD.hasPermission(player)) { - return NIL; - } EditSession editSession = WorldEditUtils.getEditSession(player); Actor actor = BukkitAdapter.adapt(player); WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java index c3acab82..9a93977e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java @@ -117,23 +117,21 @@ public class BindCommand extends SWCommand implements Listener { event.setCancelled(true); Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - PlayerCommandPreprocessEvent playerCommandPreprocessEvent = new PlayerCommandPreprocessEvent(event.getPlayer(), "/" + command); - Bukkit.getPluginManager().callEvent(playerCommandPreprocessEvent); - if (playerCommandPreprocessEvent.isCancelled()) return; + PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(event.getPlayer(), "/" + command); + Bukkit.getPluginManager().callEvent(preprocessEvent); + if (preprocessEvent.isCancelled()) return; - Bukkit.getLogger().log(Level.INFO, event.getPlayer().getName() + " dispatched command: " + command); - String[] commandSplit = command.split(" "); + String processedCommand = preprocessEvent.getMessage().substring(1); + Bukkit.getLogger().log(Level.INFO, event.getPlayer().getName() + " dispatched command: " + processedCommand); + String[] commandSplit = processedCommand.split(" "); if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) { - if (!Permission.WORLDEDIT.hasPermission(event.getPlayer())) { - return; - } EditSession editSession = WorldEditUtils.getEditSession(event.getPlayer()); Actor actor = BukkitAdapter.adapt(event.getPlayer()); - WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); + WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, processedCommand, editSession)); editSession.flushSession(); WorldEditUtils.addToPlayer(event.getPlayer(), editSession); } else { - Bukkit.getServer().dispatchCommand(event.getPlayer(), command); + Bukkit.getServer().dispatchCommand(event.getPlayer(), processedCommand); } }, 1); } From de084883713e4e23c8150535a0b73307252d498c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 08:36:51 +0100 Subject: [PATCH 114/139] Fix AxiomPermissionCheck --- .../steamwar/bausystem/features/world/AxiomPermissionCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java index c88ae5cd..587c8d59 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AxiomPermissionCheck.java @@ -33,7 +33,7 @@ public class AxiomPermissionCheck implements Listener { @EventHandler public void onAxiomHandshake(AxiomHandshakeEvent event) { - if (Permission.BUILD.hasPermission(event.getPlayer()) || BauServer.getInstance().getOwner().equals(event.getPlayer().getUniqueId())) { + if (Permission.SUPERVISOR.hasPermission(event.getPlayer()) || BauServer.getInstance().getOwner().equals(event.getPlayer().getUniqueId())) { event.setMaxBufferSize(Short.MAX_VALUE); return; } From 338980f0d327f94f700f4d170454be3c119ee55b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 08:55:33 +0100 Subject: [PATCH 115/139] Fix AntiBauAddMemberFix --- .../steamwar/bausystem/features/world/AntiBauAddMemberFix.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java index c406f5c7..dbcb192d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java @@ -24,6 +24,7 @@ import de.steamwar.linkage.Linked; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; @@ -31,7 +32,7 @@ import org.bukkit.event.player.PlayerJoinEvent; public class AntiBauAddMemberFix implements Listener { - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) { return; From 9466a8c9815e1b0c98ad8026a551cc9ad7add565 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 08:55:47 +0100 Subject: [PATCH 116/139] Fix AntiBauAddMemberFix --- .../steamwar/bausystem/features/world/AntiBauAddMemberFix.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java index dbcb192d..a7a3bad6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiBauAddMemberFix.java @@ -32,7 +32,7 @@ import org.bukkit.event.player.PlayerJoinEvent; public class AntiBauAddMemberFix implements Listener { - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOW) public void onPlayerJoin(PlayerJoinEvent event) { if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) { return; From 8053796341e995ace25ae9251f303d0a5fb1e132 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 09:15:43 +0100 Subject: [PATCH 117/139] Update permission of BackupCommand --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 1 + .../de/steamwar/bausystem/features/backup/BackupCommand.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 0bda77c1..9707d871 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -81,6 +81,7 @@ public class BauSystem extends JavaPlugin implements Listener { SWCommandUtils.addValidator(Player.class, validator(Permission.BUILD)); SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD)); SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR)); + SWCommandUtils.addValidator("owner", validator(Permission.OWNER)); LinkageUtils.link(); TickListener.impl.init(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java index 6e04d2a5..b7911275 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java @@ -62,7 +62,7 @@ public class BackupCommand extends SWCommand { } @Register(value = "create", description = "BACKUP_HELP_CREATE") - public void backupCreate(@Validator("supervisor") Player p) { + public void backupCreate(@Validator("owner") Player p) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; @@ -79,7 +79,7 @@ public class BackupCommand extends SWCommand { } @Register(value = "load", description = "BACKUP_HELP_LOAD") - public void backupLoad(@Validator("supervisor") Player p, @Mapper("backupName") String backupName) { + public void backupLoad(@Validator("owner") Player p, @Mapper("backupName") String backupName) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; From cc15781b440b07baf731fcbb2cda7f169e7e8371 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 09:32:26 +0100 Subject: [PATCH 118/139] Hotfix Config --- .../src/de/steamwar/bausystem/configplayer/Config.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java index 2f929687..045eb518 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java @@ -97,7 +97,7 @@ public class Config implements Listener { public void saveAll() { playerConfigurations.forEach((uuid, yapionObject) -> { - String string = yapionObject.toYAPION(new StringOutput()).getResult(); + String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\+", "\\"); UserConfig.updatePlayerConfig(uuid, "bausystem", string); }); playerConfigurations.clear(); @@ -112,7 +112,7 @@ public class Config implements Listener { UUID uuid = player.getUniqueId(); if (playerConfigurations.containsKey(uuid)) { YAPIONObject yapionObject = playerConfigurations.get(uuid); - String string = yapionObject.toYAPION(new StringOutput()).getResult(); + String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\+", "\\"); UserConfig.updatePlayerConfig(uuid, "bausystem", string); } } From a05116a16c88a150d23d055ddee43d10d89781bd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 12:22:56 +0100 Subject: [PATCH 119/139] Fix SpectatorListener.resendChunks --- .../bausystem/features/world/SpectatorListener.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index 51eb1fe5..58c0d508 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -42,7 +42,6 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.player.*; -import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -115,13 +114,11 @@ public class SpectatorListener implements Listener { } private static void resendChunks(Player player) { - int distance = player.getClientViewDistance(); - Location location = player.getLocation(); - for (int x = (int) Math.floor(location.getX() / 16.0) - distance; x <= (int) Math.ceil(location.getX() / 16.0) + distance; x++) { - for (int z = (int) Math.floor(location.getZ() / 16.0) - distance; z <= (int) Math.ceil(location.getZ() / 16.0) + distance; z++) { - CraftbukkitWrapper.impl.sendChunk(player, x, z); - } - } + Location location = player.getLocation().clone(); + player.teleport(location.clone().add(16.0 * player.getClientViewDistance(), 0, 16.0 * player.getClientViewDistance())); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + player.teleport(location); + }, 5); } private boolean anySupervisorOnline(Player player) { From 009a1f3fa43c5f1435f1b037e514a67fe34604fc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 13:12:10 +0100 Subject: [PATCH 120/139] Fix PanzernCommand for glass blocks --- .../bausystem/features/slaves/panzern/PanzernCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java index 8d83d3dd..cca7a266 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java @@ -123,7 +123,7 @@ public class PanzernCommand extends SWCommand { if (!material.isBlock()) { continue; } - if (material.name().contains("STAIRS") || material.name().contains("SLAB")) { + if (material.name().contains("STAIRS") || material.name().contains("SLAB") || material.name().contains("GLASS")) { strings.add(material.name().toLowerCase()); } } From d1196c6e4ee485f79f890892d3c832235ec6b261 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 13:37:17 +0100 Subject: [PATCH 121/139] Add AutostartListener Bedrock autostarter --- .../bausystem/features/autostart/AutostartListener.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 28fb7f94..28126ec5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -30,6 +30,7 @@ import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.data.type.Chest; import org.bukkit.configuration.file.FileConfiguration; @@ -77,6 +78,12 @@ public class AutostartListener implements Listener { if (event.getClickedBlock().getBlockData() instanceof Chest) { return; } + if (event.getClickedBlock().getType() == Material.BEDROCK) { + event.getClickedBlock().setType(Material.SLIME_BLOCK); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + event.getClickedBlock().setType(Material.BEDROCK, false); + }, 1); + } activate(event.getPlayer()); } From 7f62ad8005c40bcc660145ccb6e45dbda906d25e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 15:22:48 +0100 Subject: [PATCH 122/139] Update InfoCommand output --- BauSystem_Main/src/BauSystem.properties | 2 +- BauSystem_Main/src/BauSystem_de.properties | 2 +- .../bausystem/features/bau/InfoCommand.java | 43 ++++++++++++------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 0f85ca56..c2210163 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -150,7 +150,7 @@ BAU_INFO_ITEM_LORE_ITEMS = §7Items§8: §e{0} BAU_INFO_COMMAND_HELP = §8/§ebauinfo §8- §7Information regarding this build server BAU_INFO_COMMAND_OWNER = §7Owner§8: §e{0} -BAU_INFO_COMMAND_MEMBER = §7Member §8[§7{0}§8]§8: §e +BAU_INFO_COMMAND_MEMBER = §7{0} §8[§7{1}§8]§8: §e{2} BAU_INFO_COMMAND_FLAG = §7{0}§8: §7{1} BAU_INFO_COMMAND_TPS = §7TPS§8:§e diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 346e1dd1..43a2ba56 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -149,7 +149,7 @@ BAU_INFO_ITEM_LORE_PROTECT = §7Protect§8: §e{0} BAU_INFO_COMMAND_HELP = §8/§ebauinfo §8- §7Gibt Informationen über den Bau BAU_INFO_COMMAND_OWNER = §7Besitzer§8: §e{0} -BAU_INFO_COMMAND_MEMBER = §7Mitglieder §8[§7{0}§8]§8: §e +BAU_INFO_COMMAND_MEMBER = §7{0} §8[§7{1}§8]§8: §e{2} BAU_INFO_COMMAND_FLAG = §7{0}§8: §7{1} BAU_INFO_COMMAND_TPS = §7TPS§8:§e diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index 19d8aab5..b89c43b3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -13,7 +13,7 @@ import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; -import java.util.List; +import java.util.*; @Linked public class InfoCommand extends SWCommand { @@ -41,24 +41,25 @@ public class InfoCommand extends SWCommand { if (Permission.BUILD.hasPermission(p)) { List members = BauweltMember.getMembers(bauServer.getOwnerID()); - StringBuilder membermessage = new StringBuilder(); - membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size())); - - for (int i = 0; i < members.size(); i++) { - if (i != 0) { - membermessage.append("§8, "); - } - BauweltMember member = members.get(i); + Map> memberByPermission = new HashMap<>(); + members.forEach(member -> { if (Permission.SUPERVISOR.hasPermission(member)) { - membermessage.append("§e"); + memberByPermission.computeIfAbsent(Permission.SUPERVISOR, __ -> new ArrayList<>()).add(member); } else if (Permission.BUILD.hasPermission(member)) { - membermessage.append("§6"); + memberByPermission.computeIfAbsent(Permission.BUILD, __ -> new ArrayList<>()).add(member); } else { - membermessage.append("§7"); + memberByPermission.computeIfAbsent(Permission.MEMBER, __ -> new ArrayList<>()).add(member); } - membermessage.append(SteamwarUser.get(member.getMemberID()).getUserName()); - } - p.sendMessage(membermessage.toString()); + }); + + List supervisor = memberByPermission.getOrDefault(Permission.SUPERVISOR, Collections.emptyList()); + BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§eSupervisor", supervisor.size(), supervisor.isEmpty() ? "§8" : joining(supervisor)); + + List builder = memberByPermission.getOrDefault(Permission.BUILD, Collections.emptyList()); + BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§6Builder", builder.size(), builder.isEmpty() ? "§8" : joining(builder)); + + List spectator = memberByPermission.getOrDefault(Permission.MEMBER, Collections.emptyList()); + BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§7Spectator", spectator.size(), spectator.isEmpty() ? "§8" : joining(spectator)); } StringBuilder tpsMessage = new StringBuilder(); @@ -70,4 +71,16 @@ public class InfoCommand extends SWCommand { tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)); p.sendMessage(tpsMessage.toString()); } + + private String joining(List bauweltMembers) { + StringBuilder st = new StringBuilder(); + for (int i = 0; i < bauweltMembers.size(); i++) { + if (i != 0) { + st.append("§8, "); + } + st.append("§f"); + st.append(SteamwarUser.get(bauweltMembers.get(i).getMemberID()).getUserName()); + } + return st.toString(); + } } From 280b5b2613242ba0e9e52e8740aafb90e394ec56 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 16:19:57 +0100 Subject: [PATCH 123/139] Recolor Players in InfoCommand --- .../src/de/steamwar/bausystem/features/bau/InfoCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index b89c43b3..2d638888 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -78,7 +78,7 @@ public class InfoCommand extends SWCommand { if (i != 0) { st.append("§8, "); } - st.append("§f"); + st.append("§7"); st.append(SteamwarUser.get(bauweltMembers.get(i).getMemberID()).getUserName()); } return st.toString(); From fd603f3c7f6cc529b96d0b7b29e300a720dbe35a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 16:27:23 +0100 Subject: [PATCH 124/139] Fix Config --- .../src/de/steamwar/bausystem/configplayer/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java index 045eb518..c8369ef0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java @@ -112,7 +112,7 @@ public class Config implements Listener { UUID uuid = player.getUniqueId(); if (playerConfigurations.containsKey(uuid)) { YAPIONObject yapionObject = playerConfigurations.get(uuid); - String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\+", "\\"); + String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\\\+", "\\"); UserConfig.updatePlayerConfig(uuid, "bausystem", string); } } From f837b37b50560ef40ba48c2673596d112f2e4370 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Feb 2024 18:13:25 +0100 Subject: [PATCH 125/139] Fix ClipboardListener.onLogin loading copy schem for builder --- .../de/steamwar/bausystem/features/world/ClipboardListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java index 04c95e5c..c9d3887c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java @@ -36,7 +36,7 @@ public class ClipboardListener implements Listener { @EventHandler public void onLogin(PlayerJoinEvent e) { - if(!Permission.BUILD.hasPermission(e.getPlayer())) return; + if(!Permission.SUPERVISOR.hasPermission(e.getPlayer())) return; try { SchematicNode schematic = SchematicNode.getSchematicNode(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, (Integer) null); From 5a03623b1468cb78d77bb045d06b3620f857870a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Feb 2024 12:15:00 +0100 Subject: [PATCH 126/139] Fix ScriptSystem in 1.15? --- .../de/steamwar/bausystem/features/tpslimit/TPSSystem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index 4baf3259..d047f39b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -64,6 +64,8 @@ public class TPSSystem implements Listener { } public TPSSystem() { + instance = this; + if (TPSFreezeUtils.isCanFreeze()) { new TPSFreezeCommand(); new TickFreezeCommand(); @@ -82,8 +84,6 @@ public class TPSSystem implements Listener { new TickDefaultCommand(); new TPSBaseCommand(); new TickBaseCommand(); - - instance = this; } private void setTPS(double tps) { From b47d85ebe9c9b46eec5c1bda1fef64d6efbb6ca9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 2 Mar 2024 11:34:22 +0100 Subject: [PATCH 127/139] Fix Config.save --- .../src/de/steamwar/bausystem/configplayer/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java index c8369ef0..edce8c58 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java @@ -112,7 +112,7 @@ public class Config implements Listener { UUID uuid = player.getUniqueId(); if (playerConfigurations.containsKey(uuid)) { YAPIONObject yapionObject = playerConfigurations.get(uuid); - String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\\\+", "\\"); + String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\\\+", "\\\\"); UserConfig.updatePlayerConfig(uuid, "bausystem", string); } } From 1da5b65460774c1918559af501331857e4bd1841 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Mar 2024 11:06:31 +0100 Subject: [PATCH 128/139] Add ScoreboardLib and TpsLib --- .../types/ScoreboardElement_GENERIC.java | 2 +- BauSystem_Main/src/BauSystem.properties | 1 - BauSystem_Main/src/BauSystem_de.properties | 1 - .../script/lua/libs/ScoreboardLib.java | 71 +++++++++++++++++++ .../features/script/lua/libs/ServerLib.java | 13 ---- .../features/script/lua/libs/TpsLib.java | 53 ++++++++++++++ .../features/world/BauScoreboard.java | 47 +++++++++--- SCRIPT.md | 28 ++++++++ sw.def.lua | 22 +++++- 9 files changed, 210 insertions(+), 28 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ScoreboardLib.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java index 01e29833..ffd6382f 100644 --- a/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java @@ -35,6 +35,6 @@ public class ScoreboardElement_GENERIC implements LinkageType { @Override public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { buildPlan.addImport("de.steamwar.bausystem.features.world.BauScoreboard"); - methodBuilder.addLine("BauScoreboard.ELEMENTS.add(" + s + ");"); + methodBuilder.addLine("BauScoreboard.addElement(" + s + ");"); } } diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index c2210163..887439f7 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -566,7 +566,6 @@ LOADER_PAUSED=§7The Loader is now paused. LOADER_SMALL_TIME=§cThe wait time is too small LOADER_NEW_TIME=§7The wait time is now: {0} LOADER_NEW_LOAD_TIME=§7The action wait time is now: {0} -LOADER_PERMS=§cYou are not allowed to use the Loader here LOADER_NOTHING_RECORDED=§cYou have not recorded anything yet! LOADER_GUI_TITLE=Loader GUI diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 43a2ba56..46b30880 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -534,7 +534,6 @@ LOADER_PAUSED=§7Der Loader ist nun pausiert. LOADER_SMALL_TIME=§cDie Wartezeit ist zu klein LOADER_NEW_TIME=§7Die Schusswartezeit ist nun: {0} LOADER_NEW_LOAD_TIME=§7Die Setzwartezeit ist nun: {0} -LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen LOADER_NOTHING_RECORDED=§cEs wurden keine Elemente aufgenommen! LOADER_GUI_TITLE=Loader Einstellungen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ScoreboardLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ScoreboardLib.java new file mode 100644 index 00000000..af061ac3 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ScoreboardLib.java @@ -0,0 +1,71 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.script.lua.libs; + +import de.steamwar.bausystem.features.world.BauScoreboard; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.TwoArgFunction; +import org.luaj.vm2.lib.VarArgFunction; + +@Linked +public class ScoreboardLib implements LuaLib { + + @Override + public String name() { + return "scoreboard"; + } + + @Override + public LuaTable get(Player player) { + LuaTable luaTable = new LuaTable(); + + LuaTable groups = new LuaTable(); + for (ScoreboardElement.ScoreboardGroup group : ScoreboardElement.ScoreboardGroup.values()) { + groups.set(group.name(), group.ordinal()); + } + luaTable.set("group", groups); + + luaTable.set("element", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue key, LuaValue group) { + String elementKey = key.checkjstring(); + ScoreboardElement.ScoreboardGroup elementGroup = ScoreboardElement.ScoreboardGroup.values()[group.checkint()]; + + return new VarArgFunction() { + @Override + public Varargs invoke(Varargs args) { + if (args.narg() == 0) { + BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, null); + } else { + BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, args.arg1().checkjstring()); + } + return NIL; + } + }; + } + }); + return luaTable; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java index 8e800329..02ccd975 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -21,9 +21,7 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.features.tpslimit.TPSSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; -import de.steamwar.core.TPSWatcher; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import org.bukkit.Material; @@ -75,17 +73,6 @@ public class ServerLib implements LuaLib { return NIL; } }); - - LuaValue tpsLib = LuaValue.tableOf(); - tpsLib.set("oneSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND))); - tpsLib.set("tenSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS))); - tpsLib.set("oneMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE))); - tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES))); - tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES))); - tpsLib.set("current", getter(TPSWatcher::getTPS)); - tpsLib.set("limit", getter(TPSSystem.getInstance()::getCurrentTPSLimit)); - - serverLib.set("tps", tpsLib); return serverLib; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java new file mode 100644 index 00000000..3b0b430d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/TpsLib.java @@ -0,0 +1,53 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.script.lua.libs; + +import de.steamwar.bausystem.features.tpslimit.TPSSystem; +import de.steamwar.core.TPSWatcher; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; +import org.luaj.vm2.LuaTable; + +@Linked +public class TpsLib implements LuaLib { + + @Override + public Class parent() { + return ServerLib.class; + } + + @Override + public String name() { + return "tps"; + } + + @Override + public LuaTable get(Player player) { + LuaTable tpsLib = new LuaTable(); + tpsLib.set("oneSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND))); + tpsLib.set("tenSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS))); + tpsLib.set("oneMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE))); + tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES))); + tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES))); + tpsLib.set("current", getter(TPSWatcher::getTPS)); + tpsLib.set("limit", getter(TPSSystem.getInstance()::getCurrentTPSLimit)); + return tpsLib; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index 6efda09f..cce4ea38 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -4,6 +4,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import de.steamwar.scoreboard.SWScoreboard; @@ -12,26 +13,37 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import java.util.*; @Linked public class BauScoreboard implements Listener { - public static final List ELEMENTS = new ArrayList<>(); + private static final Map> ELEMENTS = new HashMap<>(); + private static final Map>> ADDITIONAL_SCOREBOARD_LINES = new HashMap<>(); + + public static void addElement(ScoreboardElement scoreboardElement) { + List elements = ELEMENTS.computeIfAbsent(scoreboardElement.getGroup(), scoreboardGroup -> new ArrayList<>()); + elements.add(scoreboardElement); + elements.sort(Comparator.comparingInt(ScoreboardElement::order)); + } + + public static void setAdditionalElement(Player player, String key, ScoreboardElement.ScoreboardGroup group, String value) { + Map> playerElements = ADDITIONAL_SCOREBOARD_LINES.computeIfAbsent(player, player1 -> new HashMap<>()); + if (value == null || value.isBlank()) { + playerElements.remove(key); + return; + } + Pair element = playerElements.computeIfAbsent(key, s -> new Pair<>(null, null)); + element.setKey(group); + element.setValue(value); + } @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - Map> map = new HashMap<>(); - for (ScoreboardElement element : ELEMENTS) { - map.computeIfAbsent(element.getGroup(), scoreboardGroup -> new ArrayList<>()).add(element); - } - map.forEach((scoreboardGroup, scoreboardElements) -> { - scoreboardElements.sort(Comparator.comparingInt(ScoreboardElement::order)); - }); - SWScoreboard.createScoreboard(player, new ScoreboardCallback() { @Override public HashMap getData() { @@ -52,9 +64,9 @@ public class BauScoreboard implements Listener { } private void calcGroup(List elements, String separator, Region region, ScoreboardElement.ScoreboardGroup group) { - if (map.containsKey(group)) { + if (ELEMENTS.containsKey(group)) { List groupElements = new ArrayList<>(); - for (ScoreboardElement element : map.get(group)) { + for (ScoreboardElement element : ELEMENTS.get(group)) { groupElements.add(element.get(region, player)); } groupElements.removeIf(Objects::isNull); @@ -63,6 +75,14 @@ public class BauScoreboard implements Listener { elements.addAll(groupElements); } } + if (ADDITIONAL_SCOREBOARD_LINES.containsKey(player)) { + ADDITIONAL_SCOREBOARD_LINES.get(player).values().forEach(scoreboardGroupStringPair -> { + if (scoreboardGroupStringPair.getKey() != group) { + return; + } + elements.add(scoreboardGroupStringPair.getValue()); + }); + } } @Override @@ -74,4 +94,9 @@ public class BauScoreboard implements Listener { } }); } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + ADDITIONAL_SCOREBOARD_LINES.remove(event.getPlayer()); + } } diff --git a/SCRIPT.md b/SCRIPT.md index ae9cb181..3ac69cb7 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -69,6 +69,7 @@ In den Scripten gibt es dazu noch folgende globale Variablen: - [`server`](#server) - [`storage`](#storage) - [`inventory`](#inventory) +- [`scoreboard`](#scoreboard) - `_worldedit` Ohne eine Kategorie sind folgende Funktionen verfügbar, die nicht allgemein sind: @@ -255,6 +256,33 @@ Wenn eine Barrier statt des richtigen Items angezeigt wird, dann ist das angegeb ⚠️⚠️⚠️ ``` +## scoreboard +Das `scoreboard`-Modul stellt Funktionen zur Verfügung, um Zeilen im Scoreboard hinzuzufügen. +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|-----------|-------------------------------------------|----------------------------------------------------------------------| +| `group` | | Siehe: [Scoreboardgroups](#scoreboardgroups) | +| `element` | element(String, Group): ScoreboardElement | Erstellt ein ScoreboardElement, welche man nachfolgend befüllen kann | + +Ein ScoreboardElement ist ein Objekt, womit du direkt auf einen Wert zugreifen kannst und es ändern kannst. +Es geht wie folgt: +```lua +key = scoreboard.element("key", scoreboard.group.OTHER) + +key("Hello World") -- Setzt im Bereich Other den Text "Hello World" unter allem anderen +key() -- Removed im Bereich Other den vorherigen Text "Hello World" +``` + +## Scoreboardgroups + +| Name | +|----------| +| `Header` | +| `Region` | +| `Other` | +| `Footer` | + # SteamWar.de-Global-Api Mit `/script` kann man Script-Bücher global abspeichern. Diese haben dann zugrif auf die `global`-Api. Die `global`-Api stellt Funktionen zur Verfügung um auf Events, Commands und Hotkeys mit einem Script zu reagieren. diff --git a/sw.def.lua b/sw.def.lua index 613437a1..e4faf43c 100644 --- a/sw.def.lua +++ b/sw.def.lua @@ -18,9 +18,29 @@ --- --- This file contains the definitions for the SteamWar.de script API. --- It is used by the IDE to provide code completion and type checking. ---- Created by Chaoscaot +--- Created by Chaoscaot and YoyoNow --- +scoreboard = {} + +---@param key string +---@param group ScoreboardGroup +---@return ScoreboardElement +function scoreboard.element(key, group) return nil end + +---@class ScoreboardElement +---@overload fun(): void +---@overload fun(value: string): void + +---@class ScoreboardGroup +---@class group +---@field HEADER ScoreboardGroup +---@field REGION ScoreboardGroup +---@field OTHER ScoreboardGroup +---@field FOOTER ScoreboardGroup +local group = {} +scoreboard.group = group + inventory = {} ---@param title string From 3ecd31e80c00c53320ad81afb6f6203cb223cb05 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Mar 2024 12:13:30 +0100 Subject: [PATCH 129/139] Update ScoreboardLib --- .../script/lua/libs/ScoreboardLib.java | 16 +++++++---- .../features/world/BauScoreboard.java | 28 +++++++++++-------- SCRIPT.md | 9 +++--- sw.def.lua | 6 ++++ 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ScoreboardLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ScoreboardLib.java index af061ac3..af9c67ae 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ScoreboardLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ScoreboardLib.java @@ -47,19 +47,23 @@ public class ScoreboardLib implements LuaLib { } luaTable.set("group", groups); - luaTable.set("element", new TwoArgFunction() { + luaTable.set("element", new VarArgFunction() { @Override - public LuaValue call(LuaValue key, LuaValue group) { - String elementKey = key.checkjstring(); - ScoreboardElement.ScoreboardGroup elementGroup = ScoreboardElement.ScoreboardGroup.values()[group.checkint()]; + public Varargs invoke(Varargs varargs) { + if (varargs.narg() < 2) { + return NIL; + } + String elementKey = varargs.arg(1).checkjstring(); + ScoreboardElement.ScoreboardGroup elementGroup = ScoreboardElement.ScoreboardGroup.values()[varargs.arg(2).checkint()]; + int priority = varargs.narg() > 2 ? varargs.arg(2).checkint() : Integer.MAX_VALUE; return new VarArgFunction() { @Override public Varargs invoke(Varargs args) { if (args.narg() == 0) { - BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, null); + BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, priority, null); } else { - BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, args.arg1().checkjstring()); + BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, priority, args.arg1().checkjstring()); } return NIL; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index cce4ea38..0961499e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -9,6 +9,8 @@ import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; +import org.apache.commons.lang3.tuple.MutableTriple; +import org.apache.commons.lang3.tuple.Triple; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -21,7 +23,7 @@ import java.util.*; public class BauScoreboard implements Listener { private static final Map> ELEMENTS = new HashMap<>(); - private static final Map>> ADDITIONAL_SCOREBOARD_LINES = new HashMap<>(); + private static final Map>> ADDITIONAL_SCOREBOARD_LINES = new HashMap<>(); public static void addElement(ScoreboardElement scoreboardElement) { List elements = ELEMENTS.computeIfAbsent(scoreboardElement.getGroup(), scoreboardGroup -> new ArrayList<>()); @@ -29,15 +31,16 @@ public class BauScoreboard implements Listener { elements.sort(Comparator.comparingInt(ScoreboardElement::order)); } - public static void setAdditionalElement(Player player, String key, ScoreboardElement.ScoreboardGroup group, String value) { - Map> playerElements = ADDITIONAL_SCOREBOARD_LINES.computeIfAbsent(player, player1 -> new HashMap<>()); + public static void setAdditionalElement(Player player, String key, ScoreboardElement.ScoreboardGroup group, int priority, String value) { + Map> playerElements = ADDITIONAL_SCOREBOARD_LINES.computeIfAbsent(player, player1 -> new HashMap<>()); if (value == null || value.isBlank()) { playerElements.remove(key); return; } - Pair element = playerElements.computeIfAbsent(key, s -> new Pair<>(null, null)); - element.setKey(group); - element.setValue(value); + MutableTriple element = playerElements.computeIfAbsent(key, s -> new MutableTriple<>(null, null, null)); + element.setLeft(group); + element.setMiddle(priority); + element.setRight(value); } @EventHandler @@ -76,12 +79,13 @@ public class BauScoreboard implements Listener { } } if (ADDITIONAL_SCOREBOARD_LINES.containsKey(player)) { - ADDITIONAL_SCOREBOARD_LINES.get(player).values().forEach(scoreboardGroupStringPair -> { - if (scoreboardGroupStringPair.getKey() != group) { - return; - } - elements.add(scoreboardGroupStringPair.getValue()); - }); + ADDITIONAL_SCOREBOARD_LINES.get(player).values() + .stream() + .filter(triple -> triple.getLeft() == group) + .sorted(Comparator.comparing(triple -> triple.getMiddle())) + .forEach(triple -> { + elements.add(triple.getRight()); + }); } } diff --git a/SCRIPT.md b/SCRIPT.md index 3ac69cb7..a4f742d8 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -260,10 +260,11 @@ Wenn eine Barrier statt des richtigen Items angezeigt wird, dann ist das angegeb Das `scoreboard`-Modul stellt Funktionen zur Verfügung, um Zeilen im Scoreboard hinzuzufügen. Es gibt folgende Funktionen: -| Name | Signature | Beschreibung | -|-----------|-------------------------------------------|----------------------------------------------------------------------| -| `group` | | Siehe: [Scoreboardgroups](#scoreboardgroups) | -| `element` | element(String, Group): ScoreboardElement | Erstellt ein ScoreboardElement, welche man nachfolgend befüllen kann | +| Name | Signature | Beschreibung | +|-----------|----------------------------------------------------|-------------------------------------------------------------------------------------------| +| `group` | | Siehe: [Scoreboardgroups](#scoreboardgroups) | +| `element` | element(String, Group): ScoreboardElement | Erstellt ein ScoreboardElement, welche man nachfolgend befüllen kann | +| `element` | element(String, Group, Integer): ScoreboardElement | Erstellt ein ScoreboardElement, welche man nachfolgend befüllen kann mit einer Sortierung | Ein ScoreboardElement ist ein Objekt, womit du direkt auf einen Wert zugreifen kannst und es ändern kannst. Es geht wie folgt: diff --git a/sw.def.lua b/sw.def.lua index e4faf43c..d3128595 100644 --- a/sw.def.lua +++ b/sw.def.lua @@ -28,6 +28,12 @@ scoreboard = {} ---@return ScoreboardElement function scoreboard.element(key, group) return nil end +---@param key string +---@param group ScoreboardGroup +---@param order number +---@return ScoreboardElement +function scoreboard.element(key, group, order) return nil end + ---@class ScoreboardElement ---@overload fun(): void ---@overload fun(value: string): void From 2ccc7920d5689b0710e4a9203ff0634c48074f23 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Mar 2024 12:21:11 +0100 Subject: [PATCH 130/139] Fix BauScoreboard --- .../features/world/BauScoreboard.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index 0961499e..74098b1b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -53,7 +53,7 @@ public class BauScoreboard implements Listener { Region region = Region.getRegion(player.getLocation()); List elements = new ArrayList<>(); - calcGroup(elements, "§0", region, ScoreboardElement.ScoreboardGroup.HEADER); + calcGroup(elements, null, region, ScoreboardElement.ScoreboardGroup.HEADER); calcGroup(elements, "§1", region, ScoreboardElement.ScoreboardGroup.REGION); calcGroup(elements, "§2", region, ScoreboardElement.ScoreboardGroup.OTHER); calcGroup(elements, "§3", region, ScoreboardElement.ScoreboardGroup.FOOTER); @@ -67,26 +67,26 @@ public class BauScoreboard implements Listener { } private void calcGroup(List elements, String separator, Region region, ScoreboardElement.ScoreboardGroup group) { + List groupElements = new ArrayList<>(); if (ELEMENTS.containsKey(group)) { - List groupElements = new ArrayList<>(); for (ScoreboardElement element : ELEMENTS.get(group)) { groupElements.add(element.get(region, player)); } - groupElements.removeIf(Objects::isNull); - if (!groupElements.isEmpty()) { - elements.add(separator); - elements.addAll(groupElements); - } } if (ADDITIONAL_SCOREBOARD_LINES.containsKey(player)) { ADDITIONAL_SCOREBOARD_LINES.get(player).values() .stream() .filter(triple -> triple.getLeft() == group) - .sorted(Comparator.comparing(triple -> triple.getMiddle())) + .sorted(Comparator.comparing(MutableTriple::getMiddle)) .forEach(triple -> { - elements.add(triple.getRight()); + groupElements.add(triple.getRight()); }); } + groupElements.removeIf(Objects::isNull); + if (!groupElements.isEmpty()) { + if (separator != null) elements.add(separator); + elements.addAll(groupElements); + } } @Override From f7481bfa0f0f726f20c1bfdffab1a9ecdb37105e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 7 Mar 2024 15:40:52 +0100 Subject: [PATCH 131/139] Add server.onlinePlayerCount to Script System --- .../features/script/lua/libs/ServerLib.java | 2 ++ SCRIPT.md | 13 +++++++------ sw.def.lua | 3 +++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java index 02ccd975..5aa0b5c0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.luaj.vm2.LuaString; @@ -46,6 +47,7 @@ public class ServerLib implements LuaLib { public LuaTable get(Player player) { LuaTable serverLib = LuaValue.tableOf(); serverLib.set("time", getter(() -> new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", player)).format(Calendar.getInstance().getTime()))); + serverLib.set("onlinePlayerCount", getter(Bukkit.getOnlinePlayers()::size)); serverLib.set("ticks", getter(TPSUtils.currentTick)); serverLib.set("getBlockAt", new OneArgFunction() { @Override diff --git a/SCRIPT.md b/SCRIPT.md index a4f742d8..8bcd9dd6 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -168,12 +168,13 @@ Es gibt folgende Funktionen: Das `server`-Modul stellt Funktionen zur Verfügung, die den Server betreffen. Es gibt folgende Funktionen: -| Name | Signature | Beschreibung | -|--------------|-------------------------|---------------------------------------------------------------------| -| `time` | time(): String | Gibt die aktuelle Zeit im Format `HH:mm:ss` zurück | -| `ticks` | ticks(): Number | Gibt die Ticks seit start des Serverstarts zurück | -| `getBlockAt` | getBlockAt(Pos): String | Gibt das Material an der Position zurück | -| `setBlockAt` | setBlockAt(Pos, String) | Setzt das Material an der angegebenen Stelle (z.B. Stein = `STONE`) | +| Name | Signature | Beschreibung | +|---------------------|------------------------------|---------------------------------------------------------------------| +| `time` | time(): String | Gibt die aktuelle Zeit im Format `HH:mm:ss` zurück | +| `ticks` | ticks(): Number | Gibt die Ticks seit start des Serverstarts zurück | +| `onlinePlayerCount` | onlinePlayerCount(): Number | Gibt die Anzal der Spieler auf dem Server zurück | +| `getBlockAt` | getBlockAt(Pos): String | Gibt das Material an der Position zurück | +| `setBlockAt` | setBlockAt(Pos, String) | Setzt das Material an der angegebenen Stelle (z.B. Stein = `STONE`) | Es gibt folgende weitere Module: diff --git a/sw.def.lua b/sw.def.lua index d3128595..978d7050 100644 --- a/sw.def.lua +++ b/sw.def.lua @@ -263,6 +263,9 @@ function server.time() return nil end ---@return number function server.ticks() return nil end +---@return number +function server.onlinePlayerCount() return nil end + ---@param position Position ---@return string function getBlockAt(position) return nil end From a91c352b15288f1c5d87745eec7002583541be0a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 7 Mar 2024 22:20:35 +0100 Subject: [PATCH 132/139] Update pos definition and some other stuff --- .../features/loader/LoaderRecorder.java | 93 +++++++++-------- .../script/lua/SteamWarLuaPlugin.java | 99 ++++++++++++++++--- .../features/script/lua/libs/PlayerLib.java | 7 ++ .../features/script/lua/libs/ServerLib.java | 16 +++ SCRIPT.md | 34 +++++-- sw.def.lua | 52 +++++++++- 6 files changed, 226 insertions(+), 75 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java index ec2153ae..cc3dce23 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java @@ -43,6 +43,8 @@ import org.bukkit.inventory.EquipmentSlot; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Consumer; public class LoaderRecorder implements Listener { @@ -124,53 +126,10 @@ public class LoaderRecorder implements Listener { addWaitTime(false); Block block = event.getClickedBlock(); - Material type = block.getType(); - switch (type) { - case COMPARATOR: - loaderElementList.add(new LoaderComparator(block.getLocation())); - message("LOADER_BUTTON_COMPARATOR"); - break; - case REPEATER: - loaderElementList.add(new LoaderRepeater(block.getLocation())); - message("LOADER_BUTTON_REPEATER"); - break; - case NOTE_BLOCK: - loaderElementList.add(new LoaderNoteBlock(block.getLocation())); - message("LOADER_BUTTON_NOTEBLOCK"); - break; - case LEVER: - loaderElementList.add(new LoaderLever(block.getLocation())); - message("LOADER_BUTTON_SWITCH"); - break; - case DAYLIGHT_DETECTOR: - loaderElementList.add(new LoaderDaylightDetector(block.getLocation())); - message("LOADER_BUTTON_DAYLIGHT_DETECTOR"); - break; - case LECTERN: - loaderElementList.add(new LoaderLectern(block.getLocation())); - message("LOADER_BUTTON_LECTERN"); - break; - case IRON_TRAPDOOR: - break; - default: - if (type.name().endsWith("_TRAPDOOR")) { - loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type)); - message("LOADER_BUTTON_TRAPDOOR"); - } else if (type.name().endsWith("_DOOR")) { - loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type)); - message("LOADER_BUTTON_DOOR"); - } else if (type.name().endsWith("FENCE_GATE")) { - loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type)); - message("LOADER_BUTTON_FENCEGATE"); - } else if (type.name().endsWith("STONE_BUTTON")) { - loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20)); - message("LOADER_BUTTON_STONE_BUTTON"); - } else if (type.name().endsWith("BUTTON")) { - loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30)); - message("LOADER_BUTTON_WOOD_BUTTON"); - } - break; - } + getLoaderInteractionElement(block, (loaderInteractionElement, s) -> { + loaderElementList.add(loaderInteractionElement); + message(s); + }); } private Map blockSet = new HashMap<>(); @@ -226,6 +185,46 @@ public class LoaderRecorder implements Listener { } } + public static void getLoaderInteractionElement(Block block, BiConsumer, String> consumer) { + Material type = block.getType(); + switch (type) { + case COMPARATOR: + consumer.accept(new LoaderComparator(block.getLocation()), "LOADER_BUTTON_COMPARATOR"); + break; + case REPEATER: + consumer.accept(new LoaderRepeater(block.getLocation()), "LOADER_BUTTON_REPEATER"); + break; + case NOTE_BLOCK: + consumer.accept(new LoaderNoteBlock(block.getLocation()), "LOADER_BUTTON_NOTEBLOCK"); + break; + case LEVER: + consumer.accept(new LoaderLever(block.getLocation()), "LOADER_BUTTON_SWITCH"); + break; + case DAYLIGHT_DETECTOR: + consumer.accept(new LoaderDaylightDetector(block.getLocation()), "LOADER_BUTTON_DAYLIGHT_DETECTOR"); + break; + case LECTERN: + consumer.accept(new LoaderLectern(block.getLocation()), "LOADER_BUTTON_LECTERN"); + break; + case IRON_TRAPDOOR: + case IRON_DOOR: + break; + default: + if (type.name().endsWith("_TRAPDOOR")) { + consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type), "LOADER_BUTTON_TRAPDOOR"); + } else if (type.name().endsWith("_DOOR")) { + consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type), "LOADER_BUTTON_DOOR"); + } else if (type.name().endsWith("FENCE_GATE")) { + consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type), "LOADER_BUTTON_FENCEGATE"); + } else if (type.name().endsWith("STONE_BUTTON")) { + consumer.accept(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20), "LOADER_BUTTON_STONE_BUTTON"); + } else if (type.name().endsWith("BUTTON")) { + consumer.accept(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30), "LOADER_BUTTON_WOOD_BUTTON"); + } + break; + } + } + private void message(String type) { SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", player, BauSystem.MESSAGE.parse(type, player), loaderElementList.size())); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index 36cf05e3..c047531c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -22,15 +22,19 @@ package de.steamwar.bausystem.features.script.lua; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.BukkitPlayer; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.extension.platform.Actor; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.bausystem.features.script.lua.libs.LuaLib; import de.steamwar.bausystem.features.world.WorldEditListener; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.inventory.SWAnvilInv; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -41,11 +45,10 @@ import org.luaj.vm2.LuaFunction; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; import org.luaj.vm2.Varargs; -import org.luaj.vm2.lib.OneArgFunction; -import org.luaj.vm2.lib.ThreeArgFunction; -import org.luaj.vm2.lib.TwoArgFunction; -import org.luaj.vm2.lib.VarArgFunction; +import org.luaj.vm2.lib.*; +import java.lang.reflect.Proxy; +import java.net.InetSocketAddress; import java.util.*; import java.util.logging.Level; @@ -104,14 +107,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction { double x = arg1.checkdouble(); double y = arg2.checkdouble(); double z = arg3.checkdouble(); - - Location loc = new Location(player.getWorld(), x, y, z); - - return tableOf(new LuaValue[] { - valueOf("x"), valueOf(loc.getBlockX()), - valueOf("y"), valueOf(loc.getBlockY()), - valueOf("z"), valueOf(loc.getBlockZ()) - }); + return pos(x, y, z); } }); env.set("exec", new VarArgFunction() { @@ -169,11 +165,86 @@ public class SteamWarLuaPlugin extends TwoArgFunction { env.set("rawget", NIL); env.set("rawlen", NIL); env.set("rawset", NIL); - env.set("setmetatable", NIL); env.set("xpcall", NIL); return null; } + public static LuaTable pos(double x, double y, double z) { + LuaTable position = new LuaTable(); + position.set("x", x); + position.set("y", y); + position.set("z", z); + + position.set("add", new OneArgFunction() { + @Override + public LuaValue call(LuaValue luaValue) { + LuaTable table = luaValue.checktable(); + double dx = table.get("x").checkdouble(); + double dy = table.get("y").checkdouble(); + double dz = table.get("z").checkdouble(); + return pos(x + dx, y + dy, z + dz); + } + }); + + position.set("subtract", new OneArgFunction() { + @Override + public LuaValue call(LuaValue luaValue) { + LuaTable table = luaValue.checktable(); + double dx = table.get("x").checkdouble(); + double dy = table.get("y").checkdouble(); + double dz = table.get("z").checkdouble(); + return pos(x - dx, y - dy, z - dz); + } + }); + + position.set("addX", new OneArgFunction() { + @Override + public LuaValue call(LuaValue luaValue) { + return pos(x + luaValue.checkdouble(), y, z); + } + }); + position.set("subtractX", new OneArgFunction() { + @Override + public LuaValue call(LuaValue luaValue) { + return pos(x - luaValue.checkdouble(), y, z); + } + }); + position.set("addY", new OneArgFunction() { + @Override + public LuaValue call(LuaValue luaValue) { + return pos(x, y + luaValue.checkdouble(), z); + } + }); + position.set("subtractY", new OneArgFunction() { + @Override + public LuaValue call(LuaValue luaValue) { + return pos(x, y - luaValue.checkdouble(), z); + } + }); + position.set("addZ", new OneArgFunction() { + @Override + public LuaValue call(LuaValue luaValue) { + return pos(x, y, z + luaValue.checkdouble()); + } + }); + position.set("subtractZ", new OneArgFunction() { + @Override + public LuaValue call(LuaValue luaValue) { + return pos(x, y, z - luaValue.checkdouble()); + } + }); + + position.set("blockPos", new ZeroArgFunction() { + @Override + public LuaValue call() { + Location location = new Location(Bukkit.getWorlds().get(0), x, y, z); + return pos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + }); + + return position; + } + public static String varArgsToString(Varargs args) { StringBuilder builder = new StringBuilder(); for (int i = 1; i <= args.narg(); i++) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java index d4895693..d8576f81 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.script.lua.libs; +import de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin; import de.steamwar.linkage.Linked; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -44,6 +45,12 @@ public class PlayerLib implements LuaLib { table.set("chat", new Print(player)); table.set("actionbar", new SendActionbar(player)); + table.set("pos", getter(() -> { + return SteamWarLuaPlugin.pos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()); + })); + table.set("blockPos", getter(() -> { + return SteamWarLuaPlugin.pos(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()); + })); table.set("x", getterAndSetter("x", () -> player.getLocation().getX(), x -> { Location location = player.getLocation(); location.setX(x); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java index 5aa0b5c0..10a41830 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -21,11 +21,14 @@ package de.steamwar.bausystem.features.script.lua.libs; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.loader.LoaderRecorder; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.luaj.vm2.LuaString; import org.luaj.vm2.LuaTable; @@ -75,6 +78,19 @@ public class ServerLib implements LuaLib { return NIL; } }); + serverLib.set("interactAt", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg1) { + LuaTable pos = arg1.checktable(); + Block block = player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()); + LoaderRecorder.getLoaderInteractionElement(block, (loaderInteractionElement, s) -> { + loaderInteractionElement.execute(aLong -> { + // Ignore + }); + }); + return NIL; + } + }); return serverLib; } } diff --git a/SCRIPT.md b/SCRIPT.md index 8bcd9dd6..33ac8003 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -74,15 +74,29 @@ In den Scripten gibt es dazu noch folgende globale Variablen: Ohne eine Kategorie sind folgende Funktionen verfügbar, die nicht allgemein sind: -| Name | Signature | Beschreibung | -|-----------|-----------------------------------|-------------------------------------------------------------------------------------------------------------------| -| `print` | print(String...) | @see chat(String...) | -| `input` | input(String, Function\) | Fragt den User nach einer Eingabe mit der Nachricht und called die zugehörige Funktion nach dieser | -| `delayed` | delayed(Number, Function\) | Wartet die angegebene Anzahl an Ticks und führt danach die zugehörige Funktion aus | -| `pos` | pos(Number, Number, Number) | Erstellt aus drei Zahlen eine Position-Table. Die Koordinaten sind unter den Namen `x`, `y` und `z` abgespeichert | -| `exec` | exec(String...) | Führt den angegebenen Befehl als Spieler aus | -| `length` | length(Any): Int | Gibt die Länge des Objekts zurück | -| `join` | length(String, String...): String | Füge die Texte mit den ersten Parameter zusammen | +| Name | Signature | Beschreibung | +|-----------|---------------------------------------|-------------------------------------------------------------------------------------------------------------------| +| `print` | print(String...) | @see chat(String...) | +| `input` | input(String, Function\) | Fragt den User nach einer Eingabe mit der Nachricht und called die zugehörige Funktion nach dieser | +| `delayed` | delayed(Number, Function\) | Wartet die angegebene Anzahl an Ticks und führt danach die zugehörige Funktion aus | +| `pos` | pos(Number, Number, Number): Position | Erstellt aus drei Zahlen eine Position-Table. Die Koordinaten sind unter den Namen `x`, `y` und `z` abgespeichert | +| `exec` | exec(String...) | Führt den angegebenen Befehl als Spieler aus | +| `length` | length(Any): Int | Gibt die Länge des Objekts zurück | +| `join` | length(String, String...): String | Füge die Texte mit den ersten Parameter zusammen | + +Position besteht aus einer x, y und z Koordinate als auch aus folgenden Methoden: + +| Name | Signature | Beschreibung | +|-----------|------------------------------|--------------------------------------------------------------| +| add | add(Position): Position | Erstellt eine neue Position mit neuen X, Y und Z Koordinaten | +| addX | addX(Number): Position | Erstellt eine neue Position mit neuer X Koordinate | +| addY | addY(Number): Position | Erstellt eine neue Position mit neuer Y Koordinate | +| addZ | addZ(Number): Position | Erstellt eine neue Position mit neuer Z Koordinate | +| subtract | subtract(Position): Position | Erstellt eine neue Position mit neuen X, Y und Z Koordinaten | +| subtractX | subtractX(Number): Position | Erstellt eine neue Position mit neuer X Koordinate | +| subtractY | subtractY(Number): Position | Erstellt eine neue Position mit neuer Y Koordinate | +| subtractZ | subtractZ(Number): Position | Erstellt eine neue Position mit neuer Z Koordinate | +| blockPos | blockPos(): Position | Erstellt eine neue Position mit Block-Koordinaten | ### player Das `player`-Modul stellt Funktionen zur Verfügung, die den Spieler betreffen. @@ -93,6 +107,8 @@ Es gibt folgende Funktionen: | `name` | name(): String | Gibt den `displayName` des Spielers zurück | | `chat` | chat(String...) | Sendet den Text in den Chat des Spielers | | `actionbar` | actionbar(String...) | Sendet den Text in die ActionBar des Spielers | +| `pos` | pos() | Position of Player | +| `blockPos` | blockPos() | Block Position of Player | | `x` | x(Number), x(): Number | Setzt oder gibt die X-Koordinate des Spielers | | `y` | y(Number), y(): Number | Setzt oder gibt die Y-Koordinate des Spielers | | `z` | z(Number), z(): Number | Setzt oder gibt die Z-Koordinate des Spielers | diff --git a/sw.def.lua b/sw.def.lua index 978d7050..eb6db3d2 100644 --- a/sw.def.lua +++ b/sw.def.lua @@ -92,6 +92,12 @@ function player.chat(...) end ---Send a message to the actionbar of the player. function player.actionbar(...) end +---@return Position +function player.pos() end + +---@return Position +function player.blockPos() end + ---@overload fun(): number ---@param newX number function player.x(newX) end @@ -248,11 +254,6 @@ function region.get(name) return nil end ---@return iregion[] function region.list() return nil end ----@class Position ----@field x number ----@field y number ----@field z number - ---@class server ---@field tps tps server = {} @@ -361,6 +362,47 @@ function delayed(ticks, callback) end ---@return Position function pos(x, y, z) return nil end +---@class Position +---@field x number +---@field y number +---@field z number +local position = {} + +---@param pos Position +---@return Position +function position.add(pos) return nil end + +---@param pos Position +---@return Position +function position.subtract(pos) return nil end + +---@param x number +---@return Position +function position.addX(x) return nil end + +---@param y number +---@return Position +function position.addY(y) return nil end + +---@param z number +---@return Position +function position.addZ(z) return nil end + +---@param x number +---@return Position +function position.subtractX(x) return nil end + +---@param y number +---@return Position +function position.subtractY(y) return nil end + +---@param z number +---@return Position +function position.subtractZ(z) return nil end + +---@return Position +function position.blockPos() return nil end + ---@return void function exec(...) end From 2d5bedc63a0fbdb4e6d42420c26c2f9df2e9a998 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Fri, 8 Mar 2024 22:10:41 +0100 Subject: [PATCH 133/139] Added block type to playerInteract event in script api --- .../steamwar/bausystem/features/script/event/EventListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java index 89f9667e..9871c27b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java @@ -125,6 +125,7 @@ public class EventListener implements Listener { table.set("blockY", event.getClickedBlock().getY()); table.set("blockZ", event.getClickedBlock().getZ()); table.set("blockFace", event.getBlockFace().name()); + table.set("blockType", event.getClickedBlock().getType().name()); } else { table.set("hasBlock", LuaValue.valueOf(false)); } From f1db3c20476ad365fdf4dca68ee502c1931d2b9d Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Fri, 8 Mar 2024 22:23:13 +0100 Subject: [PATCH 134/139] Updated doc --- SCRIPT.md | 1 + 1 file changed, 1 insertion(+) diff --git a/SCRIPT.md b/SCRIPT.md index ae9cb181..dc78efe8 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -333,6 +333,7 @@ Wenn `hasBlock` wahr ist, gibt es folgende Variablen: | `blockY` | Die Y-Koordinate des Blocks | | `blockZ` | Die Z-Koordinate des Blocks | | `blockFace` | Die Seite des Blocks die geklickt wurde | +| `blockType` | Das Material des Blocks | ### Position From b7cb909986659b4ba070f172c2897c97a2429900 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 11 Mar 2024 20:41:52 +0100 Subject: [PATCH 135/139] Add interactAt to documentation --- SCRIPT.md | 15 ++++++++------- sw.def.lua | 8 ++++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/SCRIPT.md b/SCRIPT.md index 33ac8003..58c289ca 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -184,13 +184,14 @@ Es gibt folgende Funktionen: Das `server`-Modul stellt Funktionen zur Verfügung, die den Server betreffen. Es gibt folgende Funktionen: -| Name | Signature | Beschreibung | -|---------------------|------------------------------|---------------------------------------------------------------------| -| `time` | time(): String | Gibt die aktuelle Zeit im Format `HH:mm:ss` zurück | -| `ticks` | ticks(): Number | Gibt die Ticks seit start des Serverstarts zurück | -| `onlinePlayerCount` | onlinePlayerCount(): Number | Gibt die Anzal der Spieler auf dem Server zurück | -| `getBlockAt` | getBlockAt(Pos): String | Gibt das Material an der Position zurück | -| `setBlockAt` | setBlockAt(Pos, String) | Setzt das Material an der angegebenen Stelle (z.B. Stein = `STONE`) | +| Name | Signature | Beschreibung | +|---------------------|-----------------------------|--------------------------------------------------------------------------------------------------| +| `time` | time(): String | Gibt die aktuelle Zeit im Format `HH:mm:ss` zurück | +| `ticks` | ticks(): Number | Gibt die Ticks seit start des Serverstarts zurück | +| `onlinePlayerCount` | onlinePlayerCount(): Number | Gibt die Anzal der Spieler auf dem Server zurück | +| `getBlockAt` | getBlockAt(Pos): String | Gibt das Material an der Position zurück | +| `setBlockAt` | setBlockAt(Pos, String) | Setzt das Material an der angegebenen Stelle (z.B. Stein = `STONE`) | +| `interactAt` | interactAt(Pos) | Interagiere mit einem Block in der Welt, als wenn dieser durch den Spieler gerechtsklicked wurde | Es gibt folgende weitere Module: diff --git a/sw.def.lua b/sw.def.lua index eb6db3d2..2c5dbab8 100644 --- a/sw.def.lua +++ b/sw.def.lua @@ -269,12 +269,16 @@ function server.onlinePlayerCount() return nil end ---@param position Position ---@return string -function getBlockAt(position) return nil end +function server.getBlockAt(position) return nil end ---@param position Position ---@param material string ---@return void -function setBlockAt(position, material) return nil end +function server.setBlockAt(position, material) return nil end + +---@param position Position +---@return void +function server.interactAt(position) return nil end ---@class tps local tps = {} From 5a991de55a4449d489fa75555b0cd9b2bc1b533e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 14 Mar 2024 11:49:04 +0100 Subject: [PATCH 136/139] Fix Techhider --- .../steamwar/bausystem/features/techhider/TechHiderCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java index 612cf8cb..38725cf0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -85,7 +85,7 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE Set hiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks"))); Set hiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); - TechHider current = new TechHider((p, cX, cY) -> { + TechHider current = new TechHider((TechHider.LocationEvaluator) (p, cX, cY) -> { if (rg.buildChunkOutside(cX, cY)) return true; return !hidden.get(rg).contains(p); }, Material.valueOf(obfuscateWith.toUpperCase()), hiddenBlocks.stream().map(String::toUpperCase).map(Material::valueOf).collect(Collectors.toSet()), hiddenBlockEntities); From 5a835acb804d77c8325183318f9da9bd40937cd0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 14 Mar 2024 11:50:52 +0100 Subject: [PATCH 137/139] Fix Techhider --- .../steamwar/bausystem/features/world/SpectatorListener.java | 3 +-- .../src/de/steamwar/bausystem/features/xray/XrayCommand.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index 58c0d508..5563f7a6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; -import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import de.steamwar.sql.BauweltMember; @@ -98,7 +97,7 @@ public class SpectatorListener implements Listener { materials.add(Material.WATER); materials.remove(Material.BARRIER); materials.remove(Material.STONE); - TechHider techHider = new TechHider((player, i, i1) -> { + TechHider techHider = new TechHider((TechHider.LocationEvaluator) (player, i, i1) -> { return Permission.BUILD.hasPermission(player) || Permission.isTempOnlySpectator(player) || NO_TECHHIDER.contains(player); }, Material.END_STONE, materials, new HashSet<>()); techHider.enable(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 2e5d90a0..59e88ec5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -148,7 +148,7 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen } private TechHider createXray(Region rg, Set obfuscate) { - TechHider current = new TechHider((p, cX, cY) -> { + TechHider current = new TechHider((TechHider.LocationEvaluator) (p, cX, cY) -> { if (rg.buildChunkOutside(cX, cY)) return true; return !hidden.get(rg).contains(p); }, Material.STRUCTURE_VOID, obfuscate, new HashSet<>()); From 6abeed0b02ba0aeaed9204fb4f5878fe3611d2a3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 14 Mar 2024 17:01:56 +0100 Subject: [PATCH 138/139] Fix ShieldPrinting setting air on click on block --- .../shieldprinting/ShieldPrinting.java | 12 ++---------- .../shieldprinting/ShieldPrintingCommand.java | 19 ------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 1e3fd6e1..1aa4149a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.shieldprinting; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.shieldprinting.impl.*; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; @@ -44,6 +45,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.BlockCanBuildEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; @@ -259,16 +261,6 @@ public class ShieldPrinting implements Listener { updateBossbars(); } - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (event.getClickedBlock() == null) return; - if (event.getItem() == null) return; - if (Region.getRegion(event.getClickedBlock().getLocation()) != region) return; - Vector vector = event.getClickedBlock().getLocation().toVector(); - if (!shieldMap.containsKey(vector)) return; - event.getClickedBlock().setType(Material.AIR); - } - @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { updateBossbar(event.getPlayer()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java index 20bbd8df..5bb60219 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -26,9 +26,7 @@ import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerInteractEvent; import java.util.HashMap; import java.util.Map; @@ -120,21 +118,4 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { return true; }; } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if(!Permission.BUILD.hasPermission(event.getPlayer())) return; - if (event.getClickedBlock() == null) { - return; - } - Region region = Region.getRegion(event.getClickedBlock().getLocation()); - if (region.isGlobal()) { - return; - } - ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.get(region); - if (shieldPrinting == null) { - return; - } - shieldPrinting.onPlayerInteract(event); - } } From cf329f4236057d9e2aafdc827a88b4e2168188b5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 14 Mar 2024 21:53:10 +0100 Subject: [PATCH 139/139] Fix TPSScoreboardElement --- .../src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java index d047f39b..6de8d252 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSSystem.java @@ -324,7 +324,7 @@ public class TPSSystem implements Listener { @Override public String get(Region region, Player p) { - if (TPSSystem.getInstance().currentlyStepping) { + if (TPSSystem.getInstance() != null && TPSSystem.getInstance().currentlyStepping) { long time = System.currentTimeMillis() % 1000; if (time < 250) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: §7•••";