From 50d4e7ef2fdd1db3725cb6a6087727f616deabee Mon Sep 17 00:00:00 2001 From: MoBrot <90271578+MoBrot@users.noreply.github.com> Date: Wed, 18 Jan 2023 16:35:33 +0100 Subject: [PATCH 001/175] NoSchemSharing with Testblock Fix. --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../bausystem/features/region/TestblockCommand.java | 13 +++++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 690fcb6d..c84e9d27 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1053,6 +1053,7 @@ 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 have an active NoSchemSharing ban until {0}. REGION_TNT_HELP=§8/§etnt §8- §7Change the TNT behaviour REGION_TNT_HELP_MODE=§8/§etnt §8[§7Mode§8] §8- §7Set TNT behaviour to a given mode REGION_TNT_ON=§aTNT-Damage activated diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 7320b18d..a239a281 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -1022,6 +1022,7 @@ 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 hast einen aktiven NoSchemSharing ban bis {0}. REGION_TNT_HELP=§8/§etnt §8- §7Ändere das TNT verhalten REGION_TNT_HELP_MODE=§8/§etnt §8[§7Mode§8] §8- §7Setzte das TNT verhalten auf einen Modus REGION_TNT_ON=§aTNT-Schaden aktiviert 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 a677e4df..7f31f971 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.command.*; import de.steamwar.linkage.Linked; +import de.steamwar.sql.Punishment; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; @@ -85,6 +86,14 @@ public class TestblockCommand extends SWCommand { return; } + if(Punishment.isPunished(SteamwarUser.get(p.getUniqueId()), Punishment.PunishmentType.NoSchemSharing, punishment -> { + + BauSystem.MESSAGE.parse("REGION_TB_NO_SCHEMSHARING", p, punishment.getEndTime()); + + })) { + return; + } + try { region.reset(node, RegionType.TESTBLOCK, regionExtensionType); RegionUtils.message(region, "REGION_TB_DONE"); @@ -126,14 +135,14 @@ public class TestblockCommand extends SWCommand { public TypeMapper nodeWithPublic() { return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { + public List tabCompletes(CommandSender commandSender, String[] previousArguments, String s) { List stringList = new ArrayList<>(SchematicNode.getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), s)); stringList.addAll(SchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s)); return stringList; } @Override - public SchematicNode map(CommandSender commandSender, PreviousArguments previousArguments, String s) { + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { SchematicNode node = SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s); if(node == null) { node = SchematicNode.getNodeFromPath(SteamwarUser.get(0), s); From 8a425cc435542e1d2280b54b1b304833ab6baccd Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 11:26:50 +0100 Subject: [PATCH 002/175] Prevent Water from being pasted using /tb --- .../bausystem/utils/FlatteningWrapper15.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index cadcb72a..52fd6a92 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -142,36 +142,32 @@ public class FlatteningWrapper15 implements FlatteningWrapper { if (pasteOptions.getColor() != Color.YELLOW) { changeColor(clipboard, pasteOptions.getColor()); } - if (pasteOptions.isOnlyColors()) { - Set blocks = new HashSet<>(); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); - - e.setMask(new Mask() { - @Override - public boolean test(BlockVector3 blockVector3) { - BaseBlock block = clipboard.getFullBlock(blockVector3); - String blockName = block.toString().toLowerCase(); - return blocks.contains(blockName); + e.setMask(new Mask() { + @Override + public boolean test(BlockVector3 blockVector3) { + Set blocks = new HashSet<>(); + if (pasteOptions.isOnlyColors()) { + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); } - @Nullable - @Override - public Mask2D toMask2D() { - return null; - } + BaseBlock block = clipboard.getFullBlock(blockVector3); + String blockName = block.toString().toLowerCase(); + return blockName.equals("minecraft:water") || blocks.contains(blockName); + } - public Mask copy() { - return this; - } - }); - } + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } + }); ClipboardHolder ch = new ClipboardHolder(clipboard); BlockVector3 dimensions = clipboard.getDimensions(); From 3d8a6e95fabd71041ebebd97c77bffc6fe3f530b Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 11:54:37 +0100 Subject: [PATCH 003/175] fixed mistake --- .../src/de/steamwar/bausystem/utils/FlatteningWrapper15.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 52fd6a92..7ea83656 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -159,7 +159,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); - return blockName.equals("minecraft:water") || blocks.contains(blockName); + return !blockName.equals("minecraft:water") || blocks.contains(blockName); } @Nullable From cdc0dbea86647e499099b23d3f2f420a0ada63f8 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 11:56:52 +0100 Subject: [PATCH 004/175] fixed mistake 2 --- .../bausystem/utils/FlatteningWrapper15.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 7ea83656..7cbe7348 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -142,21 +142,21 @@ public class FlatteningWrapper15 implements FlatteningWrapper { if (pasteOptions.getColor() != Color.YELLOW) { changeColor(clipboard, pasteOptions.getColor()); } + + Set blocks = new HashSet<>(); + if (pasteOptions.isOnlyColors()) { + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); + } e.setMask(new Mask() { @Override public boolean test(BlockVector3 blockVector3) { - Set blocks = new HashSet<>(); - if (pasteOptions.isOnlyColors()) { - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); - } - BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); return !blockName.equals("minecraft:water") || blocks.contains(blockName); From d2a3483d31baf4a3425cc16a914a71679900a975 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 12:12:10 +0100 Subject: [PATCH 005/175] added check if it actually is a tb --- .../bausystem/utils/FlatteningWrapper15.java | 3 ++- .../bausystem/features/region/TestblockCommand.java | 2 +- .../de/steamwar/bausystem/region/PasteOptions.java | 2 ++ .../src/de/steamwar/bausystem/region/Region.java | 12 ++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 7cbe7348..b1d4ddf2 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -159,7 +159,8 @@ public class FlatteningWrapper15 implements FlatteningWrapper { public boolean test(BlockVector3 blockVector3) { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); - return !blockName.equals("minecraft:water") || blocks.contains(blockName); + if (pasteOptions.isTestBlock() && blockName.equals("minecraft.water")) return true; + return blocks.contains(blockName); } @Nullable 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 a677e4df..8527371d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -86,7 +86,7 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node, RegionType.TESTBLOCK, regionExtensionType); + region.reset(node, RegionType.TESTBLOCK, regionExtensionType, true); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java index e28a02d8..c782a06b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java @@ -67,4 +67,6 @@ public class PasteOptions { * Used in 1.15 */ private final int waterLevel; + + private final boolean testBlock; } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 2d3fdc04..2b518c87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -425,8 +425,8 @@ public class Region { reset(null, regionType, regionExtensionType, false); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { - reset(schematic, regionType, regionExtensionType, false); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { + reset(schematic, regionType, regionExtensionType, false, isTestBlock); } public void reset(File file) { @@ -435,11 +435,11 @@ public class Region { undoSessions.push(editSession); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException { - reset(schematic, regionType, regionExtensionType, ignoreAir, false); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean isTestBlock) throws IOException { + reset(schematic, regionType, regionExtensionType, ignoreAir, false, isTestBlock); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors) throws IOException { + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors, boolean isTestBlock) throws IOException { if (!hasReset(regionType)) { return; } @@ -447,7 +447,7 @@ public class Region { regionExtensionType = RegionExtensionType.NORMAL; } - PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel); + PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, isTestBlock); Point pastePoint; File tempFile = null; From 5c8b70fc128f90b11fc5c3f4b08de7287bfaafee Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 12:15:45 +0100 Subject: [PATCH 006/175] added check if it actually is a tb --- .../bausystem/features/region/TestblockCommand.java | 2 +- BauSystem_Main/src/de/steamwar/bausystem/region/Region.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 8527371d..2db16400 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -57,7 +57,7 @@ public class TestblockCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - region.reset(RegionType.TESTBLOCK, regionExtensionType); + region.reset(RegionType.TESTBLOCK, regionExtensionType, true); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 2b518c87..e2787034 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -421,8 +421,8 @@ public class Region { reset(schematic, regionType, RegionExtensionType.NORMAL, false); } - public void reset(RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { - reset(null, regionType, regionExtensionType, false); + public void reset(RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { + reset(null, regionType, regionExtensionType, isTestBlock); } public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { @@ -430,7 +430,7 @@ public class Region { } public void reset(File file) { - EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel)); + EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false)); initSessions(); undoSessions.push(editSession); } From 4bae6b8d43ea0987c4cdd56f4160699c90a5c075 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 6 Feb 2023 09:37:34 +0100 Subject: [PATCH 007/175] finally working waterremover when doing /tb idk --- .../bausystem/utils/FlatteningWrapper15.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index b1d4ddf2..fb02039e 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -43,6 +43,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; @@ -143,8 +144,9 @@ public class FlatteningWrapper15 implements FlatteningWrapper { changeColor(clipboard, pasteOptions.getColor()); } + Set blocks = new HashSet<>(); - if (pasteOptions.isOnlyColors()) { + { blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); @@ -154,13 +156,15 @@ public class FlatteningWrapper15 implements FlatteningWrapper { blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); } + e.setMask(new Mask() { @Override public boolean test(BlockVector3 blockVector3) { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); - if (pasteOptions.isTestBlock() && blockName.equals("minecraft.water")) return true; - return blocks.contains(blockName); + if (blocks.contains(blockName) && pasteOptions.isOnlyColors()) return true; + if (pasteOptions.isTestBlock() && blockName.startsWith("minecraft:water")) return false; + return true; } @Nullable @@ -168,6 +172,9 @@ public class FlatteningWrapper15 implements FlatteningWrapper { public Mask2D toMask2D() { return null; } + public Mask copy() { + return this; + } }); ClipboardHolder ch = new ClipboardHolder(clipboard); @@ -182,7 +189,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } if (pasteOptions.isReset()) { - e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); + e.setBlocks(new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); if (pasteOptions.getWaterLevel() != 0) { e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint()).withY(pasteOptions.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock()); } From 55a63dacaf6b596dc1ae1b3cd8f525d512044c6c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 6 Feb 2023 21:38:12 +0100 Subject: [PATCH 008/175] es kann sein das da was fehlt, da ich mit den commits durcheinander gekommen bin --- .../bausystem/utils/FlatteningWrapper15.java | 10 ++++++-- .../features/region/TestblockCommand.java | 4 ++-- .../bausystem/region/PasteOptions.java | 24 ------------------- .../de/steamwar/bausystem/region/Region.java | 16 ++++++------- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index fb02039e..c64ae034 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -19,6 +19,8 @@ package de.steamwar.bausystem.utils; +import com.google.common.collect.ImmutableMap; +import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; @@ -42,8 +44,9 @@ import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; @@ -61,7 +64,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; import java.util.logging.Level; public class FlatteningWrapper15 implements FlatteningWrapper { 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 2db16400..a677e4df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -57,7 +57,7 @@ public class TestblockCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - region.reset(RegionType.TESTBLOCK, regionExtensionType, true); + region.reset(RegionType.TESTBLOCK, regionExtensionType); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); @@ -86,7 +86,7 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node, RegionType.TESTBLOCK, regionExtensionType, true); + region.reset(node, RegionType.TESTBLOCK, regionExtensionType); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java index c782a06b..fe64f44c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java @@ -28,44 +28,20 @@ import lombok.Getter; @AllArgsConstructor public class PasteOptions { - /** - * Used in 1.15 - */ private final boolean rotate; - /** - * Used in 1.15 - */ private final boolean ignoreAir; - /** - * Used in 1.15 - */ private final Color color; - /** - * Used in 1.15 - */ private final boolean onlyColors; - /** - * Used in 1.15 - */ private final boolean reset; - /** - * Used in 1.15 - */ private final Point minPoint; - /** - * Used in 1.15 - */ private final Point maxPoint; - /** - * Used in 1.15 - */ private final int waterLevel; private final boolean testBlock; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index e2787034..2f79be02 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -421,12 +421,12 @@ public class Region { reset(schematic, regionType, RegionExtensionType.NORMAL, false); } - public void reset(RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { - reset(null, regionType, regionExtensionType, isTestBlock); + public void reset(RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { + reset(null, regionType, regionExtensionType); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { - reset(schematic, regionType, regionExtensionType, false, isTestBlock); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { + reset(schematic, regionType, regionExtensionType, false); } public void reset(File file) { @@ -435,11 +435,11 @@ public class Region { undoSessions.push(editSession); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean isTestBlock) throws IOException { - reset(schematic, regionType, regionExtensionType, ignoreAir, false, isTestBlock); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException { + reset(schematic, regionType, regionExtensionType, ignoreAir, false); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors, boolean isTestBlock) throws IOException { + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors) throws IOException { if (!hasReset(regionType)) { return; } @@ -447,7 +447,7 @@ public class Region { regionExtensionType = RegionExtensionType.NORMAL; } - PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, isTestBlock); + PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK); Point pastePoint; File tempFile = null; From 5d55784f7987e19378410b56403003aeb043c9e2 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 16 Feb 2023 21:53:52 +0100 Subject: [PATCH 009/175] sollte jetzt auch mit waterlogged blocks gehen --- .../steamwar/bausystem/utils/FlatteningWrapper15.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index c64ae034..3545dd1a 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -19,8 +19,6 @@ package de.steamwar.bausystem.utils; -import com.google.common.collect.ImmutableMap; -import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; @@ -45,11 +43,11 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; +import net.minecraft.server.v1_15_R1.AreaFactory; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -169,7 +167,12 @@ public class FlatteningWrapper15 implements FlatteningWrapper { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); if (blocks.contains(blockName) && pasteOptions.isOnlyColors()) return true; - if (pasteOptions.isTestBlock() && blockName.startsWith("minecraft:water")) return false; + if (pasteOptions.isTestBlock()) { + if (blockName.startsWith("minecraft:water")) return false; + if (block.toString().toLowerCase().contains("waterlogged=true")) return false; + } + + return true; } From 2f66580e60df33eada3d57b15a41836816b37aba Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 18 Feb 2023 13:41:02 +0100 Subject: [PATCH 010/175] sollte jetzt klappen, ich werde versuchen mehr in die devlabs rein zuschauen --- .../steamwar/bausystem/utils/FlatteningWrapper15.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 3545dd1a..4e7e57ac 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.function.pattern.WaterloggedRemover; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; @@ -42,12 +43,10 @@ import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; -import net.minecraft.server.v1_15_R1.AreaFactory; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -166,10 +165,15 @@ public class FlatteningWrapper15 implements FlatteningWrapper { public boolean test(BlockVector3 blockVector3) { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); + if (blocks.contains(blockName) && pasteOptions.isOnlyColors()) return true; if (pasteOptions.isTestBlock()) { if (blockName.startsWith("minecraft:water")) return false; - if (block.toString().toLowerCase().contains("waterlogged=true")) return false; + if (blockName.contains("waterlogged=true")) try { + e.setBlock(blockVector3, new WaterloggedRemover(clipboard).applyBlock(blockVector3)); + } catch (WorldEditException ex) { + throw new RuntimeException(ex); + } } From 3f4f237d63e6ddd2f75d3c22ed34a75c01d3fe21 Mon Sep 17 00:00:00 2001 From: PsiRobot Date: Thu, 23 Mar 2023 22:27:51 +0000 Subject: [PATCH 011/175] Fixed Issue #110 Loader bugt bei Strings --- .../de/steamwar/bausystem/features/loader/Loader.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 8c12f2de..1a64a8af 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -38,6 +38,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.scheduler.BukkitTask; import java.util.*; @@ -201,8 +202,18 @@ public class Loader implements Listener { if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return; + if (event.getClickedBlock().getType() == Material.OBSERVER) return; + + if (event.getHand() == EquipmentSlot.OFF_HAND) { + return; + } + + if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) { + return; + } + LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); if (button != LoaderButton.INVALID) { actions.add(InteractionActivation.construct(p, event.getClickedBlock().getLocation(), this)); From 48b2a87c96edabf4ee721ba18087c8ea47adc4a8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 16:53:58 +0200 Subject: [PATCH 012/175] Fix ShieldPrinting Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 + BauSystem_Main/src/BauSystem_de.properties | 2 + .../shieldprinting/ShieldPrinting.java | 46 ++++++++++++++++++- .../shieldprinting/ShieldPrintingCommand.java | 23 +++++++++- .../utils/bossbar/BossBarService.java | 6 +++ 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 27f1c19d..a3860e34 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -513,6 +513,8 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server 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} SHIELD_PRINTING_START = §aThe shield printing has been started. SHIELD_PRINTING_COPY = §aThe shield has been copied. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index a1461a99..9689be29 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -506,6 +506,8 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server 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} SHIELD_PRINTING_START = §aShield printing wurde gestartet. SHIELD_PRINTING_COPY = §aSchilde wurden kopiert. 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 9cf829b5..3ddefdc2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -21,15 +21,24 @@ package de.steamwar.bausystem.features.shieldprinting; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; +import de.steamwar.bausystem.utils.bossbar.BossBarService; +import de.steamwar.bausystem.utils.bossbar.RegionedBossbar; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; +import org.bukkit.boss.BarColor; +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.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.util.Vector; import java.util.*; @@ -49,12 +58,14 @@ public class ShieldPrinting implements Listener { public ShieldPrinting(Region region) { this.region = region; Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + updateBossbars(); } public void copy() { for (Map.Entry entry : shieldMap.entrySet()) { shieldData.put(entry.getValue(), entry.getKey().toLocation(WORLD).getBlock().getBlockData()); } + updateBossbars(); } public void apply() { @@ -64,10 +75,13 @@ public class ShieldPrinting implements Listener { } public void disable() { - BlockPistonExtendEvent.getHandlerList().unregister(this); - BlockPistonRetractEvent.getHandlerList().unregister(this); + HandlerList.unregisterAll(this); shieldMap.clear(); shieldData.clear(); + + for (Player player : Bukkit.getOnlinePlayers()) { + BossBarService.instance.remove(player, region, "shieldprinting"); + } } @EventHandler @@ -97,5 +111,33 @@ public class ShieldPrinting implements Listener { } shieldMap.keySet().removeAll(toRemove); shieldMap.putAll(temp); + 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()); + } + + private void updateBossbars() { + for (Player player : Bukkit.getOnlinePlayers()) { + updateBossbar(player); + } + } + + private void updateBossbar(Player player) { + BauSystemBossbar bossbar = BossBarService.instance.get(player, region, "shieldprinting"); + bossbar.setColor(BarColor.YELLOW); + bossbar.setTitle(BauSystem.MESSAGE.parse(shieldData.isEmpty() ? "SHIELD_PRINTING_BOSSBAR" : "SHIELD_PRINTING_BOSSBAR_COPIED", player, shieldMap.size(), shieldData.size())); } } 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 a789c748..b2f31dbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -26,12 +26,15 @@ 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; @Linked -public class ShieldPrintingCommand extends SWCommand { +public class ShieldPrintingCommand extends SWCommand implements Listener { public ShieldPrintingCommand() { super("shieldprinting"); @@ -43,7 +46,7 @@ public class ShieldPrintingCommand extends SWCommand { public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) { Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { - // BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); + BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); return; } ShieldPrinting shieldPrinting; @@ -107,4 +110,20 @@ public class ShieldPrintingCommand extends SWCommand { return true; }; } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getClickedBlock() == null) { + return; + } + Region region = Region.getRegion(event.getClickedBlock().getLocation()); + if (region.isGlobal()) { + return; + } + ShieldPrinting shieldPrinting = shieldMap.get(region); + if (shieldPrinting == null) { + return; + } + shieldPrinting.onPlayerInteract(event); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java index 6c7d636d..e6ea2c16 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java @@ -37,6 +37,12 @@ import java.util.Map; @Linked public class BossBarService implements Listener { + public static BossBarService instance; + + public BossBarService() { + instance = this; + } + private final Map>> playerBossBars = new HashMap<>(); public synchronized BauSystemBossbar get(Player player, Region region, String key) { From 61895377d1f1ed09016993e778be21c18ac18dac Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 16:56:05 +0200 Subject: [PATCH 013/175] Hotfix RegionedBossbar Signed-off-by: yoyosource --- .../steamwar/bausystem/utils/bossbar/RegionedBossbar.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java index 4d922143..5fb1cc99 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java @@ -135,8 +135,10 @@ public class RegionedBossbar implements BauSystemBossbar, Listener { @Override public void cleanup() { - bossBar.removeAll(); - bossBar = null; + if (bossBar != null) { + bossBar.removeAll(); + bossBar = null; + } region = null; player = null; From a15e5aaf50cdb67281c6fc6162f1d005e867db9c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 17:07:40 +0200 Subject: [PATCH 014/175] Remove some memory Signed-off-by: yoyosource --- .../features/shieldprinting/ShieldPrinting.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 3ddefdc2..0ad8d710 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -111,6 +111,15 @@ public class ShieldPrinting implements Listener { } shieldMap.keySet().removeAll(toRemove); shieldMap.putAll(temp); + + toRemove.clear(); + for (Map.Entry entry : shieldMap.entrySet()) { + if (entry.getKey().equals(entry.getValue())) { + toRemove.add(entry.getKey()); + } + } + shieldMap.keySet().removeAll(toRemove); + updateBossbars(); } From f9919925283b9da1dd9054e43fb69534f42dbc26 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 17:39:51 +0200 Subject: [PATCH 015/175] Fix stoplag for ShieldPrinting.apply Signed-off-by: yoyosource --- .../bausystem/features/shieldprinting/ShieldPrinting.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0ad8d710..e1585fbb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -70,7 +70,7 @@ public class ShieldPrinting implements Listener { public void apply() { for (Map.Entry entry : shieldData.entrySet()) { - entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue()); + entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue(), false); } } From ad4a054a6385bfefd05ed1cfcb0c540028b60fdb Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 18 Apr 2023 11:46:58 +0200 Subject: [PATCH 016/175] Added new Buttons to Loader Detonator not nescessary since detection works differently --- .../steamwar/bausystem/features/loader/LoaderButton.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java index e5e74171..6825a247 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java @@ -46,6 +46,9 @@ public enum LoaderButton { switch (block.getType()) { case LEVER: return LoaderButton.SWITCH; + case CRIMSON_BUTTON: + case MANGROVE_BUTTON: + case WARPED_BUTTON: case ACACIA_BUTTON: case BIRCH_BUTTON: case DARK_OAK_BUTTON: @@ -53,8 +56,13 @@ public enum LoaderButton { case OAK_BUTTON: case SPRUCE_BUTTON: return LoaderButton.WOOD_BUTTON; + case POLISHED_BLACKSTONE_BUTTON: case STONE_BUTTON: return LoaderButton.STONE_BUTTON; + case CRIMSON_PRESSURE_PLATE: + case MANGROVE_PRESSURE_PLATE: + case WARPED_PRESSURE_PLATE: + // case POLISHED_BLACKSTONE_PRESSURE_PLATE: case ACACIA_PRESSURE_PLATE: case BIRCH_PRESSURE_PLATE: case DARK_OAK_PRESSURE_PLATE: From 377bcb92fb845a29f9ce9698064c86bdbd4e97b0 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 18 Apr 2023 11:55:30 +0200 Subject: [PATCH 017/175] Generalized LoaderButton assignment --- .../features/loader/LoaderButton.java | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java index 6825a247..4a1d5159 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java @@ -24,6 +24,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.bukkit.block.Block; + @AllArgsConstructor @RequiredArgsConstructor @Getter @@ -46,42 +47,25 @@ public enum LoaderButton { switch (block.getType()) { case LEVER: return LoaderButton.SWITCH; - case CRIMSON_BUTTON: - case MANGROVE_BUTTON: - case WARPED_BUTTON: - case ACACIA_BUTTON: - case BIRCH_BUTTON: - case DARK_OAK_BUTTON: - case JUNGLE_BUTTON: - case OAK_BUTTON: - case SPRUCE_BUTTON: - return LoaderButton.WOOD_BUTTON; - case POLISHED_BLACKSTONE_BUTTON: - case STONE_BUTTON: - return LoaderButton.STONE_BUTTON; - case CRIMSON_PRESSURE_PLATE: - case MANGROVE_PRESSURE_PLATE: - case WARPED_PRESSURE_PLATE: - // case POLISHED_BLACKSTONE_PRESSURE_PLATE: - case ACACIA_PRESSURE_PLATE: - case BIRCH_PRESSURE_PLATE: - case DARK_OAK_PRESSURE_PLATE: - case JUNGLE_PRESSURE_PLATE: - case OAK_PRESSURE_PLATE: - case SPRUCE_PRESSURE_PLATE: - case STONE_PRESSURE_PLATE: - return LoaderButton.PRESSURE_PLATE; - case HEAVY_WEIGHTED_PRESSURE_PLATE: - case LIGHT_WEIGHTED_PRESSURE_PLATE: - return LoaderButton.WEIGHTED_PRESSURE_PLATE; case TRIPWIRE: return LoaderButton.TRIPWIRE; case NOTE_BLOCK: return LoaderButton.NOTEBLOCK; case DAYLIGHT_DETECTOR: return LoaderButton.DAYLIGHTSENSOR; + case HEAVY_WEIGHTED_PRESSURE_PLATE: + case LIGHT_WEIGHTED_PRESSURE_PLATE: + return LoaderButton.WEIGHTED_PRESSURE_PLATE; default: - return LoaderButton.INVALID; + if (block.getType().name().contains("STONE_BUTTON")) { + return LoaderButton.STONE_BUTTON; + } else if (block.getType().name().contains("BUTTON")) { + return LoaderButton.WOOD_BUTTON; + } else if (block.getType().name().contains("PRESSURE_PLATE")) { + return LoaderButton.PRESSURE_PLATE; + } else { + return LoaderButton.INVALID; + } } } } From 3786f1e2bb7e5d03a09d3d97d171eaa7fc1c83dc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 19 Apr 2023 13:38:00 +0200 Subject: [PATCH 018/175] Add sand shield printing tracking Signed-off-by: yoyosource --- .../shieldprinting/ShieldPrinting.java | 43 +++++++++++++++++++ .../shieldprinting/ShieldPrintingCommand.java | 12 +++--- 2 files changed, 49 insertions(+), 6 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 e1585fbb..ea3b0fbc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -25,18 +25,27 @@ import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.bausystem.utils.bossbar.RegionedBossbar; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; import org.bukkit.boss.BarColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; 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.BlockFormEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.EntityBlockFormEvent; +import org.bukkit.event.entity.EntityAirChangeEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.util.Vector; @@ -47,6 +56,17 @@ public class ShieldPrinting implements Listener { private static final World WORLD = Bukkit.getWorlds().get(0); + static { + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> { + shieldPrinting.fallingBlocks.replaceAll((entity, location) -> { + if (entity.isDead()) return null; + return location; + }); + }); + }, 1, 1); + } + /** * Vector of current position, Vector of origin */ @@ -123,6 +143,29 @@ public class ShieldPrinting implements Listener { updateBossbars(); } + private Map fallingBlocks = new HashMap<>(); + + @EventHandler + public void onEntitySpawn(EntitySpawnEvent event) { + if (event.getEntityType() != EntityType.FALLING_BLOCK) return; + if (Region.getRegion(event.getLocation()) != region) return; + fallingBlocks.put(event.getEntity(), event.getLocation().getBlock().getLocation()); + } + + @EventHandler + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + if (!event.getBlock().getType().isAir()) return; + if (event.getEntityType() != EntityType.FALLING_BLOCK) return; + if (Region.getRegion(event.getBlock().getLocation()) != region) return; + Location origin = fallingBlocks.remove(event.getEntity()); + if (origin == null) return; + Location destination = event.getBlock().getLocation(); + Vector originOrigin = shieldMap.remove(origin.toVector()); + shieldMap.put(destination.toVector(), originOrigin != null ? originOrigin : origin.toVector()); + + updateBossbars(); + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getClickedBlock() == null) return; 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 b2f31dbd..a72443f5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -40,7 +40,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { super("shieldprinting"); } - private Map shieldMap = new HashMap<>(); + static final Map SHIELD_PRINTING_MAP = new HashMap<>(); @Register public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) { @@ -52,14 +52,14 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { ShieldPrinting shieldPrinting; switch (shieldPrintingState) { case START: - shieldPrinting = shieldMap.put(region, new ShieldPrinting(region)); + shieldPrinting = SHIELD_PRINTING_MAP.put(region, new ShieldPrinting(region)); if (shieldPrinting != null) { shieldPrinting.disable(); } BauSystem.MESSAGE.send("SHIELD_PRINTING_START", player); break; case COPY: - shieldPrinting = shieldMap.get(region); + shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -68,7 +68,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("SHIELD_PRINTING_COPY", player); break; case APPLY: - shieldPrinting = shieldMap.get(region); + shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -86,7 +86,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); return; } - ShieldPrinting shieldPrinting = shieldMap.remove(region); + ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.remove(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -120,7 +120,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { if (region.isGlobal()) { return; } - ShieldPrinting shieldPrinting = shieldMap.get(region); + ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { return; } From 37b76eff30ae157924c4b03fa4b2c23795faaa3c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 19 Apr 2023 18:08:36 +0200 Subject: [PATCH 019/175] Add ShowModeParameterType.TICKS_SINCE_START Signed-off-by: yoyosource --- .../bausystem/features/tracer/show/EntityShowMode.java | 2 ++ .../bausystem/features/tracer/show/ShowModeParameter.java | 5 +++++ .../features/tracer/show/ShowModeParameterType.java | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java index bfcd15e5..6f61a08e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -202,6 +202,8 @@ public class EntityShowMode implements ShowMode { entity.setDisplayName(fuseTicks + ""); } else if (showModeParameter.isCount()) { entity.setDisplayName(new HashSet<>(records).size() + ""); + } else if (showModeParameter.isTicksSinceStart()) { + entity.setDisplayName((80 - fuseTicks) + tntPosition.getRecord().getOffset() + ""); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java index d8e3a75f..4babe506 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java @@ -31,6 +31,7 @@ public class ShowModeParameter { private boolean ticks = false; private boolean count = false; private boolean buildDestroyOnly = false; + private boolean ticksSinceStart = false; public void enableWater() { this.water = true; @@ -63,4 +64,8 @@ public class ShowModeParameter { public void enableBuildDestroyOnly() { this.buildDestroyOnly = true; } + + public void enableTicksSinceStart() { + this.ticksSinceStart = true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java index 3d28237d..a80a3633 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java @@ -38,9 +38,10 @@ public enum ShowModeParameterType { }, Arrays.asList("-advanced", "-a"), "INTERPOLATE_Y", "INTERPOLATE_XZ"), SOURCE(ShowModeParameter::enableSourceOnly, Arrays.asList("-source", "-sourceonly", "-ignite"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), EXPLODE(ShowModeParameter::enableExplodeOnly, Arrays.asList("-explode", "-explodeonly"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), - TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT"), - COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "COUNT"), - BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"); + TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT", "TICKS_SINCE_START"), + COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "TICKS", "TICKS_SINCE_START"), + BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"), + TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"); @Getter private final Consumer showModeParameterConsumer; From 740d3cfb95468b5262a2a462b1ffaca3caee6a38 Mon Sep 17 00:00:00 2001 From: PsiRobot Date: Fri, 21 Apr 2023 16:45:24 +0000 Subject: [PATCH 020/175] Fix SkullCommand for Bedrock --- .../src/de/steamwar/bausystem/features/util/SkullCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b8cce749..9bb2331d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java @@ -57,7 +57,7 @@ public class SkullCommand extends SWCommand { return new TypeMapper() { @Override public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { - if (s.endsWith("⍇")) return null; + if (s.startsWith(".")) return null; return s; } From b494f0bf3a6b69d189788a7be98f1860bb09e41a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 Apr 2023 16:24:31 +0200 Subject: [PATCH 021/175] Hotfix Tracer Signed-off-by: yoyosource --- .../steamwar/bausystem/features/tracer/TraceCommand.java | 8 ++------ .../features/tracer/record/AutoTraceRecorder.java | 3 +-- .../bausystem/features/tracer/record/Recorder.java | 6 +----- .../features/tracer/record/SimpleTraceRecorder.java | 3 +-- .../bausystem/features/tracer/record/TraceRecorder.java | 3 +-- 5 files changed, 6 insertions(+), 17 deletions(-) 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 b24ec012..b79d08f0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -209,11 +209,10 @@ public class TraceCommand extends SWCommand { @AllArgsConstructor private enum ShowModeType { - ENTITY((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, 10), new ShowModeParameterType[]{}), - RAW((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, -1), new ShowModeParameterType[]{}); + ENTITY((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, 10)), + RAW((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, -1)); private BiFunction> showModeBiFunction; - private ShowModeParameterType[] removedTypes; } @ClassMapper(value = ShowModeParameterType.class, local = true) @@ -235,9 +234,6 @@ public class TraceCommand extends SWCommand { @Override public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Set showModeParameterTypeSet = new HashSet<>(); - previousArguments.getAll(ShowModeType.class).forEach(showModeType -> { - showModeParameterTypeSet.addAll(Arrays.asList(showModeType.removedTypes)); - }); Arrays.stream(previousArguments.userArgs).map(showModeParameterTypesMap::get).forEach(showModeParameterTypeSet::add); showModeParameterTypeSet.remove(null); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java index 49253e08..2af4146b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java @@ -70,10 +70,9 @@ public abstract class AutoTraceRecorder implements TraceRecorder { } @Override - public Record postClear() { + public void postClear() { recordMap.clear(); record = recordSupplier.get(); - return record; } @Override 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 8b3fcea0..5d580005 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 @@ -147,11 +147,7 @@ public class Recorder implements Listener { } public void postClear(Region region) { - TraceRecorder traceRecorder = get(region); - Record record = traceRecorder.postClear(); - if (record != null) { - StoredRecords.add(region, record); - } + get(region).postClear(); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java index a1d03f27..79e984aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java @@ -46,9 +46,8 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { } @Override - public Record postClear() { + public void postClear() { recordMap.clear(); - return record; } private Record.TNTRecord getRecord(TNTPrimed tntPrimed) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java index 2c75bf07..bb2a1325 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java @@ -30,8 +30,7 @@ public interface TraceRecorder { String scoreboard(Player player); default void recordSupplier(Supplier recordSupplier) { } - default Record postClear() { - return null; + default void postClear() { } void spawn(TNTPrimed tntPrimed); void tick(TNTPrimed tntPrimed); From a767a942fb0da7be6a80fdeb210ad0ac7db33704 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 29 Apr 2023 11:49:27 +0200 Subject: [PATCH 022/175] Add DesignEndStone or DesignEndStoneCommand Add Line for BauScoreboard to show XRay and TechHider Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 7 ++ BauSystem_Main/src/BauSystem_de.properties | 4 + .../design/endstone/DesignEndStone.java | 105 ++++++++++++++++++ .../endstone/DesignEndStoneCommand.java | 50 +++++++++ .../features/techhider/TechHiderCommand.java | 10 ++ .../features/world/BauScoreboard.java | 8 ++ .../bausystem/features/xray/XrayCommand.java | 10 ++ 7 files changed, 194 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index a3860e34..b2c9e377 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -37,6 +37,9 @@ SCOREBOARD_TPS_FROZEN = §e Frozen SCOREBOARD_TRACE_TICKS = Ticks +SCOREBOARD_TECHHIDER = TechHider +SCOREBOARD_XRAY = XRay + # Flags FLAG_COLOR = Color FLAG_TNT = TNT @@ -159,6 +162,10 @@ COUNTINGWAND_MESSAGE_LCLICK = §7Second position at: §8[§7{0}§8, §7{1}§8, COUNTINGWAND_MESSAGE_VOLUME = §e{0} COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} +# Design Endstone +DESIGN_ENDSTONE_COMMAND_HELP = §8/§edesign endstone §8- §7Show where Endstone is +DESIGN_ENDSTONE_REGION_ERROR = §cThis region has no build area + # Detonator DETONATOR_LOC_REMOVE = §e{0} removed DETONATOR_LOC_ADD = §e{0} added diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 9689be29..b14640b1 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -157,6 +157,10 @@ COUNTINGWAND_MESSAGE_LCLICK = §7Zweite Position bei: §8[§7{0}§8, §7{1}§8, COUNTINGWAND_MESSAGE_VOLUME = §e{0} COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} +# Design Endstone +DESIGN_ENDSTONE_COMMAND_HELP = §8/§edesign endstone §8- §7Zeige wo Endstone ist +DESIGN_ENDSTONE_REGION_ERROR = §cDiese Region hat keinen Baubereich + # Detonator DETONATOR_LOC_REMOVE = §e{0} entfernt DETONATOR_LOC_ADD = §e{0} hinzugefügt 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 new file mode 100644 index 00000000..78f39609 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java @@ -0,0 +1,105 @@ +/* + * 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.design.endstone; + +import de.steamwar.bausystem.region.Region; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class DesignEndStone { + + private static final World WORLD = Bukkit.getWorlds().get(0); + + private int minX, minY, minZ, maxX, maxY, maxZ; + 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(); + this.minY = region.getMinPointBuild().getY(); + this.minZ = region.getMinPointBuild().getZ(); + this.maxX = region.getMaxPointBuild().getX(); + this.maxY = region.getMaxPointBuild().getY(); + this.maxZ = region.getMaxPointBuild().getZ(); + } + + private void calc() { + entities.forEach(REntity::die); + entities.clear(); + locations.clear(); + + calc(minX, minY, minZ, maxX, maxY, minZ, 0, 0, 1, maxZ - minZ); + calc(minX, minY, maxZ, maxX, maxY, maxZ, 0, 0, -1, maxZ - minZ); + calc(minX, minY, minZ, minX, maxY, maxZ, 1, 0, 0, maxX - minX); + calc(maxX, minY, minZ, maxX, maxY, maxZ, -1, 0, 0, maxX - minX); + // calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY); + calc(minX, maxY, minZ, maxX, maxY, maxZ, 0, -1, 0, maxY - minY); + } + + private void calc(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int dirX, int dirY, int dirZ, int steps) { + for (int x = minX; x <= maxX; x++) { + for (int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + for (int step = 0; step < steps; step++) { + int cx = x + step * dirX; + int cy = y + step * dirY; + int cz = z + step * dirZ; + Material material = WORLD.getBlockAt(cx, cy, cz).getType(); + if (material == Material.END_STONE || material == Material.END_STONE_BRICKS || material == Material.END_STONE_BRICK_SLAB || material == Material.END_STONE_BRICK_STAIRS || material == Material.END_STONE_BRICK_WALL) { + Location location = new Location(WORLD, cx + 0.5, cy, cz + 0.5); + if (locations.contains(location)) break; + RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.END_STONE); + entity.setNoGravity(true); + entity.setGlowing(true); + entities.add(entity); + break; + } else if (!material.isAir()) { + break; + } + } + } + } + } + } + + public void toggle(Player player) { + if (players.contains(player)) { + players.remove(player); + entityServer.removePlayer(player); + } else { + players.add(player); + entityServer.addPlayer(player); + calc(); + } + } +} 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 new file mode 100644 index 00000000..56b2d419 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.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.design.endstone; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +@Linked +public class DesignEndStoneCommand extends SWCommand { + + public DesignEndStoneCommand() { + super("designendstone"); + } + + private Map designEndStoneMap = new HashMap<>(); + + @Register(description = "DESIGN_ENDSTONE_COMMAND_HELP") + public void genericCommand(Player player) { + Region region = Region.getRegion(player.getLocation()); + if (!region.hasType(RegionType.BUILD)) { + BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player); + return; + } + designEndStoneMap.computeIfAbsent(region, DesignEndStone::new).toggle(player); + } +} 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 622632fd..e06724ba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -50,6 +50,16 @@ public class TechHiderCommand extends SWCommand implements Listener { private Map> techHiders = new HashMap<>(); private Map> hidden = new HashMap<>(); + private static TechHiderCommand INSTANCE; + + { + INSTANCE = this; + } + + public static boolean isHidden(Region region, Player player) { + return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); + } + @LinkedInstance public XrayCommand xrayCommand; 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 ace614eb..2d170bda 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -3,10 +3,12 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.Loader; import de.steamwar.bausystem.features.script.CustomScriptManager; +import de.steamwar.bausystem.features.techhider.TechHiderCommand; import de.steamwar.bausystem.features.tpslimit.FreezeUtils; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; @@ -15,6 +17,7 @@ import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; +import de.steamwar.techhider.TechHider; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -86,6 +89,11 @@ public class BauScoreboard implements Listener { } strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode)); } + if (TechHiderCommand.isHidden(region, p)) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p)); + } else if (XrayCommand.isHidden(region, p)) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p)); + } strings.add("§3"); String traceScore = recorder.get(region).scoreboard(p); 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 f1232760..9418a7e1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -57,6 +57,16 @@ public class XrayCommand extends SWCommand implements Listener { private Map> xrayedBlocks = new HashMap<>(); private Map> hidden = new HashMap<>(); + private static XrayCommand INSTANCE; + + { + INSTANCE = this; + } + + public static boolean isHidden(Region region, Player player) { + return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); + } + @LinkedInstance public TechHiderCommand techHiderCommand; From c3838138b4f34d5a494fa649de9070c3ca8b7f65 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 29 Apr 2023 14:19:05 +0200 Subject: [PATCH 023/175] Fix DesignEndStone Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 ++ BauSystem_Main/src/BauSystem_de.properties | 2 ++ .../bausystem/features/design/endstone/DesignEndStone.java | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index b2c9e377..82d131d2 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -165,6 +165,8 @@ COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} # Design Endstone DESIGN_ENDSTONE_COMMAND_HELP = §8/§edesign endstone §8- §7Show where Endstone is DESIGN_ENDSTONE_REGION_ERROR = §cThis region has no build area +DESIGN_ENDSTONE_ENABLE = §aEndstone is activated +DESIGN_ENDSTONE_DISABLE = §cEndstone is deactivated # Detonator DETONATOR_LOC_REMOVE = §e{0} removed diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index b14640b1..ed657b0d 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -160,6 +160,8 @@ COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} # Design Endstone DESIGN_ENDSTONE_COMMAND_HELP = §8/§edesign endstone §8- §7Zeige wo Endstone ist DESIGN_ENDSTONE_REGION_ERROR = §cDiese Region hat keinen Baubereich +DESIGN_ENDSTONE_ENABLE = §aEndstone ist aktiviert +DESIGN_ENDSTONE_DISABLE = §cEndstone ist deaktiviert # Detonator DETONATOR_LOC_REMOVE = §e{0} entfernt 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 78f39609..b2c83c7e 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 @@ -19,10 +19,12 @@ package de.steamwar.bausystem.features.design.endstone; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; +import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -78,7 +80,7 @@ public class DesignEndStone { if (material == Material.END_STONE || material == Material.END_STONE_BRICKS || material == Material.END_STONE_BRICK_SLAB || material == Material.END_STONE_BRICK_STAIRS || material == Material.END_STONE_BRICK_WALL) { Location location = new Location(WORLD, cx + 0.5, cy, cz + 0.5); if (locations.contains(location)) break; - RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.END_STONE); + RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.RED_STAINED_GLASS); entity.setNoGravity(true); entity.setGlowing(true); entities.add(entity); @@ -96,10 +98,12 @@ public class DesignEndStone { if (players.contains(player)) { players.remove(player); entityServer.removePlayer(player); + BauSystem.MESSAGE.send("DESIGN_ENDSTONE_DISABLE", player, ChatMessageType.ACTION_BAR); } else { players.add(player); entityServer.addPlayer(player); calc(); + BauSystem.MESSAGE.send("DESIGN_ENDSTONE_ENABLE", player, ChatMessageType.ACTION_BAR); } } } From 4dafaab5d9a7925dbb57b7dd22fba54e3e29819d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Apr 2023 12:39:11 +0200 Subject: [PATCH 024/175] Update TNTSimulator.edit to better reflect interactability Signed-off-by: yoyosource --- .../features/simulator/TNTSimulator.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index f9513cd4..46d9779a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -167,7 +167,30 @@ public class TNTSimulator { if (elements.size() == 1) { TNTElementGUI.open(player, (TNTElement) elements.get(0), null); } else { - TNTSimulatorGui.open(player, null, null, () -> elements, null); + 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; } From f1925dc366ec73117bea4f032e0bd073ecc8d46a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 30 Apr 2023 14:20:37 +0200 Subject: [PATCH 025/175] =?UTF-8?q?=E2=80=9EBauSystem=5FMain/src/de/steamw?= =?UTF-8?q?ar/bausystem/features/loader/Loader.java=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/de/steamwar/bausystem/features/loader/Loader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1a64a8af..6cba6fe9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -211,7 +211,7 @@ public class Loader implements Listener { } if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) { - return; + return; } LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); From 8bc2fda2bab424d3670f75767f368dadd87dfa99 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 30 Apr 2023 14:22:59 +0200 Subject: [PATCH 026/175] =?UTF-8?q?=E2=80=9EBauSystem=5FMain/src/de/steamw?= =?UTF-8?q?ar/bausystem/features/loader/Loader.java=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/de/steamwar/bausystem/features/loader/Loader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1a64a8af..6cba6fe9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -211,7 +211,7 @@ public class Loader implements Listener { } if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) { - return; + return; } LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); From b4d63e1fe976dee36fafa66826a47e2e3fac07b3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 00:04:14 +0200 Subject: [PATCH 027/175] Add reworked Loader Signed-off-by: yoyosource --- .../features/loader/LoaderCommand.java | 2 +- .../bausystem/features/loadern/Loader.java | 130 ++++++++++++ .../features/loadern/LoaderCommand.java | 92 +++++++++ .../features/loadern/LoaderRecorder.java | 187 +++++++++++++++++ .../loadern/elements/ElementSettings.java | 31 +++ .../loadern/elements/LoaderElement.java | 29 +++ .../elements/LoaderInteractionElement.java | 116 +++++++++++ .../elements/impl/LoaderComparator.java | 135 +++++++++++++ .../elements/impl/LoaderDaylightDetector.java | 159 +++++++++++++++ .../loadern/elements/impl/LoaderLectern.java | 155 ++++++++++++++ .../loadern/elements/impl/LoaderLever.java | 132 ++++++++++++ .../elements/impl/LoaderNoteBlock.java | 115 +++++++++++ .../loadern/elements/impl/LoaderOpenable.java | 138 +++++++++++++ .../loadern/elements/impl/LoaderRepeater.java | 149 ++++++++++++++ .../loadern/elements/impl/LoaderTNT.java | 63 ++++++ .../loadern/elements/impl/LoaderTicks.java | 191 ++++++++++++++++++ .../loadern/elements/impl/LoaderWait.java | 88 ++++++++ 17 files changed, 1911 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java 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 ffea7e4f..95fa92b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -26,7 +26,7 @@ import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; -@Linked +// @Linked public class LoaderCommand extends SWCommand { public LoaderCommand() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java new file mode 100644 index 00000000..01d56d04 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.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.loadern; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.inventory.SWListInv; +import org.bukkit.Bukkit; +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.List; +import java.util.Map; + +public class Loader implements Listener { + + private static final Map LOADER_MAP = new HashMap<>(); + + public static Loader getLoader(Player player) { + return LOADER_MAP.get(player); + } + + public static void newLoader(Player player) { + LOADER_MAP.put(player, new Loader(player)); + } + + private final Player p; + + private Stage stage = Stage.SETUP; + private LoaderRecorder recorder; + + private List elements = new ArrayList<>(); + private int currentElement = 0; + + public Loader(Player p) { + this.p = p; + this.recorder = new LoaderRecorder(p, elements); + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + private void next() { + currentElement++; + if (currentElement >= elements.size()) { + currentElement = 0; + } + if (stage == Stage.RUNNING) { + elements.get(currentElement).execute(this::next); + } + } + + public void start() { + if (stage == Stage.END) return; + if (stage == Stage.RUNNING) return; + stage = Stage.RUNNING; + if (recorder != null) { + recorder.stop(); + recorder = null; + } + if (elements.isEmpty()) { + p.sendMessage("§cEs wurden keine Elemente aufgenommen!"); + stop(); + return; + } + elements.get(currentElement).execute(this::next); + } + + public void pause() { + if (stage == Stage.END) return; + if (stage == Stage.PAUSE) return; + stage = Stage.PAUSE; + if (recorder != null) { + recorder.stop(); + recorder = null; + } + } + + public void stop() { + stage = Stage.END; + if (recorder != null) { + recorder.stop(); + recorder = null; + } + elements.clear(); + LOADER_MAP.remove(p); + } + + public void settings() { + List> list = new ArrayList<>(); + for (LoaderElement element : elements) { + list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); + } + new SWListInv<>(p, "Loader Settings", false, list, (clickType, entry) -> { + entry.click(p, this::settings); + }).open(); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if (event.getPlayer() != p) return; + stop(); + } + + public enum Stage { + SETUP, + RUNNING, + PAUSE, + END + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java new file mode 100644 index 00000000..6539d16a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -0,0 +1,92 @@ +/* + * 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.loadern; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class LoaderCommand extends SWCommand { + + public LoaderCommand() { + super("loader"); + } + + private boolean loaderNullCheck(Loader loader, Player p) { + if (loader == null) { + BauSystem.MESSAGE.send("LOADER_NO_LOADER", p); + return true; + } + return false; + } + + @Register(value = "setup", description = "LOADER_HELP_SETUP") + public void setupLoader(@Validator Player player) { + if (Loader.getLoader(player) != null) { + player.sendMessage("Please stop the current loader first!"); + return; + } + Loader.newLoader(player); + BauSystem.MESSAGE.send("LOADER_NEW", player); + BauSystem.MESSAGE.send("LOADER_HOW_TO_START", player); + } + + @Register(value = "start", description = "LOADER_HELP_START") + public void startLoader(@Validator Player player) { + Loader loader = Loader.getLoader(player); + if (loaderNullCheck(loader, player)) return; + loader.start(); + BauSystem.MESSAGE.send("LOADER_ACTIVE", player); + } + + @Register(value = "stop", description = "LOADER_HELP_STOP") + public void stopLoader(@Validator Player player) { + Loader loader = Loader.getLoader(player); + if (loaderNullCheck(loader, player)) return; + loader.stop(); + BauSystem.MESSAGE.send("LOADER_STOP", player); + } + + @Register(value = "pause", description = "LOADER_HELP_PAUSE") + public void pauseLoader(@Validator Player player) { + Loader loader = Loader.getLoader(player); + if (loaderNullCheck(loader, player)) return; + loader.pause(); + BauSystem.MESSAGE.send("LOADER_PAUSED", player); + } + + @Register(value = "settings", description = "LOADER_HELP_PAUSE") + public void settingsLoader(@Validator Player player) { + Loader loader = Loader.getLoader(player); + if (loaderNullCheck(loader, player)) return; + loader.settings(); + } + + @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/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java new file mode 100644 index 00000000..4bc9f071 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -0,0 +1,187 @@ +/* + * 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.loadern; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.features.loadern.elements.impl.*; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +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.Action; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.EquipmentSlot; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class LoaderRecorder implements Listener { + + private Player player; + private List loaderElementList; + private Set blockSet = new HashSet<>(); + private long lastInteraction = TPSUtils.currentTick.get(); + + public LoaderRecorder(Player player, List loaderElementList) { + this.player = player; + this.loaderElementList = loaderElementList; + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + public void stop() { + addWaitTime(true); + HandlerList.unregisterAll(this); + player = null; + blockSet.clear(); + } + + private void addWaitTime(boolean last) { + if (loaderElementList.isEmpty()) { + lastInteraction = TPSUtils.currentTick.get(); + return; + } + if (loaderElementList.get(loaderElementList.size() - 1) instanceof LoaderWait) { + return; + } + long diff = TPSUtils.currentTick.get() - lastInteraction; + if (last && diff > 160) diff = 160; + lastInteraction = TPSUtils.currentTick.get(); + loaderElementList.add(new LoaderWait(diff)); + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) { + if (event.getPlayer() != player) return; + if (event.getBlock().getType() != Material.TNT) return; + + addWaitTime(false); + loaderElementList.add(new LoaderTNT(event.getBlock().getLocation())); + } + + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEvent event) { + if (event.getPlayer() != player) return; + if (player.isSneaking()) return; + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return; + if (event.getClickedBlock().getType() == Material.OBSERVER) return; + if (event.getHand() == EquipmentSlot.OFF_HAND) return; + + addWaitTime(false); + Block block = event.getClickedBlock(); + Material type = block.getType(); + switch (type) { + case COMPARATOR: + loaderElementList.add(new LoaderComparator(block.getLocation())); + break; + case REPEATER: + loaderElementList.add(new LoaderRepeater(block.getLocation())); + break; + case NOTE_BLOCK: + loaderElementList.add(new LoaderNoteBlock(block.getLocation())); + break; + case LEVER: + loaderElementList.add(new LoaderLever(block.getLocation())); + break; + case DAYLIGHT_DETECTOR: + loaderElementList.add(new LoaderDaylightDetector(block.getLocation())); + break; + case LECTERN: + loaderElementList.add(new LoaderLectern(block.getLocation())); + break; + case IRON_TRAPDOOR: + break; + default: + if (type.name().endsWith("_TRAPDOOR")) { + loaderElementList.add(new LoaderOpenable(block.getLocation(), "Trapdoor", type)); + } else if (type.name().endsWith("_DOOR")) { + loaderElementList.add(new LoaderOpenable(block.getLocation(), "Door", type)); + } else if (type.name().endsWith("FENCE_GATE")) { + loaderElementList.add(new LoaderOpenable(block.getLocation(), "Fencegate", type)); + } else if (type.name().endsWith("STONE_BUTTON")) { + loaderElementList.add(new LoaderTicks(block.getLocation(), "Stone Button", type, 20)); + } else if (type.name().endsWith("BUTTON")) { + loaderElementList.add(new LoaderTicks(block.getLocation(), "Wooden Button", type, 30)); + } + break; + } + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + if (event.getPlayer() != player) return; + + Block fromBlock = event.getTo().getBlock(); + Block toBlock = event.getTo().getBlock(); + if (!blockSet.contains(toBlock.getLocation())) { + blockSet.remove(fromBlock.getLocation()); + blockSet.add(toBlock.getLocation()); + + addWaitTime(false); + Material type = toBlock.getType(); + switch (type) { + case TRIPWIRE: + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Tripwire", Material.STRING, 30)); + break; + case LIGHT_WEIGHTED_PRESSURE_PLATE: + case HEAVY_WEIGHTED_PRESSURE_PLATE: + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Weighted Pressure Plate", type, 20)); + break; + default: + if (type.name().endsWith("PRESSURE_PLATE")) { + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Pressure Plate", type, 30)); + } + break; + } + } + + fromBlock = fromBlock.getRelative(0, 1, 0); + toBlock = toBlock.getRelative(0, 1, 0); + if (!blockSet.contains(toBlock.getLocation())) { + blockSet.remove(fromBlock.getLocation()); + blockSet.add(toBlock.getLocation()); + + addWaitTime(false); + Material type = toBlock.getType(); + switch (type) { + case TRIPWIRE: + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Tripwire", Material.STRING, 30)); + break; + case LIGHT_WEIGHTED_PRESSURE_PLATE: + case HEAVY_WEIGHTED_PRESSURE_PLATE: + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Weighted Pressure Plate", type, 20)); + break; + default: + if (type.name().endsWith("PRESSURE_PLATE")) { + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Pressure Plate", type, 30)); + } + break; + } + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java new file mode 100644 index 00000000..5142e8cf --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.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.loadern.elements; + +import de.steamwar.inventory.SWItem; +import org.bukkit.entity.Player; + +public interface ElementSettings { + SWItem menu(Player player); + void execute(Runnable nextAction); + void click(Player player, Runnable backAction, Runnable deleteAction); + + default void playerInteract() {} +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java new file mode 100644 index 00000000..4b1734bd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java @@ -0,0 +1,29 @@ +/* + * 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.loadern.elements; + +import de.steamwar.inventory.SWItem; +import org.bukkit.entity.Player; + +public interface LoaderElement { + SWItem menu(Player player); + void execute(Runnable nextAction); + void click(Player player, Runnable backAction); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java new file mode 100644 index 00000000..7785f07b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -0,0 +1,116 @@ +/* + * 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.loadern.elements; + +import de.steamwar.bausystem.features.loader.LoaderButton; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.FaceAttachable; +import org.bukkit.block.data.type.Switch; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public abstract class LoaderInteractionElement implements LoaderElement { + + protected final Location location; + protected int currentShot = 0; + protected List elements = new ArrayList<>(); + + protected LoaderInteractionElement(Location location) { + this.location = location; + + T element = createNewElement(); + element.playerInteract(); + elements.add(element); + } + + @Override + public void execute(Runnable nextAction) { + if (currentShot >= elements.size()) currentShot = 0; + elements.get(currentShot).execute(nextAction); + currentShot++; + if (currentShot >= elements.size()) currentShot = 0; + } + + @Override + public void click(Player player, Runnable backAction) { + List> entries = new ArrayList<>(); + for (T element : elements) { + entries.add(new SWListInv.SWListEntry<>(element.menu(player), element)); + } + + SWListInv listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> { + entry.click(player, () -> { + click(player, backAction); + }, () -> { + if (elements.size() == 1) return; + elements.remove(entry); + click(player, backAction); + }); + }); + listInv.setItem(48, new SWItem(Material.ARROW, "§7Back", clickType -> { + backAction.run(); + })); + listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another", clickType -> { + T element = createNewElement(); + elements.add(element); + element.click(player, () -> click(player, backAction), () -> { + if (elements.size() == 1) return; + elements.remove(element); + click(player, backAction); + }); + })); + listInv.open(); + } + + protected void update(Block block) { + Material material = block.getType(); + if (block.getBlockData() instanceof Switch) { + Switch sw = (Switch) block.getBlockData(); + FaceAttachable.AttachedFace face = sw.getAttachedFace(); + if (face == FaceAttachable.AttachedFace.FLOOR) { + updateBlock(block.getRelative(BlockFace.DOWN)); + } else if (face == FaceAttachable.AttachedFace.CEILING) { + updateBlock(block.getRelative(BlockFace.UP)); + } else { + updateBlock(block.getRelative(sw.getFacing().getOppositeFace())); + } + } else if (material == Material.TRIPWIRE) { + updateBlock(block); + } else if (material.name().endsWith("_PLATE")) { + updateBlock(block.getRelative(BlockFace.DOWN)); + } + } + + protected void updateBlock(Block block) { + BlockData data = block.getBlockData(); + block.setType(Material.BARRIER, true); + block.setBlockData(data, true); + } + + public abstract T createNewElement(); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java new file mode 100644 index 00000000..d92ea4ad --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java @@ -0,0 +1,135 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.Comparator; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderComparator extends LoaderInteractionElement { + + public LoaderComparator(Location location) { + super(location); + } + + public class ComparatorSettings implements ElementSettings { + + private boolean interact = false; + private Comparator.Mode mode = Comparator.Mode.COMPARE; + + @Override + public SWItem menu(Player player) { + return menu(player, interact, mode); + } + + private SWItem menu(Player player, boolean interact, Comparator.Mode mode) { + SWItem swItem; + if (interact) { + swItem = new SWItem(Material.STICK, "§7Comparator§8: §eInteract"); + } else if (mode == null) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Comparator§8: §eNOOP"); + } else { + swItem = new SWItem(Material.COMPARATOR, "§7Comparator§8: §e" + mode.name()); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.COMPARATOR) return; + Comparator comparator = (Comparator) location.getBlock().getBlockData(); + if (interact) { + comparator.setMode(comparator.getMode() == Comparator.Mode.COMPARE ? Comparator.Mode.SUBTRACT : Comparator.Mode.COMPARE); + } else if (mode == null) { + return; + } else { + comparator.setMode(mode); + } + location.getBlock().setBlockData(comparator, true); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(2, item(player, true, null).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(3, item(player, false, null).getItemStack(), clickType -> { + interact = false; + mode = null; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, Comparator.Mode.COMPARE).getItemStack(), clickType -> { + interact = false; + mode = Comparator.Mode.COMPARE; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, Comparator.Mode.SUBTRACT).getItemStack(), clickType -> { + interact = false; + mode = Comparator.Mode.SUBTRACT; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean interact, Comparator.Mode mode) { + SWItem swItem = menu(player, interact, mode); + if (swItem.getItemStack().equals(menu(player, this.interact, this.mode).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + @Override + public void playerInteract() { + interact = true; + mode = null; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.COMPARATOR, "§7Comparator"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public ComparatorSettings createNewElement() { + return new ComparatorSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java new file mode 100644 index 00000000..cbdcc7dc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -0,0 +1,159 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.DaylightDetector; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderDaylightDetector extends LoaderInteractionElement { + + public LoaderDaylightDetector(Location location) { + super(location); + } + + public class DaylightDetectorSettings implements ElementSettings { + + private boolean noop = false; + private boolean interact = false; + private boolean inverted = true; + private int power = 0; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, interact, inverted); + } + + private SWItem menu(Player player, boolean noop, boolean interact, boolean powered) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Daylight Detector§8: §eNOOP"); + } else if (interact) { + swItem = new SWItem(Material.STICK, "§7Daylight Detector§8: §eInteract"); + } else { + swItem = new SWItem(Material.DAYLIGHT_DETECTOR, "§7Daylight Detector§8: §e" + (powered ? "Powered" : "Unpowered")); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.DAYLIGHT_DETECTOR) return; + DaylightDetector daylightDetector = (DaylightDetector) location.getBlock().getBlockData(); + if (noop) { + return; + } else if (interact) { + daylightDetector.setInverted(!daylightDetector.isInverted()); + } else { + daylightDetector.setInverted(inverted); + } + daylightDetector.setPower(daylightDetector.isInverted() ? 15 - power : power); + location.getBlock().setBlockData(daylightDetector); + update(location.getBlock().getRelative(0, -1, 0)); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 36, "Settings"); + for (int i = 27; i < 35; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(27, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> { + noop = false; + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> { + noop = false; + interact = false; + inverted = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> { + noop = false; + interact = false; + inverted = true; + click(player, backAction, deleteAction); + }); + + for (int i = 0; i < 16; i++) { + int finalI = i; + int finalI2 = i; + if (i >= 9) finalI2++; + swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> { + power = finalI; + click(player, backAction, deleteAction); + }); + } + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean interact, boolean inverted) { + SWItem swItem = menu(player, noop, interact, inverted); + if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.inverted).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + private SWItem item(Player player, int power) { + SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, "§7Power §8:§e " + power); + swItem.getItemStack().setAmount(power == 0 ? 1 : power); + if (!this.noop && this.power == power) swItem.setEnchanted(true); + return swItem; + } + + @Override + public void playerInteract() { + noop = false; + interact = true; + inverted = false; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.DAYLIGHT_DETECTOR, "§7Daylight Detector"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public DaylightDetectorSettings createNewElement() { + return new DaylightDetectorSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java new file mode 100644 index 00000000..033d936a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java @@ -0,0 +1,155 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Lectern; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.BookMeta; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderLectern extends LoaderInteractionElement { + + + public LoaderLectern(Location location) { + super(location); + } + + public class LecternSettings implements ElementSettings { + + private boolean noop = true; + private LecternAction action = LecternAction.PAGE_NEXT; + private int page = 0; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, action, page); + } + + private SWItem menu(Player player, boolean noop, LecternAction action, int page) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Lectern§8: §eNOOP"); + } else if (action == LecternAction.PAGE_PREV) { + swItem = new SWItem(Material.STICK, "§7Lectern§8: §ePage Prev"); + } else if (action == LecternAction.PAGE_NEXT) { + swItem = new SWItem(Material.STICK, "§7Lectern§8: §ePage Next"); + } else { + swItem = new SWItem(Material.LECTERN, "§7Lectern§8: §ePage " + page); + swItem.getItemStack().setAmount(page); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.LECTERN) return; + Lectern lectern = (Lectern) location.getBlock().getState(); + if (!((org.bukkit.block.data.type.Lectern) lectern.getBlockData()).hasBook()) return; + int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size(); + if (noop) { + return; + } else if (action == LecternAction.PAGE_PREV) { + int page = lectern.getPage(); + if (page > 1) lectern.setPage(page - 1); + } else if (action == LecternAction.PAGE_NEXT) { + int page = lectern.getPage(); + if (page < pages) lectern.setPage(page + 1); + } else if (action == LecternAction.PAGE_SET) { + if (page <= pages) lectern.setPage(page); + } + lectern.update(false, true); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 36, "Settings"); + for (int i = 27; i < 35; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(27, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(3, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, LecternAction.PAGE_PREV, 0).getItemStack(), clickType -> { + noop = false; + action = LecternAction.PAGE_PREV; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, LecternAction.PAGE_NEXT, 0).getItemStack(), clickType -> { + noop = false; + action = LecternAction.PAGE_NEXT; + click(player, backAction, deleteAction); + }); + + for (int i = 0; i < 15; i++) { + int finalI = i; + int finalI2 = i; + if (i >= 9) finalI2++; + if (i >= 12) finalI2++; + swInventory.setItem(finalI2 + 9, item(player, false, LecternAction.PAGE_SET, finalI + 1).getItemStack(), clickType -> { + noop = false; + action = LecternAction.PAGE_SET; + page = finalI + 1; + click(player, backAction, deleteAction); + }); + } + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, LecternAction action, int page) { + SWItem swItem = menu(player, noop, action, page); + if (swItem.getItemStack().equals(menu(player, this.noop, this.action, this.page).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + } + + public enum LecternAction { + PAGE_NEXT, + PAGE_PREV, + PAGE_SET + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.LECTERN, "§7Lectern"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public LecternSettings createNewElement() { + return new LecternSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java new file mode 100644 index 00000000..8bd0d7b0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java @@ -0,0 +1,132 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.Switch; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderLever extends LoaderInteractionElement { + + public LoaderLever(Location location) { + super(location); + } + + public class LeverSettings implements ElementSettings { + + private boolean noop = false; + private boolean interact = false; + private boolean power = false; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, interact, power); + } + + private SWItem menu(Player player, boolean noop, boolean interact, boolean power) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Lever§8: §eNOOP"); + } else if (interact) { + swItem = new SWItem(Material.STICK, "§7Lever§8: §eInteract"); + } else { + swItem = new SWItem(Material.LEVER, "§7Lever§8: §e" + (power ? "Active" : "Inactive")); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.LEVER) return; + if (noop) return; + + Switch lever = (Switch) location.getBlock().getBlockData(); + if (interact) { + lever.setPowered(!lever.isPowered()); + } else { + lever.setPowered(power); + } + location.getBlock().setBlockData(lever); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> { + noop = false; + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> { + noop = false; + interact = false; + power = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> { + noop = false; + interact = false; + power = true; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean interact, boolean power) { + SWItem swItem = menu(player, noop, interact, power); + if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.power).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.LEVER, "§7Lever"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public LeverSettings createNewElement() { + return new LeverSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java new file mode 100644 index 00000000..5f062f87 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java @@ -0,0 +1,115 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Instrument; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.NoteBlock; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderNoteBlock extends LoaderInteractionElement { + + public LoaderNoteBlock(Location location) { + super(location); + } + + public class NoteBlockSettings implements ElementSettings { + + private boolean interact = true; + + @Override + public SWItem menu(Player player) { + return menu(player, interact); + } + + private SWItem menu(Player player, boolean interact) { + SWItem swItem; + if (interact) { + swItem = new SWItem(Material.NOTE_BLOCK, "§7Note Block§8: §eInteract"); + } else { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Note Block§8: §eNOOP"); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.NOTE_BLOCK) return; + NoteBlock noteBlock = (NoteBlock) location.getBlock().getBlockData(); + if (interact) { + if (noteBlock.getInstrument() == Instrument.BANJO) noteBlock.setInstrument(Instrument.BIT); + else noteBlock.setInstrument(Instrument.BANJO); + } else { + return; + } + location.getBlock().setBlockData(noteBlock); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(3, item(player, false).getItemStack(), clickType -> { + interact = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, true).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean interact) { + SWItem swItem = menu(player, interact); + if (swItem.getItemStack().equals(menu(player, this.interact).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.NOTE_BLOCK, "§7Note Block"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public NoteBlockSettings createNewElement() { + return new NoteBlockSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java new file mode 100644 index 00000000..1fc45d69 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java @@ -0,0 +1,138 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.Openable; +import org.bukkit.block.data.type.TrapDoor; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderOpenable extends LoaderInteractionElement { + + private String name; + private Material material; + + public LoaderOpenable(Location location, String name, Material material) { + super(location); + this.name = name; + this.material = material; + } + + public class TrapdoorSettings implements ElementSettings { + + private boolean noop = false; + private boolean interact = true; + private boolean open = false; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, interact, open); + } + + private SWItem menu(Player player, boolean noop, boolean interact, boolean powered) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7" + name +"§8: §eNOOP"); + } else if (interact) { + swItem = new SWItem(Material.STICK, "§7" + name + "§8: §eInteract"); + } else { + swItem = new SWItem(material, "§7" + name + "§8: §e" + (powered ? "Open" : "Closed")); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != material) return; + Openable openable = (Openable) location.getBlock().getBlockData(); + if (noop) { + return; + } else if (interact) { + openable.setOpen(!openable.isOpen()); + } else { + openable.setOpen(open); + } + location.getBlock().setBlockData(openable); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> { + noop = false; + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> { + noop = false; + interact = false; + open = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> { + noop = false; + interact = false; + open = true; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean interact, boolean open) { + SWItem swItem = menu(player, noop, interact, open); + if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.open).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(material, "§7" + name); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public TrapdoorSettings createNewElement() { + return new TrapdoorSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java new file mode 100644 index 00000000..a0e50e48 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java @@ -0,0 +1,149 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.Repeater; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderRepeater extends LoaderInteractionElement { + + public LoaderRepeater(Location location) { + super(location); + } + + public class RepeaterSettings implements ElementSettings { + + private boolean interact = false; + private int delay = 1; + + @Override + public SWItem menu(Player player) { + return menu(player, interact, delay); + } + + private SWItem menu(Player player, boolean interact, int delay) { + SWItem swItem; + if (interact) { + swItem = new SWItem(Material.STICK, "§7Repeater§8: §eInteract"); + } else if (delay == 0) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Repeater§8: §eNOOP"); + } else { + swItem = new SWItem(Material.REPEATER, "§7Repeater§8: §e" + delay); + swItem.getItemStack().setAmount(delay); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.REPEATER) return; + Repeater repeater = (Repeater) location.getBlock().getBlockData(); + if (interact) { + int delay = repeater.getDelay(); + delay++; + if (delay > 4) delay = 1; + repeater.setDelay(delay); + } else if (delay == 0) { + return; + } else { + repeater.setDelay(delay); + } + location.getBlock().setBlockData(repeater, true); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(1, item(player, true, -1).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(2, item(player, false, 0).getItemStack(), clickType -> { + interact = false; + delay = 0; + click(player, backAction, deleteAction); + }); + swInventory.setItem(4, item(player, false, 1).getItemStack(), clickType -> { + interact = false; + delay = 1; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, 2).getItemStack(), clickType -> { + interact = false; + delay = 2; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, 3).getItemStack(), clickType -> { + interact = false; + delay = 3; + click(player, backAction, deleteAction); + }); + swInventory.setItem(7, item(player, false, 4).getItemStack(), clickType -> { + interact = false; + delay = 4; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean interact, int delay) { + SWItem swItem = menu(player, interact, delay); + if (swItem.getItemStack().equals(menu(player, this.interact, this.delay).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + @Override + public void playerInteract() { + interact = true; + delay = 0; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.REPEATER, "§7Repeater"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public RepeaterSettings createNewElement() { + return new RepeaterSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java new file mode 100644 index 00000000..92c2bd4e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java @@ -0,0 +1,63 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.Arrays; + +public class LoaderTNT implements LoaderElement { + + private Location location; + + public LoaderTNT(Location location) { + this.location = location; + } + + @Override + public SWItem menu(Player player) { + SWItem item = new SWItem(Material.TNT, "§cTNT"); + item.setLore(Arrays.asList("§7X§8: " + location.getBlockX(), "§7Y§8: " + location.getBlockY(), "§7Z§8: " + location.getBlockZ())); + return item; + } + + @Override + public void execute(Runnable nextAction) { + Block block = location.getBlock(); + if (block.getType() != Material.AIR && block.getType() != Material.WATER) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1); + return; + } + + block.setType(Material.TNT, true); + nextAction.run(); + } + + @Override + public void click(Player player, Runnable backAction) { + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java new file mode 100644 index 00000000..54e63d34 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -0,0 +1,191 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.AnaloguePowerable; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Powerable; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderTicks extends LoaderInteractionElement { + + protected String name; + protected Material material; + protected boolean analogue; + protected int ticks; + + public LoaderTicks(Location location, String name, Material material, int ticks) { + super(location); + this.name = name; + this.material = material; + this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable; + this.ticks = ticks; + } + + public class StoneButtonSettings implements ElementSettings { + + private boolean noop = false; + private boolean waitFor = true; + private int power = 0; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, waitFor); + } + + private SWItem menu(Player player, boolean noop, boolean waitFor) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7" + name + "§8: §eNOOP"); + } else if (waitFor) { + swItem = new SWItem(material, "§7" + name + "§8: §eWaitFor"); + } else { + swItem = new SWItem(material, "§7" + name + "§8: §eNoWaitFor"); + swItem.setEnchanted(true); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + if (location.getBlock().getType() != material) { + nextAction.run(); + return; + } + if (noop) { + nextAction.run(); + return; + } + + BlockData blockData = location.getBlock().getBlockData(); + if (blockData instanceof AnaloguePowerable) { + AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData(); + analoguePowerable.setPower(power); + } else if (blockData instanceof Powerable) { + Powerable powerable = (Powerable) location.getBlock().getBlockData(); + if (ticks < 0) { + powerable.setPowered(power > 0); + } else { + powerable.setPowered(true); + } + } + + location.getBlock().setBlockData(blockData); + update(location.getBlock()); + if (ticks >= 0) { + boolean finalWaitFor = waitFor; + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (blockData instanceof AnaloguePowerable) { + ((AnaloguePowerable) blockData).setPower(0); + } else { + ((Powerable) blockData).setPowered(false); + } + location.getBlock().setBlockData(blockData); + update(location.getBlock()); + if (finalWaitFor) { + nextAction.run(); + } + }, ticks); + if (!finalWaitFor) { + nextAction.run(); + } + } + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, analogue ? 36 : 18, "Settings"); + for (int i = analogue ? 27 : 9; i < (analogue ? 35 : 18); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(analogue ? 27 : 9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(analogue ? 35 : 17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(3, item(player, true, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + if (ticks >= 0) { + swInventory.setItem(5, item(player, false, false).getItemStack(), clickType -> { + noop = false; + waitFor = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, true).getItemStack(), clickType -> { + noop = false; + waitFor = true; + click(player, backAction, deleteAction); + }); + } + + if (analogue) { + for (int i = 0; i < 16; i++) { + int finalI = i; + int finalI2 = i; + if (i >= 9) finalI2++; + swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> { + power = finalI; + click(player, backAction, deleteAction); + }); + } + } + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean waitFor) { + SWItem swItem = menu(player, noop, waitFor); + if (swItem.getItemStack().equals(menu(player, this.noop, this.waitFor).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + private SWItem item(Player player, int power) { + SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, "§7Power §8:§e " + power); + swItem.getItemStack().setAmount(power == 0 ? 1 : power); + if (!this.noop && this.power == power) swItem.setEnchanted(true); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(material, "§7" + name); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public StoneButtonSettings createNewElement() { + return new StoneButtonSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java new file mode 100644 index 00000000..5b263af9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -0,0 +1,88 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.inventory.SWAnvilInv; +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.event.Listener; + +import java.util.Arrays; + +public class LoaderWait implements LoaderElement, Listener { + + private long delay; + + public LoaderWait(long delay) { + this.delay = delay; + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.CLOCK, "§7Wartezeit: §e" + delay + " Ticks"); + swItem.getItemStack().setAmount((int) Math.max(Math.min(delay, 64), 1)); + if (delay == 0) swItem.setEnchanted(true); + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + if (delay == 0) { + nextAction.run(); + return; + } + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), nextAction, delay); + } + + @Override + public void click(Player player, Runnable backAction) { + SWInventory swInventory = new SWInventory(player, 9, "Wartezeit"); + swInventory.setItem(0, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + + swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { + delay -= clickType.isShiftClick() ? 5 : 1; + if (delay < 0) delay = 0; + swInventory.setItem(4, menu(player)); + }); + swInventory.setItem(4, menu(player).getItemStack(), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "§7Wartezeit", delay + ""); + swAnvilInv.setCallback(s -> { + try { + delay = Long.parseLong(s); + } catch (NumberFormatException ignored) { + } + click(player, backAction); + }); + swAnvilInv.open(); + }); + swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§a+1").getItemStack(), clickType -> { + delay += clickType.isShiftClick() ? 5 : 1; + swInventory.setItem(4, menu(player)); + }); + + swInventory.open(); + } +} From e997243887d38b929a0f0f2d002637f7a3e7bec8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 12:20:24 +0200 Subject: [PATCH 028/175] Update LoaderRecorder Signed-off-by: yoyosource --- .../features/loadern/LoaderRecorder.java | 56 ++--- .../loadern/elements/impl/LoaderMovement.java | 226 ++++++++++++++++++ .../loadern/elements/impl/LoaderTicks.java | 16 +- .../loadern/elements/impl/LoaderWait.java | 1 + 4 files changed, 261 insertions(+), 38 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java index 4bc9f071..329cfd55 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -37,15 +37,14 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.EquipmentSlot; -import java.util.HashSet; +import java.util.HashMap; import java.util.List; -import java.util.Set; +import java.util.Map; public class LoaderRecorder implements Listener { private Player player; private List loaderElementList; - private Set blockSet = new HashSet<>(); private long lastInteraction = TPSUtils.currentTick.get(); public LoaderRecorder(Player player, List loaderElementList) { @@ -132,56 +131,53 @@ public class LoaderRecorder implements Listener { } } + private Map blockSet = new HashMap<>(); + private Map movementSet = new HashMap<>(); + @EventHandler public void onPlayerMove(PlayerMoveEvent event) { if (event.getPlayer() != player) return; Block fromBlock = event.getTo().getBlock(); Block toBlock = event.getTo().getBlock(); - if (!blockSet.contains(toBlock.getLocation())) { - blockSet.remove(fromBlock.getLocation()); - blockSet.add(toBlock.getLocation()); - - addWaitTime(false); - Material type = toBlock.getType(); - switch (type) { - case TRIPWIRE: - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Tripwire", Material.STRING, 30)); - break; - case LIGHT_WEIGHTED_PRESSURE_PLATE: - case HEAVY_WEIGHTED_PRESSURE_PLATE: - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Weighted Pressure Plate", type, 20)); - break; - default: - if (type.name().endsWith("PRESSURE_PLATE")) { - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Pressure Plate", type, 30)); - } - break; - } - } + calcMovementBlocks(fromBlock, toBlock); fromBlock = fromBlock.getRelative(0, 1, 0); toBlock = toBlock.getRelative(0, 1, 0); - if (!blockSet.contains(toBlock.getLocation())) { - blockSet.remove(fromBlock.getLocation()); - blockSet.add(toBlock.getLocation()); + calcMovementBlocks(fromBlock, toBlock); + } + + private void calcMovementBlocks(Block fromBlock, Block toBlock) { + if (!blockSet.containsKey(toBlock.getLocation())) { + Long startTime = blockSet.remove(fromBlock.getLocation()); + LoaderMovement loaderMovement = movementSet.remove(fromBlock.getLocation()); + if (loaderMovement != null && startTime != null) { + loaderMovement.setInitialTicks(TPSUtils.currentTick.get() - startTime); + } + + blockSet.put(toBlock.getLocation(), TPSUtils.currentTick.get()); addWaitTime(false); + loaderMovement = null; Material type = toBlock.getType(); switch (type) { case TRIPWIRE: - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Tripwire", Material.STRING, 30)); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "Tripwire", Material.STRING); break; case LIGHT_WEIGHTED_PRESSURE_PLATE: case HEAVY_WEIGHTED_PRESSURE_PLATE: - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Weighted Pressure Plate", type, 20)); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "Weighted Pressure Plate", type); break; default: if (type.name().endsWith("PRESSURE_PLATE")) { - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Pressure Plate", type, 30)); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "Pressure Plate", type); } break; } + if (loaderMovement != null) { + movementSet.put(toBlock.getLocation(), loaderMovement); + loaderElementList.add(loaderMovement); + } } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java new file mode 100644 index 00000000..ee1f11ac --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -0,0 +1,226 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.AnaloguePowerable; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Powerable; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderMovement extends LoaderInteractionElement { + + private String name; + private Material material; + private boolean analogue; + + public LoaderMovement(Location location, String name, Material material) { + super(location); + this.name = name; + this.material = material; + this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable; + } + + public void setInitialTicks(long ticks) { + elements.get(currentShot).ticks = ticks; + } + + public class MovementSettings implements ElementSettings { + + private boolean noop = false; + private boolean waitFor = true; + private int power = 0; + private long ticks = 1; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, waitFor); + } + + private SWItem menu(Player player, boolean noop, boolean waitFor) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7" + name + "§8: §eNOOP"); + } else if (waitFor) { + swItem = new SWItem(material, "§7" + name + "§8: §eWaitFor"); + swItem.getItemStack().setAmount((int) Math.min(ticks, 64)); + } else { + swItem = new SWItem(material, "§7" + name + "§8: §eNoWaitFor"); + swItem.getItemStack().setAmount((int) Math.min(ticks, 64)); + swItem.setEnchanted(true); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + if (location.getBlock().getType() != material) { + nextAction.run(); + return; + } + if (noop) { + nextAction.run(); + return; + } + + BlockData blockData = location.getBlock().getBlockData(); + if (blockData instanceof AnaloguePowerable) { + AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData(); + analoguePowerable.setPower(power); + } else if (blockData instanceof Powerable) { + Powerable powerable = (Powerable) location.getBlock().getBlockData(); + if (ticks < 0) { + powerable.setPowered(power > 0); + } else { + powerable.setPowered(true); + } + } + + location.getBlock().setBlockData(blockData); + update(location.getBlock()); + if (ticks >= 0) { + boolean finalWaitFor = waitFor; + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (blockData instanceof AnaloguePowerable) { + ((AnaloguePowerable) blockData).setPower(0); + } else { + ((Powerable) blockData).setPowered(false); + } + location.getBlock().setBlockData(blockData); + update(location.getBlock()); + if (finalWaitFor) { + nextAction.run(); + } + }, ticks); + if (!finalWaitFor) { + nextAction.run(); + } + } + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, analogue ? 45 : 27, "Settings"); + for (int i = analogue ? 36 : 18; i < (analogue ? 44 : 26); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(analogue ? 36 : 18, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(3, item(player, true, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + if (ticks >= 0) { + swInventory.setItem(5, item(player, false, false).getItemStack(), clickType -> { + noop = false; + waitFor = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, true).getItemStack(), clickType -> { + noop = false; + waitFor = true; + click(player, backAction, deleteAction); + }); + } + + swInventory.setItem(12, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { + ticks -= clickType.isShiftClick() ? 5 : 1; + if (ticks < 1) ticks = 1; + swInventory.setItem(13, item(player)); + }); + swInventory.setItem(13, item(player).getItemStack(), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Ticks", ticks + ""); + swAnvilInv.setCallback(s -> { + try { + ticks = Long.parseLong(s); + if (ticks < 1) ticks = 1; + } catch (NumberFormatException ignored) { + } + click(player, backAction, deleteAction); + }); + swAnvilInv.open(); + }); + swInventory.setItem(14, new SWItem(SWItem.getDye(10), "§a+1").getItemStack(), clickType -> { + ticks += clickType.isShiftClick() ? 5 : 1; + swInventory.setItem(13, item(player)); + }); + + if (analogue) { + for (int i = 0; i < 16; i++) { + int finalI = i; + int finalI2 = i; + if (i >= 9) finalI2++; + swInventory.setItem(finalI2 + 18, item(player, finalI).getItemStack(), clickType -> { + power = finalI; + click(player, backAction, deleteAction); + }); + } + } + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean waitFor) { + SWItem swItem = menu(player, noop, waitFor); + if (swItem.getItemStack().equals(menu(player, this.noop, this.waitFor).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + private SWItem item(Player player, int power) { + SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, "§7Power §8:§e " + power); + swItem.getItemStack().setAmount(power == 0 ? 1 : power); + if (!this.noop && this.power == power) swItem.setEnchanted(true); + return swItem; + } + + private SWItem item(Player player) { + SWItem swItem = new SWItem(Material.CLOCK, "§7Ticks§8: §e" + ticks); + swItem.getItemStack().setAmount((int) Math.min(ticks, 64)); + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(material, "§7" + name); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public MovementSettings createNewElement() { + return new MovementSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 54e63d34..8e203d7d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -35,12 +35,12 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; -public class LoaderTicks extends LoaderInteractionElement { +public class LoaderTicks extends LoaderInteractionElement { - protected String name; - protected Material material; - protected boolean analogue; - protected int ticks; + private String name; + private Material material; + private boolean analogue; + private int ticks; public LoaderTicks(Location location, String name, Material material, int ticks) { super(location); @@ -50,7 +50,7 @@ public class LoaderTicks extends LoaderInteractionElement { try { delay = Long.parseLong(s); + if (delay < 0) delay = 0; } catch (NumberFormatException ignored) { } click(player, backAction); From c320f92ea31017f0ffb9ae3f8ce3c427c7c7b336 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 12:34:22 +0200 Subject: [PATCH 029/175] Update BauScoreboard design Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 7 +++---- BauSystem_Main/src/BauSystem_de.properties | 6 ++++-- .../features/tracer/record/Recorder.java | 4 ++-- .../bausystem/features/world/BauScoreboard.java | 15 +++++++++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 82d131d2..320cd623 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -37,8 +37,8 @@ SCOREBOARD_TPS_FROZEN = §e Frozen SCOREBOARD_TRACE_TICKS = Ticks -SCOREBOARD_TECHHIDER = TechHider -SCOREBOARD_XRAY = XRay +SCOREBOARD_TECHHIDER = TechHider§8: §aOn +SCOREBOARD_XRAY = XRay§8: §aOn # Flags FLAG_COLOR = Color @@ -731,7 +731,7 @@ TPSLIMIT_INVALID_FROZEN = §c and '0' # Trace TRACE_RECORD=§aon -TRACE_IDLE=§coff +TRACE_HAS_TRACES=§ehas Traces TRACE_IDLE_SINGLE=§esingle TRACE_IDLE_AUTO_EXPLODE=§eauto §8(§7explode§8) TRACE_IDLE_AUTO_IGNITE=§eauto §8(§7ignite§8) @@ -787,7 +787,6 @@ TRACE_GUI_POSITION_SOURCE = §7Source§8: §e{0} TRACE_GUI_POSITION_EXPLODED = §7Exploded§8: §e{0} # Loader -LOADER_OFF = §coff LOADER_SETUP = §eSetup LOADER_RUNNING = §aRunning LOADER_SINGLE_SIDEBAR = §aSingle diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index ed657b0d..a4eae658 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -37,6 +37,9 @@ SCOREBOARD_TPS_FROZEN = §e Eingefroren SCOREBOARD_TRACE_TICKS = Ticks +SCOREBOARD_TECHHIDER = TechHider§8: §aAn +SCOREBOARD_XRAY = XRay§8: §aAn + # Flags FLAG_COLOR = Color FLAG_TNT = TNT @@ -701,7 +704,7 @@ TPSLIMIT_INVALID_FROZEN = §c und '0' # Trace TRACE_RECORD=§aan -TRACE_IDLE=§caus +TRACE_HAS_TRACES=§ehat Traces TRACE_IDLE_SINGLE=§esingle TRACE_IDLE_AUTO_EXPLODE=§eauto §8(§7explode§8) TRACE_IDLE_AUTO_IGNITE=§eauto §8(§7ignite§8) @@ -757,7 +760,6 @@ TRACE_GUI_POSITION_SOURCE = §7Ursprung§8: §e{0} TRACE_GUI_POSITION_EXPLODED = §7Explodiert§8: §e{0} # Loader -LOADER_OFF = §caus LOADER_SETUP = §eEinrichtung LOADER_RUNNING = §aLaufend LOADER_SINGLE_SIDEBAR = §aEiner 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 5d580005..85d2ef2a 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 @@ -49,7 +49,7 @@ public class Recorder implements Listener { INSTANCE = this; } - private static class NoopTraceRecorder implements TraceRecorder { + public static class NoopTraceRecorder implements TraceRecorder { @Override public String scoreboard(Player player) { return null; @@ -82,7 +82,7 @@ public class Recorder implements Listener { private static class DisabledTracerRecorder implements TraceRecorder { @Override public String scoreboard(Player player) { - return BauSystem.MESSAGE.parse("TRACE_IDLE", player); + return null; } @Override 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 2d170bda..eaebc5ed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -8,6 +8,7 @@ import de.steamwar.bausystem.features.tpslimit.FreezeUtils; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.show.StoredRecords; import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; @@ -17,7 +18,6 @@ import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; -import de.steamwar.techhider.TechHider; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -89,22 +89,29 @@ public class BauScoreboard implements Listener { } strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode)); } + strings.add("§3"); + if (TechHiderCommand.isHidden(region, p)) { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p)); } else if (XrayCommand.isHidden(region, p)) { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p)); } - strings.add("§3"); String traceScore = recorder.get(region).scoreboard(p); if (traceScore != null) { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore); + } else if (!(recorder.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p)); } Loader loader = Loader.getLoader(p); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader != null ? loader.getStage().getChatValue() : "LOADER_OFF", p)); + if (loader != null) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p)); + } - strings.add("§5"); + if (!strings.get(strings.size() - 1).equals("§3")) { + strings.add("§5"); + } if (FreezeUtils.frozen()) { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); } else { From 043b3860a0a350066dcdc450289894876bc30a97 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 14:30:29 +0200 Subject: [PATCH 030/175] Add better Scoreboard building Signed-off-by: yoyosource --- .../types/ScoreboardElement_GENERIC.java | 40 +++++ .../loader/LoaderScoreboardElement.java | 47 ++++++ .../features/region/FireListener.java | 20 ++- .../features/region/FreezeListener.java | 20 ++- .../features/region/ProtectListener.java | 21 ++- .../region/RegionScoreboardElement.java | 47 ++++++ .../features/region/TNTListener.java | 20 ++- .../features/techhider/TechHiderCommand.java | 29 ++-- .../tpslimit/TPSScoreboardElement.java | 68 ++++++++ .../tracer/TraceScoreboardElement.java | 53 ++++++ .../features/world/BauScoreboard.java | 153 +++++------------- .../bausystem/features/xray/XrayCommand.java | 29 ++-- .../steamwar/bausystem/region/flags/Flag.java | 16 +- .../bausystem/utils/ScoreboardElement.java | 37 +++++ .../utils/TimeScoreboardElement.java | 47 ++++++ 15 files changed, 498 insertions(+), 149 deletions(-) create mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.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 new file mode 100644 index 00000000..01e29833 --- /dev/null +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java @@ -0,0 +1,40 @@ +/* + * 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.linkage.types; + +import de.steamwar.linkage.LinkageType; +import de.steamwar.linkage.plan.BuildPlan; +import de.steamwar.linkage.plan.MethodBuilder; + +import javax.lang.model.element.TypeElement; + +public class ScoreboardElement_GENERIC implements LinkageType { + + @Override + public String method() { + return "link"; + } + + @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 + ");"); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java new file mode 100644 index 00000000..847ed59b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * 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.loader; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class LoaderScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + Loader loader = Loader.getLoader(p); + if (loader == null) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java index 43aaf626..56fd3232 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java @@ -1,16 +1,19 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockSpreadEvent; @Linked -public class FireListener implements Listener { +public class FireListener implements Listener, ScoreboardElement { @EventHandler public void onFireDamage(BlockBurnEvent e) { @@ -22,4 +25,19 @@ public class FireListener implements Listener { if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.DENY) e.setCancelled(true); } + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.FIRE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FIRE).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java index f8e811aa..17e7dd43 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java @@ -4,6 +4,7 @@ import de.steamwar.bausystem.BauSystem; 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.utils.ScoreboardElement; import de.steamwar.core.Core; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; @@ -11,6 +12,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.type.Switch; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -21,7 +23,7 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.player.PlayerInteractEvent; @Linked -public class FreezeListener implements Listener { +public class FreezeListener implements Listener, ScoreboardElement { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { @@ -182,4 +184,20 @@ public class FreezeListener implements Listener { event.setCancelled(true); } } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.FREEZE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FREEZE).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java index e52d1ebb..9b173359 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java @@ -1,11 +1,14 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockExplodeEvent; @@ -14,7 +17,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import java.util.List; @Linked -public class ProtectListener implements Listener { +public class ProtectListener implements Listener, ScoreboardElement { private void explode(List blockList, Location location) { Region region = Region.getRegion(location); @@ -36,4 +39,20 @@ public class ProtectListener implements Listener { public void onExplode(EntityExplodeEvent event) { explode(event.blockList(), event.getLocation()); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.PROTECT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.PROTECT).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java new file mode 100644 index 00000000..246b9a01 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * 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.region; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class RegionScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.HEADER; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + if (GlobalRegion.getInstance() == region) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getDisplayName(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 958471e2..945858f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.script.CustomScriptManager; import de.steamwar.bausystem.features.script.custom.event.EventType; import de.steamwar.bausystem.region.Region; @@ -27,6 +28,7 @@ import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import org.bukkit.Bukkit; @@ -44,7 +46,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @Linked -public class TNTListener implements Listener { +public class TNTListener implements Listener, ScoreboardElement { @LinkedInstance public CustomScriptManager customScriptManager; @@ -88,4 +90,20 @@ public class TNTListener implements Listener { public void onExplode(EntityExplodeEvent event) { explode(event.blockList(), event.getLocation(), EventType.TNTExplodeInBuild, event); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.TNT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.TNT).getChatValue(), p); + } } 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 e06724ba..b6c6975e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.techhider; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.command.SWCommand; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; @@ -41,7 +42,7 @@ import java.util.*; import java.util.stream.Collectors; @Linked -public class TechHiderCommand extends SWCommand implements Listener { +public class TechHiderCommand extends SWCommand implements Listener, ScoreboardElement { public TechHiderCommand() { super("techhider", "hider", "obfuscate", "hide", "hide-tech"); @@ -50,16 +51,6 @@ public class TechHiderCommand extends SWCommand implements Listener { private Map> techHiders = new HashMap<>(); private Map> hidden = new HashMap<>(); - private static TechHiderCommand INSTANCE; - - { - INSTANCE = this; - } - - public static boolean isHidden(Region region, Player player) { - return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); - } - @LinkedInstance public XrayCommand xrayCommand; @@ -124,4 +115,20 @@ public class TechHiderCommand extends SWCommand implements Listener { return set; }); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (!hidden.getOrDefault(region, Collections.emptySet()).contains(p)) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java new file mode 100644 index 00000000..f22660dc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.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.tpslimit; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.core.TPSWatcher; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class TPSScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.FOOTER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (FreezeUtils.frozen()) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p); + } else { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit(); + } + } + + private String tpsColor() { + double tps = TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND); + if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.9) { + return "§a"; + } + if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.5) { + return "§e"; + } + return "§c"; + } + + private String tpsLimit() { + if (TPSLimitUtils.getCurrentTPSLimit() == 20) { + return ""; + } + return "§8/§7" + TPSLimitUtils.getCurrentTPSLimit(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java new file mode 100644 index 00000000..5e955824 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java @@ -0,0 +1,53 @@ +/* + * 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.tracer; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.show.StoredRecords; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class TraceScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + String traceScore = Recorder.INSTANCE.get(region).scoreboard(p); + if (traceScore != null) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore; + } else if (!(Recorder.INSTANCE.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p); + } + return null; + } +} 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 eaebc5ed..6efda09f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -1,21 +1,11 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.bausystem.features.techhider.TechHiderCommand; -import de.steamwar.bausystem.features.tpslimit.FreezeUtils; -import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; -import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; -import de.steamwar.bausystem.features.tracer.record.Recorder; -import de.steamwar.bausystem.features.tracer.show.StoredRecords; -import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.core.TPSWatcher; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.entity.Player; @@ -23,128 +13,65 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import java.text.SimpleDateFormat; import java.util.*; @Linked public class BauScoreboard implements Listener { - private static final Random RANDOM = new Random(); - private static final String ALL = "0123456789abcdef"; - - private static String getRandomColorCode() { - StringBuilder st = new StringBuilder(); - for (int i = 0; i < 6; i++) { - st.append("§" + ALL.charAt(RANDOM.nextInt(ALL.length()))); - } - return st.toString(); - } - - @LinkedInstance - public Recorder recorder; - - @LinkedInstance - public CustomScriptManager customScriptManager; + public static final List ELEMENTS = new ArrayList<>(); @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() { - return sidebar(player); + Region region = Region.getRegion(player.getLocation()); + + List elements = new ArrayList<>(); + calcGroup(elements, "§0", 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); + + int i = elements.size(); + HashMap result = new HashMap<>(); + for (String s : elements) { + result.put(s, i--); + } + return result; + } + + private void calcGroup(List elements, String separator, Region region, ScoreboardElement.ScoreboardGroup group) { + if (map.containsKey(group)) { + List groupElements = new ArrayList<>(); + for (ScoreboardElement element : map.get(group)) { + groupElements.add(element.get(region, player)); + } + groupElements.removeIf(Objects::isNull); + if (!groupElements.isEmpty()) { + elements.add(separator); + elements.addAll(groupElements); + } + } } @Override public String getTitle() { - // ■ Region region = Region.getRegion(player.getLocation()); - if (GlobalRegion.getInstance() == region) { - return "§eSteam§8War"; - } + if (GlobalRegion.getInstance() == region) return "§eSteam§8War"; String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), player).substring(0, 2); - return colorCode + "■ §eSteam§8War " + colorCode + "■"; + return colorCode + "■ §eSteam§8War " + colorCode + "■"; // ■ } }); } - - private HashMap sidebar(Player p) { - Region region = Region.getRegion(p.getLocation()); - - List strings = new ArrayList<>(); - if (!customScriptManager.callScoreboard(p, new HashMap<>(), strings::add)) { - // String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), p).substring(0, 2); - String colorCode = "§e"; - strings.add("§1"); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TIME", p) + "§8: §7" + new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Calendar.getInstance().getTime())); - if (GlobalRegion.getInstance() != region) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getDisplayName()); - } - - strings.add("§2"); - for (Flag flag : Flag.getFlags()) { - if (!flag.getRegionPredicate().test(region)) { - continue; - } - strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode)); - } - strings.add("§3"); - - if (TechHiderCommand.isHidden(region, p)) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p)); - } else if (XrayCommand.isHidden(region, p)) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p)); - } - - String traceScore = recorder.get(region).scoreboard(p); - if (traceScore != null) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore); - } else if (!(recorder.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p)); - } - - Loader loader = Loader.getLoader(p); - if (loader != null) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p)); - } - - if (!strings.get(strings.size() - 1).equals("§3")) { - strings.add("§5"); - } - if (FreezeUtils.frozen()) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); - } else { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); - } - } - - int i = strings.size(); - HashMap result = new HashMap<>(); - for (String s : strings) { - if (s.isEmpty()) { - s = getRandomColorCode(); - } - result.put(s, i--); - } - return result; - } - - private String tpsColor() { - double tps = TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND); - if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.9) { - return "§a"; - } - if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.5) { - return "§e"; - } - return "§c"; - } - - private String tpsLimit() { - if (TPSLimitUtils.getCurrentTPSLimit() == 20) { - return ""; - } - return "§8/§7" + TPSLimitUtils.getCurrentTPSLimit(); - } } 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 9418a7e1..1a9387c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.techhider.TechHiderCommand; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.PlayerMovementWrapper; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.command.SWCommand; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; @@ -47,7 +48,7 @@ import java.util.*; import java.util.function.BiFunction; @Linked -public class XrayCommand extends SWCommand implements Listener { +public class XrayCommand extends SWCommand implements Listener, ScoreboardElement { public XrayCommand() { super("xray"); @@ -57,16 +58,6 @@ public class XrayCommand extends SWCommand implements Listener { private Map> xrayedBlocks = new HashMap<>(); private Map> hidden = new HashMap<>(); - private static XrayCommand INSTANCE; - - { - INSTANCE = this; - } - - public static boolean isHidden(Region region, Player player) { - return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); - } - @LinkedInstance public TechHiderCommand techHiderCommand; @@ -176,4 +167,20 @@ public class XrayCommand extends SWCommand implements Listener { return set; }); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (!hidden.getOrDefault(region, Collections.emptySet()).contains(p)) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index 800c7a77..0c45d1ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -19,23 +19,21 @@ package de.steamwar.bausystem.region.flags; -import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.flagvalues.*; import de.steamwar.bausystem.shared.EnumDisplay; import lombok.Getter; import java.util.EnumSet; import java.util.Set; -import java.util.function.Predicate; @Getter public enum Flag implements EnumDisplay { - COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW, region -> false), - TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB, region -> true), - FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, region -> true), - FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, region -> true), - PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE, region -> region.getFloorLevel() != 0); + COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW), + TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB), + FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW), + FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE), + PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE); @Getter private static final Set flags; @@ -48,14 +46,12 @@ public enum Flag implements EnumDisplay { private final Class> valueType; private final Flag.Value defaultValue; private final Value[] values; - private final Predicate regionPredicate; - & Value> Flag(String chatValue, final Class> valueType, final Flag.Value defaultValue, Predicate regionPredicate) { + & Value> Flag(String chatValue, final Class> valueType, final Flag.Value defaultValue) { this.chatValue = chatValue; this.valueType = valueType; this.defaultValue = defaultValue; this.values = defaultValue.getValues(); - this.regionPredicate = regionPredicate; } public Value getFlagValueOf(final String name) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java new file mode 100644 index 00000000..5f573322 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java @@ -0,0 +1,37 @@ +/* + * 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.region.Region; +import org.bukkit.entity.Player; + +public interface ScoreboardElement { + ScoreboardGroup getGroup(); + int order(); + + String get(Region region, Player p); + + enum ScoreboardGroup { + HEADER, + REGION, + OTHER, + FOOTER + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java new file mode 100644 index 00000000..d3ca0fea --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * 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.bausystem.region.Region; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +@Linked +public class TimeScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.HEADER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TIME", p) + "§8: §7" + new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Calendar.getInstance().getTime()); + } +} From d0ab735bbf9049bb6bec30bb165c973595ef2872 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 15:06:15 +0200 Subject: [PATCH 031/175] Hotfix stuff Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 - BauSystem_Main/src/BauSystem_de.properties | 1 - .../src/de/steamwar/bausystem/features/region/FireListener.java | 1 - .../de/steamwar/bausystem/features/region/FreezeListener.java | 1 - .../src/de/steamwar/bausystem/features/region/TNTListener.java | 1 - 5 files changed, 5 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 320cd623..d71c6aaf 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -606,7 +606,6 @@ SIMULATOR_GUI_TNT_GROUP_LORE_6 = §7z§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Simulator SIMULATOR_GUI_DELETE = §cDelete TNT -SIMULATOR_GUI_START = §eStart SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eMove all diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index a4eae658..9ac07bd8 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -589,7 +589,6 @@ SIMULATOR_GUI_TNT_GROUP_LORE_1 = §7Elementanzahl§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Kanonensimulator SIMULATOR_GUI_DELETE = §cTNT löschen -SIMULATOR_GUI_START = §eStarten SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eAlle Verschieben diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java index 56fd3232..afe30aa1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java @@ -37,7 +37,6 @@ public class FireListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.FIRE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FIRE).getChatValue(), p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java index 17e7dd43..d810ce61 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java @@ -197,7 +197,6 @@ public class FreezeListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.FREEZE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FREEZE).getChatValue(), p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 945858f6..08309eb6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -103,7 +103,6 @@ public class TNTListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.TNT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.TNT).getChatValue(), p); } } From 35f882c1239fbbd8d773b91f5046b6ce14441ec7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 16:39:00 +0200 Subject: [PATCH 032/175] Update Loader Signed-off-by: yoyosource --- .../bausystem/features/loadern/LoaderRecorder.java | 2 +- .../loadern/elements/impl/LoaderComparator.java | 10 +++++----- .../features/loadern/elements/impl/LoaderLectern.java | 2 +- .../features/loadern/elements/impl/LoaderMovement.java | 3 ++- .../loadern/elements/impl/LoaderNoteBlock.java | 4 ++-- .../features/loadern/elements/impl/LoaderRepeater.java | 10 +++++----- .../features/loadern/elements/impl/LoaderTicks.java | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java index 329cfd55..04eb1c11 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -138,7 +138,7 @@ public class LoaderRecorder implements Listener { public void onPlayerMove(PlayerMoveEvent event) { if (event.getPlayer() != player) return; - Block fromBlock = event.getTo().getBlock(); + Block fromBlock = event.getFrom().getBlock(); Block toBlock = event.getTo().getBlock(); calcMovementBlocks(fromBlock, toBlock); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java index d92ea4ad..1205e4bf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java @@ -82,15 +82,15 @@ public class LoaderComparator extends LoaderInteractionElement backAction.run()); swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(2, item(player, true, null).getItemStack(), clickType -> { - interact = true; - click(player, backAction, deleteAction); - }); - swInventory.setItem(3, item(player, false, null).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, false, null).getItemStack(), clickType -> { interact = false; mode = null; click(player, backAction, deleteAction); }); + swInventory.setItem(3, item(player, true, null).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); swInventory.setItem(5, item(player, false, Comparator.Mode.COMPARE).getItemStack(), clickType -> { interact = false; mode = Comparator.Mode.COMPARE; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java index 033d936a..5df1594d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java @@ -94,7 +94,7 @@ public class LoaderLectern extends LoaderInteractionElement backAction.run()); swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(3, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> { noop = true; click(player, backAction, deleteAction); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java index ee1f11ac..176ffd19 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -50,6 +50,7 @@ public class LoaderMovement extends LoaderInteractionElement backAction.run()); swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(3, item(player, true, false).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; click(player, backAction, deleteAction); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java index 5f062f87..53811035 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java @@ -79,11 +79,11 @@ public class LoaderNoteBlock extends LoaderInteractionElement backAction.run()); swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(3, item(player, false).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, false).getItemStack(), clickType -> { interact = false; click(player, backAction, deleteAction); }); - swInventory.setItem(5, item(player, true).getItemStack(), clickType -> { + swInventory.setItem(3, item(player, true).getItemStack(), clickType -> { interact = true; click(player, backAction, deleteAction); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java index a0e50e48..102ee35c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java @@ -86,15 +86,15 @@ public class LoaderRepeater extends LoaderInteractionElement backAction.run()); swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(1, item(player, true, -1).getItemStack(), clickType -> { - interact = true; - click(player, backAction, deleteAction); - }); - swInventory.setItem(2, item(player, false, 0).getItemStack(), clickType -> { + swInventory.setItem(1, item(player, false, 0).getItemStack(), clickType -> { interact = false; delay = 0; click(player, backAction, deleteAction); }); + swInventory.setItem(2, item(player, true, -1).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); swInventory.setItem(4, item(player, false, 1).getItemStack(), clickType -> { interact = false; delay = 1; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 8e203d7d..5b615f20 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -128,7 +128,7 @@ public class LoaderTicks extends LoaderInteractionElement backAction.run()); swInventory.setItem(analogue ? 35 : 17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(3, item(player, true, false).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; click(player, backAction, deleteAction); }); From 7e78c2890a0ce1cd91b04d79b74480dfec518a18 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 16:59:06 +0200 Subject: [PATCH 033/175] Update loader and remove old one Signed-off-by: yoyosource --- .../bausystem/features/loader/Loader.java | 244 ------------------ .../features/loader/LoaderBauGuiItem.java | 107 -------- .../features/loader/LoaderButton.java | 71 ----- .../features/loader/LoaderCommand.java | 160 ------------ .../activations/AbstractLoaderActivation.java | 36 --- .../BlockPlaceLoaderActivation.java | 57 ---- .../activations/InteractionActivation.java | 174 ------------- .../bausystem/features/loadern/Loader.java | 18 +- .../LoaderScoreboardElement.java | 2 +- .../loadern/elements/impl/LoaderWait.java | 5 +- 10 files changed, 17 insertions(+), 857 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderBauGuiItem.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{loader => loadern}/LoaderScoreboardElement.java (96%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java deleted file mode 100644 index 6cba6fe9..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ /dev/null @@ -1,244 +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.loader; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.loader.activations.AbstractLoaderActivation; -import de.steamwar.bausystem.features.loader.activations.BlockPlaceLoaderActivation; -import de.steamwar.bausystem.features.loader.activations.InteractionActivation; -import de.steamwar.bausystem.shared.EnumDisplay; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -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.event.player.PlayerQuitEvent; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.scheduler.BukkitTask; - -import java.util.*; - -@Getter -@Setter -public class Loader implements Listener { - - private static final Map LOADER_MAP = new HashMap<>(); - private final Player p; - private final List actions = new LinkedList<>(); - private int ticksBetweenShots = 80; - private int ticksBetweenBlocks = 1; - private Stage stage; - private int lastActivation = -1; - private int countdown = 0; - - @Getter(AccessLevel.PRIVATE) - private final BukkitTask task; - - @Getter(AccessLevel.PRIVATE) - @Setter(AccessLevel.PRIVATE) - private AbstractLoaderActivation current; - - @Getter(AccessLevel.PRIVATE) - @Setter(AccessLevel.PRIVATE) - private ListIterator iterator; - - private Loader(Player p) { - this.p = p; - stage = Stage.SETUP; - Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::run, 1, 1); - } - - public static Loader getLoader(Player p) { - return LOADER_MAP.getOrDefault(p, null); - } - - public static Loader newLoader(Player p) { - return LOADER_MAP.put(p, new Loader(p)); - } - - public void start() { - if (stage != Stage.SETUP) return; - iterator = actions.listIterator(); - countdown = 0; - current = null; - stage = Stage.RUNNING; - } - - public void pause() { - if (stage == Stage.RUNNING) { - stage = Stage.PAUSE; - } - } - - public void resume() { - if (stage == Stage.PAUSE) { - stage = Stage.RUNNING; - } - } - - public void setup() { - stage = Stage.SETUP; - iterator = null; - current = null; - countdown = 0; - } - - public void stop() { - stage = Stage.END; - task.cancel(); - LOADER_MAP.remove(p, this); - } - - public void clear() { - if (stage == Stage.SETUP) { - actions.clear(); - BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR", p); - } else { - BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR_HELP", p); - } - } - - public void single() { - if (stage != Stage.PAUSE && stage != Stage.SETUP) return; - if (iterator == null || !iterator.hasNext()) { - iterator = actions.listIterator(); - countdown = 0; - current = null; - } - stage = Stage.SINGLE; - } - - public void run() { - if (stage == Stage.SETUP && lastActivation >= 0) - lastActivation++; - - if (stage != Stage.RUNNING && stage != Stage.SINGLE) { - return; - } - - if (countdown-- > 0) { - return; - } - - while (countdown <= 0) { - if (!iterator.hasNext()) { - countdown = getTicksBetweenShots(); - iterator = actions.listIterator(); - if (stage == Stage.SINGLE) stage = Stage.PAUSE; - return; - } - - current = iterator.next(); - - if (current.execute()) { - countdown = current.delay(this); - } else { - countdown = 1; - iterator.previous(); - } - } - } - - public void undo() { - if (actions.isEmpty() || stage != Stage.SETUP) { - return; - } - actions.remove(actions.size() - 1); - } - - @EventHandler - public void onBlockPlace(BlockPlaceEvent event) { - if (event.getPlayer() != p) { - return; - } - - if (stage != Stage.SETUP) { - return; - } - - if (event.getBlock().getType() != Material.TNT) { - return; - } - - actions.add(new BlockPlaceLoaderActivation(p, event.getBlock().getLocation(), Material.TNT)); - SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("LOADER_MESSAGE_TNT", p, actions.size())); - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (event.getPlayer() != p) { - return; - } - - if (stage != Stage.SETUP) { - return; - } - - if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) - return; - - if (event.getClickedBlock().getType() == Material.OBSERVER) - return; - - if (event.getHand() == EquipmentSlot.OFF_HAND) { - return; - } - - if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) { - return; - } - - LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); - if (button != LoaderButton.INVALID) { - actions.add(InteractionActivation.construct(p, event.getClickedBlock().getLocation(), this)); - lastActivation = 0; - SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", p, BauSystem.MESSAGE.parse(button.getName(), p), actions.size())); - } - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - if (event.getPlayer() != p) { - return; - } - stop(); - } - - @AllArgsConstructor - public enum Stage implements EnumDisplay { - SETUP("LOADER_SETUP"), - RUNNING("LOADER_RUNNING"), - SINGLE("LOADER_SINGLE_SIDEBAR"), - PAUSE("LOADER_PAUSE"), - END("LOADER_END"); - - @Getter - private String chatValue; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderBauGuiItem.java deleted file mode 100644 index 55370c3f..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderBauGuiItem.java +++ /dev/null @@ -1,107 +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.loader; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.linkage.specific.BauGuiItem; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.inventory.SWInventory; -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; - -import java.util.Arrays; - -@Linked -public class LoaderBauGuiItem extends BauGuiItem { - - public LoaderBauGuiItem() { - super(9); - } - - @Override - public ItemStack getItem(Player player) { - return SWUtils.setCustomModelData(new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("LOADER_GUI_NAME", player)), 1).getItemStack(); - } - - @Override - public boolean click(ClickType click, Player p) { - p.closeInventory(); - openLoaderGui(p); - return false; - } - - private void openLoaderGui(Player p) { - SWInventory inv = new SWInventory(p, 9, BauSystem.MESSAGE.parse("LOADER_GUI_NAME", p)); - if (Loader.getLoader(p) == null) { - inv.setItem(4, new SWItem(Material.SCUTE, BauSystem.MESSAGE.parse("LOADER_GUI_NEW", p), clickType -> { - p.closeInventory(); - p.performCommand("loader setup"); - })); - } else { - Loader loader = Loader.getLoader(p); - if (loader.getStage() != Loader.Stage.RUNNING) { - inv.setItem(0, new SWItem(Material.GREEN_DYE, BauSystem.MESSAGE.parse("LOADER_GUI_START", p), clickType -> { - p.closeInventory(); - p.performCommand("loader start"); - })); - } else { - inv.setItem(0, new SWItem(Material.RED_DYE, BauSystem.MESSAGE.parse("LOADER_GUI_PAUSE", p), clickType -> { - p.closeInventory(); - p.performCommand("loader pause"); - })); - } - inv.setItem(2, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_UNDO", p), clickType -> { - p.closeInventory(); - p.performCommand("loader undo"); - })); - inv.setItem(4, new SWItem(Material.COMPASS, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT", p), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_LORE", p, loader.getTicksBetweenShots())), false, clickType -> { - p.closeInventory(); - SWAnvilInv anvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", p)); - anvilInv.setItem(Material.CLOCK); - anvilInv.setCallback(s -> p.performCommand("loader delay " + s)); - anvilInv.open(); - })); - inv.setItem(6, new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_GUI_SPEED", p), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_SPEED_LORE", p, loader.getTicksBetweenBlocks())), false, clickType -> { - p.closeInventory(); - SWAnvilInv anvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SPEED_TITLE", p)); - anvilInv.setItem(Material.CLOCK); - anvilInv.setCallback(s -> p.performCommand("loader speed " + s)); - anvilInv.open(); - })); - inv.setItem(8, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_STOP", p), clickType -> { - p.closeInventory(); - p.performCommand("loader stop"); - })); - } - inv.open(); - } - - @Override - public Permission permission() { - return Permission.WORLD; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java deleted file mode 100644 index 4a1d5159..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ /dev/null @@ -1,71 +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.loader; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.bukkit.block.Block; - - -@AllArgsConstructor -@RequiredArgsConstructor -@Getter -public enum LoaderButton { - SWITCH(0, true, "LOADER_BUTTON_SWITCH"), - WOOD_BUTTON(30, "LOADER_BUTTON_WOOD_BUTTON"), - STONE_BUTTON(20, "LOADER_BUTTON_STONE_BUTTON"), - PRESSURE_PLATE(30, "LOADER_BUTTON_PRESSURE_PLATE"), - WEIGHTED_PRESSURE_PLATE(20, "LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE"), - TRIPWIRE(30, "LOADER_BUTTON_TRIPWIRE"), - NOTEBLOCK(1, "LOADER_BUTTON_NOTEBLOCK"), - DAYLIGHTSENSOR(0, true, "LOADER_BUTTON_DAYLIGHTSENSOR"), - INVALID(-1, "LOADER_BUTTON_INVALID"); - - private final int time; - private boolean toggle; - private final String name; - - public static LoaderButton fromBlock(Block block) { - switch (block.getType()) { - case LEVER: - return LoaderButton.SWITCH; - case TRIPWIRE: - return LoaderButton.TRIPWIRE; - case NOTE_BLOCK: - return LoaderButton.NOTEBLOCK; - case DAYLIGHT_DETECTOR: - return LoaderButton.DAYLIGHTSENSOR; - case HEAVY_WEIGHTED_PRESSURE_PLATE: - case LIGHT_WEIGHTED_PRESSURE_PLATE: - return LoaderButton.WEIGHTED_PRESSURE_PLATE; - default: - if (block.getType().name().contains("STONE_BUTTON")) { - return LoaderButton.STONE_BUTTON; - } else if (block.getType().name().contains("BUTTON")) { - return LoaderButton.WOOD_BUTTON; - } else if (block.getType().name().contains("PRESSURE_PLATE")) { - return LoaderButton.PRESSURE_PLATE; - } else { - return LoaderButton.INVALID; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java deleted file mode 100644 index 95fa92b6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ /dev/null @@ -1,160 +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.loader; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; -import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; -import de.steamwar.linkage.Linked; -import org.bukkit.entity.Player; - -// @Linked -public class LoaderCommand extends SWCommand { - - public LoaderCommand() { - super("loader", "autoloader", "al"); - addDefaultHelpMessage("LOADER_HELP_OTHER"); - } - - private boolean loaderNullCheck(Loader loader, Player p) { - if (loader == null) { - BauSystem.MESSAGE.send("LOADER_NO_LOADER", p); - return true; - } - return false; - } - - @Register(value = "setup", description = "LOADER_HELP_SETUP") - public void setupLoader(@Validator Player p) { - if (Loader.getLoader(p) != null) { - Loader.getLoader(p).setup(); - BauSystem.MESSAGE.send("LOADER_BACK_SETUP", p); - } else { - Loader.newLoader(p); - BauSystem.MESSAGE.send("LOADER_NEW", p); - BauSystem.MESSAGE.send("LOADER_HOW_TO_START", p); - } - } - - @Register(value = "start", description = "LOADER_HELP_START") - public void startLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.start(); - BauSystem.MESSAGE.send("LOADER_ACTIVE", p); - } - - @Register(value = "stop", description = "LOADER_HELP_STOP") - public void stopLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.stop(); - BauSystem.MESSAGE.send("LOADER_STOP", p); - } - - @Register(value = "pause", description = "LOADER_HELP_PAUSE") - public void pauseLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.pause(); - BauSystem.MESSAGE.send("LOADER_PAUSED", p); - } - - @Register(value = "resume", description = "LOADER_HELP_RESUME") - public void resumeLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.resume(); - BauSystem.MESSAGE.send("LOADER_RESUME", p); - } - - @Register(value = "wait", description = "LOADER_HELP_WAIT") - public void shotDelayLoader(@Validator Player p, int delay) { - if (delay < 1) { - BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p); - return; - } - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_NEW_TIME", p, delay, loader.getTicksBetweenShots()); - loader.setTicksBetweenShots(delay); - } - - @Register(value = "speed", description = "LOADER_HELP_SPEED") - public void speedLoader(@Validator Player p, int delay) { - if (delay < 0) { - BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p); - return; - } - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay, loader.getTicksBetweenBlocks()); - loader.setTicksBetweenBlocks(delay); - } - - @Register(value = "undo", description = "LOADER_HELP_UNDO") - public void undoLast(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_UNDO", p); - loader.undo(); - } - - @Register(value = "clear", description = "LOADER_HELP_CLEAR") - public void clearLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.clear(); - } - - @Register(value = "single", description = "LOADER_HELP_SINGLE") - public void singleLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.single(); - BauSystem.MESSAGE.send("LOADER_SINGLE", p); - } - - @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/activations/AbstractLoaderActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java deleted file mode 100644 index 7c4d4768..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java +++ /dev/null @@ -1,36 +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.loader.activations; - -import de.steamwar.bausystem.features.loader.Loader; -import org.bukkit.entity.Player; - -public abstract class AbstractLoaderActivation { - - Player p; - - public AbstractLoaderActivation(Player p) { - this.p = p; - } - - public abstract boolean execute(); - - public abstract int delay(Loader loader); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java deleted file mode 100644 index 910f2071..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java +++ /dev/null @@ -1,57 +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.loader.activations; - -import de.steamwar.bausystem.features.loader.Loader; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -public class BlockPlaceLoaderActivation extends AbstractLoaderActivation { - - private final Location location; - private final Material material; - - public BlockPlaceLoaderActivation(Player p, Location location, Material material) { - super(p); - this.location = location; - if (!material.isBlock()) { - throw new IllegalStateException("Only Blocks, " + material.name() + " is not a Block"); - } - this.material = material; - } - - @Override - public boolean execute() { - Block currBlock = location.getBlock(); - if (currBlock.getType() != Material.AIR && currBlock.getType() != Material.WATER) { - return false; - } - - currBlock.setType(material, true); - return true; - } - - @Override - public int delay(Loader loader) { - return loader.getTicksBetweenBlocks(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java deleted file mode 100644 index c7f27bd3..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java +++ /dev/null @@ -1,174 +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.loader.activations; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; -import de.steamwar.bausystem.features.loader.LoaderButton; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.*; -import org.bukkit.block.data.type.DaylightDetector; -import org.bukkit.block.data.type.Switch; -import org.bukkit.entity.Player; - -public abstract class InteractionActivation extends AbstractLoaderActivation { - - Location location; - LoaderButton button; - - InteractionActivation(Player p, Location location, LoaderButton button) { - super(p); - this.location = location; - this.button = button; - } - - public static InteractionActivation construct(Player p, Location location, Loader loader) { - LoaderButton button = LoaderButton.fromBlock(location.getBlock()); - if (button.isToggle()) { - return new ToggleActivation(p, location, button, loader.getLastActivation()); - } else { - return new TimedActivation(p, location, button); - } - } - - void updateButton() { - Block block = location.getBlock(); - if (block.getBlockData() instanceof Switch) { - Switch sw = (Switch) block.getBlockData(); - FaceAttachable.AttachedFace face = sw.getAttachedFace(); - if (face == FaceAttachable.AttachedFace.FLOOR) { - update(block.getRelative(BlockFace.DOWN)); - } else if (face == FaceAttachable.AttachedFace.CEILING) { - update(block.getRelative(BlockFace.UP)); - } else { - update(block.getRelative(sw.getFacing().getOppositeFace())); - } - } else if (button == LoaderButton.TRIPWIRE) { - update(block); - } else if (button == LoaderButton.PRESSURE_PLATE || button == LoaderButton.WEIGHTED_PRESSURE_PLATE) { - update(block.getRelative(BlockFace.DOWN)); - } - } - - void update(Block block) { - BlockData data = block.getBlockData(); - block.setType(Material.BARRIER, true); - block.setBlockData(data, true); - } - - boolean getBlockPower() { - Block block = location.getBlock(); - BlockData data = block.getBlockData(); - if (data instanceof Powerable) { - Powerable pow = (Powerable) data; - return pow.isPowered(); - } - if (data instanceof DaylightDetector) { - DaylightDetector detector = (DaylightDetector) data; - return detector.isInverted(); - } - if (data instanceof AnaloguePowerable) { - AnaloguePowerable powerable = (AnaloguePowerable) data; - return powerable.getPower() > 0; - } - return false; - } - - void setBlockPower(boolean state) { - Block block = location.getBlock(); - BlockData data = block.getBlockData(); - if (data instanceof Powerable) { - Powerable pow = (Powerable) data; - pow.setPowered(state); - } - if (data instanceof Openable) { - Openable openable = (Openable) data; - openable.setOpen(state); - } - if (data instanceof DaylightDetector) { - DaylightDetector detector = (DaylightDetector) data; - detector.setInverted(state); - } - if (data instanceof AnaloguePowerable) { - AnaloguePowerable powerable = (AnaloguePowerable) data; - if (block.getType() == Material.REDSTONE_WIRE) { - powerable.setPower(state ? 15 : 0); - } else { - powerable.setPower(state ? 1 : 0); - } - } - block.setBlockData(data); - } - - public static class ToggleActivation extends InteractionActivation { - - private final int delay; - - public ToggleActivation(Player p, Location location, LoaderButton button, int delay) { - super(p, location, button); - this.delay = Math.max(delay, 0); - } - - @Override - public boolean execute() { - if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID) - return false; - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - setBlockPower(!getBlockPower()); - updateButton(); - }, delay); - return true; - } - - @Override - public int delay(Loader loader) { - return delay; - } - } - - public static class TimedActivation extends InteractionActivation { - - public TimedActivation(Player p, Location location, LoaderButton button) { - super(p, location, button); - } - - @Override - public boolean execute() { - if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID) - return false; - setBlockPower(true); - updateButton(); - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - setBlockPower(false); - updateButton(); - }, button.getTime()); - return true; - } - - @Override - public int delay(Loader loader) { - return button.getTime(); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 01d56d04..d1eef52d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -21,7 +21,10 @@ package de.steamwar.bausystem.features.loadern; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.shared.EnumDisplay; import de.steamwar.inventory.SWListInv; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -47,6 +50,7 @@ public class Loader implements Listener { private final Player p; + @Getter private Stage stage = Stage.SETUP; private LoaderRecorder recorder; @@ -121,10 +125,14 @@ public class Loader implements Listener { stop(); } - public enum Stage { - SETUP, - RUNNING, - PAUSE, - END + @AllArgsConstructor + public enum Stage implements EnumDisplay { + SETUP("LOADER_SETUP"), + RUNNING("LOADER_RUNNING"), + PAUSE("LOADER_PAUSE"), + END("LOADER_END"); + + @Getter + private String chatValue; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java index 847ed59b..d0b41cc0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loader; +package de.steamwar.bausystem.features.loadern; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java index ad84fa21..67875b2b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -59,8 +59,9 @@ public class LoaderWait implements LoaderElement, Listener { @Override public void click(Player player, Runnable backAction) { - SWInventory swInventory = new SWInventory(player, 9, "Wartezeit"); - swInventory.setItem(0, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + SWInventory swInventory = new SWInventory(player, 18, "Wartezeit"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; From 792f16fadf0a4329250f6df6660e0eb36c0d5cec Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 17:13:15 +0200 Subject: [PATCH 034/175] Update Loader Signed-off-by: yoyosource --- .../bausystem/features/loadern/Loader.java | 41 ++++++++++++++++--- .../features/loadern/LoaderCommand.java | 2 +- .../elements/LoaderInteractionElement.java | 1 - .../features/script/variables/Constants.java | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index d1eef52d..40c3f750 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -21,11 +21,15 @@ package de.steamwar.bausystem.features.loadern; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.features.loadern.elements.impl.LoaderTNT; +import de.steamwar.bausystem.features.loadern.elements.impl.LoaderWait; import de.steamwar.bausystem.shared.EnumDisplay; +import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import lombok.AllArgsConstructor; import lombok.Getter; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -109,14 +113,36 @@ public class Loader implements Listener { LOADER_MAP.remove(p); } - public void settings() { + public void settings(SettingsSorting settingsSorting) { List> list = new ArrayList<>(); for (LoaderElement element : elements) { + if (settingsSorting != null) { + if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) { + continue; + } + if (settingsSorting == SettingsSorting.INTERACTIONS && (element instanceof LoaderWait || element instanceof LoaderTNT)) { + continue; + } + } list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); } - new SWListInv<>(p, "Loader Settings", false, list, (clickType, entry) -> { - entry.click(p, this::settings); - }).open(); + SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, entry) -> { + entry.click(p, () -> settings(settingsSorting)); + }); + + SWItem onlyWaitElements = new SWItem(Material.CLOCK, "§eNur Warten", clickType -> { + settings(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); + }); + if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); + swListInv.setItem(48, onlyWaitElements); + + SWItem onlyInteractionsElements = new SWItem(Material.TNT, "§eNur Interaktionen", clickType -> { + settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); + }); + if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); + swListInv.setItem(50, onlyInteractionsElements); + + swListInv.open(); } @EventHandler @@ -125,6 +151,11 @@ public class Loader implements Listener { stop(); } + public enum SettingsSorting { + WAIT, + INTERACTIONS, + } + @AllArgsConstructor public enum Stage implements EnumDisplay { SETUP("LOADER_SETUP"), @@ -133,6 +164,6 @@ public class Loader implements Listener { END("LOADER_END"); @Getter - private String chatValue; + private final String chatValue; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java index 6539d16a..b2d7a2b8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -80,7 +80,7 @@ public class LoaderCommand extends SWCommand { public void settingsLoader(@Validator Player player) { Loader loader = Loader.getLoader(player); if (loaderNullCheck(loader, player)) return; - loader.settings(); + loader.settings(null); } @ClassValidator(value = Player.class, local = true) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 7785f07b..8397779a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem.features.loadern.elements; -import de.steamwar.bausystem.features.loader.LoaderButton; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index e0ec0872..10d4a75d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -1,7 +1,7 @@ package de.steamwar.bausystem.features.script.variables; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.loadern.Loader; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.record.ActiveTracer; From b1dcd6d57bf7e2ddb7efb7e48addcac2caeb6876 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 18:00:54 +0200 Subject: [PATCH 035/175] Update Loader and fix many things Signed-off-by: yoyosource --- .../bausystem/features/loadern/Loader.java | 18 ++++- .../loadern/LoaderScoreboardElement.java | 6 +- .../elements/LoaderInteractionElement.java | 17 +++-- .../elements/impl/LoaderDaylightDetector.java | 2 +- .../loadern/elements/impl/LoaderLever.java | 2 +- .../loadern/elements/impl/LoaderMovement.java | 18 +++-- .../loadern/elements/impl/LoaderTicks.java | 74 ++++--------------- .../loadern/elements/impl/LoaderWait.java | 2 + 8 files changed, 62 insertions(+), 77 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 40c3f750..0560f1a6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -60,6 +60,7 @@ public class Loader implements Listener { private List elements = new ArrayList<>(); private int currentElement = 0; + private long totalDelay = 0; public Loader(Player p) { this.p = p; @@ -71,9 +72,18 @@ public class Loader implements Listener { currentElement++; if (currentElement >= elements.size()) { currentElement = 0; + if (totalDelay == 0) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1); + return; + } + totalDelay = 0; } if (stage == Stage.RUNNING) { - elements.get(currentElement).execute(this::next); + LoaderElement element = elements.get(currentElement); + if (element instanceof LoaderWait) { + totalDelay += ((LoaderWait) element).getDelay(); + } + element.execute(this::next); } } @@ -136,7 +146,7 @@ public class Loader implements Listener { if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); swListInv.setItem(48, onlyWaitElements); - SWItem onlyInteractionsElements = new SWItem(Material.TNT, "§eNur Interaktionen", clickType -> { + SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); }); if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); @@ -151,6 +161,10 @@ public class Loader implements Listener { stop(); } + public String getProgress() { + return "§7" + (currentElement + 1) + "§8/§7" + elements.size(); + } + public enum SettingsSorting { WAIT, INTERACTIONS, diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java index d0b41cc0..dd0a59c5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java @@ -42,6 +42,10 @@ public class LoaderScoreboardElement implements ScoreboardElement { public String get(Region region, Player p) { Loader loader = Loader.getLoader(p); if (loader == null) return null; - return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + if (loader.getStage() == Loader.Stage.RUNNING || loader.getStage() == Loader.Stage.PAUSE) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p) + " §8(" + loader.getProgress() + "§8)"; + } else { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 8397779a..948a3e1d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -86,10 +86,12 @@ public abstract class LoaderInteractionElement implem listInv.open(); } - protected void update(Block block) { - Material material = block.getType(); - if (block.getBlockData() instanceof Switch) { - Switch sw = (Switch) block.getBlockData(); + protected void update(BlockData blockData) { + Material material = blockData.getMaterial(); + Block block = location.getBlock(); + if (blockData instanceof Switch) { + Switch sw = (Switch) blockData; + updateBlock(block, sw); FaceAttachable.AttachedFace face = sw.getAttachedFace(); if (face == FaceAttachable.AttachedFace.FLOOR) { updateBlock(block.getRelative(BlockFace.DOWN)); @@ -99,14 +101,17 @@ public abstract class LoaderInteractionElement implem updateBlock(block.getRelative(sw.getFacing().getOppositeFace())); } } else if (material == Material.TRIPWIRE) { - updateBlock(block); + updateBlock(block, blockData); } else if (material.name().endsWith("_PLATE")) { updateBlock(block.getRelative(BlockFace.DOWN)); } } protected void updateBlock(Block block) { - BlockData data = block.getBlockData(); + updateBlock(block, block.getBlockData()); + } + + protected void updateBlock(Block block, BlockData data) { block.setType(Material.BARRIER, true); block.setBlockData(data, true); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index cbdcc7dc..d78e6319 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -76,7 +76,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement= 0) { boolean finalWaitFor = waitFor; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { if (blockData instanceof AnaloguePowerable) { - ((AnaloguePowerable) blockData).setPower(0); + AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData; + analoguePowerable.setPower(0); + location.getBlock().setBlockData(analoguePowerable, true); } else { - ((Powerable) blockData).setPowered(false); + Powerable powerable = (Powerable) blockData; + powerable.setPowered(false); + location.getBlock().setBlockData(powerable, true); } - location.getBlock().setBlockData(blockData); - update(location.getBlock()); if (finalWaitFor) { nextAction.run(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 5b615f20..0bdb5228 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -27,8 +27,6 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.block.data.AnaloguePowerable; -import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Powerable; import org.bukkit.entity.Player; @@ -39,22 +37,19 @@ public class LoaderTicks extends LoaderInteractionElement 0); - } else { - powerable.setPowered(true); - } - } + Powerable powerable = (Powerable) location.getBlock().getBlockData(); + powerable.setPowered(true); + location.getBlock().setBlockData(powerable, true); - location.getBlock().setBlockData(blockData); - update(location.getBlock()); - if (ticks >= 0) { - boolean finalWaitFor = waitFor; - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - if (blockData instanceof AnaloguePowerable) { - ((AnaloguePowerable) blockData).setPower(0); - } else { - ((Powerable) blockData).setPowered(false); - } - location.getBlock().setBlockData(blockData); - update(location.getBlock()); - if (finalWaitFor) { - nextAction.run(); - } - }, ticks); - if (!finalWaitFor) { + boolean finalWaitFor = waitFor; + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + powerable.setPowered(false); + location.getBlock().setBlockData(powerable, true); + if (finalWaitFor) { nextAction.run(); } + }, ticks); + if (!finalWaitFor) { + nextAction.run(); } } @Override public void click(Player player, Runnable backAction, Runnable deleteAction) { - SWInventory swInventory = new SWInventory(player, analogue ? 36 : 18, "Settings"); - for (int i = analogue ? 27 : 9; i < (analogue ? 35 : 18); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); - swInventory.setItem(analogue ? 27 : 9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); - swInventory.setItem(analogue ? 35 : 17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; @@ -145,18 +122,6 @@ public class LoaderTicks extends LoaderInteractionElement= 9) finalI2++; - swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> { - power = finalI; - click(player, backAction, deleteAction); - }); - } - } - swInventory.open(); } @@ -168,13 +133,6 @@ public class LoaderTicks extends LoaderInteractionElement Date: Mon, 1 May 2023 18:10:32 +0200 Subject: [PATCH 036/175] Fix LoaderMovement Signed-off-by: yoyosource --- .../features/loadern/elements/impl/LoaderMovement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java index e931ea50..0ca03583 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -84,7 +84,7 @@ public class LoaderMovement extends LoaderInteractionElement Date: Mon, 1 May 2023 20:17:30 +0200 Subject: [PATCH 037/175] Update scoreboard Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/loadern/Loader.java | 7 +++---- .../features/loadern/LoaderScoreboardElement.java | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 0560f1a6..06dffc03 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -136,9 +136,8 @@ public class Loader implements Listener { } list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); } - SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, entry) -> { - entry.click(p, () -> settings(settingsSorting)); - }); + SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, loaderElement) -> {}); + swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); SWItem onlyWaitElements = new SWItem(Material.CLOCK, "§eNur Warten", clickType -> { settings(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); @@ -162,7 +161,7 @@ public class Loader implements Listener { } public String getProgress() { - return "§7" + (currentElement + 1) + "§8/§7" + elements.size(); + return (currentElement + 1) + "§8/§7" + elements.size(); } public enum SettingsSorting { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java index dd0a59c5..e9fc9004 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java @@ -42,8 +42,10 @@ public class LoaderScoreboardElement implements ScoreboardElement { public String get(Region region, Player p) { Loader loader = Loader.getLoader(p); if (loader == null) return null; - if (loader.getStage() == Loader.Stage.RUNNING || loader.getStage() == Loader.Stage.PAUSE) { - return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p) + " §8(" + loader.getProgress() + "§8)"; + if (loader.getStage() == Loader.Stage.RUNNING) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: §a" + loader.getProgress(); + } else if (loader.getStage() == Loader.Stage.PAUSE) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: §c" + loader.getProgress(); } else { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); } From 6e82b57fbf8f9ef5a719a2faa3a5248370245a88 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 5 May 2023 16:51:14 +0200 Subject: [PATCH 038/175] Fix some stuff and add lores Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 32 ++++++----------- BauSystem_Main/src/BauSystem_de.properties | 32 ++++++----------- .../features/loadern/LoaderCommand.java | 2 +- .../features/loadern/LoaderRecorder.java | 36 ++++++++++++++----- .../loadern/elements/impl/LoaderMovement.java | 8 +++-- .../loadern/elements/impl/LoaderOpenable.java | 1 - .../loadern/elements/impl/LoaderTicks.java | 2 ++ .../loadern/elements/impl/LoaderWait.java | 4 +-- 8 files changed, 61 insertions(+), 56 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index d71c6aaf..7d3618d3 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -788,47 +788,36 @@ TRACE_GUI_POSITION_EXPLODED = §7Exploded§8: §e{0} # Loader LOADER_SETUP = §eSetup LOADER_RUNNING = §aRunning -LOADER_SINGLE_SIDEBAR = §aSingle LOADER_PAUSE = §7Pause LOADER_END = §8Finished -LOADER_MESSAGE_CLEAR = §7Loader cleared -LOADER_MESSAGE_CLEAR_HELP = §cYou have to be in Setup-Mode to clear the Loader -LOADER_MESSAGE_TNT = §eTNT added {0} LOADER_MESSAGE_INTERACT = §e{0} added {1} +LOADER_BUTTON_TNT = TNT LOADER_BUTTON_SWITCH=Lever -LOADER_BUTTON_WOOD_BUTTON=Button -LOADER_BUTTON_STONE_BUTTON=Button +LOADER_BUTTON_WOOD_BUTTON=Wooden Button +LOADER_BUTTON_STONE_BUTTON=Stone Button LOADER_BUTTON_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_NOTEBLOCK=Noteblock LOADER_BUTTON_DAYLIGHTSENSOR=Daylightsensor -LOADER_BUTTON_INVALID=Invalid +LOADER_BUTTON_COMPARATOR=Comparator +LOADER_BUTTON_REPEATER=Repeater +LOADER_BUTTON_LECTERN=Lectern +LOADER_BUTTON_TRAPDOOR=Trapdoor +LOADER_BUTTON_DOOR=Door +LOADER_BUTTON_FENCEGATE=Fencegate LOADER_HELP_SETUP=§8/§eloader setup §8- §7Starts recording actions -LOADER_HELP_UNDO=§8/§7loader undo §8- §7Removes last recorded action LOADER_HELP_START=§8/§eloader start §8- §7Playback of previously recorded action -LOADER_HELP_WAIT=§8/§7loader wait §8[§7Ticks§8] - §7Sets wait time between shots -LOADER_HELP_SPEED=§8/§7loader speed §8[§7Ticks§8] - §7Sets wait time between actions LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pauses Loader -LOADER_HELP_RESUME=§8/§7loader resume §8- §7Resumes Loader +LOADER_HELP_SETTINGS=§8/§7loader settings §8- §7Shows Loader settings LOADER_HELP_STOP=§8/§eloader stop §8- §7Stops recording/playback -LOADER_HELP_CLEAR=§8/§eloader clear §8- §7Clears recording -LOADER_HELP_SINGLE=§8/§eloader single §8- §7Starts a single shot -LOADER_HELP_OTHER=§7The loader works with §eIngame§8-§eTicks §7(20 ticks per Second) LOADER_NO_LOADER=§cYou have no Laoder. Create one with /loader setup -LOADER_BACK_SETUP=§7DYour Loader is in Setup again LOADER_NEW=§7Load your cannon and fire it once, to initialise the loader. LOADER_HOW_TO_START=§7Then, execute /§eloader start§7 to start the Loader LOADER_ACTIVE=§7The Loader is now active. LOADER_STOP=§7The Loader has been stopped. LOADER_PAUSED=§7The Loader is now paused. -LOADER_RESUME=§7The Loader is resuming. -LOADER_SINGLE=§7The Loader is shooting once. -LOADER_SMALL_TIME=§cThe wait time is too small -LOADER_NEW_TIME=§7The wait time is now: {0}, before {1} -LOADER_NEW_LOAD_TIME=§7The action wait time is now: {0}, before {1} -LOADER_UNDO=§7Undo succesful. LOADER_PERMS=§cYou are not allowed to use the Loader here LOADER_GUI_NAME=§eLoader LOADER_GUI_NEW=§eNew Loader @@ -842,6 +831,7 @@ LOADER_GUI_SPEED=§eSpeed LOADER_GUI_SPEED_LORE=§7Currently: §e{0} LOADER_GUI_SPEED_TITLE=§7Block placing speed LOADER_GUI_STOP=§eStop Loader + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Starts the simple Loadtimer diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 9ac07bd8..ce5c7c17 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -761,47 +761,36 @@ TRACE_GUI_POSITION_EXPLODED = §7Explodiert§8: §e{0} # Loader LOADER_SETUP = §eEinrichtung LOADER_RUNNING = §aLaufend -LOADER_SINGLE_SIDEBAR = §aEiner LOADER_PAUSE = §7Pausiert LOADER_END = §8Beendet -LOADER_MESSAGE_CLEAR = §7Loader gecleart -LOADER_MESSAGE_CLEAR_HELP = §cDu must im Setup-Modus sein um den Loader zu clearen -LOADER_MESSAGE_TNT = §eTNT hinzugefügt {0} LOADER_MESSAGE_INTERACT = §e{0} hinzugefügt {1} +LOADER_BUTTON_TNT = TNT LOADER_BUTTON_SWITCH=Hebel -LOADER_BUTTON_WOOD_BUTTON=Knopf -LOADER_BUTTON_STONE_BUTTON=Knopf +LOADER_BUTTON_WOOD_BUTTON=Holzknopf +LOADER_BUTTON_STONE_BUTTON=Steinknopf LOADER_BUTTON_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_NOTEBLOCK=Noteblock LOADER_BUTTON_DAYLIGHTSENSOR=Tageslichtsensor -LOADER_BUTTON_INVALID=Invalider +LOADER_BUTTON_COMPARATOR=Comparator +LOADER_BUTTON_REPEATER=Repeater +LOADER_BUTTON_LECTERN=Lectern +LOADER_BUTTON_TRAPDOOR=Trapdoor +LOADER_BUTTON_DOOR=Door +LOADER_BUTTON_FENCEGATE=Fencegate LOADER_HELP_SETUP=§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen -LOADER_HELP_UNDO=§8/§7loader undo §8- §7Entfernt die zuletzt aufgenommene Aktion LOADER_HELP_START=§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab -LOADER_HELP_WAIT=§8/§7loader wait §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Schüssen -LOADER_HELP_SPEED=§8/§7loader speed §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Aktionen LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pausiert das Abspielen -LOADER_HELP_RESUME=§8/§7loader resume §8- §7Spielt den Loader weiter ab +LOADER_HELP_SETTINGS=§8/§7loader settings §8- §7Zeigt die Einstellungen an LOADER_HELP_STOP=§8/§eloader stop §8- §7Stoppt die Aufnahme bzw. das Abspielen -LOADER_HELP_CLEAR=§8/§eloader clear §8- §7Cleart die Aufnahme -LOADER_HELP_SINGLE=§8/§eloader single §8- §7Spielt die Aufnahme einmal ab -LOADER_HELP_OTHER=§7Der Loader arbeitet mit §eIngame§8-§eTicks §7(20 Ticks pro Sekunde) LOADER_NO_LOADER=§cDu hast noch keinen Loader. Erstelle dir einen mit /loader setup -LOADER_BACK_SETUP=§7Dein Loader ist nun wieder im Setup LOADER_NEW=§7Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren. LOADER_HOW_TO_START=§7Führe dann /§eloader start§7 um den Loader zu starten LOADER_ACTIVE=§7Der Loader ist nun aktiviert. LOADER_STOP=§7Der Loader ist nun gestoppt. LOADER_PAUSED=§7Der Loader ist nun pausiert. -LOADER_RESUME=§7Der Loader läuft nun weiter. -LOADER_SINGLE=§7Der Loader schießt einmal. -LOADER_SMALL_TIME=§cDie Wartezeit ist zu klein -LOADER_NEW_TIME=§7Die Schusswartezeit ist nun: {0}, zuvor {1} -LOADER_NEW_LOAD_TIME=§7Die Setzwartezeit ist nun: {0}, zuvor {1} -LOADER_UNDO=§7Undo erfolgreich. LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen LOADER_GUI_NAME=§eLoader LOADER_GUI_NEW=§eNeuer Loader @@ -815,6 +804,7 @@ LOADER_GUI_SPEED=§eGeschwindigkeit LOADER_GUI_SPEED_LORE=§7Aktuell: §e{0} LOADER_GUI_SPEED_TITLE=§7Block Platzier Geschwindigkeit LOADER_GUI_STOP=§eLoader Stoppen + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Startet den einfachen Loadtimer diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java index b2d7a2b8..77168028 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -76,7 +76,7 @@ public class LoaderCommand extends SWCommand { BauSystem.MESSAGE.send("LOADER_PAUSED", player); } - @Register(value = "settings", description = "LOADER_HELP_PAUSE") + @Register(value = "settings", description = "LOADER_HELP_SETTINGS") public void settingsLoader(@Validator Player player) { Loader loader = Loader.getLoader(player); if (loaderNullCheck(loader, player)) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java index 04eb1c11..16a41002 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.loadern; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.loadern.elements.LoaderElement; import de.steamwar.bausystem.features.loadern.elements.impl.*; import de.steamwar.bausystem.features.tpslimit.TPSUtils; @@ -81,6 +82,7 @@ public class LoaderRecorder implements Listener { addWaitTime(false); loaderElementList.add(new LoaderTNT(event.getBlock().getLocation())); + message("LOADER_BUTTON_TNT"); } @EventHandler @@ -97,35 +99,46 @@ public class LoaderRecorder implements Listener { 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_DAYLIGHTSENSOR"); 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(), "Trapdoor", type)); + 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(), "Door", type)); + 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(), "Fencegate", type)); + 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(), "Stone Button", type, 20)); + 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(), "Wooden Button", type, 30)); + loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30)); + message("LOADER_BUTTON_WOOD_BUTTON"); } break; } @@ -162,15 +175,18 @@ public class LoaderRecorder implements Listener { Material type = toBlock.getType(); switch (type) { case TRIPWIRE: - loaderMovement = new LoaderMovement(toBlock.getLocation(), "Tripwire", Material.STRING); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_TRIPWIRE", Material.STRING); + message("LOADER_BUTTON_TRIPWIRE"); break; case LIGHT_WEIGHTED_PRESSURE_PLATE: case HEAVY_WEIGHTED_PRESSURE_PLATE: - loaderMovement = new LoaderMovement(toBlock.getLocation(), "Weighted Pressure Plate", type); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE", type); + message("LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE"); break; default: if (type.name().endsWith("PRESSURE_PLATE")) { - loaderMovement = new LoaderMovement(toBlock.getLocation(), "Pressure Plate", type); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_PRESSURE_PLATE", type); + message("LOADER_BUTTON_PRESSURE_PLATE"); } break; } @@ -180,4 +196,8 @@ public class LoaderRecorder implements Listener { } } } + + 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/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java index 0ca03583..ec9b7f60 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -98,6 +98,7 @@ public class LoaderMovement extends LoaderInteractionElement= 0) { @@ -115,10 +117,12 @@ public class LoaderMovement extends LoaderInteractionElement { + swInventory.setItem(12, new SWItem(SWItem.getDye(1), "§c-1", Arrays.asList("§7Shift: §c-5"), false, clickType -> {}).getItemStack(), clickType -> { ticks -= clickType.isShiftClick() ? 5 : 1; if (ticks < 1) ticks = 1; swInventory.setItem(13, item(player)); @@ -171,7 +175,7 @@ public class LoaderMovement extends LoaderInteractionElement { + swInventory.setItem(14, new SWItem(SWItem.getDye(10), "§a+1", Arrays.asList("§7Shift: §a+5"), false, clickType -> {}).getItemStack(), clickType -> { ticks += clickType.isShiftClick() ? 5 : 1; swInventory.setItem(13, item(player)); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java index 1fc45d69..876a51d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java @@ -26,7 +26,6 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.data.Openable; -import org.bukkit.block.data.type.TrapDoor; import org.bukkit.entity.Player; import java.util.Arrays; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 0bdb5228..53c9e455 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -84,11 +84,13 @@ public class LoaderTicks extends LoaderInteractionElement { powerable.setPowered(false); location.getBlock().setBlockData(powerable, true); + update(powerable); if (finalWaitFor) { nextAction.run(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java index 3ea9dc28..08ba91c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -65,7 +65,7 @@ public class LoaderWait implements LoaderElement, Listener { for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); - swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { + swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1", Arrays.asList("§7Shift: §c-5"), false, clickType -> {}).getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; if (delay < 0) delay = 0; swInventory.setItem(4, menu(player)); @@ -82,7 +82,7 @@ public class LoaderWait implements LoaderElement, Listener { }); swAnvilInv.open(); }); - swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§a+1").getItemStack(), clickType -> { + swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§a+1", Arrays.asList("§7Shift: §a+5"), false, clickType -> {}).getItemStack(), clickType -> { delay += clickType.isShiftClick() ? 5 : 1; swInventory.setItem(4, menu(player)); }); From ac2900c080aa59101c368bd0789ec245da043734 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 5 May 2023 17:07:55 +0200 Subject: [PATCH 039/175] Add Loader setWaitBetween TNT and setGlobalWait Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 +- BauSystem_Main/src/BauSystem_de.properties | 2 +- .../bausystem/features/loadern/Loader.java | 60 ++++++++++++++++--- .../features/loadern/LoaderCommand.java | 6 +- .../loadern/elements/impl/LoaderWait.java | 2 + 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 7d3618d3..3b9bba5f 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -810,7 +810,7 @@ LOADER_BUTTON_FENCEGATE=Fencegate LOADER_HELP_SETUP=§8/§eloader setup §8- §7Starts recording actions LOADER_HELP_START=§8/§eloader start §8- §7Playback of previously recorded action LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pauses Loader -LOADER_HELP_SETTINGS=§8/§7loader settings §8- §7Shows Loader settings +LOADER_HELP_GUI=§8/§7loader gui §8- §7Shows Loader gui LOADER_HELP_STOP=§8/§eloader stop §8- §7Stops recording/playback LOADER_NO_LOADER=§cYou have no Laoder. Create one with /loader setup LOADER_NEW=§7Load your cannon and fire it once, to initialise the loader. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index ce5c7c17..08371f51 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -783,7 +783,7 @@ LOADER_BUTTON_FENCEGATE=Fencegate LOADER_HELP_SETUP=§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen LOADER_HELP_START=§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pausiert das Abspielen -LOADER_HELP_SETTINGS=§8/§7loader settings §8- §7Zeigt die Einstellungen an +LOADER_HELP_GUI=§8/§7loader settings §8- §7Zeigt die Einstellungen an LOADER_HELP_STOP=§8/§eloader stop §8- §7Stoppt die Aufnahme bzw. das Abspielen LOADER_NO_LOADER=§cDu hast noch keinen Loader. Erstelle dir einen mit /loader setup LOADER_NEW=§7Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 06dffc03..d5b48efa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.loadern.elements.LoaderElement; import de.steamwar.bausystem.features.loadern.elements.impl.LoaderTNT; import de.steamwar.bausystem.features.loadern.elements.impl.LoaderWait; import de.steamwar.bausystem.shared.EnumDisplay; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import lombok.AllArgsConstructor; @@ -123,7 +124,7 @@ public class Loader implements Listener { LOADER_MAP.remove(p); } - public void settings(SettingsSorting settingsSorting) { + public void gui(SettingsSorting settingsSorting) { List> list = new ArrayList<>(); for (LoaderElement element : elements) { if (settingsSorting != null) { @@ -139,17 +140,62 @@ public class Loader implements Listener { SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, loaderElement) -> {}); swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); + SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { + gui(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); + }); + if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); + swListInv.setItem(47, onlyInteractionsElements); + SWItem onlyWaitElements = new SWItem(Material.CLOCK, "§eNur Warten", clickType -> { - settings(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); + gui(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); }); if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); swListInv.setItem(48, onlyWaitElements); - SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { - settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); - }); - if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); - swListInv.setItem(50, onlyInteractionsElements); + if (settingsSorting == SettingsSorting.WAIT) { + SWItem waitBetweenTNT = new SWItem(Material.TNT, "§7Wait Time zwischen TNT", clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(p, "§7Wartezeit", ""); + swAnvilInv.setCallback(s -> { + try { + long delay = Long.parseLong(s); + if (delay < 0) delay = 0; + for (int i = 1; i < elements.size() - 1; i++) { + if (!(elements.get(i - 1) instanceof LoaderTNT)) continue; + if (!(elements.get(i + 1) instanceof LoaderTNT)) continue; + if (!(elements.get(i) instanceof LoaderWait)) continue; + ((LoaderWait) elements.get(i)).setDelay(delay); + } + } catch (NumberFormatException ignored) { + } + gui(settingsSorting); + }); + swAnvilInv.open(); + }); + swListInv.setItem(50, waitBetweenTNT); + + SWItem waitTime = new SWItem(Material.PAPER, "§7Wait Time alle", clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(p, "§7Wartezeit", ""); + swAnvilInv.setCallback(s -> { + try { + long delay = Long.parseLong(s); + if (delay < 0) delay = 0; + long finalDelay = delay; + elements.stream() + .filter(LoaderWait.class::isInstance) + .map(LoaderWait.class::cast) + .forEach(loaderWait -> loaderWait.setDelay(finalDelay)); + } catch (NumberFormatException ignored) { + } + swListInv.open(); + }); + gui(settingsSorting); + }); + swListInv.setItem(51, waitTime); + } else { + SWItem empty = new SWItem(Material.STRUCTURE_VOID, "§7", clickType -> {}); + swListInv.setItem(50, empty); + swListInv.setItem(51, empty); + } swListInv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java index 77168028..5799bc6e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -76,11 +76,11 @@ public class LoaderCommand extends SWCommand { BauSystem.MESSAGE.send("LOADER_PAUSED", player); } - @Register(value = "settings", description = "LOADER_HELP_SETTINGS") - public void settingsLoader(@Validator Player player) { + @Register(value = "gui", description = "LOADER_HELP_GUI") + public void guiLoader(@Validator Player player) { Loader loader = Loader.getLoader(player); if (loaderNullCheck(loader, player)) return; - loader.settings(null); + loader.gui(null); } @ClassValidator(value = Player.class, local = true) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java index 08ba91c6..841969fe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -25,6 +25,7 @@ import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import lombok.Getter; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -35,6 +36,7 @@ import java.util.Arrays; public class LoaderWait implements LoaderElement, Listener { @Getter + @Setter private long delay; public LoaderWait(long delay) { From 55a720eb438e1b0474cc5ff3471c7a64418e11a7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 5 May 2023 17:15:10 +0200 Subject: [PATCH 040/175] Remove unused translations Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 12 ------------ BauSystem_Main/src/BauSystem_de.properties | 12 ------------ .../loadern/elements/LoaderInteractionElement.java | 2 +- 3 files changed, 1 insertion(+), 25 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 3b9bba5f..9a9f24af 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -819,18 +819,6 @@ LOADER_ACTIVE=§7The Loader is now active. LOADER_STOP=§7The Loader has been stopped. LOADER_PAUSED=§7The Loader is now paused. LOADER_PERMS=§cYou are not allowed to use the Loader here -LOADER_GUI_NAME=§eLoader -LOADER_GUI_NEW=§eNew Loader -LOADER_GUI_START=§eStart Loader -LOADER_GUI_PAUSE=§7pause Loader -LOADER_GUI_UNDO=§7Undo last action -LOADER_GUI_WAIT=§7Shot delay -LOADER_GUI_WAIT_LORE=§7Currently: §e{0} -LOADER_GUI_WAIT_TITLE=§7Shot delay -LOADER_GUI_SPEED=§eSpeed -LOADER_GUI_SPEED_LORE=§7Currently: §e{0} -LOADER_GUI_SPEED_TITLE=§7Block placing speed -LOADER_GUI_STOP=§eStop Loader # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 08371f51..e0d12fa6 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -792,18 +792,6 @@ LOADER_ACTIVE=§7Der Loader ist nun aktiviert. LOADER_STOP=§7Der Loader ist nun gestoppt. LOADER_PAUSED=§7Der Loader ist nun pausiert. LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen -LOADER_GUI_NAME=§eLoader -LOADER_GUI_NEW=§eNeuer Loader -LOADER_GUI_START=§eLoader starten -LOADER_GUI_PAUSE=§7Loader pausieren -LOADER_GUI_UNDO=§7Letzte Aktion Rückgängig machen -LOADER_GUI_WAIT=§7Schuss Delay -LOADER_GUI_WAIT_LORE=§7Aktuell: §e{0} -LOADER_GUI_WAIT_TITLE=§7Schuss Delay -LOADER_GUI_SPEED=§eGeschwindigkeit -LOADER_GUI_SPEED_LORE=§7Aktuell: §e{0} -LOADER_GUI_SPEED_TITLE=§7Block Platzier Geschwindigkeit -LOADER_GUI_STOP=§eLoader Stoppen # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 948a3e1d..0d38cd7a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -74,7 +74,7 @@ public abstract class LoaderInteractionElement implem listInv.setItem(48, new SWItem(Material.ARROW, "§7Back", clickType -> { backAction.run(); })); - listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another", clickType -> { + listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> { T element = createNewElement(); elements.add(element); element.click(player, () -> click(player, backAction), () -> { From bb654018d602792ac27f77b6a8ea322af8ff54e4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 May 2023 01:43:28 +0200 Subject: [PATCH 041/175] Update some multilingual stuff for Loader and LoaderCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 10 ++++++++++ BauSystem_Main/src/BauSystem_de.properties | 10 ++++++++++ .../bausystem/features/loadern/Loader.java | 20 +++++++++---------- .../features/loadern/LoaderCommand.java | 2 +- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 9a9f24af..7a451354 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -807,7 +807,9 @@ LOADER_BUTTON_LECTERN=Lectern LOADER_BUTTON_TRAPDOOR=Trapdoor LOADER_BUTTON_DOOR=Door LOADER_BUTTON_FENCEGATE=Fencegate + LOADER_HELP_SETUP=§8/§eloader setup §8- §7Starts recording actions +LOADER_SETUP_STOP_FIRST=§cPlease stop the current loader first! LOADER_HELP_START=§8/§eloader start §8- §7Playback of previously recorded action LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pauses Loader LOADER_HELP_GUI=§8/§7loader gui §8- §7Shows Loader gui @@ -820,6 +822,14 @@ LOADER_STOP=§7The Loader has been stopped. LOADER_PAUSED=§7The Loader is now paused. 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 +LOADER_GUI_SHOW_INTERACTIONS=§eShow only Interactions +LOADER_GUI_SHOW_WAITS=§eShow only Waits +LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time between TNT +LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all +LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Starts the simple Loadtimer diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index e0d12fa6..38a4e4cb 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -780,7 +780,9 @@ LOADER_BUTTON_LECTERN=Lectern LOADER_BUTTON_TRAPDOOR=Trapdoor LOADER_BUTTON_DOOR=Door LOADER_BUTTON_FENCEGATE=Fencegate + LOADER_HELP_SETUP=§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen +LOADER_SETUP_STOP_FIRST=§cBitte stoppe zuerst den Loader LOADER_HELP_START=§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pausiert das Abspielen LOADER_HELP_GUI=§8/§7loader settings §8- §7Zeigt die Einstellungen an @@ -793,6 +795,14 @@ LOADER_STOP=§7Der Loader ist nun gestoppt. LOADER_PAUSED=§7Der Loader ist nun pausiert. LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen +LOADER_NOTHING_RECORDED=§cEs wurden keine Elemente aufgenommen! +LOADER_GUI_TITLE=Loader Einstellungen +LOADER_GUI_SHOW_INTERACTIONS=§eZeige Interaktionen +LOADER_GUI_SHOW_WAITS=§eZeige Wartezeiten +LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time zwischen TNT +LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle +LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Startet den einfachen Loadtimer diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index d5b48efa..a50ad0bc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -97,7 +97,7 @@ public class Loader implements Listener { recorder = null; } if (elements.isEmpty()) { - p.sendMessage("§cEs wurden keine Elemente aufgenommen!"); + BauSystem.MESSAGE.send("LOADER_NOTHING_RECORDED", p); stop(); return; } @@ -137,24 +137,24 @@ public class Loader implements Listener { } list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); } - SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, loaderElement) -> {}); + SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {}); swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); - SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { + SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_INTERACTIONS", p), clickType -> { gui(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); }); if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); swListInv.setItem(47, onlyInteractionsElements); - SWItem onlyWaitElements = new SWItem(Material.CLOCK, "§eNur Warten", clickType -> { + SWItem onlyWaitElements = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS", p), clickType -> { gui(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); }); if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); swListInv.setItem(48, onlyWaitElements); if (settingsSorting == SettingsSorting.WAIT) { - SWItem waitBetweenTNT = new SWItem(Material.TNT, "§7Wait Time zwischen TNT", clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(p, "§7Wartezeit", ""); + SWItem waitBetweenTNT = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT", p), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), ""); swAnvilInv.setCallback(s -> { try { long delay = Long.parseLong(s); @@ -173,8 +173,8 @@ public class Loader implements Listener { }); swListInv.setItem(50, waitBetweenTNT); - SWItem waitTime = new SWItem(Material.PAPER, "§7Wait Time alle", clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(p, "§7Wartezeit", ""); + SWItem waitTime = new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_ALL", p), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), ""); swAnvilInv.setCallback(s -> { try { long delay = Long.parseLong(s); @@ -186,9 +186,9 @@ public class Loader implements Listener { .forEach(loaderWait -> loaderWait.setDelay(finalDelay)); } catch (NumberFormatException ignored) { } - swListInv.open(); + gui(settingsSorting); }); - gui(settingsSorting); + swAnvilInv.open(); }); swListInv.setItem(51, waitTime); } else { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java index 5799bc6e..070b2e95 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -44,7 +44,7 @@ public class LoaderCommand extends SWCommand { @Register(value = "setup", description = "LOADER_HELP_SETUP") public void setupLoader(@Validator Player player) { if (Loader.getLoader(player) != null) { - player.sendMessage("Please stop the current loader first!"); + BauSystem.MESSAGE.send("LOADER_SETUP_STOP_FIRST", player); return; } Loader.newLoader(player); From be33184cfede23c99bbb538bb536e397e2bf9490 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 May 2023 01:50:56 +0200 Subject: [PATCH 042/175] Update some gui texts Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 5 +++++ BauSystem_Main/src/BauSystem_de.properties | 5 +++++ .../features/loadern/elements/impl/LoaderComparator.java | 7 ++++--- .../loadern/elements/impl/LoaderDaylightDetector.java | 7 ++++--- .../features/loadern/elements/impl/LoaderLectern.java | 7 ++++--- .../features/loadern/elements/impl/LoaderLever.java | 7 ++++--- .../features/loadern/elements/impl/LoaderMovement.java | 6 +++--- .../features/loadern/elements/impl/LoaderNoteBlock.java | 7 ++++--- .../features/loadern/elements/impl/LoaderOpenable.java | 7 ++++--- .../features/loadern/elements/impl/LoaderRepeater.java | 7 ++++--- .../features/loadern/elements/impl/LoaderTicks.java | 6 +++--- .../features/loadern/elements/impl/LoaderWait.java | 4 ++-- 12 files changed, 46 insertions(+), 29 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 7a451354..cd378576 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -829,6 +829,11 @@ LOADER_GUI_SHOW_WAITS=§eShow only Waits LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time between TNT LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time +LOADER_GUI_SETTINGS_TITLE=Settings +LOADER_GUI_SETTINGS_BACK=§8Back +LOADER_GUI_SETTINGS_DELETE=§cDelete +LOADER_GUI_WAIT_TITLE=Settings +LOADER_GUI_WAIT_BACK=§8Back # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 38a4e4cb..2515d945 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -802,6 +802,11 @@ LOADER_GUI_SHOW_WAITS=§eZeige Wartezeiten LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time zwischen TNT LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit +LOADER_GUI_SETTINGS_TITLE=Einstellungen +LOADER_GUI_SETTINGS_BACK=§8Zurück +LOADER_GUI_SETTINGS_DELETE=§cLöschen +LOADER_GUI_WAIT_TITLE=Wartezeit +LOADER_GUI_WAIT_BACK=§8Zurück # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java index 1205e4bf..52d51fe5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -77,10 +78,10 @@ public class LoaderComparator extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, false, null).getItemStack(), clickType -> { interact = false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index d78e6319..cc1927b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -81,10 +82,10 @@ public class LoaderDaylightDetector extends LoaderInteractionElement backAction.run()); - swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(27, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(35, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java index 5df1594d..c60e9f30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -89,10 +90,10 @@ public class LoaderLectern extends LoaderInteractionElement backAction.run()); - swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(27, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(35, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java index e83d5539..06105eaf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -78,10 +79,10 @@ public class LoaderLever extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java index ec9b7f60..6147d9c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -136,10 +136,10 @@ public class LoaderMovement extends LoaderInteractionElement backAction.run()); - swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(analogue ? 36 : 18, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java index 53811035..f36271b3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -74,10 +75,10 @@ public class LoaderNoteBlock extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, false).getItemStack(), clickType -> { interact = false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java index 876a51d4..599582ef 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -83,10 +84,10 @@ public class LoaderOpenable extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java index 102ee35c..3e0354d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -81,10 +82,10 @@ public class LoaderRepeater extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(1, item(player, false, 0).getItemStack(), clickType -> { interact = false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 53c9e455..1b6da9e4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -102,10 +102,10 @@ public class LoaderTicks extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java index 841969fe..75374abc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -63,9 +63,9 @@ public class LoaderWait implements LoaderElement, Listener { @Override public void click(Player player, Runnable backAction) { - SWInventory swInventory = new SWInventory(player, 18, "Wartezeit"); + SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", player)); for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); - swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_BACK", player)).getItemStack(), clickType -> backAction.run()); swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1", Arrays.asList("§7Shift: §c-5"), false, clickType -> {}).getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; From a73372a406b58436f0e94f2598d03688115661db Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 May 2023 22:36:33 +0200 Subject: [PATCH 043/175] Update some more messages Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 ++ BauSystem_Main/src/BauSystem_de.properties | 2 ++ .../features/loadern/elements/impl/LoaderComparator.java | 2 +- .../features/loadern/elements/impl/LoaderDaylightDetector.java | 2 +- .../bausystem/features/loadern/elements/impl/LoaderLectern.java | 2 +- .../bausystem/features/loadern/elements/impl/LoaderLever.java | 2 +- .../features/loadern/elements/impl/LoaderMovement.java | 2 +- .../features/loadern/elements/impl/LoaderNoteBlock.java | 2 +- .../features/loadern/elements/impl/LoaderOpenable.java | 2 +- .../features/loadern/elements/impl/LoaderRepeater.java | 2 +- .../bausystem/features/loadern/elements/impl/LoaderTicks.java | 2 +- .../bausystem/features/loadern/elements/impl/LoaderWait.java | 2 +- 12 files changed, 14 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index cd378576..d6e9c273 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -835,6 +835,8 @@ LOADER_GUI_SETTINGS_DELETE=§cDelete LOADER_GUI_WAIT_TITLE=Settings LOADER_GUI_WAIT_BACK=§8Back +LOADER_GUI_CLICK_TO_EDIT=§7Click to edit + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Starts the simple Loadtimer diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 2515d945..692c5253 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -808,6 +808,8 @@ LOADER_GUI_SETTINGS_DELETE=§cLöschen LOADER_GUI_WAIT_TITLE=Wartezeit LOADER_GUI_WAIT_BACK=§8Zurück +LOADER_GUI_CLICK_TO_EDIT=§7Click to edit + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Startet den einfachen Loadtimer diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java index 52d51fe5..25f874c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java @@ -57,7 +57,7 @@ public class LoaderComparator extends LoaderInteractionElement Date: Tue, 9 May 2023 11:25:47 +0200 Subject: [PATCH 044/175] Removing 1.15 only TPSWarp limiter... --- .../de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java index fff2ebe6..482ff2ee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.tpslimit; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.utils.NMSWrapper; -import de.steamwar.core.Core; import de.steamwar.core.TPSWatcher; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; @@ -42,9 +41,6 @@ public class TPSWarpUtils { public static void setTPS(double tps) { double d = 50 - (50 / (tps / 20.0)); nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000)); - if (Core.getVersion() != 15) { - return; - } if (nanoDOffset == 0) { if (bukkitTask == null) return; bukkitTask.cancel(); From 3c7168494f0d6ecde5e433d6fbe1921c9a2ddc35 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 9 May 2023 11:42:39 +0200 Subject: [PATCH 045/175] Fix TPS Warp inversion --- .../de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java index 482ff2ee..b6f4fa9a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java @@ -45,7 +45,7 @@ public class TPSWarpUtils { if (bukkitTask == null) return; bukkitTask.cancel(); bukkitTask = null; - } else if (bukkitTask != null) { + } else if (bukkitTask == null) { bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> nanoOffset += nanoDOffset, 1, 1); } } From 7785bb4c11cbc7f64371ee65d6c7a29fef12de05 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 16:44:21 +0200 Subject: [PATCH 046/175] Reenable item Signed-off-by: yoyosource --- .../features/world/OtherTNTListener.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/OtherTNTListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/OtherTNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/OtherTNTListener.java new file mode 100644 index 00000000..7cf94fc1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/OtherTNTListener.java @@ -0,0 +1,43 @@ +/* + * 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.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +@Linked +public class OtherTNTListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onExplosion(EntityExplodeEvent e) { + e.blockList().removeIf(block -> { + if(block.getType() == Material.TNT) { + return false; + } else { + block.setType(Material.AIR); + return true; + } + }); + } +} From 7c9c27ae3e89c87d4f88b99b07f4a67f4b2d3548 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 17:19:27 +0200 Subject: [PATCH 047/175] Update LoaderDaylightDetector Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 10 +++++++++- BauSystem_Main/src/BauSystem_de.properties | 2 +- .../bausystem/features/loadern/LoaderRecorder.java | 2 +- .../features/loadern/elements/ElementSettings.java | 5 +++++ .../loadern/elements/LoaderInteractionElement.java | 5 +++++ .../elements/impl/LoaderDaylightDetector.java | 12 ++++++------ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index d6e9c273..5dfba6ed 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -800,7 +800,7 @@ LOADER_BUTTON_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_NOTEBLOCK=Noteblock -LOADER_BUTTON_DAYLIGHTSENSOR=Daylightsensor +LOADER_BUTTON_DAYLIGHT_DETECTOR=Daylight Detector LOADER_BUTTON_COMPARATOR=Comparator LOADER_BUTTON_REPEATER=Repeater LOADER_BUTTON_LECTERN=Lectern @@ -836,6 +836,14 @@ LOADER_GUI_WAIT_TITLE=Settings LOADER_GUI_WAIT_BACK=§8Back LOADER_GUI_CLICK_TO_EDIT=§7Click to edit +LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1} +LOADER_SETTING_NAME=§7{0} +LOADER_SETTING_MODES=§7Modes§8: §e{0} +LOADER_SETTING_POWER=§7Power§8: §e{0} +LOADER_INTERACTION_NOOP=NOOP +LOADER_INTERACTION_INTERACT=Interact +LOADER_INTERACTION_POWERED=Powered +LOADER_INTERACTION_UNPOWERED=Unpowered # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 692c5253..5495c3be 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -773,7 +773,7 @@ LOADER_BUTTON_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_NOTEBLOCK=Noteblock -LOADER_BUTTON_DAYLIGHTSENSOR=Tageslichtsensor +LOADER_BUTTON_DAYLIGHT_DETECTOR=Tageslichtsensor LOADER_BUTTON_COMPARATOR=Comparator LOADER_BUTTON_REPEATER=Repeater LOADER_BUTTON_LECTERN=Lectern diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java index 16a41002..135cd7ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -115,7 +115,7 @@ public class LoaderRecorder implements Listener { break; case DAYLIGHT_DETECTOR: loaderElementList.add(new LoaderDaylightDetector(block.getLocation())); - message("LOADER_BUTTON_DAYLIGHTSENSOR"); + message("LOADER_BUTTON_DAYLIGHT_DETECTOR"); break; case LECTERN: loaderElementList.add(new LoaderLectern(block.getLocation())); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java index 5142e8cf..f2a63b69 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements; +import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; @@ -28,4 +29,8 @@ public interface ElementSettings { void click(Player player, Runnable backAction, Runnable deleteAction); default void playerInteract() {} + + default String translateItemName(String name, String mode, Player player) { + return BauSystem.MESSAGE.parse("LOADER_GUI_ITEM_NAME", player, BauSystem.MESSAGE.parse(name, player), BauSystem.MESSAGE.parse(mode, player)); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 0d38cd7a..eabd054f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements; +import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import org.bukkit.Location; @@ -117,4 +118,8 @@ public abstract class LoaderInteractionElement implem } public abstract T createNewElement(); + + protected final String translateItemName(String name, Player player) { + return BauSystem.MESSAGE.parse("LOADER_SETTING_NAME", player, BauSystem.MESSAGE.parse(name, player)); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index d5c0192e..f81236c7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -53,11 +53,11 @@ public class LoaderDaylightDetector extends LoaderInteractionElement Date: Tue, 9 May 2023 18:28:53 +0200 Subject: [PATCH 048/175] Add all translations Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 38 +++++++++++++++---- BauSystem_Main/src/BauSystem_de.properties | 30 +++++++++++++++ .../bausystem/features/loadern/Loader.java | 9 ++--- .../loadern/elements/ElementSettings.java | 4 +- .../elements/impl/LoaderDaylightDetector.java | 4 +- .../loadern/elements/impl/LoaderLectern.java | 12 +++--- .../loadern/elements/impl/LoaderLever.java | 10 ++--- .../loadern/elements/impl/LoaderMovement.java | 22 +++++------ .../elements/impl/LoaderNoteBlock.java | 8 ++-- .../loadern/elements/impl/LoaderOpenable.java | 10 ++--- .../loadern/elements/impl/LoaderRepeater.java | 10 ++--- .../loadern/elements/impl/LoaderTNT.java | 4 +- .../loadern/elements/impl/LoaderTicks.java | 10 ++--- .../loadern/elements/impl/LoaderWait.java | 8 ++-- 14 files changed, 107 insertions(+), 72 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 5dfba6ed..9f4b2edb 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -791,8 +791,8 @@ LOADER_RUNNING = §aRunning LOADER_PAUSE = §7Pause LOADER_END = §8Finished -LOADER_MESSAGE_INTERACT = §e{0} added {1} -LOADER_BUTTON_TNT = TNT +LOADER_MESSAGE_INTERACT=§e{0} added {1} +LOADER_BUTTON_TNT=TNT LOADER_BUTTON_SWITCH=Lever LOADER_BUTTON_WOOD_BUTTON=Wooden Button LOADER_BUTTON_STONE_BUTTON=Stone Button @@ -835,15 +835,37 @@ LOADER_GUI_SETTINGS_DELETE=§cDelete LOADER_GUI_WAIT_TITLE=Settings LOADER_GUI_WAIT_BACK=§8Back -LOADER_GUI_CLICK_TO_EDIT=§7Click to edit +LOADER_GUI_CLICK_TO_EDIT=§7Klicke zum editieren LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1} LOADER_SETTING_NAME=§7{0} -LOADER_SETTING_MODES=§7Modes§8: §e{0} -LOADER_SETTING_POWER=§7Power§8: §e{0} +LOADER_SETTING_MODES=§7Modi§8: §e{0} +LOADER_SETTING_POWER=§7Redstone Stärke§8: §e{0} +LOADER_SETTING_TICKS=§7Ticks§8: §e{0} +LOADER_SETTING_REPEATER=§7Repeater§8: §e{0} +LOADER_SETTING_WAIT=§7Wartezeit§8: §e{0} Tick(s) +LOADER_SETTING_WAIT_NAME=Wartezeit +LOADER_SETTING_TICKS_NAME=Ticks +LOADER_SETTING_TICKS_REMOVE_ONE=§c-1 +LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5 +LOADER_SETTING_TICKS_ADD_ONE=§a+1 +LOADER_SETTING_TICKS_ADD_ONE_SHIFT=§7Shift§8: §a+5 +LOADER_SETTING_TNT_NAME=§cTNT +LOADER_SETTING_TNT_X=§7X§8: §e{0} +LOADER_SETTING_TNT_Y=§7Y§8: §e{0} +LOADER_SETTING_TNT_Z=§7Z§8: §e{0} LOADER_INTERACTION_NOOP=NOOP -LOADER_INTERACTION_INTERACT=Interact -LOADER_INTERACTION_POWERED=Powered -LOADER_INTERACTION_UNPOWERED=Unpowered +LOADER_INTERACTION_INTERACT=Interagiere +LOADER_INTERACTION_POWERED=Aktiviert +LOADER_INTERACTION_UNPOWERED=Deaktiviert +LOADER_INTERACTION_PAGE_PREV=Vorherige Seite +LOADER_INTERACTION_PAGE_NEXT=Nächste Seite +LOADER_INTERACTION_PAGE=Seite {0} +LOADER_INTERACTION_ACTIVE=Aktiviert +LOADER_INTERACTION_INACTIVE=Deaktiviert +LOADER_INTERACTION_WAIT_FOR=Darauf warten +LOADER_INTERACTION_NO_WAIT_FOR=Nicht darauf warten +LOADER_INTERACTION_OPEN=Geöffnet +LOADER_INTERACTION_CLOSED=Geschlossen # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 5495c3be..97ba1f97 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -809,6 +809,36 @@ LOADER_GUI_WAIT_TITLE=Wartezeit LOADER_GUI_WAIT_BACK=§8Zurück LOADER_GUI_CLICK_TO_EDIT=§7Click to edit +LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1} +LOADER_SETTING_NAME=§7{0} +LOADER_SETTING_MODES=§7Modes§8: §e{0} +LOADER_SETTING_POWER=§7Power§8: §e{0} +LOADER_SETTING_TICKS=§7Ticks§8: §e{0} +LOADER_SETTING_REPEATER=§7Repeater§8: §e{0} +LOADER_SETTING_WAIT=§7Wait§8: §e{0} Tick(s) +LOADER_SETTING_WAIT_NAME=Wait +LOADER_SETTING_TICKS_NAME=Ticks +LOADER_SETTING_TICKS_REMOVE_ONE=§c-1 +LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5 +LOADER_SETTING_TICKS_ADD_ONE=§a+1 +LOADER_SETTING_TICKS_ADD_ONE_SHIFT=§7Shift§8: §a+5 +LOADER_SETTING_TNT_NAME=§cTNT +LOADER_SETTING_TNT_X=§7X§8: §e{0} +LOADER_SETTING_TNT_Y=§7Y§8: §e{0} +LOADER_SETTING_TNT_Z=§7Z§8: §e{0} +LOADER_INTERACTION_NOOP=NOOP +LOADER_INTERACTION_INTERACT=Interact +LOADER_INTERACTION_POWERED=Powered +LOADER_INTERACTION_UNPOWERED=Unpowered +LOADER_INTERACTION_PAGE_PREV=Previous Page +LOADER_INTERACTION_PAGE_NEXT=Next Page +LOADER_INTERACTION_PAGE=Page {0} +LOADER_INTERACTION_ACTIVE=Active +LOADER_INTERACTION_INACTIVE=Inactive +LOADER_INTERACTION_WAIT_FOR=Wait for +LOADER_INTERACTION_NO_WAIT_FOR=No wait for +LOADER_INTERACTION_OPEN=Open +LOADER_INTERACTION_CLOSED=Closed # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index a50ad0bc..612ebd28 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -36,10 +36,7 @@ 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.List; -import java.util.Map; +import java.util.*; public class Loader implements Listener { @@ -135,7 +132,9 @@ public class Loader implements Listener { continue; } } - list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); + SWItem item = element.menu(p); + item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, elements.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p))); + list.add(new SWListInv.SWListEntry<>(item, element)); } SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {}); swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java index f2a63b69..be62173c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java @@ -30,7 +30,7 @@ public interface ElementSettings { default void playerInteract() {} - default String translateItemName(String name, String mode, Player player) { - return BauSystem.MESSAGE.parse("LOADER_GUI_ITEM_NAME", player, BauSystem.MESSAGE.parse(name, player), BauSystem.MESSAGE.parse(mode, player)); + default String translateItemName(String name, String mode, Player player, Object... args) { + return BauSystem.MESSAGE.parse("LOADER_GUI_ITEM_NAME", player, BauSystem.MESSAGE.parse(name, player), BauSystem.MESSAGE.parse(mode, player, args)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index f81236c7..42d1909f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -148,9 +148,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement {}).getItemStack(), clickType -> { + swInventory.setItem(12, new SWItem(SWItem.getDye(1), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { ticks -= clickType.isShiftClick() ? 5 : 1; if (ticks < 1) ticks = 1; swInventory.setItem(13, item(player)); }); swInventory.setItem(13, item(player).getItemStack(), clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Ticks", ticks + ""); + SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_NAME", player), ticks + ""); swAnvilInv.setCallback(s -> { try { ticks = Long.parseLong(s); @@ -175,7 +175,7 @@ public class LoaderMovement extends LoaderInteractionElement {}).getItemStack(), clickType -> { + swInventory.setItem(14, new SWItem(SWItem.getDye(10), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { ticks += clickType.isShiftClick() ? 5 : 1; swInventory.setItem(13, item(player)); }); @@ -205,25 +205,23 @@ public class LoaderMovement extends LoaderInteractionElement backAction.run()); - swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1", Arrays.asList("§7Shift: §c-5"), false, clickType -> {}).getItemStack(), clickType -> { + swInventory.setItem(3, new SWItem(SWItem.getDye(1), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; if (delay < 0) delay = 0; swInventory.setItem(4, menu(player)); }); swInventory.setItem(4, menu(player).getItemStack(), clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "§7Wartezeit", delay + ""); + SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_SETTING_WAIT_NAME", player), delay + ""); swAnvilInv.setCallback(s -> { try { delay = Long.parseLong(s); @@ -84,7 +84,7 @@ public class LoaderWait implements LoaderElement, Listener { }); swAnvilInv.open(); }); - swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§a+1", Arrays.asList("§7Shift: §a+5"), false, clickType -> {}).getItemStack(), clickType -> { + swInventory.setItem(5, new SWItem(SWItem.getDye(10), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { delay += clickType.isShiftClick() ? 5 : 1; swInventory.setItem(4, menu(player)); }); From f6357c2a376b401411fb1b8b725f1d24e3db28ad Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 18:31:03 +0200 Subject: [PATCH 049/175] Fix package name Signed-off-by: yoyosource --- .../bausystem/features/{loadern => loader}/Loader.java | 8 ++++---- .../features/{loadern => loader}/LoaderCommand.java | 2 +- .../features/{loadern => loader}/LoaderRecorder.java | 6 +++--- .../{loadern => loader}/LoaderScoreboardElement.java | 2 +- .../{loadern => loader}/elements/ElementSettings.java | 2 +- .../{loadern => loader}/elements/LoaderElement.java | 2 +- .../elements/LoaderInteractionElement.java | 2 +- .../elements/impl/LoaderComparator.java | 6 +++--- .../elements/impl/LoaderDaylightDetector.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderLectern.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderLever.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderMovement.java | 6 +++--- .../elements/impl/LoaderNoteBlock.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderOpenable.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderRepeater.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderTNT.java | 4 ++-- .../{loadern => loader}/elements/impl/LoaderTicks.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderWait.java | 4 ++-- .../bausystem/features/script/variables/Constants.java | 2 +- 19 files changed, 44 insertions(+), 44 deletions(-) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/Loader.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/LoaderCommand.java (98%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/LoaderRecorder.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/LoaderScoreboardElement.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/ElementSettings.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/LoaderElement.java (94%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/LoaderInteractionElement.java (98%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderComparator.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderDaylightDetector.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderLectern.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderLever.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderMovement.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderNoteBlock.java (95%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderOpenable.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderRepeater.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderTNT.java (94%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderTicks.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderWait.java (96%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index 612ebd28..6b61f14f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern; +package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.LoaderElement; -import de.steamwar.bausystem.features.loadern.elements.impl.LoaderTNT; -import de.steamwar.bausystem.features.loadern.elements.impl.LoaderWait; +import de.steamwar.bausystem.features.loader.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT; +import de.steamwar.bausystem.features.loader.elements.impl.LoaderWait; import de.steamwar.bausystem.shared.EnumDisplay; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java similarity index 98% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java index 070b2e95..ee03be16 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern; +package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java index 135cd7ac..f42ad0db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern; +package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.loadern.elements.LoaderElement; -import de.steamwar.bausystem.features.loadern.elements.impl.*; +import de.steamwar.bausystem.features.loader.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.impl.*; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java index e9fc9004..b3e2ba2f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern; +package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java index be62173c..7650878c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements; +package de.steamwar.bausystem.features.loader.elements; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java similarity index 94% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java index 4b1734bd..eb173dc5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements; +package de.steamwar.bausystem.features.loader.elements; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java similarity index 98% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java index eabd054f..dad60ebf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements; +package de.steamwar.bausystem.features.loader.elements; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java index 25f874c3..fef006f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java index 42d1909f..10c2b74c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java index 5ed7cfdf..b2cf3ff4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java index 1e20094c..911daf57 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java index 00d6855d..55c41fd7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderNoteBlock.java similarity index 95% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderNoteBlock.java index 40a7a198..b8c04fe8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderNoteBlock.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Instrument; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java index a63cbdb1..de4abe42 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java index b73f3a56..26234c54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java similarity index 94% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java index 929b14c2..6c95bf71 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.LoaderElement; import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java index 6f09ba4a..098d29ea 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java index 2dc8eb19..0c694a87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.LoaderElement; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index 10d4a75d..e0ec0872 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -1,7 +1,7 @@ package de.steamwar.bausystem.features.script.variables; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.Loader; +import de.steamwar.bausystem.features.loader.Loader; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.record.ActiveTracer; From 76631908f0898b370510e45f7e718769d036b666 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 19:45:27 +0200 Subject: [PATCH 050/175] Add Flag.ITEMS for 1.19 server and up Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 9 ++ BauSystem_Main/src/BauSystem_de.properties | 9 ++ .../features/region/ItemsCommand.java | 87 +++++++++++++++++++ .../features/region/ItemsListener.java | 68 +++++++++++++++ .../bausystem/region/FlagStorage.java | 2 +- .../steamwar/bausystem/region/flags/Flag.java | 4 +- .../region/flags/flagvalues/ItemMode.java | 60 +++++++++++++ 7 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsListener.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 9f4b2edb..fcc1f0e5 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -46,6 +46,7 @@ FLAG_TNT = TNT FLAG_FIRE = Fire FLAG_FREEZE = Freeze FLAG_PROTECT = Protect +FLAG_ITEMS = Items FLAG_FIRE_ALLOW = §con FLAG_FIRE_DENY = §aoff @@ -60,6 +61,9 @@ FLAG_TNT_ALLOW = §aon FLAG_TNT_DENY = §coff FLAG_TNT_ONLY_TB = §7no §ebuild area +FLAG_ITEMS_ACTIVE = §aon +FLAG_ITEMS_INACTIVE = §coff + FLAG_COLOR_WHITE = §fWhite FLAG_COLOR_ORANGE = §6Orange FLAG_COLOR_MAGENTA = §dMagenta @@ -1052,6 +1056,11 @@ 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=§cItems disabled in this region +REGION_ITEMS_ENABLED_GLOBAL=§cItems disabled in this world +REGION_ITEMS_DISABLED=§aItems enabled in this region REGION_PROTECT_HELP=§8/§eprotect §8- §7Protect the region REGION_PROTECT_DISABLE=§cProtection disabled REGION_PROTECT_ENABLE=§aProtection enabled diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 97ba1f97..b9e86e58 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -46,6 +46,7 @@ FLAG_TNT = TNT FLAG_FIRE = Fire FLAG_FREEZE = Freeze FLAG_PROTECT = Protect +FLAG_ITEMS = Items FLAG_FIRE_ALLOW = §can FLAG_FIRE_DENY = §aaus @@ -60,6 +61,9 @@ FLAG_TNT_ALLOW = §aan FLAG_TNT_DENY = §caus FLAG_TNT_ONLY_TB = §7Kein §eBaurahmen +FLAG_ITEMS_ACTIVE = §aan +FLAG_ITEMS_INACTIVE = §caus + FLAG_COLOR_WHITE = §fWeiß FLAG_COLOR_ORANGE = §6Orange FLAG_COLOR_MAGENTA = §dMagenta @@ -1021,6 +1025,11 @@ 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=§cItems deaktiviert in dieser Region +REGION_ITEMS_ENABLED_GLOBAL=§cItems sind auf dem Server deaktiviert. +REGION_ITEMS_DISABLED=§aItems aktiviert in dieser Region REGION_PROTECT_HELP=§8/§eprotect §8- §7Schütze die Region REGION_PROTECT_DISABLE=§cBoden Schutz aufgehoben REGION_PROTECT_ENABLE=§aBoden geschützt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java new file mode 100644 index 00000000..8eb42c64 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -0,0 +1,87 @@ +/* + * 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.region; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ItemMode; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; +import org.bukkit.entity.Player; + +@Linked +@MinVersion(19) +public class ItemsCommand extends SWCommand { + + public ItemsCommand() { + super("items"); + } + + @Register(description = "REGION_ITEMS_HELP") + public void toggleCommand(@Validator Player p) { + Region region = Region.getRegion(p.getLocation()); + if (region != GlobalRegion.getInstance() && GlobalRegion.getInstance().getPlain(Flag.ITEMS, ItemMode.class) == ItemMode.INACTIVE) { + RegionUtils.actionBar(region, "REGION_ITEMS_ENABLED_GLOBAL"); + return; + } + + if (toggle(region)) { + RegionUtils.actionBar(region, getEnableMessage()); + } else { + RegionUtils.actionBar(region, getDisableMessage()); + } + } + + private String getNoPermMessage() { + return "REGION_ITEMS_NO_PERMS"; + } + + private String getEnableMessage(){ + return "REGION_ITEMS_ENABLED"; + } + + private String getDisableMessage(){ + return "REGION_ITEMS_DISABLED"; + } + + private boolean toggle(Region region) { + switch (region.getPlain(Flag.ITEMS, ItemMode.class)) { + case ACTIVE: + region.set(Flag.ITEMS, ItemMode.INACTIVE); + return false; + default: + case INACTIVE: + region.set(Flag.ITEMS, ItemMode.ACTIVE); + 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/ItemsListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsListener.java new file mode 100644 index 00000000..1becf08b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsListener.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.region; + +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.region.flags.flagvalues.ItemMode; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.ItemSpawnEvent; + +@Linked +@MinVersion(19) +public class ItemsListener implements Listener, ScoreboardElement { + + private static ItemMode getMode(Region region) { + ItemMode itemMode = GlobalRegion.getInstance().getPlain(Flag.ITEMS, ItemMode.class); + if (itemMode == ItemMode.INACTIVE) return ItemMode.INACTIVE; + return region.getPlain(Flag.ITEMS, ItemMode.class); + } + + @EventHandler + public void onItemSpawn(ItemSpawnEvent event) { + if (getMode(Region.getRegion(event.getLocation())) == ItemMode.INACTIVE) { + event.setCancelled(true); + } + } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 3; + } + + @Override + public String get(Region region, Player p) { + ItemMode itemMode = getMode(region); + if (itemMode == ItemMode.ACTIVE) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.ITEMS.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(itemMode.getChatValue(), p); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java index b89f3df5..e0ee43a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java @@ -84,7 +84,7 @@ public class FlagStorage { } public Flag.Value get(final Flag flagType) { - return flags.get(flagType); + return flags.getOrDefault(flagType, flagType.getDefaultValue()); } public boolean set(final Tag tag) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index 0c45d1ce..86888666 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -33,7 +33,9 @@ public enum Flag implements EnumDisplay { TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB), FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW), FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE), - PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE); + PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE), + ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.ACTIVE), + ; @Getter private static final Set flags; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java new file mode 100644 index 00000000..c0cefa38 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java @@ -0,0 +1,60 @@ +/* + * 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.region.flags.flagvalues; + +import de.steamwar.bausystem.region.flags.Flag; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ItemMode implements Flag.Value { + + ACTIVE("FLAG_ITEMS_ACTIVE"), + INACTIVE("FLAG_ITEMS_INACTIVE"); + + private static ItemMode[] values; + private final String chatValue; + + @Override + public ItemMode[] getValues() { + if (ItemMode.values == null) { + ItemMode.values = ItemMode.values(); //NOSONAR + } + return ItemMode.values; + } + + @Override + public ItemMode getValue() { + return this; + } + + @Override + public ItemMode getValueOf(final String name) { + try { + return ItemMode.valueOf(name.toUpperCase()); + } catch (IllegalArgumentException e) { + if (name.equalsIgnoreCase("false")) { + return ItemMode.INACTIVE; + } + return ItemMode.ACTIVE; + } + } +} From d715a6a066fca112d88af81f393874fe46f03bf7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 19:56:41 +0200 Subject: [PATCH 051/175] Hotfix BauInfoBauGuiItem Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + .../de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index fcc1f0e5..438728ee 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -144,6 +144,7 @@ BAU_INFO_ITEM_LORE_DAMAGE= BAU_INFO_ITEM_LORE_FIRE = §7Fire§8: §e{0} BAU_INFO_ITEM_LORE_COLOR = §7Color§8: §e{0} BAU_INFO_ITEM_LORE_PROTECT = §7Protect§8: §e{0} +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: §e{0} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java index 7f3c27b9..d8ba9171 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import de.steamwar.sql.SteamwarUser; @@ -58,6 +59,9 @@ public class BauInfoBauGuiItem extends BauGuiItem { if (flag == Flag.PROTECT && region.getFloorLevel() == 0) { continue; } + if (flag == Flag.ITEMS && Core.getVersion() < 19) { + continue; + } Flag.Value value = region.get(flag); if (value != null) { stringList.add(BauSystem.MESSAGE.parse("BAU_INFO_ITEM_LORE_" + flag.name(), player, BauSystem.MESSAGE.parse(value.getChatValue(), player))); From 911f91a5706d3e8e3cd4d5de15c4549ec09d54e8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 21:10:52 +0200 Subject: [PATCH 052/175] Fix messages Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 6 +++--- BauSystem_Main/src/BauSystem_de.properties | 6 +++--- .../de/steamwar/bausystem/features/region/ItemsCommand.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 438728ee..448fd952 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1059,9 +1059,9 @@ 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=§cItems disabled in this region -REGION_ITEMS_ENABLED_GLOBAL=§cItems disabled in this world -REGION_ITEMS_DISABLED=§aItems enabled in this region +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 diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index b9e86e58..804afa46 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -1027,9 +1027,9 @@ 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=§cItems deaktiviert in dieser Region -REGION_ITEMS_ENABLED_GLOBAL=§cItems sind auf dem Server deaktiviert. -REGION_ITEMS_DISABLED=§aItems aktiviert in dieser Region +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 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 8eb42c64..3b99382d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -43,7 +43,7 @@ public class ItemsCommand extends SWCommand { public void toggleCommand(@Validator Player p) { Region region = Region.getRegion(p.getLocation()); if (region != GlobalRegion.getInstance() && GlobalRegion.getInstance().getPlain(Flag.ITEMS, ItemMode.class) == ItemMode.INACTIVE) { - RegionUtils.actionBar(region, "REGION_ITEMS_ENABLED_GLOBAL"); + RegionUtils.actionBar(region, "REGION_ITEMS_DISABLED_GLOBAL"); return; } From d2473ee72f91608653e8701f57532de52554ff83 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 10 May 2023 20:59:42 +0200 Subject: [PATCH 053/175] Add global ItemsCommand Signed-off-by: yoyosource --- .../bausystem/features/region/ItemsCommand.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 3b99382d..157f16ae 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -54,6 +54,16 @@ public class ItemsCommand extends SWCommand { } } + @Register(value = "global", description = "REGION_ITEMS_HELP") + public void globalToggleCommand(@Validator Player p) { + Region region = GlobalRegion.getInstance(); + if (toggle(region)) { + RegionUtils.actionBar(region, getEnableMessage()); + } else { + RegionUtils.actionBar(region, getDisableMessage()); + } + } + private String getNoPermMessage() { return "REGION_ITEMS_NO_PERMS"; } From 6b395bde172f395567d55a711dbebd9a9d317c19 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 10 May 2023 21:03:28 +0200 Subject: [PATCH 054/175] Remove help Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/region/ItemsCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 157f16ae..cbde76cf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -54,7 +54,7 @@ public class ItemsCommand extends SWCommand { } } - @Register(value = "global", description = "REGION_ITEMS_HELP") + @Register(value = "global") public void globalToggleCommand(@Validator Player p) { Region region = GlobalRegion.getInstance(); if (toggle(region)) { From 072833f503b2dd1d3e8e5a6eae24a131c829cfb9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 13 May 2023 11:09:28 +0200 Subject: [PATCH 055/175] Fix TPSLimit Freeze Signed-off-by: yoyosource --- .../bausystem/features/script/variables/Constants.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index e0ec0872..b14310b2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.features.script.variables; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.tpslimit.FreezeUtils; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.record.ActiveTracer; @@ -275,7 +276,10 @@ public class Constants { }); CONSTANTS.put("tps", player -> { - return new ConstantDoubleValue(TPSWatcher::getTPS); + return new ConstantDoubleValue(() -> { + if (FreezeUtils.isFrozen()) return 0.0; + return TPSWatcher.getTPS(); + }); }); CONSTANTS.put("tps_limit", player -> { return new ConstantDoubleValue(TPSLimitUtils::getCurrentTPSLimit); From 16a6d10472fac763b225fedbb9eaa7db87897953 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 19 May 2023 19:29:38 +0200 Subject: [PATCH 056/175] Script System Lua Todo: * /script and global script storage * Code Cleanup --- .../linkage/types/LuaLib_GENERIC.java | 21 ++ .../linkage/types/Operator_GENERIC.java | 40 -- .../linkage/types/SpecialCommand_GENERIC.java | 40 -- BauSystem_Main/build.gradle | 2 + .../features/region/TNTListener.java | 19 +- .../features/script/CustomScriptManager.java | 342 ------------------ .../features/script/ScriptCommand.java | 153 -------- .../features/script/ScriptExecutor.java | 304 ---------------- .../features/script/ScriptListener.java | 30 +- .../features/script/ScriptRunner.java | 75 ++++ .../features/script/ScriptSyntaxSender.java | 105 ------ .../features/script/SpecialCommand.java | 86 ----- .../features/script/command/Call.java | 49 --- .../features/script/command/Exit.java | 41 --- .../bausystem/features/script/command/If.java | 68 ---- .../features/script/command/Jump.java | 49 --- .../features/script/command/Return.java | 43 --- .../features/script/command/Sleep.java | 58 --- .../script/command/arithmetic/other/Ceil.java | 107 ------ .../command/arithmetic/other/Floor.java | 107 ------ .../command/arithmetic/other/Round.java | 107 ------ .../features/script/command/io/Echo.java | 62 ---- .../script/command/io/Echoactionbar.java | 62 ---- .../features/script/command/io/Input.java | 79 ---- .../script/command/string/Insert.java | 98 ----- .../script/command/string/Remove.java | 89 ----- .../script/command/string/Replace.java | 98 ----- .../script/command/string/Substring.java | 99 ----- .../script/command/variable/Const.java | 87 ----- .../script/command/variable/Convert.java | 74 ---- .../script/command/variable/Global.java | 67 ---- .../script/command/variable/Unglobal.java | 49 --- .../script/command/variable/Unvar.java | 49 --- .../features/script/command/variable/Var.java | 67 ---- .../script/command/world/GetMaterial.java | 89 ----- .../script/command/world/SetMaterial.java | 92 ----- .../features/script/custom/MenuScript.java | 29 -- .../features/script/custom/Script.java | 23 -- .../custom/command/CommandListener.java | 45 --- .../script/custom/command/CustomCommand.java | 87 ----- .../custom/command/InventoryCommand.java | 51 --- .../script/custom/command/MenuCommand.java | 99 ----- .../script/custom/event/CustomEvent.java | 34 -- .../script/custom/event/EventType.java | 133 ------- .../script/custom/event/InventoryEvent.java | 47 --- .../script/custom/event/MenuEvent.java | 76 ---- .../features/script/custom/hotkey/Hotkey.java | 29 -- .../script/custom/hotkey/HotkeyListener.java | 57 --- .../script/custom/hotkey/Hotkeys.java | 135 ------- .../script/custom/hotkey/InventoryHotkey.java | 51 --- .../script/custom/hotkey/MenuHotkey.java | 80 ---- .../script/event/CommandListener.java | 22 ++ .../{custom => }/event/EventListener.java | 85 +++-- .../script/expression/Expression.java | 242 ------------- .../features/script/expression/Operator.java | 37 -- .../expression/UnknownOperatorException.java | 27 -- .../expression/VarNotFoundException.java | 27 -- .../operator/comparison/EqualOperator.java | 61 ---- .../operator/comparison/GreaterOperator.java | 50 --- .../comparison/GreaterOrEqualOperator.java | 50 --- .../operator/comparison/LessOperator.java | 50 --- .../comparison/LessOrEqualOperator.java | 50 --- .../operator/comparison/NotEqualOperator.java | 61 ---- .../operator/logic/AndOperator.java | 47 --- .../operator/logic/BitwiseAndOperator.java | 55 --- .../operator/logic/BitwiseOrOperator.java | 55 --- .../operator/logic/BitwiseXorOperator.java | 55 --- .../expression/operator/logic/OrOperator.java | 47 --- .../operator/math/BitwiseLeftOperator.java | 46 --- .../math/BitwiseLogicRightOperator.java | 46 --- .../operator/math/BitwiseRightOperator.java | 46 --- .../operator/math/DivideOperator.java | 49 --- .../operator/math/MinusOperator.java | 50 --- .../operator/math/ModuloOperator.java | 46 --- .../operator/math/MultiplyOperator.java | 57 --- .../operator/math/PlusOperator.java | 53 --- .../operator/math/PowerOperator.java | 46 --- .../script/items/ScriptMenuBauGuiItem.java | 55 --- .../features/script/lua/CommandRegister.java | 15 + .../script/lua/SteamWarGlobalLuaPlugin.java | 74 ++++ .../script/lua/SteamWarLuaPlugin.java | 144 ++++++++ .../features/script/lua/SteamWarPlatform.java | 40 ++ .../features/script/lua/libs/LuaLib.java | 88 +++++ .../features/script/lua/libs/PlayerLib.java | 66 ++++ .../features/script/lua/libs/RegionLib.java | 58 +++ .../features/script/lua/libs/ServerLib.java | 65 ++++ .../features/script/variables/Constants.java | 315 ---------------- .../features/script/variables/Context.java | 42 --- .../features/script/variables/Value.java | 188 ---------- SCRIPT.md | 183 ++++++++++ 90 files changed, 919 insertions(+), 5857 deletions(-) create mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java delete mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java delete mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java rename BauSystem_Main/src/de/steamwar/bausystem/features/script/{custom => }/event/EventListener.java (52%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Operator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/UnknownOperatorException.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/VarNotFoundException.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/EqualOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOrEqualOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOrEqualOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/NotEqualOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/AndOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseAndOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseOrOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseXorOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/OrOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLeftOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLogicRightOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseRightOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MinusOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/ModuloOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MultiplyOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PlusOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PowerOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/items/ScriptMenuBauGuiItem.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java create mode 100644 SCRIPT.md diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java new file mode 100644 index 00000000..79c02770 --- /dev/null +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java @@ -0,0 +1,21 @@ +package de.steamwar.linkage.types; + +import de.steamwar.linkage.LinkageType; +import de.steamwar.linkage.plan.BuildPlan; +import de.steamwar.linkage.plan.MethodBuilder; + +import javax.lang.model.element.TypeElement; + +public class LuaLib_GENERIC implements LinkageType { + + @Override + public String method() { + return "link"; + } + + @Override + public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { + buildPlan.addImport("de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin"); + methodBuilder.addLine("SteamWarLuaPlugin.add(" + s + ");"); + } +} diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java deleted file mode 100644 index 8a1916a8..00000000 --- a/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java +++ /dev/null @@ -1,40 +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.linkage.types; - -import de.steamwar.linkage.LinkageType; -import de.steamwar.linkage.plan.BuildPlan; -import de.steamwar.linkage.plan.MethodBuilder; - -import javax.lang.model.element.TypeElement; - -public class Operator_GENERIC implements LinkageType { - - @Override - public String method() { - return "linkScriptCommands"; - } - - @Override - public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { - buildPlan.addImport("de.steamwar.bausystem.features.script.expression.Expression"); - methodBuilder.addLine("Expression.registerOperator(" + s + ");"); - } -} diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java deleted file mode 100644 index 97c63276..00000000 --- a/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java +++ /dev/null @@ -1,40 +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.linkage.types; - -import de.steamwar.linkage.LinkageType; -import de.steamwar.linkage.plan.BuildPlan; -import de.steamwar.linkage.plan.MethodBuilder; - -import javax.lang.model.element.TypeElement; - -public class SpecialCommand_GENERIC implements LinkageType { - - @Override - public String method() { - return "linkScriptCommands"; - } - - @Override - public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { - buildPlan.addImport("de.steamwar.bausystem.features.script.ScriptExecutor"); - methodBuilder.addLine("ScriptExecutor.SPECIAL_COMMANDS.add(" + s + ");"); - } -} diff --git a/BauSystem_Main/build.gradle b/BauSystem_Main/build.gradle index 1052e30a..2e9a8d6c 100644 --- a/BauSystem_Main/build.gradle +++ b/BauSystem_Main/build.gradle @@ -64,4 +64,6 @@ dependencies { annotationProcessor swdep('SpigotCore') compileOnly swdep('FastAsyncWorldEdit-1.18') + + implementation 'org.luaj:luaj-jse:3.0.1' } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 08309eb6..d65a8750 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -20,8 +20,6 @@ package de.steamwar.bausystem.features.region; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.bausystem.features.script.custom.event.EventType; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; @@ -48,10 +46,7 @@ import java.util.concurrent.atomic.AtomicBoolean; @Linked public class TNTListener implements Listener, ScoreboardElement { - @LinkedInstance - public CustomScriptManager customScriptManager; - - private void explode(List blockList, Location location, EventType eventType, Event event) { + private void explode(List blockList) { AtomicBoolean inBuild = new AtomicBoolean(); blockList.removeIf(block -> { Region region = Region.getRegion(block.getLocation()); @@ -71,24 +66,16 @@ public class TNTListener implements Listener, ScoreboardElement { } return value == TNTMode.DENY; }); - if (inBuild.get()) { - Region region = Region.getRegion(location); - for (Player player : Bukkit.getOnlinePlayers()) { - if (region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { - customScriptManager.callEvent(eventType, player, event); - } - } - } } @EventHandler public void onBlockExplode(BlockExplodeEvent event) { - explode(event.blockList(), event.getBlock().getLocation(), null, null); + explode(event.blockList()); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onExplode(EntityExplodeEvent event) { - explode(event.blockList(), event.getLocation(), EventType.TNTExplodeInBuild, event); + explode(event.blockList()); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java deleted file mode 100644 index 0c4e50af..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java +++ /dev/null @@ -1,342 +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.script; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.script.custom.MenuScript; -import de.steamwar.bausystem.features.script.custom.Script; -import de.steamwar.bausystem.features.script.custom.command.CustomCommand; -import de.steamwar.bausystem.features.script.custom.command.InventoryCommand; -import de.steamwar.bausystem.features.script.custom.command.MenuCommand; -import de.steamwar.bausystem.features.script.custom.event.CustomEvent; -import de.steamwar.bausystem.features.script.custom.event.EventType; -import de.steamwar.bausystem.features.script.custom.event.InventoryEvent; -import de.steamwar.bausystem.features.script.custom.event.MenuEvent; -import de.steamwar.bausystem.features.script.custom.hotkey.Hotkey; -import de.steamwar.bausystem.features.script.custom.hotkey.Hotkeys; -import de.steamwar.bausystem.features.script.custom.hotkey.InventoryHotkey; -import de.steamwar.bausystem.features.script.custom.hotkey.MenuHotkey; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.bausystem.utils.FlatteningWrapper; -import de.steamwar.inventory.SWItem; -import de.steamwar.inventory.SWListInv; -import de.steamwar.linkage.Linked; -import de.steamwar.sql.UserConfig; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import yapion.hierarchy.output.LengthOutput; -import yapion.hierarchy.output.StringOutput; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONMap; -import yapion.hierarchy.types.YAPIONObject; -import yapion.hierarchy.types.YAPIONValue; -import yapion.parser.YAPIONParser; - -import java.util.*; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -@Linked -public class CustomScriptManager implements Listener { - - public final Map> playerMap = Collections.synchronizedMap(new HashMap<>()); // new ConcurrentHashMap<>(); - - private void updateInventory(Player p) { - playerMap.computeIfPresent(p, (player, customCommands) -> { - customCommands.removeIf(script -> !(script instanceof MenuScript)); - return customCommands; - }); - for (ItemStack item : p.getInventory().getContents()) { - if (item == null || FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) { - continue; - } - - BookMeta bookMeta = ((BookMeta) item.getItemMeta()); - if (bookMeta.getPageCount() == 0) { - continue; - } - if (bookMeta.getPage(1).isEmpty()) { - continue; - } - String s = bookMeta.getPage(1).split("\n")[0]; - if (s.startsWith("#!CMD /")) { - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryCommand(bookMeta, s.substring(6).split(" "))); - } else if (s.startsWith("#!EVENT ")) { - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryEvent(bookMeta, s.substring(8).split(" "))); - } else if (s.startsWith("#!HOTKEY ")) { - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryHotkey(bookMeta, s.substring(9).split(" "))); - } - } - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - load(e.getPlayer()); - } - - private synchronized void load(Player p) { - updateInventory(p); - - String s = UserConfig.getConfig(p.getUniqueId(), "bausystem-scripts"); - if (s == null) { - s = UserConfig.getConfig(p.getUniqueId(), "bausystem-commands"); - UserConfig.removePlayerConfig(p.getUniqueId(), "bausystem-commands"); - } - YAPIONObject yapionObject; - if (s == null) { - yapionObject = new YAPIONObject(); - yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).add("FF", new YAPIONArray().add("#!EVENT FF /gui Script\ngui")); - } else { - yapionObject = YAPIONParser.parse(s); - if (yapionObject.containsKey("")) { - yapionObject.add("commands", yapionObject.getMap("")); - yapionObject.remove(""); - yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).add("FF", new YAPIONArray().add("#!EVENT FF /gui Script\ngui")); - } - } - - yapionObject.getYAPIONMapOrSetDefault("commands", new YAPIONMap()).forEach((key, value) -> { - String[] command = ((YAPIONValue) key).get().split(" "); - List pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList()); - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuCommand(pages, command)); - }); - - yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).forEach((key, value) -> { - String[] event = ((YAPIONValue) key).get().split(" "); - List pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList()); - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuEvent(pages, event)); - }); - - yapionObject.getYAPIONMapOrSetDefault("hotkeys", new YAPIONMap()).forEach((key, value) -> { - String[] hotkey = ((YAPIONValue) key).get().split(" "); - List pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList()); - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuHotkey(pages, hotkey)); - }); - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent e) { - save(e.getPlayer()); - playerMap.remove(e.getPlayer()); - } - - private YAPIONObject output(Player p) { - if (!playerMap.containsKey(p)) return new YAPIONObject(); - YAPIONObject yapionObject = new YAPIONObject(); - - YAPIONMap commandsMap = new YAPIONMap(); - yapionObject.add("commands", commandsMap); - playerMap.get(p).stream().filter(MenuCommand.class::isInstance).map(MenuCommand.class::cast).forEach(menuCommand -> { - menuCommand.save(commandsMap); - }); - - YAPIONMap eventsMap = new YAPIONMap(); - yapionObject.add("events", eventsMap); - playerMap.get(p).stream().filter(MenuEvent.class::isInstance).map(MenuEvent.class::cast).forEach(menuCommand -> { - menuCommand.save(eventsMap); - }); - - YAPIONMap hotkeysMap = new YAPIONMap(); - yapionObject.add("hotkeys", hotkeysMap); - playerMap.get(p).stream().filter(MenuHotkey.class::isInstance).map(MenuHotkey.class::cast).forEach(menuCommand -> { - menuCommand.save(hotkeysMap); - }); - return yapionObject; - } - - private boolean save(Player p) { - if (!playerMap.containsKey(p)) { - UserConfig.removePlayerConfig(p.getUniqueId(), "bausystem-scripts"); - return true; - } - YAPIONObject yapionObject = output(p); - if (yapionObject.toYAPION(new LengthOutput()).getLength() > 64 * 1024) { - return false; - } - UserConfig.updatePlayerConfig(p.getUniqueId(), "bausystem-scripts", yapionObject.toYAPION(new StringOutput()).getResult()); - return true; - } - - @EventHandler - public void onInventoryClose(InventoryCloseEvent e) { - if (e.getPlayer() instanceof Player) { - updateInventory((Player) e.getPlayer()); - } - } - - public void openCommandsMenu(Player p) { - List> menuCommands = new ArrayList<>(); - playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(MenuScript.class::isInstance).map(MenuScript.class::cast).forEach(menuItem -> { - SWItem swItem = menuItem.toItem(p); - ItemStack itemStack = swItem.getItemStack(); - if (menuItem instanceof MenuHotkey) { - itemStack.setType(Material.CHAIN_COMMAND_BLOCK); - } else if (menuItem instanceof MenuEvent) { - itemStack.setType(Material.REPEATING_COMMAND_BLOCK); - } else { - itemStack.setType(Material.COMMAND_BLOCK); - } - swItem.setItemStack(itemStack); - swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_1", p), BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_2", p))); - - menuCommands.add(new SWListInv.SWListEntry<>(swItem, menuItem)); - }); - - int length = (int) output(p).toYAPION(new LengthOutput()).getLength(); - double percentage = ((int) ((length / 655336.0) * 1000)) / 10.0; - String menuName = BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_NAME", p, percentage > 99 ? "§c" : (percentage >= 75 ? "§6" : "§a"), percentage); - - SWListInv menuCommandSWListInv = new SWListInv<>(p, menuName, false, menuCommands, (clickType, menuCommand) -> { - if (!clickType.isShiftClick()) { - playerMap.get(p).removeIf(customCommand -> customCommand == menuCommand); - } - SWUtils.giveItemToPlayer(p, menuCommand.toItem(p).getItemStack()); - p.closeInventory(); - save(p); - }); - menuCommandSWListInv.setItem(49, new SWItem(Material.HOPPER, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_ADD_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_ADD_LORE", p)), false, clickType -> { - ItemStack item = p.getItemOnCursor(); - if (item.getType().isAir()) { - return; - } - if (FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) { - return; - } - - BookMeta bookMeta = ((BookMeta) item.getItemMeta()); - if (bookMeta.getPageCount() == 0) { - return; - } - if (bookMeta.getPage(1).isEmpty()) { - return; - } - String s = bookMeta.getPage(1).split("\n")[0]; - if (s.startsWith("#!CMD /")) { - MenuCommand menuCommand = new MenuCommand(bookMeta.getPages(), s.substring(6).split(" ")); - for (Script script : playerMap.computeIfAbsent(p, player -> new ArrayList<>())) { - if (!(script instanceof MenuCommand)) { - continue; - } - if (((MenuCommand) script).equals(menuCommand)) { - BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_DUPLICATE_COMMAND", p, String.join(" ", menuCommand.command())); - return; - } - } - scriptBookLimit(p, menuCommand); - } else if (s.startsWith("#!EVENT ")) { - MenuEvent menuEvent = new MenuEvent(bookMeta.getPages(), s.substring(8).split(" ")); - try { - EventType.valueOf(menuEvent.eventName()); - } catch (Exception e) { - BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_UNKNOWN_EVENT", p, menuEvent.eventName()); - return; - } - scriptBookLimit(p, menuEvent); - } else if (s.startsWith("#!HOTKEY ")) { - scriptBookLimit(p, new MenuHotkey(bookMeta.getPages(), s.substring(9).split(" "))); - } - })); - menuCommandSWListInv.open(); - } - - private void scriptBookLimit(Player p, Script menuScript) { - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(menuScript); - if (!save(p)) { - playerMap.get(p).removeIf(script -> script == menuScript); - p.closeInventory(); - SWUtils.giveItemToPlayer(p, p.getItemOnCursor()); - save(p); - BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_LIMIT", p); - return; - } - p.setItemOnCursor(null); - openCommandsMenu(p); - } - - public boolean callCommand(Player p, PlayerCommandPreprocessEvent e, String message) { - List customCommands = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomCommand.class::isInstance).map(CustomCommand.class::cast).collect(Collectors.toList()); - String[] command = message.split(" "); - for (CustomCommand customCommand : customCommands) { - if (customCommand.execute(command, e)) { - return true; - } - } - return false; - } - - public boolean callScoreboard(Player p, Map variables, Consumer echoConsumer) { - Map valueMap = new HashMap<>(); - for (Map.Entry entry : variables.entrySet()) { - valueMap.put(entry.getKey(), new Value.StringValue(entry.getValue())); - } - List customEvents = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomEvent.class::isInstance).map(CustomEvent.class::cast).collect(Collectors.toList()); - boolean hasScript = false; - for (CustomEvent customEvent : customEvents) { - if (customEvent.eventName().equals(EventType.Scoreboard.name())) { - customEvent.execute(p, valueMap, echoConsumer); - hasScript = true; - } - } - return hasScript; - } - - public void callEvent(EventType eventType, Player p, Event e) { - if (eventType == null) return; - if (!eventType.getEventType().equals(e.getClass())) return; - - List customEvents = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomEvent.class::isInstance).map(CustomEvent.class::cast).collect(Collectors.toList()); - for (CustomEvent customEvent : customEvents) { - if (customEvent.eventName().equals(eventType.name())) { - Map variables = eventType.getEventValues().apply(e); - if (variables == null) { - variables = new HashMap<>(); - } - if (e instanceof Cancellable) { - variables.put("cancel", new Value.BooleanValue(((Cancellable) e).isCancelled())); - } - customEvent.execute(p, variables, null); - if (variables.containsKey("cancel")) { - Value value = variables.get("cancel"); - ((Cancellable) e).setCancelled(value.asBoolean()); - } - } - } - } - - public void callHotkey(int modifiers, char pressedHotkey, Player p, boolean pressed) { - List hotkeys = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(Hotkey.class::isInstance).map(Hotkey.class::cast).collect(Collectors.toList()); - for (Hotkey hotkey : hotkeys) { - if (Hotkeys.isSame(modifiers, pressedHotkey, hotkey.hotkey())) { - hotkey.execute(p, pressed); - } - } - } -} 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 d9bed371..6952d796 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java @@ -1,163 +1,10 @@ package de.steamwar.bausystem.features.script; -import de.steamwar.bausystem.BauSystem; import de.steamwar.command.SWCommand; -import de.steamwar.inventory.SWItem; -import de.steamwar.inventory.SWListInv; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; - -import static de.steamwar.bausystem.features.script.ScriptExecutor.SPECIAL_COMMANDS; - -@Linked public class ScriptCommand extends SWCommand { public ScriptCommand() { super("script"); } - - @LinkedInstance - public CustomScriptManager customScriptManager = null; - - private List loreBuilder(Player p, String... strings) { - List result = new ArrayList<>(); - for (String s : strings) { - result.addAll(split(BauSystem.MESSAGE.parse(s, p))); - } - return result; - } - - @Register(description = "SCRIPT_COMMAND_HELP") - public void menuCommand(Player p) { - List> swItems = new ArrayList<>(); - addEmptyItems(swItems, 2); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_HOTKEYS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5")), null)); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_COMMANDS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1", "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2")), null)); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_EVENTS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_1", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_2", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_3", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_4", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_5", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_6", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_7", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_8", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_9", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_10", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_11", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_12", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_13", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_14", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_15", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_16", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_17", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_18", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1")), null)); - addEmptyItems(swItems, 1); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_OTHER", loreBuilder(p, "SCRIPT_GUI_OTHER_LORE_1", "SCRIPT_GUI_OTHER_LORE_2", "SCRIPT_GUI_OTHER_LORE_3", "SCRIPT_GUI_OTHER_LORE_4", "SCRIPT_GUI_OTHER_LORE_5", "SCRIPT_GUI_OTHER_LORE_6", "SCRIPT_GUI_OTHER_LORE_7", "SCRIPT_GUI_OTHER_LORE_8", "SCRIPT_GUI_OTHER_LORE_9", "SCRIPT_GUI_OTHER_LORE_10", "SCRIPT_GUI_OTHER_LORE_11", "SCRIPT_GUI_OTHER_LORE_12", "SCRIPT_GUI_OTHER_LORE_13", "SCRIPT_GUI_OTHER_LORE_14", "SCRIPT_GUI_OTHER_LORE_15", "SCRIPT_GUI_OTHER_LORE_16", "SCRIPT_GUI_OTHER_LORE_17", "SCRIPT_GUI_OTHER_LORE_18")), null)); - addEmptyItems(swItems, 2); - addCustomScriptsItems(swItems, p); - addEmptyItems(swItems, 45 - swItems.size() % 45); - addEmptyItems(swItems, 4); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_VARIABLES", new ArrayList<>()), null)); - addEmptyItems(swItems, 4); - addConstantItem(swItems, p, Material.CLOCK, "SCRIPT_GUI_CONSTANT_TIME_NAME", "SCRIPT_GUI_CONSTANT_TIME_LORE"); - addConstantItem(swItems, p, Material.CLOCK, "SCRIPT_GUI_CONSTANT_TICKS_NAME", "SCRIPT_GUI_CONSTANT_TICKS_LORE"); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_NAME", "SCRIPT_GUI_CONSTANT_TRACE_LORE"); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME", "SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE"); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME", "SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE"); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME", "SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE"); - addConstantItem(swItems, p, Material.HOPPER, "SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME", "SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE"); - addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_TNT_NAME", "SCRIPT_GUI_CONSTANT_TNT_LORE"); - addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_ONLY_TB_NAME", "SCRIPT_GUI_CONSTANT_ONLY_TB_LORE"); - addConstantItem(swItems, p, Material.GUNPOWDER, "SCRIPT_GUI_CONSTANT_FREEZE_NAME", "SCRIPT_GUI_CONSTANT_FREEZE_LORE"); - addConstantItem(swItems, p, Material.FIRE_CHARGE, "SCRIPT_GUI_CONSTANT_FIRE_NAME", "SCRIPT_GUI_CONSTANT_FIRE_LORE"); - addConstantItem(swItems, p, Material.OBSIDIAN, "SCRIPT_GUI_CONSTANT_PROTECT_NAME", "SCRIPT_GUI_CONSTANT_PROTECT_LORE"); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_X_NAME", "SCRIPT_GUI_CONSTANT_X_LORE"); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Y_NAME", "SCRIPT_GUI_CONSTANT_Y_LORE"); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Z_NAME", "SCRIPT_GUI_CONSTANT_Z_LORE"); - addConstantItem(swItems, p, Material.NAME_TAG, "SCRIPT_GUI_CONSTANT_NAME_NAME", "SCRIPT_GUI_CONSTANT_NAME_LORE"); - addConstantItem(swItems, p, Material.IRON_BOOTS, "SCRIPT_GUI_CONSTANT_SNEAK_NAME", "SCRIPT_GUI_CONSTANT_SNEAK_LORE"); - addConstantItem(swItems, p, Material.DIAMOND_BOOTS, "SCRIPT_GUI_CONSTANT_SPRINTING_NAME", "SCRIPT_GUI_CONSTANT_SPRINTING_LORE"); - addConstantItem(swItems, p, Material.ARROW, "SCRIPT_GUI_CONSTANT_SLOT_NAME", "SCRIPT_GUI_CONSTANT_SLOT_LORE"); - addConstantItem(swItems, p, Material.GRASS_BLOCK, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE"); - addConstantItem(swItems, p, Material.IRON_BLOCK, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE"); - addConstantItem(swItems, p, Material.BIRCH_SIGN, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE"); - addConstantItem(swItems, p, Material.ACACIA_SIGN, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE"); - addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME", "SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE"); - addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_NAME_NAME", "SCRIPT_GUI_CONSTANT_REGION_NAME_LORE"); - addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_NAME", "SCRIPT_GUI_CONSTANT_TPS_LORE"); - addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME", "SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE"); - addEmptyItems(swItems, 45 - swItems.size() % 45); - - SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("SCRIPT_GUI_NAME", p), swItems, (clickType, o) -> { - if (o != null) { - BauSystem.MESSAGE.send("SCRIPT_GUI_COMMAND_CHAT", p, o.command()); - for (String s : o.description()) { - if (s.isEmpty()) { - BauSystem.MESSAGE.sendPrefixless("PREFIX", p); - } else { - BauSystem.MESSAGE.send(s, p); - } - } - p.closeInventory(); - } - }); - swListInv.open(); - } - - private void addEmptyItems(List> swItems, int count) { - for (int i = 0; i < count; i++) { - swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", new ArrayList<>(), false, clickType -> { - }), null)); - } - } - - private SWItem createItem(Player p, Material material, String name, List lore) { - return new SWItem(material, BauSystem.MESSAGE.parse(name, p), lore, false, clickType -> { - }); - } - - private void addConstantItem(List> swItems, Player p, Material material, String name, String lore) { - List itemLore = new ArrayList<>(); - itemLore.add(BauSystem.MESSAGE.parse(lore, p)); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, material, name, itemLore), null)); - } - - private void addCustomScriptsItems(List> swItems, Player p) { - List specialCommands = new ArrayList<>(SPECIAL_COMMANDS); - specialCommands.sort(Comparator.comparing(specialCommand -> specialCommand.getClass().getTypeName())); - specialCommands.forEach(specialCommand -> { - List strings = new ArrayList<>(); - boolean b = false; - for (String s : specialCommand.description()) { - if (s.isEmpty()) { - b = true; - strings.add(""); - continue; - } - s = BauSystem.MESSAGE.parse(s, p); - if (b) { - strings.addAll(split(s)); - } else { - strings.add(s); - } - } - - SWItem swItem = new SWItem(specialCommand.material(), BauSystem.MESSAGE.parse("SCRIPT_GUI_COMMAND_NAME", p, specialCommand.command()), strings, false, clickType -> { - }); - swItems.add(new SWListInv.SWListEntry<>(swItem, specialCommand)); - }); - } - - private List split(String s) { - List strings = new ArrayList<>(); - while (s.length() > 60) { - int index = s.indexOf(' ', 60); - if (index == -1) { - strings.add("§7" + s); - s = null; - break; - } else { - strings.add("§7" + s.substring(0, index)); - s = s.substring(index + 1); - } - } - if (s != null) { - strings.add("§7" + s); - } - return strings; - } - - @Register(value = "menu", description = "SCRIPT_COMMAND_HELP_MENU") - public void menuGUICommand(Player p) { - customScriptManager.openCommandsMenu(p); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java deleted file mode 100644 index 25b29147..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ /dev/null @@ -1,304 +0,0 @@ -package de.steamwar.bausystem.features.script; - -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.features.script.expression.Expression; -import de.steamwar.bausystem.features.script.expression.UnknownOperatorException; -import de.steamwar.bausystem.features.script.expression.VarNotFoundException; -import de.steamwar.bausystem.features.script.variables.Constants; -import de.steamwar.bausystem.features.script.variables.Context; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.bausystem.features.world.WorldEditListener; -import de.steamwar.bausystem.linkage.LinkageUtils; -import de.steamwar.bausystem.utils.WorldEditUtils; -import lombok.Getter; -import lombok.Setter; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.*; -import java.util.function.Consumer; -import java.util.logging.Level; - -public final class ScriptExecutor { - - public static final Set SPECIAL_COMMANDS = new HashSet<>(); - - static { - LinkageUtils.linkScriptCommands(); - } - - private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null; - - private String specialCommand = null; - - @Getter - private final Player player; - - @Getter - private final Context localVariables = new Context(); - - @Getter - private final Context globalVariables; - - private final List commands = new ArrayList<>(); - - @Getter - public final Map jumpPoints = new HashMap<>(); - - @Getter - private final LinkedList returnStack = new LinkedList<>(); - - @Getter - @Setter - private int index = 0; - - @Getter - private final Consumer echoConsumer; - - public ScriptExecutor(BookMeta bookMeta, Player player, Consumer echoConsumer) { - this(bookMeta, player, new HashMap<>(), echoConsumer); - } - - public ScriptExecutor(List pages, Player player, Consumer echoConsumer) { - this(pages, player, new HashMap<>(), echoConsumer); - } - - public ScriptExecutor(BookMeta bookMeta, Player player, Map localVariables, Consumer echoConsumer) { - this.player = player; - globalVariables = ScriptListener.getGlobalContext(player); - - parseMeta(bookMeta); - this.echoConsumer = echoConsumer != null ? echoConsumer : s -> { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", player, s); - }; - if (commands.isEmpty()) return; - localVariables.forEach(this.localVariables::putValue); - resume(); - } - - public ScriptExecutor(List pages, Player player, Map localVariables, Consumer echoConsumer) { - this.player = player; - globalVariables = ScriptListener.getGlobalContext(player); - - parseList(pages); - this.echoConsumer = echoConsumer != null ? echoConsumer : s -> { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", player, s); - }; - if (commands.isEmpty()) return; - localVariables.forEach(this.localVariables::putValue); - resume(); - } - - private void parseMeta(BookMeta bookMeta) { - boolean initial = true; - for (String page : bookMeta.getPages()) { - initial = parsePage(page, initial); - } - } - - private void parseList(List pages) { - boolean initial = true; - for (String page : pages) { - initial = parsePage(page, initial); - } - } - - private boolean parsePage(String page, boolean initial) { - for (String command : page.split("\n")) { - command = command.replaceAll(" +", " "); - if (command.startsWith("#") || command.trim().isEmpty()) { - if (initial && command.startsWith("#!CMD /")) { - specialCommand = command.substring(7).split(" ")[0]; - } - initial = false; - continue; - } - initial = false; - if (command.startsWith(".")) { - jumpPoints.put(command.substring(1), commands.size()); - continue; - } - commands.add(command); - } - return initial; - } - - public void resume() { - if (!player.isOnline()) { - return; - } - - int executionPoints = 0; - - while (index < commands.size()) { - String command = commands.get(index).trim(); - index++; - if (executionPoints++ > 200) { - BauSystem.MESSAGE.send("SCRIPT_SLEEP_ERROR", player); - return; - } - - String[] strings = replaceExpressions(command); - if (strings.length == 0) { - return; - } - boolean found = false; - for (SpecialCommand specialCommand : SPECIAL_COMMANDS) { - if (specialCommand.command().equalsIgnoreCase(strings[0])) { - found = true; - if (!specialCommand.execute(strings, this)) { - return; - } - } - } - if (found) { - continue; - } - - if (strings[0].contains(":")) { - continue; - } - - // Variable Replaces in commands. - command = String.join(" ", strings); - - PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + (specialCommand != null && command.startsWith(specialCommand) ? "script:" : "") + command); - Bukkit.getServer().getPluginManager().callEvent(preprocessEvent); - if (preprocessEvent.isCancelled()) { - continue; - } - - Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); - if (!strings[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + strings[0])) { - EditSession editSession = WorldEditUtils.getEditSession(player); - Actor actor = BukkitAdapter.adapt(player); - WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); - editSession.flushSession(); - WorldEditUtils.addToPlayer(player, editSession); - } else { - Bukkit.getServer().dispatchCommand(player, command); - } - } - } - - private String[] replaceExpressions(String s) { - s = s.replaceAll(" +", " "); - StringBuilder result = new StringBuilder(); - int depth = 0; - StringBuilder st = new StringBuilder(); - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c == '{') { - st.append(c); - depth++; - } else if (c == '}') { - st.append(c); - depth--; - if (depth == 0) { - try { - Expression expression = new Expression(player, st.toString(), this); - result.append(expression.eval().asString()); - st = new StringBuilder(); - } catch (IllegalArgumentException e) { - BauSystem.MESSAGE.send(e.getMessage(), player); - return new String[0]; - } catch (VarNotFoundException e) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_UNKNOWN_VAR", player, e.getMessage()); - return new String[0]; - } catch (IndexOutOfBoundsException e) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_EXPRESSION", player, st.toString()); - return new String[0]; - } catch (UnknownOperatorException e) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION", player, e.getMessage()); - return new String[0]; - } - } - } else if (st.length() > 0) { - st.append(c); - } else { - result.append(c); - } - } - return result.toString().split(" "); - } - - public Value getOrItselfValue(String variable) { - if (!isVariable(variable)) { - return Value.parse(variable); - } - - if (localVariables.hasValue(variable)) { - return localVariables.getValue(variable); - } - if (globalVariables.hasValue(variable)) { - return globalVariables.getValue(variable); - } - return Constants.getConstant(variable, player); - } - - public Value getValueOrNull(String variable) { - if (localVariables.hasValue(variable)) { - return localVariables.getValue(variable); - } - if (globalVariables.hasValue(variable)) { - return globalVariables.getValue(variable); - } - if (Constants.isConstant(variable)) { - return Constants.getConstant(variable, player); - } - return null; - } - - public String getOrItself(String variable) { - if (isVariable(variable)) { - return getValue(variable); - } - return variable; - } - - public boolean isVariable(String variable) { - return Constants.isConstant(variable) || globalVariables.hasValue(variable) || localVariables.hasValue(variable); - } - - public String getValue(String variable) { - if (localVariables.hasValue(variable)) { - return localVariables.getValue(variable).asString(); - } - if (globalVariables.hasValue(variable)) { - return globalVariables.getValue(variable).asString(); - } - if (Constants.isConstant(variable)) { - return Constants.getConstant(variable, player).asString(); - } - return ""; - } - - public String getConstant(String variable) { - if (Constants.isConstant(variable)) { - return Constants.getConstant(variable, player).asString(); - } - return "0"; - } - - public String getGlobal(String variable) { - if (globalVariables.hasValue(variable)) { - return globalVariables.getValue(variable).asString(); - } - return "0"; - } - - public String getLocal(String variable) { - if (localVariables.hasValue(variable)) { - return localVariables.getValue(variable).asString(); - } - return "0"; - } -} 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 ef9abe06..f2b5852c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -1,6 +1,5 @@ package de.steamwar.bausystem.features.script; -import de.steamwar.bausystem.features.script.variables.Context; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; @@ -9,22 +8,19 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; -import java.util.HashMap; +import java.util.Collections; import java.util.HashSet; -import java.util.Map; import java.util.Set; @Linked public class ScriptListener implements Listener { - private static final Map GLOBAL_CONTEXT = new HashMap<>(); - - private Set playerSet = new HashSet<>(); + private final Set playerSet = new HashSet<>(); @EventHandler(priority = EventPriority.HIGH) public void onLeftClick(PlayerInteractEvent event) { @@ -44,20 +40,22 @@ public class ScriptListener implements Listener { } event.setCancelled(true); - new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer(), null); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerJoin(PlayerJoinEvent event) { - GLOBAL_CONTEXT.put(event.getPlayer(), new Context()); + ScriptRunner.runScript(((BookMeta) item.getItemMeta()).getPages().stream().reduce((s, s2) -> s + "\n" + s2).orElse(null), event.getPlayer()); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - GLOBAL_CONTEXT.remove(event.getPlayer()); + ScriptRunner.remove(event.getPlayer()); } - public static Context getGlobalContext(Player player) { - return GLOBAL_CONTEXT.computeIfAbsent(player, ignore -> new Context()); + @EventHandler + public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { + ItemStack item = event.getOffHandItem(); + if (item == null || FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) { + return; + } + + event.setCancelled(true); + ScriptRunner.createGlobalScript(Collections.singletonList(((BookMeta) item.getItemMeta()).getPages().stream().reduce((s, s2) -> s + "\n" + s2).orElse(null)), event.getPlayer()); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java new file mode 100644 index 00000000..8c4ce348 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java @@ -0,0 +1,75 @@ +package de.steamwar.bausystem.features.script; + +import de.steamwar.bausystem.features.script.lua.CommandRegister; +import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin; +import de.steamwar.bausystem.features.script.lua.SteamWarPlatform; +import org.bukkit.entity.Player; +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ScriptRunner { + + // Script Table + // User + // Key -> bau-script- + // Value -> + + private static final Map>> EVENT_MAP = new HashMap<>(); + private static final Map> COMMAND_MAP = new HashMap<>(); + + public static void runScript(String script, Player player) { + Globals globals = SteamWarPlatform.createClickGlobals(player); + + try { + globals.load(script).call(); + } catch (Exception e) { + player.sendMessage("§cFehler beim Ausführen des Scripts: " + e.getMessage()); + } + } + + public static void createGlobalScript(List scripts, Player player) { + EVENT_MAP.remove(player); + Globals globals = SteamWarPlatform.createGlobalGlobals(player, + (s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction), + commandRegister -> COMMAND_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).put(commandRegister.getName(), commandRegister)); + + for (String script : scripts) { + globals.load(script).call(); + } + } + + public static void remove(Player player) { + EVENT_MAP.remove(player); + } + + public static void callEvent(Player player, SteamWarGlobalLuaPlugin.EventType event, LuaValue eventValue) { + Map> stringListMap = EVENT_MAP.get(player); + if (stringListMap == null) { + return; + } + + List luaFunctions = stringListMap.get(event); + if (luaFunctions == null) { + return; + } + + for (LuaFunction luaFunction : luaFunctions) { + luaFunction.call(eventValue); + } + } + + public static void callCommand(Player player, String command, LuaValue args) { + CommandRegister commandRegister = COMMAND_MAP.get(player).get(command.toLowerCase()); + if (commandRegister == null) { + return; + } + + commandRegister.getFunction().call(args); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java deleted file mode 100644 index 8c9763c3..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java +++ /dev/null @@ -1,105 +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.script; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.custom.event.EventType; -import de.steamwar.bausystem.features.script.expression.Expression; -import de.steamwar.linkage.Linked; -import lombok.SneakyThrows; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import yapion.hierarchy.output.StringOutput; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONObject; - -import java.util.Arrays; - -@Linked -public class ScriptSyntaxSender implements Listener { - - private byte[] syntax; - - { - Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(BauSystem.getInstance(), "sw:script_syntax"); - - // Whole Syntax object - YAPIONObject yapionObject = new YAPIONObject(); - - ScriptExecutor.SPECIAL_COMMANDS.toString(); - - // Operators - YAPIONArray operators = new YAPIONArray(); - yapionObject.add("@operators", operators); - Expression.OPERATORS.forEach((s, operator) -> { - operators.add(s); - }); - - // Headers - YAPIONArray headers = new YAPIONArray(); - yapionObject.add("@headers", headers); - headers.add("CMD /.*"); - headers.add("EVENT " + Arrays.stream(EventType.values()).map(Enum::name).reduce((s, s2) -> s + "|" + s2).map(s -> "(" + s + ")").orElse("") + "( .+)?"); - headers.add("HOTKEY .+"); - - // Variable prefixes - YAPIONArray prefixes = new YAPIONArray(); - yapionObject.add("@prefixes", prefixes); - prefixes.add("global"); - prefixes.add("const"); - prefixes.add("local"); - - // Variable suffixes - YAPIONArray suffixes = new YAPIONArray(); - yapionObject.add("@suffixes", suffixes); - suffixes.add("isset"); - suffixes.add("type"); - suffixes.add("length"); - - // Commands - ScriptExecutor.SPECIAL_COMMANDS.forEach(specialCommand -> { - YAPIONArray yapionArray = new YAPIONArray(); - yapionObject.add(specialCommand.command(), yapionArray); - if (specialCommand.repeating()) { - yapionArray.add(true); - } else { - yapionArray.add(false); - } - for (SpecialCommand.TokenType[] types : specialCommand.getSyntax()) { - YAPIONArray syntax = new YAPIONArray(); - yapionArray.add(syntax); - for (SpecialCommand.TokenType type : types) { - syntax.add(type.ordinal()); - } - } - }); - syntax = yapionObject.toJSONLossy(new StringOutput()).getResult().getBytes(); - } - - @EventHandler - @SneakyThrows - public void onPlayerJoin(PlayerJoinEvent event) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - event.getPlayer().sendPluginMessage(BauSystem.getInstance(), "sw:script_syntax", syntax); - }, 5); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java deleted file mode 100644 index 3cb32f9b..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java +++ /dev/null @@ -1,86 +0,0 @@ -package de.steamwar.bausystem.features.script; - -import org.bukkit.Material; - -public interface SpecialCommand { - - default String[] description() { - return new String[0]; - } - - default Material material() { - return Material.PAPER; - } - - String command(); - - boolean execute(String[] command, ScriptExecutor scriptExecutor); - - default boolean repeating() { - return false; - } - - TokenType[][] getSyntax(); - - default long asLong(String value) { - try { - return Long.parseLong(value); - } catch (NumberFormatException e) { - return 0; - } - } - - default boolean asBoolean(String value) { - return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"); - } - - default String asString(String value) { - return value; - } - - default void jumpToIndex(ScriptExecutor scriptExecutor, String jumpPoint) { - scriptExecutor.jumpPoints.computeIfPresent(jumpPoint, (s, integer) -> { - scriptExecutor.setIndex(integer); - return integer; - }); - } - - default void jumpToIndexWithMessage(ScriptExecutor scriptExecutor, String jumpPoint, String message) { - Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null); - if (jp == null) { - scriptExecutor.getPlayer().sendMessage(message); - return; - } - scriptExecutor.setIndex(jp); - } - - default void jumpToIndexWithMessageAndReturnStack(ScriptExecutor scriptExecutor, String jumpPoint, String message) { - Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null); - if (jp == null) { - scriptExecutor.getPlayer().sendMessage(message); - return; - } - scriptExecutor.getReturnStack().add(scriptExecutor.getIndex()); - scriptExecutor.setIndex(jp); - } - - default void returnFromStackWithMessage(ScriptExecutor scriptExecutor, String message) { - if (scriptExecutor.getReturnStack().isEmpty()) { - scriptExecutor.getPlayer().sendMessage(message); - return; - } - scriptExecutor.setIndex(scriptExecutor.getReturnStack().pop()); - } - - enum TokenType { - any, // This does not include jump_point and variable - expression, - jump_point, - variable, - - text_type, - number_type, - floating_number_type, - boolean_type, - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java deleted file mode 100644 index 4cb22c65..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Call implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_CALL_HELP_1", - "", - "SCRIPT_COMMAND_CALL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.LEATHER_BOOTS; - } - - @Override - public String command() { - return "call"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT", scriptExecutor.getPlayer()); - return true; - } - jumpToIndexWithMessageAndReturnStack(scriptExecutor, command[1], BauSystem.MESSAGE.parse("SCRIPT_COMMAND_CALL_ERROR", scriptExecutor.getPlayer(), command[1])); - return true; - } - - private TokenType[][] syntax = { - { TokenType.jump_point }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java deleted file mode 100644 index c274d252..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Exit implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_EXIT_HELP_1", - "", - "SCRIPT_COMMAND_EXIT_HELP_2" - }; - } - - @Override - public Material material() { - return Material.BARRIER; - } - - @Override - public String command() { - return "exit"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - return false; - } - - private TokenType[][] syntax = {}; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java deleted file mode 100644 index 47d92f25..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class If implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_IF_HELP_1", - "SCRIPT_COMMAND_IF_HELP_2", - "", - "SCRIPT_COMMAND_IF_HELP_3" - }; - } - - @Override - public Material material() { - return Material.OBSERVER; - } - - @Override - public String command() { - return "if"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length < 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length < 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT", scriptExecutor.getPlayer()); - return true; - } - - Value v = scriptExecutor.getOrItselfValue(command[1]); - if (!(v instanceof Value.BooleanValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_NO_BOOLEAN", scriptExecutor.getPlayer()); - return false; - } - if (v.asBoolean() && command.length > 2) { - jumpToIndex(scriptExecutor, command[2]); - } else if (command.length > 3) { - jumpToIndex(scriptExecutor, command[3]); - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.boolean_type, TokenType.jump_point }, - { TokenType.boolean_type, TokenType.jump_point, TokenType.jump_point }, - { TokenType.expression, TokenType.jump_point }, - { TokenType.expression, TokenType.jump_point, TokenType.jump_point } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java deleted file mode 100644 index 10ff4ab1..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Jump implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_JUMP_HELP_1", - "", - "SCRIPT_COMMAND_JUMP_HELP_2" - }; - } - - @Override - public Material material() { - return Material.LEATHER_BOOTS; - } - - @Override - public String command() { - return "jump"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT", scriptExecutor.getPlayer()); - return true; - } - jumpToIndexWithMessage(scriptExecutor, command[1], BauSystem.MESSAGE.parse("SCRIPT_COMMAND_JUMP_ERROR", scriptExecutor.getPlayer(), command[1])); - return true; - } - - private TokenType[][] syntax = { - { TokenType.jump_point } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java deleted file mode 100644 index 0d9e6492..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Return implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_RETURN_HELP_1", - "", - "SCRIPT_COMMAND_RETURN_HELP_2" - }; - } - - @Override - public Material material() { - return Material.DIAMOND_BOOTS; - } - - @Override - public String command() { - return "return"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - returnFromStackWithMessage(scriptExecutor, BauSystem.MESSAGE.parse("SCRIPT_COMMAND_RETURN_ERROR", scriptExecutor.getPlayer())); - return true; - } - - private TokenType[][] syntax = {}; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java deleted file mode 100644 index 3cb0f025..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Bukkit; -import org.bukkit.Material; - -@Linked -public class Sleep implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_SLEEP_HELP_1", - "", - "SCRIPT_COMMAND_SLEEP_HELP_2" - }; - } - - @Override - public Material material() { - return Material.CLOCK; - } - - @Override - public String command() { - return "sleep"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER", scriptExecutor.getPlayer()); - return true; - } - long sleepTime = asLong(command[1]); - if (sleepTime < 0) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_SLEEP_ERROR", scriptExecutor.getPlayer()); - return true; - } - if (sleepTime == 0) { - return true; - } - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), scriptExecutor::resume, sleepTime); - return false; - } - - private TokenType[][] syntax = { - { TokenType.number_type } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java deleted file mode 100644 index da87c9f9..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java +++ /dev/null @@ -1,107 +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.script.command.arithmetic.other; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Ceil implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2", - "", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3" - }; - } - - @Override - public Material material() { - return Material.REDSTONE_TORCH; - } - - @Override - public String command() { - return "ceil"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - Value v1; - Value v2; - if (command.length == 3) { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - v2 = new Value.LongValue(0); - } else { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - } - if (!(v1 instanceof Value.DoubleValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - if (v2.asLong() < 0) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - - if (v2.asLong() == 0) { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue((long) Math.ceil(v1.asDouble()))); - } else { - double pow = Math.pow(10, v2.asLong()); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.ceil(v1.asDouble() * pow) / pow)); - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type }, - { TokenType.variable, TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.floating_number_type, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java deleted file mode 100644 index ce5d0730..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java +++ /dev/null @@ -1,107 +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.script.command.arithmetic.other; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Floor implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2", - "", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3" - }; - } - - @Override - public Material material() { - return Material.REDSTONE_TORCH; - } - - @Override - public String command() { - return "floor"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - Value v1; - Value v2; - if (command.length == 3) { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - v2 = new Value.LongValue(0); - } else { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - } - if (!(v1 instanceof Value.DoubleValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - if (v2.asLong() < 0) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - - if (v2.asLong() == 0) { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue((long) Math.floor(v1.asDouble()))); - } else { - double pow = Math.pow(10, v2.asLong()); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.floor(v1.asDouble() * pow) / pow)); - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type }, - { TokenType.variable, TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.floating_number_type, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java deleted file mode 100644 index 2af5d261..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java +++ /dev/null @@ -1,107 +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.script.command.arithmetic.other; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Round implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2", - "", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3" - }; - } - - @Override - public Material material() { - return Material.REDSTONE_TORCH; - } - - @Override - public String command() { - return "round"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - Value v1; - Value v2; - if (command.length == 3) { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - v2 = new Value.LongValue(0); - } else { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - } - if (!(v1 instanceof Value.DoubleValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - if (v2.asLong() < 0) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - - if (v2.asLong() == 0) { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(Math.round(v1.asDouble()))); - } else { - double pow = Math.pow(10, v2.asLong()); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.round(v1.asDouble() * pow) / pow)); - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type }, - { TokenType.variable, TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.floating_number_type, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java deleted file mode 100644 index da83635c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.steamwar.bausystem.features.script.command.io; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Material; - -@Linked -public class Echo implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_IO_ECHO_HELP_1", - "", - "SCRIPT_COMMAND_IO_ECHO_HELP_2" - }; - } - - @Override - public Material material() { - return Material.OAK_SIGN; - } - - @Override - public String command() { - return "echo"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - scriptExecutor.getEchoConsumer().accept(""); - return true; - } - StringBuilder st = new StringBuilder(); - for (int i = 1; i < command.length; i++) { - if (i != 1) { - st.append(" "); - } - st.append(command[i]); - } - scriptExecutor.getEchoConsumer().accept(ChatColor.translateAlternateColorCodes('&', st.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java deleted file mode 100644 index c5c99240..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.steamwar.bausystem.features.script.command.io; - -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Material; - -@Linked -public class Echoactionbar implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1", - "", - "SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2" - }; - } - - @Override - public Material material() { - return Material.BIRCH_SIGN; - } - - @Override - public String command() { - return "echoactionbar"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - SWUtils.sendToActionbar(scriptExecutor.getPlayer(), ""); - return true; - } - StringBuilder st = new StringBuilder(); - for (int i = 1; i < command.length; i++) { - if (i != 1) { - st.append(" "); - } - st.append(command[i]); - } - SWUtils.sendToActionbar(scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java deleted file mode 100644 index 4ecb4237..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java +++ /dev/null @@ -1,79 +0,0 @@ -package de.steamwar.bausystem.features.script.command.io; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.linkage.Linked; -import org.bukkit.ChatColor; -import org.bukkit.Material; - -@Linked -public class Input implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_IO_INPUT_HELP_1", - "", - "SCRIPT_COMMAND_IO_INPUT_HELP_2" - }; - } - - @Override - public Material material() { - return Material.ANVIL; - } - - @Override - public String command() { - return "input"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - StringBuilder st = new StringBuilder(); - for (int i = 2; i < command.length; i++) { - if (i != 2) { - st.append(" "); - } - st.append(command[i]); - } - SWAnvilInv swAnvilInv = new SWAnvilInv(scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString())); - swAnvilInv.setCallback(s -> { - try { - long value = Long.parseLong(s); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(value)); - } catch (NumberFormatException e) { - if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.BooleanValue(s.equalsIgnoreCase("true"))); - } else { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(s)); - } - } - scriptExecutor.resume(); - }); - swAnvilInv.addCloseCallback(scriptExecutor::resume); - swAnvilInv.open(); - return false; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java deleted file mode 100644 index 00dbf597..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java +++ /dev/null @@ -1,98 +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.script.command.string; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Insert implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_STRING_INSERT_HELP_1", - "SCRIPT_COMMAND_STRING_INSERT_HELP_2", - "", - "SCRIPT_COMMAND_STRING_INSERT_HELP_3" - }; - } - - @Override - public Material material() { - return Material.HOPPER; - } - - @Override - public String command() { - return "insert"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 3) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER", scriptExecutor.getPlayer()); - return true; - } - - String resultName = command[1]; - Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 3]); - Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - Value v3 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - - if (!(v1 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v3 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - - scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(new StringBuilder(v1.asString()).insert((int) v3.asLong(), v2.asString()).toString())); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.variable, TokenType.number_type }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java deleted file mode 100644 index 002fd3c5..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java +++ /dev/null @@ -1,89 +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.script.command.string; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Remove implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_STRING_REMOVE_HELP_1", - "SCRIPT_COMMAND_STRING_REMOVE_HELP_2", - "", - "SCRIPT_COMMAND_STRING_REMOVE_HELP_3" - }; - } - - @Override - public Material material() { - return Material.SHEARS; - } - - @Override - public String command() { - return "remove"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - String resultName = command[1]; - Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - - if (!(v1 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - - scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(v1.asString().replace(v2.asString(), ""))); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.variable, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java deleted file mode 100644 index a7a5716f..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java +++ /dev/null @@ -1,98 +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.script.command.string; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Replace implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_STRING_REPLACE_HELP_1", - "SCRIPT_COMMAND_STRING_REPLACE_HELP_2", - "", - "SCRIPT_COMMAND_STRING_REPLACE_HELP_3" - }; - } - - @Override - public Material material() { - return Material.WOODEN_AXE; - } - - @Override - public String command() { - return "replace"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 3) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - String resultName = command[1]; - Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 3]); - Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - Value v3 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - - if (!(v1 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v3 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - - scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(v1.asString().replace(v2.asString(), v3.asString()))); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.variable, TokenType.variable, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java deleted file mode 100644 index 8624cae1..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java +++ /dev/null @@ -1,99 +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.script.command.string; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Substring implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1", - "SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2", - "", - "SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3" - }; - } - - @Override - public Material material() { - return Material.STICKY_PISTON; - } - - @Override - public String command() { - return "substring"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - String resultName = command[1]; - Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - - if (!(v1 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - - Value result; - try { - if (v2.asLong() < 0) { - result = new Value.StringValue(v1.asString().substring(v1.asString().length() - 1 - (int) v2.asLong())); - } else { - result = new Value.StringValue(v1.asString().substring((int) v2.asLong())); - } - } catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException e) { - result = new Value.StringValue(""); - } - scriptExecutor.getLocalVariables().putValue(resultName, result); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.number_type }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java deleted file mode 100644 index 850a6642..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java +++ /dev/null @@ -1,87 +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.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Constants; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Const implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_CONST_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_CONST_HELP_2" - }; - } - - @Override - public Material material() { - return Material.STRUCTURE_BLOCK; - } - - @Override - public String command() { - return "const"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - String varName = command[1]; - StringBuilder varValue = new StringBuilder(); - for (int i = 2; i < command.length; i++) { - if (varValue.length() != 0) { - varValue.append(" "); - } - varValue.append(command[i]); - } - Constants.getConstant(varName, scriptExecutor.getPlayer()).fromValue(Value.parse(varValue.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java deleted file mode 100644 index a99c0bb6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java +++ /dev/null @@ -1,74 +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.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Convert implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2", - }; - } - - @Override - public Material material() { - return Material.ENDER_CHEST; - } - - @Override - public String command() { - return "convert"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - scriptExecutor.getLocalVariables().putValue(command[1], Value.parse(command[2])); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java deleted file mode 100644 index ae3f33a7..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.steamwar.bausystem.features.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Global implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.MAP; - } - - @Override - public String command() { - return "global"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - String varName = command[1]; - StringBuilder varValue = new StringBuilder(); - for (int i = 2; i < command.length; i++) { - if (varValue.length() != 0) { - varValue.append(" "); - } - varValue.append(command[i]); - } - scriptExecutor.getGlobalVariables().putValue(varName, Value.parse(varValue.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java deleted file mode 100644 index 06e9e7b1..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.features.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Unglobal implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.BEACON; - } - - @Override - public String command() { - return "unglobal"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - scriptExecutor.getGlobalVariables().removeValue(command[1]); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java deleted file mode 100644 index 76230f87..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.features.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Unvar implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2" - }; - } - - @Override - public Material material() { - return Material.STRUCTURE_VOID; - } - - @Override - public String command() { - return "unvar"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - scriptExecutor.getLocalVariables().removeValue(command[1]); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java deleted file mode 100644 index 6cda1236..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.steamwar.bausystem.features.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Var implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_VAR_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_VAR_HELP_2" - }; - } - - @Override - public Material material() { - return Material.STRUCTURE_BLOCK; - } - - @Override - public String command() { - return "var"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - String varName = command[1]; - StringBuilder varValue = new StringBuilder(); - for (int i = 2; i < command.length; i++) { - if (varValue.length() != 0) { - varValue.append(" "); - } - varValue.append(command[i]); - } - scriptExecutor.getLocalVariables().putValue(varName, Value.parse(varValue.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java deleted file mode 100644 index e5511e98..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java +++ /dev/null @@ -1,89 +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.script.command.world; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; - -@Linked -public class GetMaterial implements SpecialCommand { - - private final World world = Bukkit.getWorlds().get(0); - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1", - "", - "SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.STICKY_PISTON; - } - - @Override - public String command() { - return "getmaterial"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 3) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 4) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - - int x = (int) scriptExecutor.getOrItselfValue(command[2]).asLong(); - int y = (int) scriptExecutor.getOrItselfValue(command[3]).asLong(); - int z = (int) scriptExecutor.getOrItselfValue(command[4]).asLong(); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(world.getBlockAt(x, y, z).getType().name())); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.number_type, TokenType.number_type, TokenType.number_type } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java deleted file mode 100644 index 1411c708..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java +++ /dev/null @@ -1,92 +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.script.command.world; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; - -@Linked -public class SetMaterial implements SpecialCommand { - - private final World world = Bukkit.getWorlds().get(0); - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1", - "", - "SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.PISTON; - } - - @Override - public String command() { - return "setmaterial"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 3) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 4) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - - int x = (int) scriptExecutor.getOrItselfValue(command[2]).asLong(); - int y = (int) scriptExecutor.getOrItselfValue(command[3]).asLong(); - int z = (int) scriptExecutor.getOrItselfValue(command[4]).asLong(); - try { - world.getBlockAt(x, y, z).setType(Material.valueOf(scriptExecutor.getOrItself(command[1]))); - } catch (Exception e) { - // Ignored - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.number_type, TokenType.number_type, TokenType.number_type } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java deleted file mode 100644 index 49befa41..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java +++ /dev/null @@ -1,29 +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.script.custom; - -import de.steamwar.inventory.SWItem; -import org.bukkit.entity.Player; -import yapion.hierarchy.types.YAPIONMap; - -public interface MenuScript { - void save(YAPIONMap yapionMap); - SWItem toItem(Player p); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java deleted file mode 100644 index 17693f8a..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java +++ /dev/null @@ -1,23 +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.script.custom; - -public interface Script { -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java deleted file mode 100644 index 4c2e7ddf..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java +++ /dev/null @@ -1,45 +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.script.custom.command; - -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - - -@Linked -public class CommandListener implements Listener { - - @LinkedInstance - public CustomScriptManager manager; - - @EventHandler - public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) { - if (e.getMessage().startsWith("/script:")) { - e.setMessage("/" + e.getMessage().substring(8)); - return; - } - - manager.callCommand(e.getPlayer(), e, e.getMessage()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java deleted file mode 100644 index b0a7d386..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java +++ /dev/null @@ -1,87 +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.script.custom.command; - -import de.steamwar.bausystem.features.script.custom.Script; -import de.steamwar.bausystem.features.script.variables.Value; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -import java.util.HashMap; -import java.util.Map; - -public interface CustomCommand extends Script { - String[] command(); - - default Map check(String[] args, String[] command) { - if (args.length < command.length) { - return null; - } - - if (!args[0].equals(command[0])) { - return null; - } - - Map arguments = new HashMap<>(); - if (!check(arguments, args, command, 0, 0)) { - return null; - } - return arguments; - } - - default boolean check(Map arguments, String[] args, String[] command, int argsIndex, int commandIndex) { - if (command.length <= commandIndex) { - for (int i = argsIndex; i < args.length; i++) { - if (!(args[i].startsWith("(") && args[i].endsWith(")"))) { - return false; - } - } - return true; - } - if (args.length <= argsIndex) return true; - - String currentArg = args[argsIndex]; - String currentCommand = command[commandIndex]; - - if (currentArg.startsWith("<") && currentArg.endsWith(">")) { - arguments.put(trim(currentArg, 1), new Value.StringValue(currentCommand)); - return check(arguments, args, command, argsIndex + 1, commandIndex + 1); - } else if (currentArg.startsWith("(<") && currentArg.endsWith(">)")) { - arguments.put(trim(currentArg, 2), new Value.StringValue(currentCommand)); - return check(arguments, args, command, argsIndex + 1, commandIndex + 1); - } else if (currentArg.startsWith("(") && currentArg.endsWith(")")) { - if (!trim(currentArg, 1).equals(currentCommand)) { - arguments.put(trim(currentArg, 1), new Value.BooleanValue(false)); - return check(arguments, args, command, argsIndex + 1, commandIndex); - } else { - arguments.put(trim(currentArg, 1), new Value.BooleanValue(true)); - return check(arguments, args, command, argsIndex + 1, commandIndex + 1); - } - } else { - if (!currentArg.equals(currentCommand)) return false; - return check(arguments, args, command, argsIndex + 1, commandIndex + 1); - } - } - - default String trim(String s, int count) { - return s.substring(count, s.length() - count); - } - - boolean execute(String[] command, PlayerCommandPreprocessEvent e); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java deleted file mode 100644 index 34cfc738..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java +++ /dev/null @@ -1,51 +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.script.custom.command; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.variables.Value; -import lombok.RequiredArgsConstructor; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.Map; - -@RequiredArgsConstructor -public -class InventoryCommand implements CustomCommand { - public final BookMeta bookMeta; - public final String[] args; - - @Override - public String[] command() { - return args; - } - - public boolean execute(String[] command, PlayerCommandPreprocessEvent e) { - Map arguments = check(args, command); - if (arguments == null) { - return false; - } - - e.setCancelled(true); - new ScriptExecutor(bookMeta, e.getPlayer(), arguments, null); - return true; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java deleted file mode 100644 index 5583f360..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java +++ /dev/null @@ -1,99 +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.script.custom.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.custom.MenuScript; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.inventory.SWItem; -import lombok.RequiredArgsConstructor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.inventory.meta.BookMeta; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONMap; - -import java.util.List; -import java.util.Map; - -@RequiredArgsConstructor -public -class MenuCommand implements CustomCommand, MenuScript { - public final List pages; - public final String[] args; - - @Override - public String[] command() { - return args; - } - - public boolean execute(String[] command, PlayerCommandPreprocessEvent e) { - Map arguments = check(args, command); - if (arguments == null) { - return false; - } - - e.setCancelled(true); - new ScriptExecutor(pages, e.getPlayer(), arguments, null); - return true; - } - - public boolean equals(MenuCommand menuCommand) { - if (menuCommand.args.length != args.length) { - return false; - } - if (!args[0].equals(menuCommand.args[0])) { - return false; - } - for (int i = 0; i < args.length; i++) { - if (i == 0) continue; - String s1 = args[i]; - String s2 = menuCommand.args[i]; - if (!s1.equals(s2)) { - return false; - } - if (!(s1.startsWith("<") && s1.endsWith(">") && s2.startsWith("<") && s2.endsWith(">"))) { - return false; - } - if (!(s1.startsWith("(<") && s1.endsWith(">)") && s2.startsWith("(<") && s2.endsWith(">)"))) { - return false; - } - } - return true; - } - - @Override - public void save(YAPIONMap yapionMap) { - YAPIONArray yapionArray = new YAPIONArray(); - pages.forEach(yapionArray::add); - yapionMap.put(String.join(" ", args), yapionArray); - } - - @Override - public SWItem toItem(Player p) { - SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_COMMAND_ITEM_NAME", p, String.join(" ", args))); - BookMeta bookMeta = (BookMeta) swItem.getItemMeta(); - bookMeta.setPages(pages.toArray(new String[0])); - swItem.setItemMeta(bookMeta); - return swItem; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java deleted file mode 100644 index ec4bebd7..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java +++ /dev/null @@ -1,34 +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.script.custom.event; - -import de.steamwar.bausystem.features.script.custom.Script; -import de.steamwar.bausystem.features.script.variables.Value; -import org.bukkit.entity.Player; - -import java.util.Map; -import java.util.function.Consumer; - -public interface CustomEvent extends Script { - - String eventName(); - boolean execute(Player p, Map variables, Consumer echoConsumer); - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java deleted file mode 100644 index 3a6d471d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java +++ /dev/null @@ -1,133 +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.script.custom.event; - -import de.steamwar.bausystem.features.script.variables.Value; -import lombok.Getter; -import org.bukkit.Location; -import org.bukkit.event.Event; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.player.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -@Getter -public enum EventType { - FF(PlayerSwapHandItemsEvent.class, event -> null), - PlaceBlock(BlockPlaceEvent.class, event -> { - Map valueMap = new HashMap<>(); - addBlockXYZ(valueMap, event.getBlockPlaced().getLocation()); - valueMap.put("blockType", new Value.StringValue(event.getBlockPlaced().getType().name())); - return valueMap; - }), - BreakBlock(BlockBreakEvent.class, event -> { - Map valueMap = new HashMap<>(); - addBlockXYZ(valueMap, event.getBlock().getLocation()); - valueMap.put("blockType", new Value.StringValue(event.getBlock().getType().name())); - return valueMap; - }), - RightClick(PlayerInteractEvent.class, event -> { - Map valueMap = new HashMap<>(); - valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand())); - valueMap.put("action", new Value.StringValue(event.getAction().name())); - valueMap.put("handType", new Value.StringValue(event.getMaterial().name())); - valueMap.put("hasBlock", new Value.BooleanValue(event.hasBlock())); - if (event.hasBlock()) { - addBlockXYZ(valueMap, event.getClickedBlock().getLocation()); - valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name())); - } - return valueMap; - }), - LeftClick(PlayerInteractEvent.class, event -> { - Map valueMap = new HashMap<>(); - valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand())); - valueMap.put("action", new Value.StringValue(event.getAction().name())); - valueMap.put("handType", new Value.StringValue(event.getMaterial().name())); - valueMap.put("hasBlock", new Value.BooleanValue(event.hasBlock())); - if (event.hasBlock()) { - addBlockXYZ(valueMap, event.getClickedBlock().getLocation()); - valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name())); - } - return valueMap; - }), - TNTSpawn(EntitySpawnEvent.class, event -> null), - TNTExplode(EntityExplodeEvent.class, event -> { - Map valueMap = new HashMap<>(); - addXYZ(valueMap, event.getLocation()); - return valueMap; - }), - TNTExplodeInBuild(EntityExplodeEvent.class, event -> { - Map valueMap = new HashMap<>(); - addXYZ(valueMap, event.getLocation()); - return valueMap; - }), - SelfJoin(PlayerJoinEvent.class, event -> { - Map valueMap = new HashMap<>(); - addXYZ(valueMap, event.getPlayer().getLocation()); - return valueMap; - }), - SelfLeave(PlayerQuitEvent.class, event -> { - Map valueMap = new HashMap<>(); - addXYZ(valueMap, event.getPlayer().getLocation()); - return valueMap; - }), - DropItem(PlayerDropItemEvent.class, event -> { - Map valueMap = new HashMap<>(); - valueMap.put("material", new Value.StringValue(event.getItemDrop().getItemStack().getType().name())); - addXYZ(valueMap, event.getItemDrop().getLocation()); - return valueMap; - }), - EntityDeath(EntityDeathEvent.class, event -> { - Map valueMap = new HashMap<>(); - valueMap.put("entityType", new Value.StringValue(event.getEntityType().name())); - addXYZ(valueMap, event.getEntity().getLocation()); - return valueMap; - }), - Scoreboard(Event.class, event -> { - return new HashMap<>(); - }), - ; - - private static void addXYZ(Map valueMap, Location location) { - valueMap.put("x", new Value.DoubleValue(location.getX())); - valueMap.put("y", new Value.DoubleValue(location.getY())); - valueMap.put("z", new Value.DoubleValue(location.getZ())); - } - - private static void addBlockXYZ(Map valueMap, Location location) { - valueMap.put("blockX", new Value.LongValue(location.getBlockX())); - valueMap.put("blockY", new Value.LongValue(location.getBlockY())); - valueMap.put("blockZ", new Value.LongValue(location.getBlockZ())); - } - - private Class eventType; - private Function> eventValues; - - EventType(Class eventType, Function> eventValues) { - this.eventType = eventType; - this.eventValues = event -> eventValues.apply((T) event); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java deleted file mode 100644 index d323dbc8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java +++ /dev/null @@ -1,47 +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.script.custom.event; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.variables.Value; -import lombok.RequiredArgsConstructor; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.Map; -import java.util.function.Consumer; - -@RequiredArgsConstructor -public -class InventoryEvent implements CustomEvent { - public final BookMeta bookMeta; - public final String[] args; - - @Override - public String eventName() { - return args[0]; - } - - @Override - public boolean execute(Player p, Map variables, Consumer echoConsumer) { - new ScriptExecutor(bookMeta, p, variables, echoConsumer); - return true; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java deleted file mode 100644 index 96a7d6d2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java +++ /dev/null @@ -1,76 +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.script.custom.event; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.custom.MenuScript; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.inventory.SWItem; -import lombok.RequiredArgsConstructor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.BookMeta; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONMap; - -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; - -@RequiredArgsConstructor -public -class MenuEvent implements CustomEvent, MenuScript { - public final List pages; - public final String[] args; - - @Override - public String eventName() { - return args[0]; - } - - @Override - public boolean execute(Player p, Map variables, Consumer echoConsumer) { - new ScriptExecutor(pages, p, variables, echoConsumer); - return false; - } - - @Override - public void save(YAPIONMap yapionMap) { - YAPIONArray yapionArray = new YAPIONArray(); - pages.forEach(yapionArray::add); - yapionMap.put(String.join(" ", args), yapionArray); - } - - @Override - public SWItem toItem(Player p) { - StringBuilder st = new StringBuilder(); - for (int i = 1; i < args.length; i++) { - if (i != 1) st.append(" "); - st.append(args[i]); - } - - SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_EVENT_ITEM_NAME", p, args[0], st.toString())); - BookMeta bookMeta = (BookMeta) swItem.getItemMeta(); - bookMeta.setPages(pages.toArray(new String[0])); - swItem.setItemMeta(bookMeta); - return swItem; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java deleted file mode 100644 index 2c9bd6c8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java +++ /dev/null @@ -1,29 +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.script.custom.hotkey; - -import de.steamwar.bausystem.features.script.custom.Script; -import org.bukkit.entity.Player; - -public interface Hotkey extends Script { - - String hotkey(); - boolean execute(Player p, boolean pressed); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java deleted file mode 100644 index 5f8adadd..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java +++ /dev/null @@ -1,57 +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.script.custom.hotkey; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.messaging.PluginMessageListener; - -@Linked -public class HotkeyListener implements PluginMessageListener { - - { - Bukkit.getServer().getMessenger().registerIncomingPluginChannel(BauSystem.getInstance(), "sw:hotkeys", this); - } - - @LinkedInstance - public CustomScriptManager manager; - - @Override - public void onPluginMessageReceived(String channel, Player player, byte[] message) { - if (!channel.equals("sw:hotkeys")) return; - if (message.length < 5) return; - int action = message[4] & 0xFF; - if (action == 2) return; - int key = (message[0] & 0xFF) << 24 | (message[1] & 0xFF) << 16 | (message[2] & 0xFF) << 8 | (message[3] & 0xFF); - if (!(key >= 'A' && key <= 'Z' || key >= '0' && key <= '9')) return; - if (message.length >= 9) { - int mods = (message[5] & 0xFF) << 24 | (message[6] & 0xFF) << 16 | (message[7] & 0xFF) << 8 | (message[8] & 0xFF); - // player.sendMessage("Hotkey: " + (char) key + " " + action + " " + Long.toBinaryString(mods)); - manager.callHotkey(mods, ((char) key), player, action == 1); - } else { - // player.sendMessage("Hotkey: " + (char) key + " " + action); - manager.callHotkey(0, ((char) key), player, action == 1); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java deleted file mode 100644 index 056afaea..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java +++ /dev/null @@ -1,135 +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.script.custom.hotkey; - -import java.util.HashSet; -import java.util.Set; - -public interface Hotkeys { - - public static boolean isSame(int mods, char key, String checkAgainst) { - Set modifiers = Modifier.get(mods); - Key k = Key.fromString(key + ""); - if (k == null) { - return false; - } - - try { - String[] split = checkAgainst.split("\\+"); - Set checkModifiers = new HashSet<>(); - Key checkKey = null; - for (String s : split) { - Modifier m = Modifier.fromString(s); - if (m != null) { - checkModifiers.add(m); - } else { - checkKey = Key.fromString(s); - } - } - return checkKey == k && checkModifiers.equals(modifiers); - } catch (Exception e) { - return false; - } - } - - enum Modifier { - SHIFT, - CTRL, - ALT, - META, - ; - - public static Set get(int mods) { - Set modifiers = new HashSet<>(); - for (Modifier modifier : values()) { - if ((mods & (1 << modifier.ordinal())) != 0) { - modifiers.add(modifier); - } - } - return modifiers; - } - - public static Modifier fromString(String string) { - try { - return valueOf(string.toUpperCase()); - } catch (IllegalArgumentException e) { - return null; - } - } - } - - enum Key { - // A-Z - A, - B, - C, - D, - E, - F, - G, - H, - I, - J, - K, - L, - M, - N, - O, - P, - Q, - R, - S, - T, - U, - V, - W, - X, - Y, - Z, - - // 0-9 - NUM_0, - NUM_1, - NUM_2, - NUM_3, - NUM_4, - NUM_5, - NUM_6, - NUM_7, - NUM_8, - NUM_9, - ; - - public static Key fromString(String key) { - key = key.toUpperCase(); - try { - return Key.valueOf(key); - } catch (IllegalArgumentException e) { - // ignore - } - try { - return Key.valueOf("NUM_" + key); - } catch (IllegalArgumentException e) { - // ignore - } - return null; - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java deleted file mode 100644 index f467e460..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java +++ /dev/null @@ -1,51 +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.script.custom.hotkey; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.variables.Value; -import lombok.RequiredArgsConstructor; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.HashMap; -import java.util.Map; - -@RequiredArgsConstructor -public -class InventoryHotkey implements Hotkey { - - public final BookMeta bookMeta; - public final String[] args; - - @Override - public String hotkey() { - return args[0]; - } - - @Override - public boolean execute(Player p, boolean pressed) { - Map variables = new HashMap<>(); - variables.put("pressed", new Value.BooleanValue(pressed)); - variables.put("released", new Value.BooleanValue(!pressed)); - new ScriptExecutor(bookMeta, p, variables, null); - return false; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java deleted file mode 100644 index 0407f621..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java +++ /dev/null @@ -1,80 +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.script.custom.hotkey; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.custom.MenuScript; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.inventory.SWItem; -import lombok.RequiredArgsConstructor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.BookMeta; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONMap; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@RequiredArgsConstructor -public -class MenuHotkey implements Hotkey, MenuScript { - - public final List pages; - public final String[] args; - - @Override - public String hotkey() { - return args[0]; - } - - @Override - public boolean execute(Player p, boolean pressed) { - Map variables = new HashMap<>(); - variables.put("pressed", new Value.BooleanValue(pressed)); - variables.put("released", new Value.BooleanValue(!pressed)); - new ScriptExecutor(pages, p, variables, null); - return false; - } - - @Override - public void save(YAPIONMap yapionMap) { - YAPIONArray yapionArray = new YAPIONArray(); - pages.forEach(yapionArray::add); - yapionMap.put(String.join(" ", args), yapionArray); - } - - @Override - public SWItem toItem(Player p) { - StringBuilder st = new StringBuilder(); - for (int i = 1; i < args.length; i++) { - if (i != 1) st.append(" "); - st.append(args[i]); - } - - SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_HOTKEY_ITEM_NAME", p, args[0], st.toString())); - BookMeta bookMeta = (BookMeta) swItem.getItemMeta(); - bookMeta.setPages(pages.toArray(new String[0])); - swItem.setItemMeta(bookMeta); - return swItem; - } -} 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 new file mode 100644 index 00000000..e0602616 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java @@ -0,0 +1,22 @@ +package de.steamwar.bausystem.features.script.event; + +import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.linkage.Linked; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.luaj.vm2.LuaValue; + +@Linked +public class CommandListener implements Listener { + + @EventHandler + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + String[] split = event.getMessage().split(" "); + LuaValue[] values = new LuaValue[split.length - 1]; + for (int i = 1; i < split.length; i++) { + values[i - 1] = LuaValue.valueOf(split[i]); + } + ScriptRunner.callCommand(event.getPlayer(), split[0].substring(1), LuaValue.listOf(values)); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java similarity index 52% rename from BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java index 4ee1a97d..3a43a83d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java @@ -1,31 +1,12 @@ -/* - * 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.script.custom.event; +package de.steamwar.bausystem.features.script.event; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.CustomScriptManager; +import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; import org.bukkit.Bukkit; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -39,6 +20,8 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.player.*; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; import java.util.HashMap; import java.util.HashSet; @@ -48,9 +31,6 @@ import java.util.Set; @Linked public class EventListener implements Listener { - @LinkedInstance - public CustomScriptManager manager; - private static final Map LAST_FS = new HashMap<>(); { @@ -61,18 +41,18 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { - manager.callEvent(EventType.SelfJoin, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - manager.callEvent(EventType.SelfLeave, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL); } @EventHandler public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { if (LAST_FS.containsKey(event.getPlayer())) { - manager.callEvent(EventType.FF, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.FF, LuaValue.NIL); } else { LAST_FS.put(event.getPlayer(), System.currentTimeMillis()); } @@ -80,12 +60,22 @@ public class EventListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { - manager.callEvent(EventType.PlaceBlock, event.getPlayer(), event); + LuaTable table = new LuaTable(); + table.set("x", event.getBlock().getX()); + table.set("y", event.getBlock().getY()); + table.set("z", event.getBlock().getZ()); + table.set("type", event.getBlock().getType().name()); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.PlaceBlock, table); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { - manager.callEvent(EventType.BreakBlock, event.getPlayer(), event); + LuaTable table = new LuaTable(); + table.set("x", event.getBlock().getX()); + table.set("y", event.getBlock().getY()); + table.set("z", event.getBlock().getZ()); + table.set("type", event.getBlock().getType().name()); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.BreakBlock, table); } private Set ignore = new HashSet<>(); @@ -95,11 +85,25 @@ public class EventListener implements Listener { if (ignore.remove(event.getPlayer())) { return; } + LuaTable table = new LuaTable(); + table.set("action", event.getAction().name()); + table.set("hand", event.getHand().name()); + table.set("block", event.getItem().getType().name()); + if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) { + table.set("hasBlock", LuaValue.valueOf(true)); + table.set("blockX", event.getClickedBlock().getX()); + table.set("blockY", event.getClickedBlock().getY()); + table.set("blockZ", event.getClickedBlock().getZ()); + table.set("blockFace", event.getBlockFace().name()); + } else { + table.set("hasBlock", LuaValue.valueOf(false)); + } + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { - manager.callEvent(EventType.RightClick, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.RightClick, table); } if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) { - manager.callEvent(EventType.LeftClick, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.LeftClick, table); } } @@ -112,7 +116,7 @@ public class EventListener implements Listener { for (Player player : Bukkit.getOnlinePlayers()) { if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { - manager.callEvent(EventType.TNTSpawn, player, event); + ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTSpawn, LuaValue.NIL); } } } @@ -124,9 +128,14 @@ public class EventListener implements Listener { } Region tntRegion = Region.getRegion(event.getLocation()); + LuaTable table = new LuaTable(); + table.set("x", event.getLocation().getX()); + table.set("y", event.getLocation().getY()); + table.set("z", event.getLocation().getZ()); + for (Player player : Bukkit.getOnlinePlayers()) { if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { - manager.callEvent(EventType.TNTExplode, player, event); + ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table); } } } @@ -134,13 +143,17 @@ public class EventListener implements Listener { @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { ignore.add(event.getPlayer()); - manager.callEvent(EventType.DropItem, event.getPlayer(), event); + LuaTable table = new LuaTable(); + table.set("type", event.getItemDrop().getItemStack().getType().name()); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table); } @EventHandler public void onEntityDeath(EntityDeathEvent event) { for (Player player : Bukkit.getOnlinePlayers()) { - manager.callEvent(EventType.EntityDeath, player, event); + LuaTable table = new LuaTable(); + table.set("type", event.getEntityType().name()); + ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.EntityDeath, table); } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java deleted file mode 100644 index 9bf807fb..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java +++ /dev/null @@ -1,242 +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.script.expression; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.variables.Constants; -import de.steamwar.bausystem.features.script.variables.Value; -import org.bukkit.entity.Player; - -import java.util.*; - -public class Expression { - - private static int highestPrecedence = 1; - - public static final Map OPERATORS = new HashMap<>(); - - public static void registerOperator(Operator operator) { - highestPrecedence = Math.max(highestPrecedence, operator.getPriority()) + 1; - OPERATORS.put(operator.getOperator(), operator); - } - - private Player p; - private ScriptExecutor scriptExecutor; - - private String s; - - public Expression(Player p, String s, ScriptExecutor scriptExecutor) { - s = s.substring(1, s.length() - 1); - this.p = p; - this.s = s; - this.scriptExecutor = scriptExecutor; - } - - public Value eval() { - List tokens = new ArrayList<>(tokenize(s)); - List priorities = priorities(tokens); - - while (true) { - int toCalc = getToCalc(priorities); - if (priorities.get(toCalc) == 0) break; - if (priorities.get(toCalc) == highestPrecedence) { - String s = (String) tokens.get(toCalc); - if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) { - tokens.set(toCalc, new Value.BooleanValue(Boolean.parseBoolean(s))); - priorities.set(toCalc, 0); - continue; - } - String[] strings = s.split("\\."); - if (strings.length == 1) { - Value value = scriptExecutor.getValueOrNull(strings[0]); - if (value == null) { - throw new VarNotFoundException(strings[0]); - } - tokens.set(toCalc, value); - priorities.set(toCalc, 0); - } else { - boolean searchGlobal = false; - boolean searchConst = false; - boolean searchLocal = false; - if (strings[0].equals("global")) { - searchGlobal = true; - strings = Arrays.copyOfRange(strings, 1, strings.length); - } else if (strings[0].equals("const")) { - searchConst = true; - strings = Arrays.copyOfRange(strings, 1, strings.length); - } else if (strings[0].equals("local")) { - searchLocal = true; - strings = Arrays.copyOfRange(strings, 1, strings.length); - } - String varName = strings[0]; - Value value; - if (searchGlobal) { - value = scriptExecutor.getGlobalVariables().getValue(varName); - } else if (searchConst) { - value = Constants.getConstant(varName, p); - } else if (searchLocal) { - value = scriptExecutor.getLocalVariables().getValue(varName); - } else { - value = scriptExecutor.getValueOrNull(varName); - } - for (int i = 1; i < strings.length; i++) { - switch (strings[i]) { - case "isset": - value = new Value.BooleanValue(value != null); - break; - case "type": - value = new Value.StringValue(value == null ? "" : value.type()); - break; - case "length": - value = new Value.LongValue(value == null ? 0 : value.asString().length()); - break; - } - } - if (value == null) { - throw new VarNotFoundException(strings[0]); - } - tokens.set(toCalc, value); - priorities.set(toCalc, 0); - } - } else { - Value first = parse(tokens.get(toCalc - 1)); - Value second = parse(tokens.get(toCalc + 1)); - String op = (String) tokens.get(toCalc); - Operator operation = OPERATORS.get(op); - if (operation == null) { - throw new UnknownOperatorException(op); - } - Value result = operation.operate(first, second); - tokens.set(toCalc - 1, result); - tokens.remove(toCalc); - tokens.remove(toCalc); - priorities.remove(toCalc); - priorities.remove(toCalc); - priorities.set(toCalc - 1, 0); - } - } - - return parse(tokens.get(0)); - } - - private Value parse(Object token) { - if (token instanceof Value) { - return (Value) token; - } else if (token instanceof String) { - String s = (String) token; - if (s.startsWith("{") && s.endsWith("}")) { - return new Expression(p, s, scriptExecutor).eval(); - } else { - return Value.parse(s); - } - } else { - throw new IllegalArgumentException("Unknown token: " + token); - } - } - - private String getExpressionString(String s, int index) { - StringBuilder result = new StringBuilder(); - int depth = 0; - for (int i = index; i < s.length(); i++) { - char c = s.charAt(i); - if (c == '{') { - depth++; - } else if (c == '}') { - result.append(c); - depth--; - if (depth == 0) { - return result.toString(); - } - } - if (depth > 0) { - result.append(c); - } - } - return result.toString(); - } - - private List tokenize(String s) { - List tokens = new ArrayList<>(); - StringBuilder token = new StringBuilder(); - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c == ' ') continue; - if (c == '{') { - String subExpression = getExpressionString(s, i); - tokens.add(subExpression); - i += subExpression.length() - 1; - continue; - } - StringBuilder op = new StringBuilder(); - for (int j = i; j < s.length(); j++) { - char k = s.charAt(j); - if (k == '+' || k == '-' || k == '*' || k == '/' || k == '%' || k == '^' || k == '&' || k == '|' || k == '>' || k == '<' || k == '=' || k == '!') { - op.append(k); - } else { - break; - } - } - if (op.length() > 0) { - if (token.length() > 0) { - tokens.add(token.toString()); - token = new StringBuilder(); - } - tokens.add(op.toString()); - i += op.length() - 1; - continue; - } - token.append(c); - } - if (token.length() > 0) { - tokens.add(token.toString()); - } - return tokens; - } - - private List priorities(List tokens) { - List priorities = new ArrayList<>(); - for (Object obj : tokens) { - String token = (String) obj; - Operator operator = OPERATORS.get(token); - if (token.startsWith("{") && token.endsWith("}")) { - priorities.add(0); - } else if (!token.matches("[0-9]+([.,][0-9]+)?") && operator == null) { - priorities.add(highestPrecedence); - } else if (operator != null) { - priorities.add(operator.getPriority()); - } else { - priorities.add(0); - } - } - return priorities; - } - - private int getToCalc(List priorities) { - int max = 0; - int index = 0; - for (int i = 0; i < priorities.size(); i++) { - if (priorities.get(i) > max) { - max = priorities.get(i); - index = i; - } - } - return index; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Operator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Operator.java deleted file mode 100644 index 6fa67838..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Operator.java +++ /dev/null @@ -1,37 +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.script.expression; - -import de.steamwar.bausystem.features.script.variables.Value; - -public interface Operator { - String getOperator(); - int getPriority(); - Value operate(Value value, Value value2); - - default boolean is(Value value, Class... classes) { - for (Class clazz : classes) { - if (clazz.isInstance(value)) { - return true; - } - } - return false; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/UnknownOperatorException.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/UnknownOperatorException.java deleted file mode 100644 index 163970c2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/UnknownOperatorException.java +++ /dev/null @@ -1,27 +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.script.expression; - -public class UnknownOperatorException extends RuntimeException{ - - public UnknownOperatorException(String message) { - super(message); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/VarNotFoundException.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/VarNotFoundException.java deleted file mode 100644 index a007601d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/VarNotFoundException.java +++ /dev/null @@ -1,27 +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.script.expression; - -public class VarNotFoundException extends RuntimeException{ - - public VarNotFoundException(String message) { - super(message); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/EqualOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/EqualOperator.java deleted file mode 100644 index 09ab767c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/EqualOperator.java +++ /dev/null @@ -1,61 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class EqualOperator implements Operator { - - @Override - public String getOperator() { - return "=="; - } - - @Override - public int getPriority() { - return 6; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.DoubleValue && value2 instanceof Value.LongValue) { - return new Value.BooleanValue(value.asDouble() == value2.asDouble()); - } - if (value instanceof Value.LongValue && value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() == value2.asDouble()); - } - if (!value.type().equals(value2.type())) { - return new Value.BooleanValue(false); - } - if (value instanceof Value.StringValue) { - return new Value.BooleanValue(value.asString().equals(value2.asString())); - } - if (value instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() == value2.asDouble()); - } - if (value instanceof Value.LongValue) { - return new Value.BooleanValue(value.asLong() == value2.asLong()); - } - return new Value.BooleanValue(value.asBoolean() == value2.asBoolean()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOperator.java deleted file mode 100644 index 6234e2fb..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class GreaterOperator implements Operator { - - @Override - public String getOperator() { - return ">"; - } - - @Override - public int getPriority() { - return 7; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() > value2.asDouble()); - } else { - return new Value.BooleanValue(value.asLong() > value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOrEqualOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOrEqualOperator.java deleted file mode 100644 index 6320c8a2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOrEqualOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class GreaterOrEqualOperator implements Operator { - - @Override - public String getOperator() { - return ">="; - } - - @Override - public int getPriority() { - return 7; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() >= value2.asDouble()); - } else { - return new Value.BooleanValue(value.asLong() >= value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOperator.java deleted file mode 100644 index 93cd46ed..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class LessOperator implements Operator { - - @Override - public String getOperator() { - return "<"; - } - - @Override - public int getPriority() { - return 7; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() < value2.asDouble()); - } else { - return new Value.BooleanValue(value.asLong() < value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOrEqualOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOrEqualOperator.java deleted file mode 100644 index 5accf5cb..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOrEqualOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class LessOrEqualOperator implements Operator { - - @Override - public String getOperator() { - return "<="; - } - - @Override - public int getPriority() { - return 7; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() <= value2.asDouble()); - } else { - return new Value.BooleanValue(value.asLong() <= value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/NotEqualOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/NotEqualOperator.java deleted file mode 100644 index b41eea55..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/NotEqualOperator.java +++ /dev/null @@ -1,61 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class NotEqualOperator implements Operator { - - @Override - public String getOperator() { - return "!="; - } - - @Override - public int getPriority() { - return 6; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.DoubleValue && value2 instanceof Value.LongValue) { - return new Value.BooleanValue(value.asDouble() != value2.asDouble()); - } - if (value instanceof Value.LongValue && value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() != value2.asDouble()); - } - if (!value.type().equals(value2.type())) { - return new Value.BooleanValue(false); - } - if (value instanceof Value.StringValue) { - return new Value.BooleanValue(!value.asString().equals(value2.asString())); - } - if (value instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() != value2.asDouble()); - } - if (value instanceof Value.LongValue) { - return new Value.BooleanValue(value.asLong() != value2.asLong()); - } - return new Value.BooleanValue(value.asBoolean() != value2.asBoolean()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/AndOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/AndOperator.java deleted file mode 100644 index ec6b219e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/AndOperator.java +++ /dev/null @@ -1,47 +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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class AndOperator implements Operator { - - @Override - public String getOperator() { - return "&&"; - } - - @Override - public int getPriority() { - return 2; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class) || is(value2, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE"); - } - return new Value.BooleanValue(value.asBoolean() && value2.asBoolean()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseAndOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseAndOperator.java deleted file mode 100644 index e269c7fc..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseAndOperator.java +++ /dev/null @@ -1,55 +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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseAndOperator implements Operator { - - @Override - public String getOperator() { - return "&"; - } - - @Override - public int getPriority() { - return 5; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR"); - } - if (value.getClass() != value2.getClass()) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR"); - } - if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) { - return new Value.BooleanValue(value.asBoolean() && value2.asBoolean()); - } - return new Value.LongValue(value.asLong() & value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseOrOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseOrOperator.java deleted file mode 100644 index 21966f44..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseOrOperator.java +++ /dev/null @@ -1,55 +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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseOrOperator implements Operator { - - @Override - public String getOperator() { - return "|"; - } - - @Override - public int getPriority() { - return 4; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR"); - } - if (value.getClass() != value2.getClass()) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR"); - } - if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) { - return new Value.BooleanValue(value.asBoolean() || value2.asBoolean()); - } - return new Value.LongValue(value.asLong() | value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseXorOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseXorOperator.java deleted file mode 100644 index f5e02568..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseXorOperator.java +++ /dev/null @@ -1,55 +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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseXorOperator implements Operator { - - @Override - public String getOperator() { - return "^"; - } - - @Override - public int getPriority() { - return 3; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR"); - } - if (value.getClass() != value2.getClass()) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR"); - } - if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) { - return new Value.BooleanValue(value.asBoolean() ^ value2.asBoolean()); - } - return new Value.LongValue(value.asLong() ^ value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/OrOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/OrOperator.java deleted file mode 100644 index 81b63190..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/OrOperator.java +++ /dev/null @@ -1,47 +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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class OrOperator implements Operator { - - @Override - public String getOperator() { - return "||"; - } - - @Override - public int getPriority() { - return 1; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class) || is(value2, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE"); - } - return new Value.BooleanValue(value.asBoolean() || value2.asBoolean()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLeftOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLeftOperator.java deleted file mode 100644 index 172fc2ed..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLeftOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseLeftOperator implements Operator { - - @Override - public String getOperator() { - return "<<"; - } - - @Override - public int getPriority() { - return 8; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_LEFT_ERROR"); - } - return new Value.LongValue(value.asLong() << value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLogicRightOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLogicRightOperator.java deleted file mode 100644 index cd0952a8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLogicRightOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseLogicRightOperator implements Operator { - - @Override - public String getOperator() { - return ">>>"; - } - - @Override - public int getPriority() { - return 8; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_LOGIC_ERROR"); - } - return new Value.LongValue(value.asLong() >>> value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseRightOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseRightOperator.java deleted file mode 100644 index f260489e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseRightOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseRightOperator implements Operator { - - @Override - public String getOperator() { - return ">>"; - } - - @Override - public int getPriority() { - return 8; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_ERROR"); - } - return new Value.LongValue(value.asLong() >> value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java deleted file mode 100644 index a4ab1c8c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java +++ /dev/null @@ -1,49 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class DivideOperator implements Operator { - - @Override - public String getOperator() { - return "/"; - } - - @Override - public int getPriority() { - return 10; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR"); - } - if (value2.asDouble() == 0) { - return new Value.DoubleValue(Double.NaN); - } - return new Value.DoubleValue(value.asDouble() / value2.asDouble()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MinusOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MinusOperator.java deleted file mode 100644 index 877ce2af..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MinusOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class MinusOperator implements Operator { - - @Override - public String getOperator() { - return "-"; - } - - @Override - public int getPriority() { - return 9; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.DoubleValue(value.asDouble() - value2.asDouble()); - } else { - return new Value.LongValue(value.asLong() - value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/ModuloOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/ModuloOperator.java deleted file mode 100644 index af241af4..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/ModuloOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class ModuloOperator implements Operator { - - @Override - public String getOperator() { - return "%"; - } - - @Override - public int getPriority() { - return 10; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.LongValue && value2 instanceof Value.LongValue) { - return new Value.LongValue(value.asLong() % value2.asLong()); - } - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR"); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MultiplyOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MultiplyOperator.java deleted file mode 100644 index 34a99c5a..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MultiplyOperator.java +++ /dev/null @@ -1,57 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class MultiplyOperator implements Operator { - - @Override - public String getOperator() { - return "*"; - } - - @Override - public int getPriority() { - return 10; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR"); - } - if (value instanceof Value.StringValue) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < value2.asLong(); i++) { - sb.append(value.asString()); - } - return new Value.StringValue(sb.toString()); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.DoubleValue(value.asDouble() * value2.asDouble()); - } else { - return new Value.LongValue(value.asLong() * value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PlusOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PlusOperator.java deleted file mode 100644 index 6b92dd84..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PlusOperator.java +++ /dev/null @@ -1,53 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class PlusOperator implements Operator { - - @Override - public String getOperator() { - return "+"; - } - - @Override - public int getPriority() { - return 9; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.BooleanValue || value2 instanceof Value.BooleanValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR"); - } - if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) { - return new Value.StringValue(value.asString() + value2.asString()); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.DoubleValue(value.asDouble() + value2.asDouble()); - } else { - return new Value.LongValue(value.asLong() + value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PowerOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PowerOperator.java deleted file mode 100644 index f756a796..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PowerOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class PowerOperator implements Operator { - - @Override - public String getOperator() { - return "**"; - } - - @Override - public int getPriority() { - return 11; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_POW_ERROR"); - } - return new Value.DoubleValue(Math.pow(value.asDouble(), value2.asDouble())); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/items/ScriptMenuBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/items/ScriptMenuBauGuiItem.java deleted file mode 100644 index 437b4760..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/items/ScriptMenuBauGuiItem.java +++ /dev/null @@ -1,55 +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.script.items; - -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; - -@Linked -public class ScriptMenuBauGuiItem extends BauGuiItem { - - public ScriptMenuBauGuiItem() { - super(15); - } - - @Override - public ItemStack getItem(Player player) { - return new SWItem(Material.WRITTEN_BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_ITEM_NAME", player)).getItemStack(); - } - - @Override - public boolean click(ClickType click, Player p) { - p.closeInventory(); - p.performCommand("script"); - return false; - } - - @Override - public Permission permission() { - return Permission.MEMBER; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java new file mode 100644 index 00000000..2e6d9c46 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java @@ -0,0 +1,15 @@ +package de.steamwar.bausystem.features.script.lua; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.luaj.vm2.LuaFunction; + +import java.util.List; + +@AllArgsConstructor +@Getter +public class CommandRegister { + + private final String name; + private final LuaFunction function; +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java new file mode 100644 index 00000000..544b8af9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java @@ -0,0 +1,74 @@ +package de.steamwar.bausystem.features.script.lua; + +import lombok.AllArgsConstructor; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaString; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.TwoArgFunction; +import org.luaj.vm2.lib.VarArgFunction; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +@AllArgsConstructor +public class SteamWarGlobalLuaPlugin extends TwoArgFunction { + private final BiConsumer eventConsumer; + private final Consumer commandRegisterConsumer; + + @Override + public LuaValue call(LuaValue modname, LuaValue env) { + LuaValue types = tableOf(); + for (EventType value : EventType.values()) { + types.set(value.name(), value.ordinal()); + } + env.set("type", types); + + + env.set("event", new On()); + env.set("command", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + LuaString command = arg1.checkstring(); + LuaFunction function = arg2.checkfunction(); + + commandRegisterConsumer.accept(new CommandRegister(command.tojstring().toLowerCase(), function)); + + return NIL; + } + }); + return NIL; + } + + class On extends TwoArgFunction { + @Override + public LuaValue call(LuaValue eventName, LuaValue function) { + int ord = eventName.checkint(); + LuaFunction luaFunction = function.checkfunction(); + + int nArgs = luaFunction.narg(); + if (nArgs != 1) { + return LuaValue.valueOf("Expected 1 argument, got " + nArgs); + } + + eventConsumer.accept(EventType.values()[ord], luaFunction); + + return LuaValue.NIL; + } + } + + public enum EventType { + FF, + PlaceBlock, + BreakBlock, + RightClick, + LeftClick, + TNTSpawn, + TNTExplode, + TNTExplodeInBuild, + SelfJoin, + SelfLeave, + DropItem, + EntityDeath; + } +} 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 new file mode 100644 index 00000000..21b24e5e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -0,0 +1,144 @@ +package de.steamwar.bausystem.features.script.lua; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.script.lua.libs.LuaLib; +import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.features.tracer.record.ActiveTracer; +import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder; +import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.record.TraceRecorder; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; +import de.steamwar.core.TPSWatcher; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWItem; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.luaj.vm2.*; +import org.luaj.vm2.lib.*; + +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.function.Supplier; + +public class SteamWarLuaPlugin extends TwoArgFunction { + + public static final Map, List> LUA_LIBS = new HashMap<>(); + + public static void add(LuaLib luaLib) { + LUA_LIBS.computeIfAbsent(luaLib.parent(), l -> new ArrayList<>()).add(luaLib); + } + + private final Player player; + + public SteamWarLuaPlugin(Player player) { + this.player = player; + } + + @Override + public LuaValue call(LuaValue modname, LuaValue env) { + LuaValue materialLib = tableOf(); + for (Material mat : Material.values()) { + materialLib.set(mat.name().toLowerCase(), valueOf(mat.name())); + } + + initialize(env, null); + + env.set("print", new Print()); + env.set("input", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + String message = arg1.tojstring(); + LuaFunction callback = arg2.checkfunction(); + + SWAnvilInv inv = new SWAnvilInv(player, message); + inv.setCallback(s -> callback.call(valueOf(s))); + inv.open(); + + return LuaValue.NIL; + } + }); + env.set("timeout", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + long time = arg1.checklong(); + LuaFunction callback = arg2.checkfunction(); + + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> callback.call(), time); + return LuaValue.NIL; + } + }); + env.set("pos", new ThreeArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) { + 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()) + }); + } + }); + env.set("exec", new VarArgFunction() { + @Override + public Varargs invoke(Varargs args) { + player.performCommand(varArgsToString(args)); + + return LuaValue.NIL; + } + }); + + env.set("collectgarbage", NIL); + env.set("dofile", NIL); + env.set("load", NIL); + env.set("loadfile", NIL); + env.set("pcall", NIL); + env.set("rawequal", NIL); + env.set("rawget", NIL); + env.set("rawlen", NIL); + env.set("rawset", NIL); + env.set("setmetatable", NIL); + env.set("xpcall", NIL); + return null; + } + + public static String varArgsToString(Varargs args) { + StringBuilder builder = new StringBuilder(); + for (int i = 1; i <= args.narg(); i++) { + LuaValue arg = args.arg(i); + builder.append(arg.tojstring()); + builder.append(" "); + } + return builder.toString(); + } + + private void initialize(LuaValue parent, Class clazz) { + LUA_LIBS.get(clazz).forEach(luaLib -> { + LuaTable luaTable = luaLib.get(player); + parent.set(luaLib.name(), luaTable); + initialize(luaTable, luaLib.getClass()); + }); + } + + class Print extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + player.sendMessage(varArgsToString(args)); + return LuaValue.NIL; + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java new file mode 100644 index 00000000..e30f70f8 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java @@ -0,0 +1,40 @@ +package de.steamwar.bausystem.features.script.lua; + +import org.bukkit.entity.Player; +import org.luaj.vm2.Globals; +import org.luaj.vm2.LoadState; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.compiler.LuaC; +import org.luaj.vm2.lib.Bit32Lib; +import org.luaj.vm2.lib.PackageLib; +import org.luaj.vm2.lib.StringLib; +import org.luaj.vm2.lib.TableLib; +import org.luaj.vm2.lib.jse.JseBaseLib; +import org.luaj.vm2.lib.jse.JseMathLib; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +public class SteamWarPlatform { + + public static Globals createClickGlobals(Player player) { + Globals globals = new Globals(); + globals.load(new JseBaseLib()); + globals.load(new PackageLib()); + globals.load(new JseMathLib()); + globals.load(new TableLib()); + globals.load(new Bit32Lib()); + globals.load(new StringLib()); + globals.load(new SteamWarLuaPlugin(player)); + + LoadState.install(globals); + LuaC.install(globals); + return globals; + } + + public static Globals createGlobalGlobals(Player player, BiConsumer eventConsumer, Consumer commandConsumer) { + Globals globals = createClickGlobals(player); + globals.load(new SteamWarGlobalLuaPlugin(eventConsumer, commandConsumer)); + return globals; + } +} 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 new file mode 100644 index 00000000..2e369f5f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java @@ -0,0 +1,88 @@ +package de.steamwar.bausystem.features.script.lua.libs; + +import lombok.AllArgsConstructor; +import org.bukkit.entity.Player; +import org.luaj.vm2.*; +import org.luaj.vm2.lib.VarArgFunction; +import org.luaj.vm2.lib.ZeroArgFunction; + +import java.util.function.Consumer; +import java.util.function.Supplier; + +public interface LuaLib { + + static LuaValue runGetter(Supplier supplier) { + T value = supplier.get(); + if (value == null) { + return LuaValue.NIL; + } + Class clazz = value.getClass(); + if (clazz == Integer.class || clazz == Long.class) { + return LuaValue.valueOf((int) value); + } else if (clazz == Double.class || clazz == Float.class) { + return LuaValue.valueOf((double) value); + } else if (clazz == String.class) { + return LuaValue.valueOf((String) value); + } else if (clazz == Boolean.class) { + return LuaValue.valueOf((boolean) value); + } + return LuaValue.NIL; + } + + default LuaFunction getter(Supplier supplier) { + return new ZeroArgFunction() { + @Override + public LuaValue call() { + return runGetter(supplier); + } + }; + } + + default LuaFunction getterAndSetter(Supplier supplier, Consumer consumer) { + return new GetterAndSetter<>(supplier, consumer); + } + + default String varArgsToString(Varargs varargs) { + return de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin.varArgsToString(varargs); + } + + default Class parent() { + return null; + } + String name(); + LuaTable get(Player player); + + @AllArgsConstructor + class GetterAndSetter extends VarArgFunction { + + private Supplier supplier; + private Consumer consumer; + + @Override + public Varargs invoke(Varargs args) { + if (args.narg() == 0) { + return runGetter(supplier); + } else { + if (args.narg() == 1) { + LuaValue luaValue = args.arg(0); + try { + if (luaValue instanceof LuaBoolean) { + consumer.accept(luaValue.toboolean()); + } else if (luaValue instanceof LuaInteger) { + consumer.accept(luaValue.toint()); + } else if (luaValue instanceof LuaDouble) { + consumer.accept(luaValue.todouble()); + } else if (luaValue instanceof LuaString) { + consumer.accept(luaValue.toString()); + } else { + throw new LuaError("Invalid lua type: " + luaValue.typename()); + } + } catch (Throwable throwable) { + throw new LuaError("Error in '" + checkfunction().name() + "' " + throwable.getMessage()); + } + } + return 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 new file mode 100644 index 00000000..9c6cfab1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java @@ -0,0 +1,66 @@ +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.entity.Player; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; + +@Linked +public class PlayerLib implements LuaLib { + + public String name() { + return "player"; + } + + public LuaTable get(Player player) { + LuaTable table = new LuaTable(); + table.set("name", getter(player::getName)); + table.set("message", new Print(player)); + table.set("actionbar", new SendActionbar(player)); + + table.set("x", getterAndSetter(player.getLocation()::getX, player.getLocation()::setX)); + table.set("y", getterAndSetter(player.getLocation()::getY, player.getLocation()::setY)); + table.set("z", getterAndSetter(player.getLocation()::getZ, player.getLocation()::setZ)); + table.set("yaw", getterAndSetter(player.getLocation()::getYaw, player.getLocation()::setYaw)); + table.set("pitch", getterAndSetter(player.getLocation()::getPitch, player.getLocation()::setPitch)); + + table.set("sneaking", getter(player::isSneaking)); + table.set("sprinting", getter(player::isSprinting)); + table.set("slot", getterAndSetter(player.getInventory()::getHeldItemSlot, player.getInventory()::setHeldItemSlot)); + table.set("item", getter(player.getInventory().getItemInMainHand().getType()::name)); + table.set("offHandItem", getter(player.getInventory().getItemInOffHand().getType()::name)); + return table; + } + + private class Print extends VarArgFunction { + private final Player player; + + public Print(Player player) { + this.player = player; + } + + @Override + public Varargs invoke(Varargs args) { + player.sendMessage(varArgsToString(args)); + return LuaValue.NIL; + } + } + + private class SendActionbar extends VarArgFunction { + private final Player player; + + public SendActionbar(Player player) { + this.player = player; + } + + @Override + public Varargs invoke(Varargs args) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(varArgsToString(args))); + 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 new file mode 100644 index 00000000..b85a6c3f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java @@ -0,0 +1,58 @@ +package de.steamwar.bausystem.features.script.lua.libs; + +import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.tracer.record.ActiveTracer; +import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder; +import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; + +@Linked +public class RegionLib implements LuaLib { + + + @Override + public String name() { + return "region"; + } + + @Override + public LuaTable get(Player player) { + LuaTable table = LuaValue.tableOf(); + + table.set("name", getter(() -> Region.getRegion(player.getLocation()).getName())); + table.set("type", getter(() -> Region.getRegion(player.getLocation()).getPrototype().getName())); + + LuaValue tntLib = LuaValue.tableOf(); + tntLib.set("mode", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class).name())); + tntLib.set("enabled", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY)); + tntLib.set("onlyTb", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB)); + + table.set("tnt", tntLib); + + table.set("fire", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW)); + table.set("freeze", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE)); + table.set("protect", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE)); + + LuaValue traceLib = LuaValue.tableOf(); + traceLib.set("active", getter(() -> !Region.getRegion(player.getLocation()).isGlobal() && Recorder.INSTANCE.get(Region.getRegion(player.getLocation())) instanceof ActiveTracer)); + traceLib.set("auto", getter(() -> !Region.getRegion(player.getLocation()).isGlobal() && Recorder.INSTANCE.get(Region.getRegion(player.getLocation())) instanceof AutoTraceRecorder)); + traceLib.set("status", getter(() -> Recorder.INSTANCE.get(Region.getRegion(player.getLocation())).scriptState())); + traceLib.set("time", getter(() -> Recorder.INSTANCE.get(Region.getRegion(player.getLocation())).scriptTime())); + + table.set("trace", traceLib); + + Loader loader = Loader.getLoader(player); + table.set("loader", getter(() -> loader == null ? "OFF" : loader.getStage().name())); + + return table; + } +} 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 new file mode 100644 index 00000000..5c0ae63d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -0,0 +1,65 @@ +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.TPSUtils; +import de.steamwar.core.TPSWatcher; +import de.steamwar.inventory.SWItem; +import de.steamwar.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.luaj.vm2.LuaString; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.OneArgFunction; +import org.luaj.vm2.lib.TwoArgFunction; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +@Linked +public class ServerLib implements LuaLib { + @Override + public String name() { + return "server"; + } + + @Override + 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("ticks", getter(TPSUtils.currentTick)); + serverLib.set("getBlockAt", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg1) { + LuaTable pos = arg1.checktable(); + return valueOf(player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()).getType().name()); + } + }); + serverLib.set("setBlockAt", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + LuaTable pos = arg1.checktable(); + LuaString material = arg2.checkstring(); + Material mat = SWItem.getMaterial(material.tojstring()); + if (mat == null) { + return NIL; + } + player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()).setType(mat); + 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(TPSLimitUtils::getCurrentTPSLimit)); + + serverLib.set("tps", tpsLib); + return serverLib; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java deleted file mode 100644 index b14310b2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ /dev/null @@ -1,315 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; -import de.steamwar.bausystem.features.tpslimit.FreezeUtils; -import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; -import de.steamwar.bausystem.features.tpslimit.TPSUtils; -import de.steamwar.bausystem.features.tracer.record.ActiveTracer; -import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder; -import de.steamwar.bausystem.features.tracer.record.Recorder; -import de.steamwar.bausystem.features.tracer.record.TraceRecorder; -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.flags.flagvalues.FireMode; -import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; -import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; -import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; -import de.steamwar.core.TPSWatcher; -import de.steamwar.sql.SteamwarUser; -import lombok.experimental.UtilityClass; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.ItemMeta; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import java.util.function.Supplier; - -@UtilityClass -public class Constants { - - private final Map> CONSTANTS = new HashMap<>(); - - private static class ConstantDoubleValue extends Value.DoubleValue { - - private Supplier doubleSupplier; - - public ConstantDoubleValue(Supplier doubleSupplier) { - super(doubleSupplier.get()); - this.doubleSupplier = doubleSupplier; - } - - @Override - public long asLong() { - value = doubleSupplier.get(); - return super.asLong(); - } - - @Override - public double asDouble() { - value = doubleSupplier.get(); - return super.asDouble(); - } - - @Override - public boolean asBoolean() { - value = doubleSupplier.get(); - return super.asBoolean(); - } - - @Override - public String asString() { - value = doubleSupplier.get(); - return super.asString(); - } - } - - private static class ConstantLongValue extends Value.LongValue { - - private Supplier longSupplier; - - public ConstantLongValue(Supplier longSupplier) { - super(longSupplier.get()); - this.longSupplier = longSupplier; - } - - @Override - public long asLong() { - value = longSupplier.get(); - return super.asLong(); - } - - @Override - public double asDouble() { - value = longSupplier.get(); - return super.asDouble(); - } - - @Override - public boolean asBoolean() { - value = longSupplier.get(); - return super.asBoolean(); - } - - @Override - public String asString() { - value = longSupplier.get(); - return super.asString(); - } - } - - private static class ConstantBooleanValue extends Value.BooleanValue { - - private Supplier booleanSupplier; - - public ConstantBooleanValue(Supplier booleanSupplier) { - super(booleanSupplier.get()); - this.booleanSupplier = booleanSupplier; - } - - @Override - public long asLong() { - value = booleanSupplier.get(); - return super.asLong(); - } - - @Override - public double asDouble() { - value = booleanSupplier.get(); - return super.asDouble(); - } - - @Override - public boolean asBoolean() { - value = booleanSupplier.get(); - return super.asBoolean(); - } - - @Override - public String asString() { - value = booleanSupplier.get(); - return super.asString(); - } - } - - private static class ConstantStringValue extends Value.StringValue { - - private Supplier stringSupplier; - - public ConstantStringValue(Supplier stringSupplier) { - super(stringSupplier.get()); - this.stringSupplier = stringSupplier; - } - - @Override - public long asLong() { - value = stringSupplier.get(); - return super.asLong(); - } - - @Override - public double asDouble() { - value = stringSupplier.get(); - return super.asDouble(); - } - - @Override - public boolean asBoolean() { - value = stringSupplier.get(); - return super.asBoolean(); - } - - @Override - public String asString() { - value = stringSupplier.get(); - return super.asString(); - } - } - - static { - CONSTANTS.put("trace", player -> { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return new ConstantBooleanValue(() -> false); - } - return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof ActiveTracer); - }); - CONSTANTS.put("autotrace", player -> { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return new ConstantBooleanValue(() -> false); - } - return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof AutoTraceRecorder); - }); - CONSTANTS.put("trace_status", player -> { - TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); - return new ConstantStringValue(recorder::scriptState); - }); - CONSTANTS.put("trace_time", player -> { - TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); - return new ConstantLongValue(recorder::scriptTime); - }); - - CONSTANTS.put("tnt", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY); - }); - CONSTANTS.put("tnt_onlytb", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB); - }); - - CONSTANTS.put("fire", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW); - }); - - CONSTANTS.put("freeze", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE); - }); - - CONSTANTS.put("protect", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE); - }); - - CONSTANTS.put("x", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getX()); - }); - CONSTANTS.put("y", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getY()); - }); - CONSTANTS.put("z", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getZ()); - }); - CONSTANTS.put("name", player -> { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - return new ConstantStringValue(user::getUserName); - }); - CONSTANTS.put("sneaking", player -> { - return new ConstantBooleanValue(player::isSneaking); - }); - CONSTANTS.put("sprinting", player -> { - return new ConstantBooleanValue(player::isSprinting); - }); - CONSTANTS.put("slot", player -> { - return new ConstantLongValue(() -> (long) player.getInventory().getHeldItemSlot()); - }); - CONSTANTS.put("slotmaterial", player -> { - return new ConstantStringValue(() -> player.getInventory().getItemInMainHand().getType().name()); - }); - CONSTANTS.put("offhandmaterial", player -> { - return new ConstantStringValue(() -> player.getInventory().getItemInOffHand().getType().name()); - }); - CONSTANTS.put("materialname", player -> { - return new ConstantStringValue(() -> { - ItemMeta itemMeta = player.getInventory().getItemInMainHand().getItemMeta(); - if (itemMeta == null) { - return ""; - } - return itemMeta.getDisplayName(); - }); - }); - CONSTANTS.put("offmaterialname", player -> { - return new ConstantStringValue(() -> { - ItemMeta itemMeta = player.getInventory().getItemInOffHand().getItemMeta(); - if (itemMeta == null) { - return ""; - } - return itemMeta.getDisplayName(); - }); - }); - - CONSTANTS.put("region_type", player -> { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return new ConstantStringValue(() -> "global"); - } - return new ConstantStringValue(() -> region.getPrototype().getDisplayName().replace(' ', '_').toLowerCase()); - }); - CONSTANTS.put("region_name", player -> { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return new ConstantStringValue(() -> "Global"); - } - return new ConstantStringValue(() -> region.getPrototype().getDisplayName()); - }); - - CONSTANTS.put("tps", player -> { - return new ConstantDoubleValue(() -> { - if (FreezeUtils.isFrozen()) return 0.0; - return TPSWatcher.getTPS(); - }); - }); - CONSTANTS.put("tps_limit", player -> { - return new ConstantDoubleValue(TPSLimitUtils::getCurrentTPSLimit); - }); - - CONSTANTS.put("ticks", player -> { - return new ConstantLongValue(TPSUtils.currentTick); - }); - CONSTANTS.put("time", player -> { - return new ConstantStringValue(() -> new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", player)).format(Calendar.getInstance().getTime())); - }); - - CONSTANTS.put("loader_status", player -> { - Loader loader = Loader.getLoader(player); - if (loader == null) { - return new ConstantStringValue(() -> "OFF"); - } - return new ConstantStringValue(() -> loader.getStage().name()); - }); - } - - public Set allVariables() { - return CONSTANTS.keySet(); - } - - public boolean isConstant(String variableName) { - return CONSTANTS.containsKey(variableName); - } - - public Value getConstant(String variableName, Player player) { - return CONSTANTS.get(variableName).apply(player); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java deleted file mode 100644 index e1662028..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class Context { - - private Map variables = new HashMap<>(); - - public void putValue(String variableName, Value value) { - if (variables.containsKey(variableName)) { - if (variables.get(variableName).type().equals(value.type())) { - variables.get(variableName).fromValue(value); - } else { - variables.put(variableName, value); - } - } else { - variables.put(variableName, value); - } - } - - public void removeValue(String variableName) { - variables.remove(variableName); - } - - public boolean hasValue(String variableName) { - return variables.containsKey(variableName); - } - - public Value getValue(String variableName) { - return variables.get(variableName); - } - - public Set allVariables() { - return variables.keySet(); - } - - public Set> entrySet() { - return variables.entrySet(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java deleted file mode 100644 index 5373ff5d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java +++ /dev/null @@ -1,188 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -import lombok.AllArgsConstructor; -import lombok.ToString; - -public interface Value { - - static Value parse(String varValue) { - try { - return new Value.LongValue(Long.parseLong(varValue)); - } catch (NumberFormatException ne) { - try { - return new Value.DoubleValue(Double.parseDouble(varValue)); - } catch (NumberFormatException e) { - if (varValue.equalsIgnoreCase("true") || varValue.equalsIgnoreCase("false")) { - return new Value.BooleanValue(varValue.equalsIgnoreCase("true")); - } else { - return new Value.StringValue(varValue); - } - } - } - } - - String type(); - long asLong(); - double asDouble(); - boolean asBoolean(); - String asString(); - - void fromValue(Value value); - - @AllArgsConstructor - @ToString - class DoubleValue implements Value { - - protected double value; - - @Override - public String type() { - return "floating_number"; - } - - @Override - public long asLong() { - return Math.round(value); - } - - @Override - public double asDouble() { - return value; - } - - @Override - public boolean asBoolean() { - return value != 0; - } - - @Override - public String asString() { - return value + ""; - } - - @Override - public void fromValue(Value value) { - this.value = value.asDouble(); - } - } - - @AllArgsConstructor - @ToString - class LongValue implements Value { - - protected long value; - - @Override - public String type() { - return "number"; - } - - @Override - public long asLong() { - return value; - } - - @Override - public double asDouble() { - return value; - } - - @Override - public boolean asBoolean() { - return value != 0; - } - - @Override - public String asString() { - return value + ""; - } - - @Override - public void fromValue(Value value) { - this.value = value.asLong(); - } - } - - @AllArgsConstructor - @ToString - class BooleanValue implements Value { - - protected boolean value; - - @Override - public String type() { - return "boolean"; - } - - @Override - public long asLong() { - return value ? 1 : 0; - } - - @Override - public double asDouble() { - return value ? 1 : 0; - } - - @Override - public boolean asBoolean() { - return value; - } - - @Override - public String asString() { - return value + ""; - } - - @Override - public void fromValue(Value value) { - this.value = value.asBoolean(); - } - } - - @AllArgsConstructor - @ToString - class StringValue implements Value { - - protected String value; - - @Override - public String type() { - return "text"; - } - - @Override - public long asLong() { - try { - return Long.parseLong(value); - } catch (NumberFormatException e) { - return 0; - } - } - - @Override - public double asDouble() { - try { - return Double.parseDouble(value); - } catch (NumberFormatException e) { - return 0; - } - } - - @Override - public boolean asBoolean() { - return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"); - } - - @Override - public String asString() { - return value; - } - - @Override - public void fromValue(Value value) { - this.value = value.asString(); - } - } - -} diff --git a/SCRIPT.md b/SCRIPT.md new file mode 100644 index 00000000..f93a5f16 --- /dev/null +++ b/SCRIPT.md @@ -0,0 +1,183 @@ +# SteamWar.de - Script System + +--- + +* [SteamWar.de - Script System](#steamwarde---script-system) + * [Einleitung](#einleitung) +* [Basis-Apis](#basis-apis) +* [SteamWar.de-Api](#steamwarde-api) + * [global](#global) + * [player](#player) + * [region](#region) + * [tnt](#tnt) + * [server](#server) +* [SteamWar.de-Global-Api](#steamwarde-global-api) + * [Event Type](#event-type) + * [BlockEvent](#blockevent) + * [InteractEvent](#interactevent) + * [Position](#position) +* [Beispiele](#beispiele) + * [Hello, World!](#hello-world) + * [Code](#code) + * [Ausgabe](#ausgabe) + + + +## Einleitung +Das Script System auf SteamWar.de basiert auf [Lua](https://www.lua.org/docs.html). Der Code wird einfach in ein Minecraft Buch geschrieben und kann mit einem Links-Klick ausgeführt werden. + +# Basis-Apis +Es werden folgende Standard-Apis zur Verfügung gestellt: +- [`math`](https://www.lua.org/manual/5.4/manual.html#6.7) +- [`string`](https://www.lua.org/manual/5.4/manual.html#6.4) +- [`table`](https://www.lua.org/manual/5.4/manual.html#6.6) +- `bit32` + +# SteamWar.de-Api +In den Scripten gibt es dazu noch folgende globale Variablen: +- [`player`](#player) +- [`region`](#region) +- [`server`](#server) + +### global +Die `global`-Api stellt Funktionen zur Verfügung, QOL sind. +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|-----------|----------------------------------|----------------------------------------------------------------------------------------------------| +| `print` | print(String...) | @see message(String...) | +| `input` | input(String, Function\) | Fragt den User nach einer Eingabe mit der Nachricht und called die zugehörige Funktion nach dieser | +| `timeout` | timeout(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 | +| `exec` | exec(String...) | Führt den angegebenen Befehl als Spieler aus | + +### player +Die `player`-Api stellt Funktionen zur Verfügung, die den Spieler betreffen. +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|---------------|--------------------------------|-------------------------------------------------------------| +| `name` | name(): String | Gibt den `displayName` des Spielers zurück | +| `message` | message(String...) | Sendet den Text in den Chat des Spielers | +| `actionbar` | actionbar(String...) | Sendet den Text in die ActionBar des Spielers | +| `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 | +| `yaw` | yaw(Number), yaw(): Number | Setzt oder gibt den Yaw des Spielers | +| `pitch` | pitch(Number), pitch(): Number | Setzt oder gibt den Pitch des Spielers | +| `sneaking` | sneaking(): Boolean | Wahr, wenn der Spieler am Sneaken ist | +| `sprinting` | sprinting(): Boolean | Wahr, wenn der Spieler am Sprinten ist | +| `slot` | slot(Number), slot(): Number | Setzt oder gibt den Slot des gehaltenden Items des Spielers | +| `item` | item(): String | Gibt den Item Type der Main-Hand zurück | +| `offHandItem` | offHandItem(): String | Gibt den Item Type der Off-Hand zurück | + + +### region +Die `region`-Api stellt Funktion zur Verfügung, die die Region des Spielers betreffen. +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|--------|----------------|--------------------------------------------| +| `name` | name(): String | Gibt den Namen der Region zurück | +| `type` | type(): String | Gibt den Namen des Typen der Region zurück | + +Es gibt folgende Variablen: + +| Name | Beschreibung | +|--------|--------------| +| `tnt` | [tnt](#tnt) | + +#### tnt + + +## server + +# 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. + +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|-----------|---------------------------------|---------------------------------| +| `event` | event(EventType, Function(Any)) | Registriere einen Event Handler | +| `command` | cmd(String, Function(Any)) | Registriere einen Command | + +Es gibt folgende Variablen: + +| Name | Beschreibung | +|--------|----------------------------------| +| `type` | Siehe: [Event Type](#event-type) | + +## Event Type +Es gibt folgende Event-Typen: + +| Name | Wenn | Parameter | +|---------------------|-----------------------------------------------------|---------------------------------| +| `FF` | Beim Doppelten Drücken der Swap-Hands taste | NIL | +| `PlaceBlock` | Beim Platzieren von Blöcken | [BlockEvent](#blockevent) | +| `BreakBlock` | Beim Zerstören von Blöcken | [BlockEvent](#blockevent) | +| `RightClick` | Beim Rechts klicken | [InteractEvent](#interactevent) | +| `LeftClick` | Beim Links Klicken | [InteractEvent](#interactevent) | +| `TNTSpawn` | Wenn ein TNT in der aktuellen Region spawnt | NIL | +| `TNTExplode` | Wenn ein TNT in der aktuellen Region explodiert | [Position](#position) | +| `TNTExplodeInBuild` | Wenn ein TNT in der aktuellen Bau Region explodiert | [Position](#position) | +| `SelfJoin` | Wenn man selbst den Server betritt | NIL | +| `SelfLeave` | Wenn man den Server verlässt | NIL | +| `DropItem` | Wenn man ein item Droppt | (type: Material) | +| `EntityDeath` | Wenn ein Entity Stirbt | (type: Entity Type) | + +### BlockEvent +Das übergebene Objekt an den Handler hat folgende Variablen: + +| Name | Beschreibung | +|--------|-----------------------------| +| `x` | Die X-Koordinate des Blocks | +| `y` | Die Y-Koordinate des Blocks | +| `z` | Die Z-Koordinate des Blocks | +| `type` | Das Material des Blocks | + +### InteractEvent +Das übergebene Objekt an den Handler hat folgende Variablen: + +| Name | Beschreibung | +|------------|-------------------------------------------------------------------------------------------------------------------------------| +| `action` | Die Action die ausgeführt wurde, Mögliche Werte: `RIGHT_CLICK_BLOCK`, `RIGHT_CLICK_AIR`, `LEFT_CLICK_BLOCK`, `LEFT_CLICK_AIR` | +| `hand` | Die Hand die zum ausführen genutzt wird, Mögliche Werte: `HAND`, `OFF_HAND` | +| `block` | Der Typ des Items mit dem geklickt wurde | +| `hasBlock` | Wahr, wenn auf einen Block geklickt wurde | + +Wenn `hasBlock` wahr ist, gibt es folgende Variablen: + +| Name | Beschreibung | +|-------------|-----------------------------------------| +| `blockX` | Die X-Koordinate des Blocks | +| `blockY` | Die Y-Koordinate des Blocks | +| `blockZ` | Die Z-Koordinate des Blocks | +| `blockFace` | Die Seite des Blocks die geklickt wurde | + + +### Position +Die Position ist ein Objekt mit folgenden Variablen: + +| Name | Beschreibung | +|------|------------------| +| `x` | Die X-Koordinate | +| `y` | Die Y-Koordinate | +| `z` | Die Z-Koordinate | + + +# Beispiele + +## Hello, World! +Ein einfaches Hello, World!-Script. + +#### Code +```lua +print("Hello, World!") +``` + +#### Ausgabe +``` +Hello, World! +``` From 95f0625031ac6d3ffe50823600cb96b8a555a24c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 19 May 2023 19:34:45 +0200 Subject: [PATCH 057/175] Add Copyright --- .../linkage/types/LuaLib_GENERIC.java | 19 +++++++++++++++ .../features/script/ScriptCommand.java | 19 +++++++++++++++ .../features/script/ScriptListener.java | 19 +++++++++++++++ .../features/script/ScriptRunner.java | 19 +++++++++++++++ .../features/script/UnsignCommand.java | 24 +++++++++---------- .../script/event/CommandListener.java | 19 +++++++++++++++ .../features/script/event/EventListener.java | 19 +++++++++++++++ .../features/script/lua/CommandRegister.java | 19 +++++++++++++++ .../script/lua/SteamWarGlobalLuaPlugin.java | 19 +++++++++++++++ .../script/lua/SteamWarLuaPlugin.java | 19 +++++++++++++++ .../features/script/lua/SteamWarPlatform.java | 19 +++++++++++++++ .../features/script/lua/libs/LuaLib.java | 19 +++++++++++++++ .../features/script/lua/libs/PlayerLib.java | 19 +++++++++++++++ .../features/script/lua/libs/RegionLib.java | 19 +++++++++++++++ .../features/script/lua/libs/ServerLib.java | 19 +++++++++++++++ 15 files changed, 278 insertions(+), 12 deletions(-) diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java index 79c02770..570f6a33 100644 --- a/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.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.linkage.types; import de.steamwar.linkage.LinkageType; 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 6952d796..782e6238 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.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.script; import de.steamwar.command.SWCommand; 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 f2b5852c..20f0e595 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.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.script; import de.steamwar.bausystem.utils.FlatteningWrapper; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java index 8c4ce348..7c3bac7f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.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.script; import de.steamwar.bausystem.features.script.lua.CommandRegister; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/UnsignCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/UnsignCommand.java index 5c4ebb6d..37dda16d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/UnsignCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/UnsignCommand.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) 2021 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.script; 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 e0602616..8e0da5ef 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 @@ -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.script.event; import de.steamwar.bausystem.features.script.ScriptRunner; 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 3a43a83d..e3c09df6 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 @@ -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.script.event; import de.steamwar.bausystem.BauSystem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java index 2e6d9c46..df4fd3bc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.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.script.lua; import lombok.AllArgsConstructor; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java index 544b8af9..3e5dc4a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.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.script.lua; import lombok.AllArgsConstructor; 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 21b24e5e..f2280f4a 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 @@ -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.script.lua; import de.steamwar.bausystem.BauSystem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java index e30f70f8..2cd2e023 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.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.script.lua; import org.bukkit.entity.Player; 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 2e369f5f..4167c4cc 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 @@ -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.script.lua.libs; import lombok.AllArgsConstructor; 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 9c6cfab1..e4f2f12b 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 @@ -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.script.lua.libs; import de.steamwar.linkage.Linked; 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 b85a6c3f..293bdad1 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 @@ -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.script.lua.libs; import de.steamwar.bausystem.features.loader.Loader; 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 5c0ae63d..54754471 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 @@ -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.script.lua.libs; import de.steamwar.bausystem.BauSystem; From edd44c172cfc13e2eea45289f95df490db18a59d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 19 May 2023 20:12:52 +0200 Subject: [PATCH 058/175] Add Hotkeys --- .../bausystem/features/script/Hotkey.java | 77 +++++++++++++++++++ .../features/script/ScriptRunner.java | 14 ++-- .../features/script/event/HotkeyListener.java | 54 +++++++++++++ .../script/lua/SteamWarGlobalLuaPlugin.java | 14 +++- .../features/script/lua/SteamWarPlatform.java | 4 +- 5 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/Hotkey.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/Hotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/Hotkey.java new file mode 100644 index 00000000..d149eedd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/Hotkey.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.script; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; + +@AllArgsConstructor +@Builder +@EqualsAndHashCode +public class Hotkey { + + private final int charcode; + + private final boolean ctrl; + private final boolean shift; + private final boolean alt; + private final boolean meta; + + public static Hotkey fromString(String string) { + String[] parts = string.split("\\+"); + HotkeyBuilder builder = Hotkey.builder(); + + for (String part : parts) { + switch (part.toLowerCase()) { + case "ctrl": + builder.ctrl(true); + break; + case "shift": + builder.shift(true); + break; + case "alt": + builder.alt(true); + break; + case "meta": + builder.meta(true); + break; + default: + if (part.length() == 1) { + builder.charcode(Character.toLowerCase(part.charAt(0))); + } else { + throw new IllegalArgumentException("Invalid hotkey: " + string); + } + } + } + + return builder.build(); + } + + public static Hotkey fromChar(int c, int mods) { + return Hotkey.builder() + .charcode(Character.toLowerCase(c)) + .shift((mods & 1) != 0) + .ctrl((mods & 2) != 0) + .alt((mods & 4) != 0) + .meta((mods & 8) != 0) + .build(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java index 7c3bac7f..ab4feb4a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java @@ -27,10 +27,7 @@ import org.luaj.vm2.Globals; import org.luaj.vm2.LuaFunction; import org.luaj.vm2.LuaValue; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class ScriptRunner { @@ -40,6 +37,7 @@ public class ScriptRunner { // Value -> private static final Map>> EVENT_MAP = new HashMap<>(); + private static final Map>> HOTKEY_MAP = new HashMap<>(); private static final Map> COMMAND_MAP = new HashMap<>(); public static void runScript(String script, Player player) { @@ -55,7 +53,8 @@ public class ScriptRunner { public static void createGlobalScript(List scripts, Player player) { EVENT_MAP.remove(player); Globals globals = SteamWarPlatform.createGlobalGlobals(player, - (s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction), + (s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new EnumMap<>(SteamWarGlobalLuaPlugin.EventType.class)).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction), + (s, luaFunction) -> HOTKEY_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(Hotkey.fromString(s), s1 -> new ArrayList<>()).add(luaFunction), commandRegister -> COMMAND_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).put(commandRegister.getName(), commandRegister)); for (String script : scripts) { @@ -91,4 +90,9 @@ public class ScriptRunner { commandRegister.getFunction().call(args); } + + public static void callHotkey(int mods, int key, Player player, boolean pressed) { + Hotkey hotkey = Hotkey.fromChar(key, mods); + HOTKEY_MAP.get(player).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))); + } } 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 new file mode 100644 index 00000000..d6280b50 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java @@ -0,0 +1,54 @@ +/* + * 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.script.event; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.linkage.Linked; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageListener; + +@Linked +public class HotkeyListener implements PluginMessageListener { + + { + Bukkit.getServer().getMessenger().registerIncomingPluginChannel(BauSystem.getInstance(), "sw:hotkeys", this); + } + + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] message) { + if (!channel.equals("sw:hotkeys")) return; + if (message.length < 5) return; + int action = message[4] & 0xFF; + if (action == 2) return; + int key = (message[0] & 0xFF) << 24 | (message[1] & 0xFF) << 16 | (message[2] & 0xFF) << 8 | (message[3] & 0xFF); + if (!(key >= 'A' && key <= 'Z' || key >= '0' && key <= '9')) return; + if (message.length >= 9) { + int mods = (message[5] & 0xFF) << 24 | (message[6] & 0xFF) << 16 | (message[7] & 0xFF) << 8 | (message[8] & 0xFF); + // player.sendMessage("Hotkey: " + (char) key + " " + action + " " + Long.toBinaryString(mods)); + ScriptRunner.callHotkey(mods, key, player, action == 1); + } else { + // player.sendMessage("Hotkey: " + (char) key + " " + action); + ScriptRunner.callHotkey(0, key, player, action == 1); + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java index 3e5dc4a0..f45d4549 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java @@ -23,9 +23,7 @@ import lombok.AllArgsConstructor; import org.luaj.vm2.LuaFunction; import org.luaj.vm2.LuaString; import org.luaj.vm2.LuaValue; -import org.luaj.vm2.Varargs; import org.luaj.vm2.lib.TwoArgFunction; -import org.luaj.vm2.lib.VarArgFunction; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -33,6 +31,7 @@ import java.util.function.Consumer; @AllArgsConstructor public class SteamWarGlobalLuaPlugin extends TwoArgFunction { private final BiConsumer eventConsumer; + private final BiConsumer hotkeyConsumer; private final Consumer commandRegisterConsumer; @Override @@ -56,6 +55,17 @@ public class SteamWarGlobalLuaPlugin extends TwoArgFunction { return NIL; } }); + env.set("hotkey", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + LuaString key = arg1.checkstring(); + LuaFunction function = arg2.checkfunction(); + + hotkeyConsumer.accept(key.tojstring().toLowerCase(), function); + + return null; + } + }); return NIL; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java index 2cd2e023..a20fa190 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java @@ -51,9 +51,9 @@ public class SteamWarPlatform { return globals; } - public static Globals createGlobalGlobals(Player player, BiConsumer eventConsumer, Consumer commandConsumer) { + public static Globals createGlobalGlobals(Player player, BiConsumer eventConsumer, BiConsumer hotkeyConsumer, Consumer commandConsumer) { Globals globals = createClickGlobals(player); - globals.load(new SteamWarGlobalLuaPlugin(eventConsumer, commandConsumer)); + globals.load(new SteamWarGlobalLuaPlugin(eventConsumer, hotkeyConsumer, commandConsumer)); return globals; } } From 2d8056883c1d6be65b1233c1cb64b153ddca0dd6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 May 2023 11:27:36 +0200 Subject: [PATCH 059/175] Update Docs and Add Global GUI Signed-off-by: Chaoscaot --- BauSystem_Main/src/BauSystem.properties | 288 +----------------- BauSystem_Main/src/BauSystem_de.properties | 281 +---------------- .../features/script/ScriptCommand.java | 8 + .../bausystem/features/script/ScriptGUI.java | 121 ++++++++ .../features/script/ScriptHelper.java | 55 ++++ .../features/script/ScriptListener.java | 13 +- .../features/script/ScriptRunner.java | 32 +- .../script/event/CommandListener.java | 2 +- .../features/script/event/EventListener.java | 3 +- .../features/script/lua/CommandRegister.java | 2 - .../script/lua/SteamWarGlobalLuaPlugin.java | 4 +- .../script/lua/SteamWarLuaPlugin.java | 31 +- .../features/script/lua/SteamWarPlatform.java | 8 + .../src/de/steamwar/sql/Script.java | 99 ++++++ SCRIPT.md | 134 +++++++- 15 files changed, 473 insertions(+), 608 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptHelper.java create mode 100644 BauSystem_Main/src/de/steamwar/sql/Script.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 448fd952..47fedf61 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -230,299 +230,31 @@ GUI_EDITOR_TITLE_MORE=Select item # Script ## Errors -SCRIPT_SLEEP_ERROR = §cInsert a sleep into your script -SCRIPT_COMMAND_ERROR_UNKNOWN_VAR = §cUnknown variable {0} -SCRIPT_COMMAND_ERROR_EXPRESSION = §cExpression error with: {0} -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR = §cThe first argument is missing and should be a variable -SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER = §cThe first argument is missing and should be a number -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE = §cThe first argument is missing and should be a variable or a number -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT = §cThe first argument is missing and should be a jump-point -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR = §cThe second argument is missing and should be a variable -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE = §cThe econd argument is missing and should be a value -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT = §cThe second argument is missing and should be a jump-point -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR = §cThe third argument is missing and should be a variable -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE = §cThe third argument is missing and should be a value -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER = §cThe third argument is missing and should be a variable or a number -SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE = §cThe fourth argument is missing and should be a value - -SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE = §cOnly booleans can be compared -SCRIPT_COMMAND_ERROR_NUMBER_COMPARE = §cOnly numbers can be compared -SCRIPT_COMMAND_ERROR_NO_BOOLEAN = §cThe value is not a boolean - -SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED = §cOnly strings are allowed -SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED = §cOnly numbers are allowed - -SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION = §cUnknown operation: {0} - -## Commands -SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR = §cOnly numbers or strings can be added -SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR = §cOnly numbers can be divided -SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR = §cOnly numbers can be multiplied -SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR = §cOnly numbers can be subtracted -SCRIPT_COMMAND_ARITHMETIC_POW_ERROR = §cOnly numbers can be raised to a power -SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR = §cOnly whole numbers can be used for modulo -SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR = §cOnly whole numbers and booleans can be used for and -SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR = §cOnly whole numbers and booleans can be used for or -SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR = §cOnly whole numbers and booleans can be used for xor -SCRIPT_COMMAND_ARITHMETIC_BIT_LEFT_ERROR = §cOnly whole numbers can be used for left shift value -SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_ERROR = §cOnly whole numbers can be used for right shift value -SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_LOGIC_ERROR = §cOnly whole numbers can be used for logic right shift value - -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1 = §eceil §8<§7variable§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2 = §eceil §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3 = Ceils the second number and writes it in the first or ceils the second number with the precision from the third number and writes it in the first -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1 = §cOnly floating point numbers can be ceiled -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2 = §cThe precision needs to be a whole number - -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1 = §efloor §8<§7variable§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2 = §efloor §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3 = Floors the second number and writes it in the first or floors the second number with the precision from the third number and writes it in the first -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1 = §cOnly floating point numbers can be floored -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2 = §cThe precision needs to be a whole number - -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1 = §eround §8<§7variable§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2 = §eround §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3 = Round the second number and writes it in the first or rounds the second number with the precision from the third number and writes it in the first -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1 = §cOnly floating point numbers can be rounded -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2 = §cThe precision needs to be a whole number - -SCRIPT_COMMAND_IO_ECHO_HELP_1 = §eecho §8<§7value§8> -SCRIPT_COMMAND_IO_ECHO_HELP_2 = §7Send a message to the player. If the value is empty, the message will be empty as well -SCRIPT_COMMAND_IO_ECHO_MESSAGE = §f{0} - -SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1 = §eechoactionbar §8<§7value§8> -SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2 = §7Send a message to the player to the action bar. If the value is empty, the message will be empty as well - -SCRIPT_COMMAND_IO_INPUT_HELP_1 = §einput §8<§7variable§8> §8<§7text§8> -SCRIPT_COMMAND_IO_INPUT_HELP_2 = §7Request an input from the player, which will be written in the variable. The text is optional - -SCRIPT_COMMAND_STRING_INSERT_HELP_1 = §einsert §8<§7variable§8> §8<§7variable§8> §8<§7number§8> -SCRIPT_COMMAND_STRING_INSERT_HELP_2 = §einsert §8<§7variable§8> §8<§7variable§8> §8<§7variable§8> §8<§7number§8> -SCRIPT_COMMAND_STRING_INSERT_HELP_3 = Insert something into a String at a given index. The number is the index and the variable is the string. Optionally the result can be written in another or a new variable - -SCRIPT_COMMAND_STRING_REMOVE_HELP_1 = §eremove §8<§7variable§8> §8<§7from variable§8> -SCRIPT_COMMAND_STRING_REMOVE_HELP_2 = §eremove §8<§7variable§8> §8<§7variable§8> §8<§7from variable§8> -SCRIPT_COMMAND_STRING_REMOVE_HELP_3 = Removes all occurrences of a string from another string. - -SCRIPT_COMMAND_STRING_REPLACE_HELP_1 = §ereplace §8<§7variable§8> §8<§7from variable§8> §8<§7to variable§8> -SCRIPT_COMMAND_STRING_REPLACE_HELP_2 = §ereplace §8<§7variable§8> §8<§7variable§8> §8<§7from variable§8> §8<§7to variable§8> -SCRIPT_COMMAND_STRING_REPLACE_HELP_3 = Replaces all occurrences of a string from another string with a given string - -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1 = §esubstring §8<§7variable§8> §8<§7number§8> -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2 = §esubstring §8<§7variable§8> §8<§7variable§8> §8<§7number§8> -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3 = Shortens a string either from the start or the end, depending on whether the given index is positive (start) or negative (end) - -SCRIPT_COMMAND_VARIABLE_CONST_HELP_1 = §econst §8<§7variable§8> §8[§7value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_CONST_HELP_2 = Writes a value in a constant, which can be a number, a boolean or a string - -SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1 = §econvert §8<§7variable§8> §8<§7value§8> -SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2 = Converts a value to 'number' if it's a number, or to 'boolean' if it's either 'true' or 'false'. Otherwise it remains of type 'text'. - -SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1 = §eglobal §8<§7variable§8> §8[§7value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2 = Writes a value in a variable, which can be a number, a boolean or a string - -SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1 = §eunglobal §8<§7variable§8> -SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2 = Deletes a global variable. - -SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1 = §eunvar §8<§7variable§8> -SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2 = Deletes a local variable. - -SCRIPT_COMMAND_VARIABLE_VAR_HELP_1 = §evar §8<§7variable§8> §8[§7value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_VAR_HELP_2 = Writes a value in a variable, which can be a number, a boolean or a string - -SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1 = §egetmaterial §8<§7variable§8> §8<§7number§8> §8<§7number§8> §8<§7number§8> -SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2 = Writes the material of a block in the world in the variable - -SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1 = §esetmaterial §8<§7variable§8> §8<§7number§8> §8<§7number§8> §8<§7number§8> -SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2 = Sets a block in the world with the given material, given in the variable - -SCRIPT_COMMAND_EXIT_HELP_1 = §eexit -SCRIPT_COMMAND_EXIT_HELP_2 = Exits the script - -SCRIPT_COMMAND_IF_HELP_1 = §eif §8<§7true/false§8> §8<§7jump-point§8> -SCRIPT_COMMAND_IF_HELP_2 = §eif §8<§7true/false§8> §8<§7jump-point§8> §8<§7jump-point§8> -SCRIPT_COMMAND_IF_HELP_3 = §7Jump to the first jump-point if the given value is true or the second jump-point otherwise. - -SCRIPT_COMMAND_JUMP_HELP_1 = §ejump §8<§7jump-point§8> -SCRIPT_COMMAND_JUMP_HELP_2 = §7Jump to a jump-point. A jump-point is a line with §8'§7.§8'§7 before. -SCRIPT_COMMAND_JUMP_ERROR = §cUnknown jump-point: {0} - -SCRIPT_COMMAND_CALL_HELP_1 = §ecall §8<§7jump-point§8> -SCRIPT_COMMAND_CALL_HELP_2 = §7Jump to a jump-point. A jump-point is a line with §8'§7.§8'§7 before. Building a return stack alongside. Use 'return' to jump back. -SCRIPT_COMMAND_CALL_ERROR = §cUnknown jump-point: {0} - -SCRIPT_COMMAND_RETURN_HELP_1 = §ereturn -SCRIPT_COMMAND_RETURN_HELP_2 = §7Jump back to the last 'call' command -SCRIPT_COMMAND_RETURN_ERROR = §cNo 'call' command executed before - -SCRIPT_COMMAND_SLEEP_HELP_1 = §esleep §8<§7time§8> -SCRIPT_COMMAND_SLEEP_HELP_2 = Pauses the execution by the given number of game ticks. -SCRIPT_COMMAND_SLEEP_ERROR = §cThe given number needs to be greater than zero. +SCRIPT_ERROR_GUI=§cError in parsing script: Line {0} +SCRIPT_ERROR_GLOBAL=§cError in global script: Line {0} +SCRIPT_ERROR_CLICK=§cError in script: Line {0} ## GUI SCRIPT_GUI_ITEM_NAME = §eScript Help ## CustomScript -SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} §8-§7 {1} -SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} §8-§7 {1} -SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e{0} +SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} +SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} +SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e/{0} ## Script Menu GUI SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Click to retrieve SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift-Click to copy -SCRIPT_MENU_GUI_NAME = §eScript Commands {0}{1}§7% +SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Right-Click to edit +SCRIPT_MENU_GUI_NAME = §eScript-Menu SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eInsert SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Click with a book to insert -SCRIPT_MENU_GUI_DUPLICATE_COMMAND = §cCommand '{0}' already defined +SCRIPT_MENU_GUI_DUPLICATE_SCRIPT = §cScript '{0}' already defined +SCRIPT_MENU_GUI_ENTER_NAME = §eEnter a name SCRIPT_MENU_GUI_UNKNOWN_EVENT = §cEvent '{0}' cannot be defined SCRIPT_MENU_GUI_LIMIT = §cScript-Book limit reached -## ScriptCommand -SCRIPT_COMMAND_HELP = §8/§escript §8- §7Opens the ScriptGUI -SCRIPT_COMMAND_HELP_MENU = §8/§escript menu §8- §7Opens the ScriptGUI for custom commands shares across baus - -## Script GUI -SCRIPT_GUI_NAME = Script Elements -SCRIPT_GUI_COMMAND_CHAT = §eScript Command§8: §e{0} - -SCRIPT_GUI_CUSTOM_HOTKEYS = §eCustom Hotkeys -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1 = §7Write§8: §e#!HOTKEY 'Char' -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2 = §7at the beginning of a Script Book to use a custom hotkey. The 'Char' can be any char between '§eA§7' and '§eZ§7' as well as '§e0§7' and '§e9§7'. While executing two variables are available: §epressed§7, §ereleased§7. -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3 = §7You can add modifiers like "SHIFT", "CTRL", "ALT" or "META" to the hotkey. §7Example: §e#!HOTKEY SHIFT+A -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4 = §7 -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5 = §cThis can only be used in conjunction with the Fabric-Mod: §eAdvancedScripts §7found on §ehttps://steamwar.de/downloads - -SCRIPT_GUI_CUSTOM_COMMANDS = §eCustom Commands -SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1 = §7Write§8: §e#!CMD 'COMMAND' -SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2 = §7at the beginning of a Script Book to use a custom command. The command always starts with §e/§7 and can be structured as you wish. Everything in pointy Brackets '§e<>§7' will be counted as a Parameter and therefore as a variable. Parameters in round brackets '§e()§7' are optional. Simple texts as parameters get a variable with the same name with the values true/false, depending on whether the value was given or not - -SCRIPT_GUI_CUSTOM_EVENTS = §eCustom Events -SCRIPT_GUI_CUSTOM_EVENTS_LORE_1 = §7Write§8: §e#!EVENT 'EventName' -SCRIPT_GUI_CUSTOM_EVENTS_LORE_2 = §7at the beginning of a Script Book to use a custom event. Every event can ve canceled by using 'var cancel true'. After the event name are the variables which are usable in a Script Book. -SCRIPT_GUI_CUSTOM_EVENTS_LORE_3 = §7Usable Events are: -SCRIPT_GUI_CUSTOM_EVENTS_LORE_4 = §eFF -SCRIPT_GUI_CUSTOM_EVENTS_LORE_5 = §ePlaceBlock §8-§7 blockX, blockY, blockZ, blockType -SCRIPT_GUI_CUSTOM_EVENTS_LORE_6 = §eBreakBlock §8-§7 blockX, blockY, blockZ, blockType -SCRIPT_GUI_CUSTOM_EVENTS_LORE_7 = §eRightClick §8-§7 blockInHand, action, handType, -SCRIPT_GUI_CUSTOM_EVENTS_LORE_8 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e* -SCRIPT_GUI_CUSTOM_EVENTS_LORE_9 = §eLeftClick §8-§7 blockInHand, action, handType, -SCRIPT_GUI_CUSTOM_EVENTS_LORE_10 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e* -SCRIPT_GUI_CUSTOM_EVENTS_LORE_11 = §eTNTSpawn -SCRIPT_GUI_CUSTOM_EVENTS_LORE_12 = §eTNTExplode §8-§7 x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_13 = §eTNTExplodeInBuild §8-§7 x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_14 = §eSelfJoin §8-§7 x, y, z, playerName -SCRIPT_GUI_CUSTOM_EVENTS_LORE_15 = §eSelfLeave §8-§7 x, y, z, playerName -SCRIPT_GUI_CUSTOM_EVENTS_LORE_16 = §eDropItem §8-§7 material, x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_17 = §eEntityDeath §8-§7 entityType, x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_18 = §eScoreboard -SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1 = §e* §8-§7 Everything in brackets is only set if the variable before is set on §etrue§7. - -SCRIPT_GUI_OTHER = §eOther -SCRIPT_GUI_OTHER_LORE_1 = §7Comments start with §e#§7. -SCRIPT_GUI_OTHER_LORE_2 = §7Jump_Points start with §e.§7. -SCRIPT_GUI_OTHER_LORE_3 = §7A variable name enclosed in '§e{}§7' is replaced by its value. A variable can be prefixed with '§econst.§7' or '§elocal.§7' or '§eglobal.§7'. -SCRIPT_GUI_OTHER_LORE_4 = §7The following applies: -SCRIPT_GUI_OTHER_LORE_5 = §7- Local variables are only available in the script book. -SCRIPT_GUI_OTHER_LORE_6 = §7- Global variables are available in every script book. -SCRIPT_GUI_OTHER_LORE_7 = §7- Constant variables are variables from the server (e.g. player name, TPS, etc.) -SCRIPT_GUI_OTHER_LORE_8 = §7A variable can be appended with '§e.length§7' or '§e.type§7' or '§e.isset§7'. -SCRIPT_GUI_OTHER_LORE_9 = §7The following applies: -SCRIPT_GUI_OTHER_LORE_10 = §7- Length returns the length of the variable as a number. -SCRIPT_GUI_OTHER_LORE_11 = §7- Type returns the type (number, floating_number, text or boolean) as text. -SCRIPT_GUI_OTHER_LORE_12 = §7- Isset returns as a boolean whether the variable exists. -SCRIPT_GUI_OTHER_LORE_13 = §7Mathematical as well as logical operations can be specified in '§e{}§7'. -SCRIPT_GUI_OTHER_LORE_14 = §7The following applies: -SCRIPT_GUI_OTHER_LORE_15 = §7- arithmetic operators: §e+ * - /§7 as well as §e%§7 for modulo -SCRIPT_GUI_OTHER_LORE_16 = §7- Logical operators: §e==§7; §e!=§7; §e<=§7; §e>=§7; §e<§7; §e>§7; §e&&§7; §e||§7 (this is the character for or) -SCRIPT_GUI_OTHER_LORE_17 = §7- Bitwise operators: §e&§7; §e|§7; §e^ -SCRIPT_GUI_OTHER_LORE_18 = §7- Shift operators: §e<<§7; §e>>§7; §e>>>§7 - -SCRIPT_GUI_COMMAND_NAME = §7Command: §e{0} - -SCRIPT_GUI_CUSTOM_VARIABLES = §eCustom Variables - -SCRIPT_GUI_CONSTANT_TIME_NAME = §7Constant §etime -SCRIPT_GUI_CONSTANT_TIME_LORE = §7Formatted time variable. - -SCRIPT_GUI_CONSTANT_TICKS_NAME = §7Constant §eticks -SCRIPT_GUI_CONSTANT_TICKS_LORE = §7Ticks since server start. - -SCRIPT_GUI_CONSTANT_TRACE_NAME = §7Constant §etrace -SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 if the trace is activated. - -SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME = §7Constant §eautotrace -SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE = §etrue§7 if the auto trace is activated. - -SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME = §7Constant §etrace_status -SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE = §7One of: §eOFF§8, §eIDLE§8, §eIDLE_AUTO_EXPLODE§8, §eIDLE_AUTO_IGNITE§8, §eIDLE_SINGLE - -SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME = §7Constant §etrace_time -SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE = §e0§7 if the trace is not active, otherwise the time in ticks since the trace was started. - -SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME = §7Constant §eloader_status -SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE = §7One of: §eOFF§8, §eSETUP§8, §eRUNNING§8, §eSINGLE§8, §ePAUSE§8, §eEND - -SCRIPT_GUI_CONSTANT_TNT_NAME = §7Constant §etnt -SCRIPT_GUI_CONSTANT_TNT_LORE = §etrue§7 if tnt is not deactivated. - -SCRIPT_GUI_CONSTANT_ONLY_TB_NAME = §7Constant §etnt_onlytb -SCRIPT_GUI_CONSTANT_ONLY_TB_LORE = §etrue§7 if tnt no build is activated. - -SCRIPT_GUI_CONSTANT_FREEZE_NAME = §7Constant §efreeze -SCRIPT_GUI_CONSTANT_FREEZE_LORE = §etrue§7 if freeze is not deactivated. - -SCRIPT_GUI_CONSTANT_FIRE_NAME = §7Constant §efire -SCRIPT_GUI_CONSTANT_FIRE_LORE = §etrue§7 if fire is not deactivated. - -SCRIPT_GUI_CONSTANT_PROTECT_NAME = §7Constant §eprotect -SCRIPT_GUI_CONSTANT_PROTECT_LORE = §etrue§7 if protect is activated. - -SCRIPT_GUI_CONSTANT_X_NAME = §7Constant §ex -SCRIPT_GUI_CONSTANT_X_LORE = §ex§7 position of the player. - -SCRIPT_GUI_CONSTANT_Y_NAME = §7Constant §ey -SCRIPT_GUI_CONSTANT_Y_LORE = §ey§7 position of the player. - -SCRIPT_GUI_CONSTANT_Z_NAME = §7Constant §ez -SCRIPT_GUI_CONSTANT_Z_LORE = §ez§7 position of the player. - -SCRIPT_GUI_CONSTANT_NAME_NAME = §7Constant §ename -SCRIPT_GUI_CONSTANT_NAME_LORE = §eDisplay§7 name of the player. - -SCRIPT_GUI_CONSTANT_SNEAK_NAME = §7Constant §esneaking -SCRIPT_GUI_CONSTANT_SNEAK_LORE = §etrue§7 if the player is sneaking. - -SCRIPT_GUI_CONSTANT_SPRINTING_NAME = §7Constant §esprinting -SCRIPT_GUI_CONSTANT_SPRINTING_LORE = §etrue§7 is the player is sprinting. - -SCRIPT_GUI_CONSTANT_SLOT_NAME = §7Constant §eslot -SCRIPT_GUI_CONSTANT_SLOT_LORE = §e0-8§7 for the selected slot. - -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME = §7Constant §eslotmaterial -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE = §eMaterial§7 of the item in the current slot - -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME = §7Constant §eoffhandmaterial -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE = §eMaterial§7 of the item in the off hand - -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME = §7Constant §ematerialname -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE = §eName§7 of the item in the current slot - -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME = §7Constant §eoffmaterialname -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE = §eName§7 of the item in the off hand - -SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME = §7Constant §eregion_type -SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eregion type§7 of the current region - -SCRIPT_GUI_CONSTANT_REGION_NAME_NAME = §7Constant §eregion_name -SCRIPT_GUI_CONSTANT_REGION_NAME_LORE = §eregion name§7 of the current region - -SCRIPT_GUI_CONSTANT_TPS_NAME = §7Constant §etps -SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 of the server - -SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit -SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server - # Shield Printing SHIELD_PRINTING_NO_REGION = §cYou are not in a region. SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 804afa46..50f587a4 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -226,295 +226,26 @@ GUI_EDITOR_ITEM_CLOSE=§eSchließen GUI_EDITOR_TITLE_MORE=Item auswählen # Script -## Errors -SCRIPT_SLEEP_ERROR = §cFüge ein sleep in dein Script ein -SCRIPT_COMMAND_ERROR_UNKNOWN_VAR = §cUnbekannte Variable {0} -SCRIPT_COMMAND_ERROR_EXPRESSION = §cExpression fehler in: {0} -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR = §cDas erste Argument fehlt und sollte eine Variable sein -SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER = §cDas erste Argument fehlt und sollte eine Zahl sein -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE = §cDas erste Argument fehlt und sollte eine Variable oder ein Wert sein -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT = §cDas erste Argument fehlt und sollte ein Jump-Point sein -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR = §cDas zweite Argument fehlt und sollte eine Variable sein -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE = §cDas zweite Argument fehlt und sollte ein Wert sein -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT = §cDas dritte Argument fehlt und sollte ein Jump-Point sein -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR = §cDas dritte Argument fehlt und sollte eine Variable sein -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE = §cDas dritte Argument fehlt und sollte ein Wert sein -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER = §cDas dritte Argument fehlt und sollte eine Variable/Zahl sein -SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE = §cDas vierte Argument fehlt und sollte ein Wert sein - -SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE = §cNur Booleans können verglichen werden -SCRIPT_COMMAND_ERROR_NUMBER_COMPARE = §cNur Zahlen können verglichen werden - -SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED = §cNur Strings können verwendet werden -SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED = §cNur Zahlen können verwendet werden - -SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION = §cUnbekannte Operation: {0} - -## Commands -SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR = §cNur Zahlen können addiert werden -SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR = §cNur Zahlen können dividiert werden -SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR = §cNur Zahlen können multipliziert werden -SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR = §cNur Zahlen können subtrahiert werden -SCRIPT_COMMAND_ARITHMETIC_POW_ERROR = §cNur Zahlen können potenziert werden -SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR = §cNur ganze Zahlen können für modulo verwendet werden -SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR = §cNur ganze Zahlen und booleans können für und verwendet werden -SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR = §cNur ganze Zahlen und booleans können für oder verwendet werden -SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR = §cNur ganze Zahlen und booleans können für xor verwendet werden - -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1 = §eceil §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2 = §eceil §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3 = Aufrunden der zweiten Zahl und schreibt es in die erste oder aufrunden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste. -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1 = §cNur Fließ-Komma-Zahlen können aufgerundet werden -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden - -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1 = §efloor §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2 = §efloor §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3 = Abrunden der zweiten Zahl und schreibt es in die erste oder abrunden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste. -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1 = §cNur Fließ-Komma-Zahlen können abgerundet werden -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden - -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1 = §eround §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2 = §eround §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3 = Runden der zweiten Zahl und schreibt es in die erste oder runden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste. -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1 = §cNur Fließ-Komma-Zahlen können gerundet werden -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden - -SCRIPT_COMMAND_IO_ECHO_HELP_1 = §eecho §8<§7Wert§8> -SCRIPT_COMMAND_IO_ECHO_HELP_2 = §7Schreibe etwas dem Spieler. Wenn kein Wert angegeben wurde ist die Nachricht leer. -SCRIPT_COMMAND_IO_ECHO_MESSAGE = §f{0} - -SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1 = §eechoactionbar §8<§7Wert§8> -SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2 = §7Schreibe etwas dem Spieler in der ActionBar. Wenn kein Wert angegeben wurde ist die Nachricht leer. - -SCRIPT_COMMAND_IO_INPUT_HELP_1 = §einput §8<§7Variable§8> §8<§7Text§8> -SCRIPT_COMMAND_IO_INPUT_HELP_2 = §7Fordere eine Eingabe von dem Spieler, welche in die Variable geschrieben wird. Der Text ist optional. - -SCRIPT_COMMAND_STRING_INSERT_HELP_1 = §einsert §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8> -SCRIPT_COMMAND_STRING_INSERT_HELP_2 = §einsert §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8> -SCRIPT_COMMAND_STRING_INSERT_HELP_3 = Füge etwas in einen String an einer Stelle ein. Die Zahl ist für die Position und die Variable davor für was. Schreibe optional dies in eine neue oder andere Variable. - -SCRIPT_COMMAND_STRING_REMOVE_HELP_1 = §eremove §8<§7Variable§8> §8<§7Von Variable§8> -SCRIPT_COMMAND_STRING_REMOVE_HELP_2 = §eremove §8<§7Variable§8> §8<§7Variable§8> §8<§7Von Variable§8> -SCRIPT_COMMAND_STRING_REMOVE_HELP_3 = Lösche eine Zeichenkette aus dem Ursprung. Dies ersetzt nicht nur die erste Stelle sondern alle. - -SCRIPT_COMMAND_STRING_REPLACE_HELP_1 = §ereplace §8<§7Variable§8> §8<§7Von Variable§8> §8<§7Zu Variable§8> -SCRIPT_COMMAND_STRING_REPLACE_HELP_2 = §ereplace §8<§7Variable§8> §8<§7Variable§8> §8<§7Von Variable§8> §8<§7Zu Variable§8> -SCRIPT_COMMAND_STRING_REPLACE_HELP_3 = Ersetzte eine Zeichenkette aus dem Ursprung mit einer neuen Zeichenkette. Dies ersetzt nicht nur die erste Stelle sondern alle. - -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1 = §esubstring §8<§7Variable§8> §8<§7Zahl§8> -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2 = §esubstring §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8> -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3 = Kürze einen String entweder vorne oder hinter, je nachdem ob die Zahl positiv (vorne) oder negativ (hinten) ist. - -SCRIPT_COMMAND_VARIABLE_CONST_HELP_1 = §econst §8<§7Variable§8> §8[§7Value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_CONST_HELP_2 = Schreibt in eine Konstante einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text. - -SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1 = §econvert §8<§7Variable§8> §8<§7Value§8> -SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2 = Konvertiere den Value zu 'number' wenn es eine Zahl ist, oder zu 'boolean' bei 'true' oder 'false' und behalte 'text' bei wenn nichts zutrifft. - -SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1 = §eglobal §8<§7Variable§8> §8[§7Value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2 = Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text. - -SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1 = §eunglobal §8<§7Variable§8> -SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2 = Lösche eine Globale variable. - -SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1 = §eunvar §8<§7Variable§8> -SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2 = Lösche eine Locale variable. - -SCRIPT_COMMAND_VARIABLE_VAR_HELP_1 = §evar §8<§7Variable§8> §8[§7Value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_VAR_HELP_2 = Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text. - -SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1 = §egetmaterial §8<§7Variable§8> §8<§7Zahl§8> §8<§7Zahl§8> §8<§7Zahl§8> -SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2 = Schreibt das material von einem Block in der Welt in die Variable. - -SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1 = §esetmaterial §8<§7Variable§8> §8<§7Zahl§8> §8<§7Zahl§8> §8<§7Zahl§8> -SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2 = Setzt an einem Block in der Welt das Material der ersten Variable. - -SCRIPT_COMMAND_EXIT_HELP_1 = §eexit -SCRIPT_COMMAND_EXIT_HELP_2 = Beendet das ausführen des Scripts. - -SCRIPT_COMMAND_IF_HELP_1 = §eif §8<§7true/false§8> §8<§7jump-point§8> -SCRIPT_COMMAND_IF_HELP_2 = §eif §8<§7true/false§8> §8<§7jump-point§8> §8<§7jump-point§8> -SCRIPT_COMMAND_IF_HELP_3 = §7Springe zu ersten Stelle, wenn der Wert true ist. Oder zu dem zweiten, wenn dies nicht der fall ist. - -SCRIPT_COMMAND_JUMP_HELP_1 = §ejump §8<§7Jump-Point§8> -SCRIPT_COMMAND_JUMP_HELP_2 = §7Springe zu einer anderen Zeile. Hierbei ist ein Jump-Point eine Zeile mit §8'§7.§8'§7 vor. -SCRIPT_COMMAND_JUMP_ERROR = §cDer Jump-Point ({0}) ist nicht definiert. - -SCRIPT_COMMAND_CALL_HELP_1 = §ecall §8<§7Jump-Point§8> -SCRIPT_COMMAND_CALL_HELP_2 = §7Springe zu einer anderen Zeile. Hierbei ist ein Jump-Point eine Zeile mit §8'§7.§8'§7 vor. Hierbei wird auf den ReturnStack die jetzige Zeile geschrieben, dahin kann man wieder mit 'return' zurück springen. -SCRIPT_COMMAND_CALL_ERROR = §cDer Jump-Point ({0}) ist nicht definiert. - -SCRIPT_COMMAND_RETURN_HELP_1 = §ereturn -SCRIPT_COMMAND_RETURN_HELP_2 = §7Springe zum letzten 'call' Befehl. -SCRIPT_COMMAND_RETURN_ERROR = §cEs wurde kein 'call' Befehl ausgeführt - -SCRIPT_COMMAND_SLEEP_HELP_1 = §esleep §8<§7Time§8> -SCRIPT_COMMAND_SLEEP_HELP_2 = Pausiert das Ausführen des Scripts. Das erste Argument ist in GameTicks. -SCRIPT_COMMAND_SLEEP_ERROR = §cDie Zeit muss eine Zahl großer 0 sein. - ## GUI SCRIPT_GUI_ITEM_NAME = §eScript Hilfe ## CustomScript -SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} §8-§7 {1} -SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} §8-§7 {1} -SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e{0} +SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} +SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} +SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e/{0} ## Script Menu GUI SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Klicke zum rausnehmen SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift Klicke zum kopieren -SCRIPT_MENU_GUI_NAME = §eScript Commands {0}{1}§7% +SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Rechts Klicke zum editieren +SCRIPT_MENU_GUI_NAME = §eScript-Menü SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eHinzufügen SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Klicke mit einem Buch zum hinzufügen -SCRIPT_MENU_GUI_DUPLICATE_COMMAND = §cCommand '{0}' bereits definiert +SCRIPT_MENU_GUI_DUPLICATE_SCRIPT = §cCommand '{0}' bereits definiert SCRIPT_MENU_GUI_UNKNOWN_EVENT = §cEvent '{0}' ist nicht definierbar SCRIPT_MENU_GUI_LIMIT = §cScript-Buch Limit erreicht -## ScriptCommand -SCRIPT_COMMAND_HELP = §8/§escript §8- §7Öffnet die ScriptGUI -SCRIPT_COMMAND_HELP_MENU = §8/§escript menu §8- §7Öffnet die ScriptMenuGUI für Custom Command bauübergreifend - -## Script GUI -SCRIPT_GUI_NAME = Script Elements -SCRIPT_GUI_COMMAND_CHAT = §eScript Command§8: §e{0} - -SCRIPT_GUI_CUSTOM_HOTKEYS = §eCustom Hotkeys -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1 = §7Schreibe§8: §e#!HOTKEY 'Char' -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2 = §7am Anfang eines Skript Buches, um einen benutzerdefinierten Hotkey zu verwenden. Das 'Char' kann ein beliebiges Zeichen zwischen '§eA§7' und '§eZ§7' sowie '§e0§7' und '§e9§7' sein. Während der Ausführung sind zwei Variablen verfügbar: §epressed§7, §ereleased§7 -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3 = §7Sie können dem Hotkey Modifikatoren wie "SHIFT", "CTRL", "ALT" oder "META" hinzufügen. §7Beispiel: §e#!HOTKEY SHIFT+A -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4 = §7 -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5 = §cDies kann nur in Verbindung mit den Fabric-Mod: §eAdvancedScripts §7runterladbar unter §ehttps://steamwar.de/downloads §cverwendet werden. - -SCRIPT_GUI_CUSTOM_COMMANDS = §eCustom Commands -SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1 = §7Schreibe§8: §e#!CMD 'COMMAND' -SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2 = §7an den Anfang eines Script Buches um ein Custom Command zu nutzen. Der Befehl startet immer mit §e/§7 und kann dann so aufgebaut sein wie du willst. Alles was in Spitzen Klammern steht '§e<>§7' wird als Parameter und somit als Variable gewertet. Parameter, welche in runden Klammern stehen sind Optional. Einfache Texte als Parameter bekommen eine gleichnamige Variable mit true/false als Wert je nachdem ob dieser angegeben wurde oder nicht - -SCRIPT_GUI_CUSTOM_EVENTS = §eCustom Events -SCRIPT_GUI_CUSTOM_EVENTS_LORE_1 = §7Schreibe§8: §e#!EVENT 'EventName' -SCRIPT_GUI_CUSTOM_EVENTS_LORE_2 = §7an den Anfang eines Script Buches um ein Custom Event zu nutzen. Jedes Event kann durch 'var cancel true' gecancelt werden. Hinter dem Event Namen stehen die Variablen, welche im Script durch das Event nutztbar sind. -SCRIPT_GUI_CUSTOM_EVENTS_LORE_3 = §7Nutzbare Events sind: -SCRIPT_GUI_CUSTOM_EVENTS_LORE_4 = §eFF -SCRIPT_GUI_CUSTOM_EVENTS_LORE_5 = §ePlaceBlock §8-§7 blockX, blockY, blockZ, blockType -SCRIPT_GUI_CUSTOM_EVENTS_LORE_6 = §eBreakBlock §8-§7 blockX, blockY, blockZ, blockType -SCRIPT_GUI_CUSTOM_EVENTS_LORE_7 = §eRightClick §8-§7 blockInHand, action, handType, -SCRIPT_GUI_CUSTOM_EVENTS_LORE_8 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e* -SCRIPT_GUI_CUSTOM_EVENTS_LORE_9 = §eLeftClick §8-§7 blockInHand, action, handType, -SCRIPT_GUI_CUSTOM_EVENTS_LORE_10 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e* -SCRIPT_GUI_CUSTOM_EVENTS_LORE_11 = §eTNTSpawn -SCRIPT_GUI_CUSTOM_EVENTS_LORE_12 = §eTNTExplode §8-§7 x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_13 = §eTNTExplodeInBuild §8-§7 x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_14 = §eSelfJoin §8-§7 x, y, z, playerName -SCRIPT_GUI_CUSTOM_EVENTS_LORE_15 = §eSelfLeave §8-§7 x, y, z, playerName -SCRIPT_GUI_CUSTOM_EVENTS_LORE_16 = §eDropItem §8-§7 material, x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_17 = §eEntityDeath §8-§7 entityType, x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1 = §e* §8-§7 Alles in den Klammern ist nur gesetzt, wenn die Variable davor auf §etrue§7 gesetzt ist. - -SCRIPT_GUI_OTHER = §eOther -SCRIPT_GUI_OTHER_LORE_1 = §7Kommentare fangen mit §e#§7 an. -SCRIPT_GUI_OTHER_LORE_2 = §7Jump_Points fangen mit §e.§7 an. -SCRIPT_GUI_OTHER_LORE_3 = §7Einen Variablennamen, der in '§e{}§7' eingeschlossen ist wird durch seinen Wert ersetzt. Eine Variable kann mit den Präfixen '§econst.§7' oder '§elocal.§7' oder '§eglobal.§7' versehen werden. -SCRIPT_GUI_OTHER_LORE_4 = §7Dabei gilt: -SCRIPT_GUI_OTHER_LORE_5 = §7- Lokalevariablen sind nur in dem Script-Buch verfügbar. -SCRIPT_GUI_OTHER_LORE_6 = §7- Gloablevariablen sind in jedem Script-Buch verfügbar. -SCRIPT_GUI_OTHER_LORE_7 = §7- Konstantevariablen sind Variablen vom Server (z.B. Spielername, TPS usw.) -SCRIPT_GUI_OTHER_LORE_8 = §7Eine Variable kann mit den Appendixen '§e.length§7' oder '§e.type§7' oder '§e.isset§7' versehen werden. -SCRIPT_GUI_OTHER_LORE_9 = §7Dabei gilt: -SCRIPT_GUI_OTHER_LORE_10 = §7- Length gibt die Länge der variable als Zahl zurück. -SCRIPT_GUI_OTHER_LORE_11 = §7- Type gibt den typen (number, floating number, text oder boolean) als Text zurück. -SCRIPT_GUI_OTHER_LORE_12 = §7- Isset gibt als boolean zurück, ob die Variable existiert. -SCRIPT_GUI_OTHER_LORE_13 = §7Mathematische sowie logische Operationsvorgänge können in '§e{}§7' angegeben werden. -SCRIPT_GUI_OTHER_LORE_14 = §7Dabei gilt: -SCRIPT_GUI_OTHER_LORE_15 = §7- Rechenoperatoren: §e+ * - /§7 sowie §e%§7 für Modulo -SCRIPT_GUI_OTHER_LORE_16 = §7- Logische Operatoren: §e==§7; §e!=§7; §e<=§7; §e>=§7; §e<§7; §e>§7; §e&&§7; §e||§7 (Dies ist das Zeichen für oder) -SCRIPT_GUI_OTHER_LORE_17 = §7- Bitweise Operatoren: §e&§7; §e|§7; §e^ -SCRIPT_GUI_OTHER_LORE_18 = §7- Shift Operatoren: §e<<§7; §e>>§7; §e>>>§7 - -SCRIPT_GUI_COMMAND_NAME = §7Command: §e{0} - -SCRIPT_GUI_CUSTOM_VARIABLES = §eCustom Variables - -SCRIPT_GUI_CONSTANT_TIME_NAME = §7Constant §etime -SCRIPT_GUI_CONSTANT_TIME_LORE = §7Formattierte Uhrzeit - -SCRIPT_GUI_CONSTANT_TICKS_NAME = §7Constant §eticks -SCRIPT_GUI_CONSTANT_TICKS_LORE = §7Ticks seit dem Serverstart - -SCRIPT_GUI_CONSTANT_TRACE_NAME = §7Constant §etrace -SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 wenn gerade der Tracer an ist. - -SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME = §7Constant §eautotrace -SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE = §etrue§7 wenn gerade der AutoTracer an ist. - -SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME = §7Constant §etrace_status -SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE = §7Ein Wert von: §eOFF§8, §eIDLE§8, §eIDLE_AUTO_EXPLODE§8, §eIDLE_AUTO_IGNITE§8, §eIDLE_SINGLE - -SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME = §7Constant §etrace_time -SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE = §e0§7 wenn gerade kein TNT getraced wird, ansonsten die Zeit in Ticks seit dem Start des Tracers. - -SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME = §7Constant §eloader_status -SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE = §7Ein Wert von: §eOFF§8, §eSETUP§8, §eRUNNING§8, §eSINGLE§8, §ePAUSE§8, §eEND - -SCRIPT_GUI_CONSTANT_TNT_NAME = §7Constant §etnt -SCRIPT_GUI_CONSTANT_TNT_LORE = §etrue§7 wenn TNT nicht ausgeschaltet ist. - -SCRIPT_GUI_CONSTANT_ONLY_TB_NAME = §7Constant §etnt_onlytb -SCRIPT_GUI_CONSTANT_ONLY_TB_LORE = §etrue§7 wenn TNT Nur Testblock an ist. - -SCRIPT_GUI_CONSTANT_FREEZE_NAME = §7Constant §efreeze -SCRIPT_GUI_CONSTANT_FREEZE_LORE = §etrue§7 wenn Freeze nicht ausgeschaltet ist. - -SCRIPT_GUI_CONSTANT_FIRE_NAME = §7Constant §efire -SCRIPT_GUI_CONSTANT_FIRE_LORE = §etrue§7 wenn Fire nicht ausgeschaltet ist. - -SCRIPT_GUI_CONSTANT_PROTECT_NAME = §7Constant §eprotect -SCRIPT_GUI_CONSTANT_PROTECT_LORE = §etrue§7 wenn Protect angeschaltet ist. - -SCRIPT_GUI_CONSTANT_X_NAME = §7Constant §ex -SCRIPT_GUI_CONSTANT_X_LORE = §ex§7 Position des Spielers. - -SCRIPT_GUI_CONSTANT_Y_NAME = §7Constant §ey -SCRIPT_GUI_CONSTANT_Y_LORE = §ey§7 Position des Spielers. - -SCRIPT_GUI_CONSTANT_Z_NAME = §7Constant §ez -SCRIPT_GUI_CONSTANT_Z_LORE = §ez§7 Position des Spielers. - -SCRIPT_GUI_CONSTANT_NAME_NAME = §7Constant §ename -SCRIPT_GUI_CONSTANT_NAME_LORE = §eDisplay§7 Name des Spielers. - -SCRIPT_GUI_CONSTANT_SNEAK_NAME = §7Constant §esneaking -SCRIPT_GUI_CONSTANT_SNEAK_LORE = §etrue§7 wenn der Spieler gerade sneakt. - -SCRIPT_GUI_CONSTANT_SPRINTING_NAME = §7Constant §esprinting -SCRIPT_GUI_CONSTANT_SPRINTING_LORE = §etrue§7 wenn der Spieler gerade rennt. - -SCRIPT_GUI_CONSTANT_SLOT_NAME = §7Constant §eslot -SCRIPT_GUI_CONSTANT_SLOT_LORE = §e0-8§7 für den ausgewählten slot. - -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME = §7Constant §eslotmaterial -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE = §eMaterial§7 des Items im Slot - -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME = §7Constant §eoffhandmaterial -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE = §eMaterial§7 des Items in der Off Hand - -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME = §7Constant §ematerialname -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE = §eName§7 des Items im Slot - -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME = §7Constant §eoffmaterialname -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE = §eName§7 des Items in der Off Hand - -SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME = §7Constant §eregion_type -SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eRegionstype§7 der jetztigen Region - -SCRIPT_GUI_CONSTANT_REGION_NAME_NAME = §7Constant §eregion_name -SCRIPT_GUI_CONSTANT_REGION_NAME_LORE = §eRegionsname§7 der jetztigen Region - -SCRIPT_GUI_CONSTANT_TPS_NAME = §7Constant §etps -SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 vom Server - -SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit -SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server - # Shield Printing SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. 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 782e6238..9d640d52 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java @@ -20,10 +20,18 @@ package de.steamwar.bausystem.features.script; import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; +@Linked public class ScriptCommand extends SWCommand { public ScriptCommand() { super("script"); } + + @Register + public void genericCommand(Player player) { + ScriptGUI.open(player); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java new file mode 100644 index 00000000..720feb78 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java @@ -0,0 +1,121 @@ +/* + * 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.script; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.script.lua.SteamWarPlatform; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import de.steamwar.linkage.Linked; +import de.steamwar.sql.Script; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.luaj.vm2.Globals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@Linked +public class ScriptGUI implements Listener { + public static void open(Player player) { + open(player, null); + } + + private static void open(Player player, ItemStack setCursor) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + List> entries = new ArrayList<>(); + List lore = new ArrayList<>(); + Globals globals = SteamWarPlatform.createGlobalParser( + (eventType, luaFunction) -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_EVENT_ITEM_NAME", player, eventType.name())), + (s, luaFunction) -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_HOTKEY_ITEM_NAME", player, s)), + commandRegister -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_COMMAND_ITEM_NAME", player, commandRegister.getName())) + ); + + Script.list(user).forEach(script -> { + try { + globals.load(script.getScript()).call(); + } catch (Exception e) { + String[] sp = e.getMessage().split(":"); + lore.add(BauSystem.MESSAGE.parse("SCRIPT_ERROR_GUI", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)))); + } + + if(!lore.isEmpty()) { + lore.add(""); + } + lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_1", player)); + lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_2", player)); + lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_3", player)); + + entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.ENCHANTED_BOOK, script.getName(), new ArrayList<>(lore), false, clickType -> {}), script)); + lore.clear(); + }); + + SWListInv