From 0a4944877862f38e358c21ab8aa71a2143bc0787 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 15 Jan 2021 17:29:15 +0100 Subject: [PATCH 01/91] Add TraceGUI --- .../bausystem/commands/CommandTrace.java | 6 + .../commands/CommandTraceTabCompleter.java | 2 +- .../steamwar/bausystem/gui/GuiTraceShow.java | 134 ++++++++++++++++++ .../tracer/show/ShowModeParameter.java | 16 +++ .../tracer/show/TraceShowManager.java | 5 + 5 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index a4594cd..3b30892 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.gui.GuiTraceShow; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.ShowModeParameter; import de.steamwar.bausystem.tracer.show.StoredRecords; @@ -39,6 +40,7 @@ public class CommandTrace implements CommandExecutor { player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen"); player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer"); player.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart"); + player.sendMessage("§8/§etrace show gui §8- §7Zeigt die Trace show gui"); player.sendMessage("§8/§etrace show §8<§edefault§8|§eadvanced§8> §8<§e-water§8|§e-interpolate-xz§8|§e-interpolate-y§8> §8- §7Zeigt alle TNT-Positionen"); player.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen"); player.sendMessage("§8/§etrace delete §8- §7Löscht alle TNT-Positionen"); @@ -90,6 +92,10 @@ public class CommandTrace implements CommandExecutor { if (args.length < 2) { TraceShowManager.show(player, new Basic(player, new ShowModeParameter())); } else { + if (args[1].equalsIgnoreCase("gui")) { + GuiTraceShow.openGui(player); + return false; + } ShowModeParameter showModeParameter = ShowModeParameter.parseArguments(args, 2); switch (args[1].toLowerCase()) { case "advanced": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 5efe116..e2930a2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -39,7 +39,7 @@ public class CommandTraceTabCompleter implements TabCompleter { tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO), "start")); tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() != RecordStatus.IDLE && RecordStateMachine.getRecordStatus() != RecordStatus.IDLE_AUTO), "stop")); tabCompletes.add(new TabComplete((player, args) -> args.length == 1, "toggleauto", "auto", "show", "hide", "delete", "clear")); - tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "basic", "advanced")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "basic", "advanced", "gui")); tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && (args[1].equalsIgnoreCase("basic") || args[1].equalsIgnoreCase("advanced")), "-water")); tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && args[1].equalsIgnoreCase("advanced"), "-interpolate-xz", "-interpolate-y")); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java new file mode 100644 index 0000000..e8949e9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -0,0 +1,134 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.gui; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.show.ShowMode; +import de.steamwar.bausystem.tracer.show.ShowModeParameter; +import de.steamwar.bausystem.tracer.show.TraceShowManager; +import de.steamwar.bausystem.tracer.show.mode.Advanced; +import de.steamwar.bausystem.tracer.show.mode.Basic; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class GuiTraceShow { + + private static final Map SHOW_MODE_PARAMETER_HASH_MAP = new HashMap<>(); + + public static void openGui(Player player) { + ShowModeParameter playerShowMode = new ShowModeParameter(); + playerShowMode.setInterpolate_Y(false); + playerShowMode.setInterpolate_XZ(false); + SHOW_MODE_PARAMETER_HASH_MAP.put(player, playerShowMode); + + SWInventory swInventory = new SWInventory(player, 9, BauSystem.PREFIX + "ShowGUI"); + swInventory.addCloseCallback(clickType -> SHOW_MODE_PARAMETER_HASH_MAP.remove(player)); + + SWItem trace_show = new SWItem(Material.LIME_CONCRETE, "§aTraces Angezeigt", new ArrayList<>(), false, clickType -> {}); + SWItem trace_hide = new SWItem(Material.RED_CONCRETE, "§cTraces Ausgeblendet", new ArrayList<>(), false, clickType -> {}); + setActiveShow(player, swInventory, trace_show, trace_hide); + + SWItem water = new SWItem(Material.TNT, "§eWasser §7Positionen", Arrays.asList("§7Zeigt alles TNT, welches", "§7im Wasser explodiert ist"), false, clickType -> {}); + swInventory.setItem(5, water); + swInventory.setCallback(5, clickType -> toggleHideTNTinWaterExploded(player, swInventory, water)); + + SWItem interpolateY = new SWItem(Material.QUARTZ_STAIRS, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse"), false, clickType -> {}); + swInventory.setItem(6, interpolateY); + swInventory.setCallback(6, clickType -> toggleInterpolateYPosition(player, swInventory, interpolateY)); + + SWItem interpolateXZ = new SWItem(Material.QUARTZ_SLAB, "§eInterpolation §7XZ-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der XZ-Achse"), false, clickType -> {}); + swInventory.setItem(7, interpolateXZ); + swInventory.setCallback(7, clickType -> toggleInterpolateXZPosition(player, swInventory, interpolateXZ)); + // Water Bucket (-water) + // TNT (-water-exploded) + // Quartz_Stair (-interpolate-y) + // Quartz_Slab (-interpolate-xz) + swInventory.open(); + } + + private static void setActiveShow(Player player, SWInventory swInventory, SWItem shown, SWItem hidden) { + if (TraceShowManager.hasActiveShow(player)) { + swInventory.setItem(1, shown); + swInventory.setCallback(1, clickType -> { + TraceShowManager.hide(player); + player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet"); + setActiveShow(player, swInventory, shown, hidden); + }); + } else { + swInventory.setItem(1, hidden); + swInventory.setCallback(1, clickType -> { + show(player); + player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); + setActiveShow(player, swInventory, shown, hidden); + }); + } + } + + private static void toggleHideTNTinWaterExploded(Player player, SWInventory swInventory, SWItem swItem) { + ShowModeParameter showModeParameter = SHOW_MODE_PARAMETER_HASH_MAP.get(player); + showModeParameter.setWater(!showModeParameter.isWater()); + show(player); + + swItem.setEnchanted(showModeParameter.isWater()); + swInventory.setItem(5, swItem); + swInventory.setCallback(5, clickType -> toggleHideTNTinWaterExploded(player, swInventory, swItem)); + } + + private static void toggleInterpolateYPosition(Player player, SWInventory swInventory, SWItem swItem) { + ShowModeParameter showModeParameter = SHOW_MODE_PARAMETER_HASH_MAP.get(player); + showModeParameter.setInterpolate_Y(!showModeParameter.isInterpolate_Y()); + show(player); + + swItem.setEnchanted(showModeParameter.isInterpolate_Y()); + swInventory.setItem(6, swItem); + swInventory.setCallback(6, clickType -> toggleInterpolateYPosition(player, swInventory, swItem)); + } + + private static void toggleInterpolateXZPosition(Player player, SWInventory swInventory, SWItem swItem) { + ShowModeParameter showModeParameter = SHOW_MODE_PARAMETER_HASH_MAP.get(player); + showModeParameter.setInterpolate_XZ(!showModeParameter.isInterpolate_XZ()); + show(player); + + swItem.setEnchanted(showModeParameter.isInterpolate_XZ()); + swInventory.setItem(7, swItem); + swInventory.setCallback(7, clickType -> toggleInterpolateXZPosition(player, swInventory, swItem)); + } + + private static void show(Player player) { + ShowModeParameter showModeParameter = SHOW_MODE_PARAMETER_HASH_MAP.get(player); + ShowMode showMode; + if (showModeParameter.isAdvanced()) { + showMode = new Advanced(player, showModeParameter); + } else { + showMode = new Basic(player, showModeParameter); + } + TraceShowManager.show(player, showMode); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java index e3ee044..27900a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java @@ -44,6 +44,22 @@ public class ShowModeParameter { return interpolate_XZ; } + public void setWater(boolean water) { + this.water = water; + } + + public void setInterpolate_Y(boolean interpolate_Y) { + this.interpolate_Y = interpolate_Y; + } + + public void setInterpolate_XZ(boolean interpolate_XZ) { + this.interpolate_XZ = interpolate_XZ; + } + + public boolean isAdvanced() { + return interpolate_Y | interpolate_XZ; + } + public static ShowModeParameter parseArguments(String[] args, int index) { ShowModeParameter showModeParameter = new ShowModeParameter(); for (int i = index; i < args.length; i++) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index 70e8afd..21c09f1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -51,4 +51,9 @@ public class TraceShowManager implements Listener { public void onLeave(PlayerQuitEvent event) { showModes.remove(event.getPlayer()); } + + public static boolean hasActiveShow(Player player) { + return showModes.containsKey(player); + } + } From c4867658a609c50e729eb7c0a9e86beaf32b1eb6 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 16 Jan 2021 18:20:57 +0100 Subject: [PATCH 02/91] Fix issue with ShowModeParameter --- .../de/steamwar/bausystem/tracer/show/ShowModeParameter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java index 27900a5..153e580 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java @@ -57,7 +57,7 @@ public class ShowModeParameter { } public boolean isAdvanced() { - return interpolate_Y | interpolate_XZ; + return interpolate_Y || interpolate_XZ; } public static ShowModeParameter parseArguments(String[] args, int index) { From a22e1d37b92e9b537a1040d125e1f22a4affbec7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 11:04:46 +0100 Subject: [PATCH 03/91] Add CommandBuildMode --- .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../bausystem/commands/CommandBuildMode.java | 86 +++++++++++++++++++ .../bausystem/commands/CommandTNT.java | 8 ++ .../bausystem/world/BauScoreboard.java | 13 ++- .../de/steamwar/bausystem/world/Region.java | 19 +++- BauSystem_Main/src/plugin.yml | 1 + 6 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 9a7276b..2563e1b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -82,6 +82,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); getCommand("tnt").setExecutor(new CommandTNT()); + getCommand("buildmode").setExecutor(new CommandBuildMode()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java new file mode 100644 index 0000000..d65fe6b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java @@ -0,0 +1,86 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.world.Region; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityExplodeEvent; + +public class CommandBuildMode extends ToggleCommand { + + public CommandBuildMode() { + super(false); + } + + public static ToggleCommand getInstance() { + return getInstance(CommandBuildMode.class); + } + + @Override + String getNoPermMessage() { + return "§cDu darfst hier den Build mode nicht (de-)aktivieren"; + } + + @Override + String getEnableMessage() { + return "§aBuild mode aktiviert"; + } + + @Override + String getDisableMessage() { + return "§cBuild mode deaktiviert"; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) + return false; + Player player = (Player) sender; + if (!CommandTNT.getInstance().isOn()) { + player.sendMessage(BauSystem.PREFIX + "§cUm den Build mode zu nutzen muss TNT an sein."); + return false; + } + return super.onCommand(sender, command, label, args); + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } + } + return false; + }); + if (!blocksDestroyed) { + return; + } + Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(BauSystem.PREFIX + "§cEs ist etwas explodiert und hätte blöcke zerstört.")); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7298c9b..de342b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -45,6 +45,14 @@ public class CommandTNT extends ToggleCommand { return "§aTNT-Schaden aktiviert"; } + @Override + public void toggle() { + if (CommandBuildMode.getInstance().isOn()) { + CommandBuildMode.getInstance().toggle(); + } + super.toggle(); + } + @EventHandler public void onExplode(EntityExplodeEvent e) { e.blockList().clear(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index c15abc1..e1b775f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.world; +import de.steamwar.bausystem.commands.CommandBuildMode; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; @@ -61,7 +62,7 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); + strings.add("§eTNT§8: " + tntString()); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); @@ -104,4 +105,14 @@ public class BauScoreboard implements Listener { return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } + private String tntString() { + if (!CommandTNT.getInstance().isOn()) { + if (CommandBuildMode.getInstance().isOn()) { + return "§eTestblock"; + } + return "§aan"; + } + return "§caus"; + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 5bc4449..b1f4ed4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -80,6 +80,14 @@ public class Region { return prototype.inRegion(this, l); } + public boolean hasBuildRegion() { + return prototype.buildArea != null; + } + + public boolean inBuildRegion(Location l) { + return prototype.buildArea.inRegion(this, l); + } + public void fastreset(){ prototype.fastreset(this); } @@ -101,7 +109,8 @@ public class Region { } public static class Prototype{ - private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + // private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + private static final String SECTION_PATH = "/home/yoyonow/Dev1.15//UserBau/f75632be-e3ec-4069-9bec-d13ac6891177/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; @@ -116,6 +125,8 @@ public class Region { private final boolean rotate; private final Prototype testblock; //nullable + private final Prototype buildArea; //nullable + private final String protectSchematic; //nullable private Prototype(ConfigurationSection config){ @@ -130,9 +141,13 @@ public class Region { ConfigurationSection testblockSection = config.getConfigurationSection("testblock"); testblock = testblockSection != null ? new Prototype(testblockSection) : null; + + ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea"); + buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null; + protectSchematic = config.getString("protection", null); - if(!config.getName().equals("testblock")) + if(!config.getName().equals("testblock") && !config.getName().equals("buildArea")) prototypes.put(config.getName(), this); } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index bc85fb9..b589f20 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -10,6 +10,7 @@ commands: debugstick: tnt: fire: + buildmode: trace: tpslimit: testblock: From 0be031f5fed5dab3ed0aaf09d096574fe0c904ef Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 11:25:34 +0100 Subject: [PATCH 04/91] Add CommandBuildMode --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandBuildMode.java | 12 ------------ .../de/steamwar/bausystem/commands/CommandTNT.java | 8 -------- .../de/steamwar/bausystem/world/BauScoreboard.java | 2 +- .../src/de/steamwar/bausystem/world/Region.java | 3 +-- 5 files changed, 3 insertions(+), 24 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 2563e1b..6f8ef7c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -81,8 +81,8 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); - getCommand("tnt").setExecutor(new CommandTNT()); getCommand("buildmode").setExecutor(new CommandBuildMode()); + getCommand("tnt").setExecutor(new CommandTNT()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java index d65fe6b..51a3454 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java @@ -55,18 +55,6 @@ public class CommandBuildMode extends ToggleCommand { return "§cBuild mode deaktiviert"; } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) - return false; - Player player = (Player) sender; - if (!CommandTNT.getInstance().isOn()) { - player.sendMessage(BauSystem.PREFIX + "§cUm den Build mode zu nutzen muss TNT an sein."); - return false; - } - return super.onCommand(sender, command, label, args); - } - @EventHandler public void onEntityExplode(EntityExplodeEvent event) { boolean blocksDestroyed = event.blockList().removeIf(block -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index de342b1..7298c9b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -45,14 +45,6 @@ public class CommandTNT extends ToggleCommand { return "§aTNT-Schaden aktiviert"; } - @Override - public void toggle() { - if (CommandBuildMode.getInstance().isOn()) { - CommandBuildMode.getInstance().toggle(); - } - super.toggle(); - } - @EventHandler public void onExplode(EntityExplodeEvent e) { e.blockList().clear(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index e1b775f..5a696e8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -108,7 +108,7 @@ public class BauScoreboard implements Listener { private String tntString() { if (!CommandTNT.getInstance().isOn()) { if (CommandBuildMode.getInstance().isOn()) { - return "§eTestblock"; + return "§7nur §eTestblock"; } return "§aan"; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index b1f4ed4..f1949b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -109,8 +109,7 @@ public class Region { } public static class Prototype{ - // private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; - private static final String SECTION_PATH = "/home/yoyonow/Dev1.15//UserBau/f75632be-e3ec-4069-9bec-d13ac6891177/"; + private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; From 28b3733b83f1862314893f998db8e0453467c436 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 18:18:18 +0100 Subject: [PATCH 05/91] Simplify CommandTNT --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandBuildMode.java | 74 ------------ .../bausystem/commands/CommandTNT.java | 112 +++++++++++++++--- .../commands/CommandTNTTabComplete.java | 59 +++++++++ .../bausystem/world/BauScoreboard.java | 13 +- BauSystem_Main/src/plugin.yml | 1 - 6 files changed, 159 insertions(+), 102 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 6f8ef7c..96bde54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -81,8 +81,8 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); - getCommand("buildmode").setExecutor(new CommandBuildMode()); getCommand("tnt").setExecutor(new CommandTNT()); + getCommand("tnt").setTabCompleter(new CommandTNTTabComplete()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java deleted file mode 100644 index 51a3454..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.commands; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.world.Region; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityExplodeEvent; - -public class CommandBuildMode extends ToggleCommand { - - public CommandBuildMode() { - super(false); - } - - public static ToggleCommand getInstance() { - return getInstance(CommandBuildMode.class); - } - - @Override - String getNoPermMessage() { - return "§cDu darfst hier den Build mode nicht (de-)aktivieren"; - } - - @Override - String getEnableMessage() { - return "§aBuild mode aktiviert"; - } - - @Override - String getDisableMessage() { - return "§cBuild mode deaktiviert"; - } - - @EventHandler - public void onEntityExplode(EntityExplodeEvent event) { - boolean blocksDestroyed = event.blockList().removeIf(block -> { - for (Region region : Region.getRegions()) { - if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { - return true; - } - } - return false; - }); - if (!blocksDestroyed) { - return; - } - Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(BauSystem.PREFIX + "§cEs ist etwas explodiert und hätte blöcke zerstört.")); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7298c9b..7726448 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -19,34 +19,118 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.world.Welt; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityExplodeEvent; -public class CommandTNT extends ToggleCommand { +public class CommandTNT implements CommandExecutor { - public CommandTNT(){ - super(true); + private static TNTMode tntMode = TNTMode.OFF; + + public static TNTMode getTntMode() { + return tntMode; } - public static ToggleCommand getInstance(){ - return getInstance(CommandTNT.class); + public enum TNTMode { + ON("§aan"), + ONLY_TB("§7nur §eTestblock"), + OFF("§caus"); + + private String name; + + TNTMode(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } - @Override - String getNoPermMessage() { + private String getNoPermMessage() { return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"; } - @Override - String getEnableMessage(){ + + private String getEnableMessage() { return "§cTNT-Schaden deaktiviert"; } - @Override - String getDisableMessage(){ + + private String getDisableMessage() { return "§aTNT-Schaden aktiviert"; } - @EventHandler - public void onExplode(EntityExplodeEvent e) { - e.blockList().clear(); + private String getTestblockEnableMessage() { + return "§aTNT-Schaden beim Testblock aktiviert"; } + + private String getDamageMessage() { + return "§cEs ist etwas explodiert und hätte blöcke zerstört"; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { + if (!(sender instanceof Player)) return false; + Player player = (Player) sender; + + if (Welt.noPermission(player, Permission.world)) { + player.sendMessage(BauSystem.PREFIX + getNoPermMessage()); + return false; + } + + if (args.length != 0 && args[0].equalsIgnoreCase("on")) { + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + return false; + } + + switch (tntMode) { + case ON: + case ONLY_TB: + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + break; + case OFF: + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + break; + } + return false; + } + + @EventHandler + public void onExplode(EntityExplodeEvent event) { + if (tntMode == TNTMode.ON) return; + if (tntMode == TNTMode.OFF) { + event.blockList().clear(); + } else { + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } + } + return false; + }); + if (!blocksDestroyed) { + return; + } + sendToActionBar(getDamageMessage()); + } + } + + private void sendToActionBar(String message) { + Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message))); + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java new file mode 100644 index 0000000..d79f448 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -0,0 +1,59 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class CommandTNTTabComplete implements TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) return new ArrayList<>(); + return detonaterTabComplete((Player) sender, args); + } + + private List detonaterTabComplete(Player player, String[] args) { + List tabComplete = new ArrayList<>(); + tabComplete.add("an"); + + if (args.length >= 2) { + return new ArrayList<>(); + } + return manageList(tabComplete, args, 0); + } + + private List manageList(List strings, String[] args, int index) { + for (int i = strings.size() - 1; i >= 0; i--) { + if (!strings.get(i).startsWith(args[index])) { + strings.remove(i); + } + } + return strings; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 5a696e8..8aaf994 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem.world; -import de.steamwar.bausystem.commands.CommandBuildMode; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; @@ -62,7 +61,7 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - strings.add("§eTNT§8: " + tntString()); + strings.add("§eTNT§8: " + CommandTNT.getTntMode().getName()); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); @@ -105,14 +104,4 @@ public class BauScoreboard implements Listener { return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } - private String tntString() { - if (!CommandTNT.getInstance().isOn()) { - if (CommandBuildMode.getInstance().isOn()) { - return "§7nur §eTestblock"; - } - return "§aan"; - } - return "§caus"; - } - } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index b589f20..bc85fb9 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -10,7 +10,6 @@ commands: debugstick: tnt: fire: - buildmode: trace: tpslimit: testblock: From 38b545483a7b2f4053a1ddb86874b5d2f76b5509 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 19:01:52 +0100 Subject: [PATCH 06/91] Fix PR stuff --- .../src/de/steamwar/bausystem/gui/GuiTraceShow.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java index e8949e9..48b588b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -54,15 +54,15 @@ public class GuiTraceShow { SWItem trace_hide = new SWItem(Material.RED_CONCRETE, "§cTraces Ausgeblendet", new ArrayList<>(), false, clickType -> {}); setActiveShow(player, swInventory, trace_show, trace_hide); - SWItem water = new SWItem(Material.TNT, "§eWasser §7Positionen", Arrays.asList("§7Zeigt alles TNT, welches", "§7im Wasser explodiert ist"), false, clickType -> {}); + SWItem water = new SWItem(Material.TNT, "§eWasser §7Positionen", Arrays.asList("§7Zeigt alles TNT, welches", "§7im Wasser explodiert ist."), false, clickType -> {}); swInventory.setItem(5, water); swInventory.setCallback(5, clickType -> toggleHideTNTinWaterExploded(player, swInventory, water)); - SWItem interpolateY = new SWItem(Material.QUARTZ_STAIRS, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse"), false, clickType -> {}); + SWItem interpolateY = new SWItem(Material.QUARTZ_STAIRS, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse."), false, clickType -> {}); swInventory.setItem(6, interpolateY); swInventory.setCallback(6, clickType -> toggleInterpolateYPosition(player, swInventory, interpolateY)); - SWItem interpolateXZ = new SWItem(Material.QUARTZ_SLAB, "§eInterpolation §7XZ-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der XZ-Achse"), false, clickType -> {}); + SWItem interpolateXZ = new SWItem(Material.QUARTZ_SLAB, "§eInterpolation §7XZ-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der XZ-Achse."), false, clickType -> {}); swInventory.setItem(7, interpolateXZ); swInventory.setCallback(7, clickType -> toggleInterpolateXZPosition(player, swInventory, interpolateXZ)); // Water Bucket (-water) From 9bb234bf32b8bcbf9f41272c2c490a0d1bdcba9e Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 21:03:04 +0100 Subject: [PATCH 07/91] Fix Region.Prototype.SECTION_PATH --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 3 +++ BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 9a7276b..279e3fb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -42,6 +42,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; +import java.nio.file.Paths; import java.util.UUID; import java.util.logging.Level; @@ -74,6 +75,8 @@ public class BauSystem extends JavaPlugin implements Listener { return; } + System.out.println(Bukkit.getWorlds().get(0).getWorldFolder().getAbsolutePath()); + getCommand("trace").setExecutor(new CommandTrace()); getCommand("trace").setTabCompleter(new CommandTraceTabCompleter()); getCommand("tpslimit").setExecutor(new CommandTPSLimiter()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index d066d09..f428ee3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -105,7 +105,7 @@ public class Region { } public static class Prototype{ - private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + private static final String SECTION_PATH = Bukkit.getWorlds().get(0).getWorldFolder().getAbsolutePath() + "/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; From ae6d5ee6713bd591b2ea725e3e4839085e903217 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 Jan 2021 13:58:02 +0100 Subject: [PATCH 08/91] Fix PR stuff --- .../bausystem/commands/CommandTNT.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7726448..94f4d4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -31,9 +31,10 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; -public class CommandTNT implements CommandExecutor { +public class CommandTNT implements CommandExecutor, Listener { private static TNTMode tntMode = TNTMode.OFF; @@ -58,6 +59,10 @@ public class CommandTNT implements CommandExecutor { } + public CommandTNT() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + } + private String getNoPermMessage() { return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"; } @@ -71,11 +76,11 @@ public class CommandTNT implements CommandExecutor { } private String getTestblockEnableMessage() { - return "§aTNT-Schaden beim Testblock aktiviert"; + return "§aTNT-Schaden am Testblock aktiviert"; } private String getDamageMessage() { - return "§cEs ist etwas explodiert und hätte blöcke zerstört"; + return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; } @Override @@ -110,22 +115,25 @@ public class CommandTNT implements CommandExecutor { @EventHandler public void onExplode(EntityExplodeEvent event) { - if (tntMode == TNTMode.ON) return; - if (tntMode == TNTMode.OFF) { - event.blockList().clear(); - } else { - boolean blocksDestroyed = event.blockList().removeIf(block -> { - for (Region region : Region.getRegions()) { - if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { - return true; + switch (tntMode) { + case ON: + break; + case OFF: + event.blockList().clear(); + break; + case ONLY_TB: + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } } + return false; + }); + if (blocksDestroyed) { + sendToActionBar(getDamageMessage()); } - return false; - }); - if (!blocksDestroyed) { - return; - } - sendToActionBar(getDamageMessage()); + break; } } From 84686357c598977ea13ad19cad11e7f3f0b92fae Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 Jan 2021 14:02:01 +0100 Subject: [PATCH 09/91] Fix PR stuff --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 279e3fb..4dbb0a1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -75,8 +75,6 @@ public class BauSystem extends JavaPlugin implements Listener { return; } - System.out.println(Bukkit.getWorlds().get(0).getWorldFolder().getAbsolutePath()); - getCommand("trace").setExecutor(new CommandTrace()); getCommand("trace").setTabCompleter(new CommandTraceTabCompleter()); getCommand("tpslimit").setExecutor(new CommandTPSLimiter()); From 36a601a610f9eda8fe4278d3065d10fc25cdb9f7 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 Jan 2021 16:13:32 +0100 Subject: [PATCH 10/91] Fix PR stuff --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 1 - BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 4dbb0a1..9a7276b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -42,7 +42,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -import java.nio.file.Paths; import java.util.UUID; import java.util.logging.Level; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index f428ee3..a518b80 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -105,7 +105,6 @@ public class Region { } public static class Prototype{ - private static final String SECTION_PATH = Bukkit.getWorlds().get(0).getWorldFolder().getAbsolutePath() + "/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; @@ -147,7 +146,7 @@ public class Region { } public void fastreset(Region region){ - File file = new File(SECTION_PATH + schematic); + File file = new File(schematic); int x = region.minX + offsetX + sizeX/2; int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ/2; @@ -166,7 +165,7 @@ public class Region { int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ / 2; if(schem == null) - paste(new File(SECTION_PATH + schematic), x, y, z, rotate); + paste(new File(schematic), x, y, z, rotate); else paste(schem.load(), x, y, z, rotate); } @@ -180,7 +179,7 @@ public class Region { int y = region.minY + testblock.offsetY - 1; int z = region.minZ + offsetZ + sizeZ / 2; if(schem == null) - paste(new File(SECTION_PATH + protectSchematic), x, y, z, rotate); + paste(new File(protectSchematic), x, y, z, rotate); else paste(schem.load(), x, y, z, rotate); } From f04bf70087b00500c61556e1f7f05dd66b91b93a Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 14:50:19 +0100 Subject: [PATCH 11/91] Fix Build issues --- .../steamwar/bausystem/commands/CommandInfo.java | 2 +- .../steamwar/bausystem/commands/CommandTNT.java | 16 +++++++++++++--- .../commands/CommandTNTTabComplete.java | 9 +++++++-- .../steamwar/bausystem/world/ScriptListener.java | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 0b506d9..82b2563 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getInstance().isOn() ? "§aAUS" : "§cAN")); + sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? "§cAN" : "§aAUS")); sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 94f4d4e..bbebb25 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -68,11 +68,11 @@ public class CommandTNT implements CommandExecutor, Listener { } private String getEnableMessage() { - return "§cTNT-Schaden deaktiviert"; + return "§aTNT-Schaden aktiviert"; } private String getDisableMessage() { - return "§aTNT-Schaden aktiviert"; + return "§cTNT-Schaden deaktiviert"; } private String getTestblockEnableMessage() { @@ -93,11 +93,21 @@ public class CommandTNT implements CommandExecutor, Listener { return false; } - if (args.length != 0 && args[0].equalsIgnoreCase("on")) { + if (args.length != 0 && (args[0].equalsIgnoreCase("an") || args[0].equalsIgnoreCase("on"))) { tntMode = TNTMode.ON; sendToActionBar(getEnableMessage()); return false; } + if (args.length != 0 && (args[0].equalsIgnoreCase("aus") || args[0].equalsIgnoreCase("off"))) { + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + return false; + } + if (args.length != 0 && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + return false; + } switch (tntMode) { case ON: diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index d79f448..5ce5c30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -34,12 +34,17 @@ public class CommandTNTTabComplete implements TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); - return detonaterTabComplete((Player) sender, args); + return tntTabComplete((Player) sender, args); } - private List detonaterTabComplete(Player player, String[] args) { + private List tntTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); tabComplete.add("an"); + tabComplete.add("on"); + tabComplete.add("aus"); + tabComplete.add("off"); + tabComplete.add("testblock"); + tabComplete.add("tb"); if (args.length >= 2) { return new ArrayList<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 762aff6..d0f2fc8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -284,7 +284,7 @@ public class ScriptListener implements Listener { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; case "tnt": - return CommandTNT.getInstance().isOn() ? 1 : 0; + return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; case "freeze": return CommandFreeze.getInstance().isOn() ? 1 : 0; case "fire": From bd8a34dd1583fbbe8db6f16c0ef287783fcb5f2e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 24 Jan 2021 14:58:58 +0100 Subject: [PATCH 12/91] Fixing region size --- BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index a518b80..1a13714 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -140,9 +140,9 @@ public class Region { } public boolean inRegion(Region region, Location l){ - return inRange(l.getX(), region.minX + offsetX, sizeX + offsetX) && - inRange(l.getY(), region.minY + offsetY, sizeY + offsetY) && - inRange(l.getZ(), region.minZ + offsetZ, sizeZ + offsetZ); + return inRange(l.getX(), region.minX + offsetX, sizeX) && + inRange(l.getY(), region.minY + offsetY, sizeY) && + inRange(l.getZ(), region.minZ + offsetZ, sizeZ); } public void fastreset(Region region){ From 7871a88824cd63a2f82328d0a5ed9b61945212da Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 17:02:34 +0100 Subject: [PATCH 13/91] Add CommandTNT by Region.buildAreaEnabled() --- .../de/steamwar/bausystem/commands/CommandTNT.java | 11 ++++++++--- .../bausystem/commands/CommandTNTTabComplete.java | 11 +++++++---- .../src/de/steamwar/bausystem/world/Region.java | 14 +++++++++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index bbebb25..3443dee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -103,7 +103,7 @@ public class CommandTNT implements CommandExecutor, Listener { sendToActionBar(getDisableMessage()); return false; } - if (args.length != 0 && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { + if (args.length != 0 && Region.buildAreaEnabled() && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { tntMode = TNTMode.ONLY_TB; sendToActionBar(getTestblockEnableMessage()); return false; @@ -116,8 +116,13 @@ public class CommandTNT implements CommandExecutor, Listener { sendToActionBar(getDisableMessage()); break; case OFF: - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); + if (Region.buildAreaEnabled()) { + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + } else { + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + } break; } return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index 5ce5c30..dbc18b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.world.Region; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -34,17 +35,19 @@ public class CommandTNTTabComplete implements TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); - return tntTabComplete((Player) sender, args); + return tntTabComplete(args); } - private List tntTabComplete(Player player, String[] args) { + private List tntTabComplete(String[] args) { List tabComplete = new ArrayList<>(); tabComplete.add("an"); tabComplete.add("on"); tabComplete.add("aus"); tabComplete.add("off"); - tabComplete.add("testblock"); - tabComplete.add("tb"); + if (Region.buildAreaEnabled()) { + tabComplete.add("testblock"); + tabComplete.add("tb"); + } if (args.length >= 2) { return new ArrayList<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index f1949b1..6f7ec11 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -37,6 +37,11 @@ import java.util.logging.Level; public class Region { private static final List regions = new ArrayList<>(); + private static boolean buildArea = false; + + public static boolean buildAreaEnabled() { + return buildArea; + } static{ YamlConfiguration config = new YamlConfiguration(); @@ -143,6 +148,9 @@ public class Region { ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea"); buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null; + if (buildArea != null) { + Region.buildArea = true; + } protectSchematic = config.getString("protection", null); @@ -151,9 +159,9 @@ public class Region { } public boolean inRegion(Region region, Location l){ - return inRange(l.getX(), region.minX + offsetX, sizeX + offsetX) && - inRange(l.getY(), region.minY + offsetY, sizeY + offsetY) && - inRange(l.getZ(), region.minZ + offsetZ, sizeZ + offsetZ); + return inRange(l.getX(), region.minX + offsetX, sizeX) && + inRange(l.getY(), region.minY + offsetY, sizeY) && + inRange(l.getZ(), region.minZ + offsetZ, sizeZ); } public void fastreset(Region region){ From f887e633adc1a9371ae35b39468cca7a6f124305 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 20:07:19 +0100 Subject: [PATCH 14/91] Add CommandTNT by Region.buildAreaEnabled() --- .../bausystem/commands/CommandInfo.java | 2 +- .../bausystem/commands/CommandTNT.java | 35 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 82b2563..c6810f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? "§cAN" : "§aAUS")); + sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + CommandTNT.getTntMode().getName()); sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 3443dee..23ab3b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -93,20 +93,27 @@ public class CommandTNT implements CommandExecutor, Listener { return false; } - if (args.length != 0 && (args[0].equalsIgnoreCase("an") || args[0].equalsIgnoreCase("on"))) { - tntMode = TNTMode.ON; - sendToActionBar(getEnableMessage()); - return false; - } - if (args.length != 0 && (args[0].equalsIgnoreCase("aus") || args[0].equalsIgnoreCase("off"))) { - tntMode = TNTMode.OFF; - sendToActionBar(getDisableMessage()); - return false; - } - if (args.length != 0 && Region.buildAreaEnabled() && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); - return false; + if (args.length != 0) { + switch (args[0].toLowerCase()) { + case "an": + case "on": + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + return false; + case "aus": + case "off": + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + return false; + case "testblock": + case "tb": + if (!Region.buildAreaEnabled()) break; + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + return false; + default: + break; + } } switch (tntMode) { From 4e4a1eb3e8908c7644990e4c375bfe8b1e157372 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 21:12:36 +0100 Subject: [PATCH 15/91] Add TNTMode to ONLY_TB --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 23ab3b6..e4dd091 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -38,6 +38,12 @@ public class CommandTNT implements CommandExecutor, Listener { private static TNTMode tntMode = TNTMode.OFF; + static { + if (Region.buildAreaEnabled()) { + tntMode = TNTMode.ONLY_TB; + } + } + public static TNTMode getTntMode() { return tntMode; } From 093ab5802ed0c6a108fc8a7a44e4908b9d410202 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 21:15:19 +0100 Subject: [PATCH 16/91] Add TNTMode to ONLY_TB --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index e4dd091..91eb203 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -36,13 +36,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; public class CommandTNT implements CommandExecutor, Listener { - private static TNTMode tntMode = TNTMode.OFF; - - static { - if (Region.buildAreaEnabled()) { - tntMode = TNTMode.ONLY_TB; - } - } + private static TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; public static TNTMode getTntMode() { return tntMode; From ea345fb46cbeabad7ce488cec259bf89c2cec2a7 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 14:32:52 +0100 Subject: [PATCH 17/91] Add Region section Support for /tnt /fire /freeze --- .../bausystem/commands/CommandFire.java | 29 +++-- .../bausystem/commands/CommandFreeze.java | 103 ++++++++++++----- .../bausystem/commands/CommandInfo.java | 15 ++- .../bausystem/commands/CommandProtect.java | 40 +++---- .../bausystem/commands/CommandReset.java | 42 ++++--- .../bausystem/commands/CommandTNT.java | 106 ++++++++--------- .../bausystem/commands/CommandTestblock.java | 40 +++---- .../commands/RegionToggleCommand.java | 83 +++++++++++++ .../bausystem/commands/ToggleCommand.java | 87 -------------- .../bausystem/world/BauScoreboard.java | 10 +- .../de/steamwar/bausystem/world/Region.java | 109 +++++++++++++++++- .../bausystem/world/ScriptListener.java | 16 ++- 12 files changed, 417 insertions(+), 263 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/ToggleCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 4403ec7..bd640fb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -19,18 +19,15 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.world.Region; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockSpreadEvent; -public class CommandFire extends ToggleCommand { +public class CommandFire extends RegionToggleCommand { - public CommandFire(){ - super(true); - } - - public static ToggleCommand getInstance(){ - return getInstance(CommandFire.class); + public CommandFire() { + super(); } @Override @@ -45,15 +42,29 @@ public class CommandFire extends ToggleCommand { String getDisableMessage(){ return "§aFeuerschaden aktiviert"; } + @Override + String getNoRegionMessage() { + return "§cDu befindest dich derzeit in keiner Region"; + } + + @Override + boolean toggle(Region region) { + region.setFire(!region.isFire()); + return region.isFire(); + } @EventHandler public void onFireDamage(BlockBurnEvent e) { - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFire()) e.setCancelled(true); + }); } @EventHandler public void onFireSpread(BlockSpreadEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFire()) e.setCancelled(true); + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 6443e32..9a9c80f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -1,36 +1,41 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 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 . -*/ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.commands; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.world.Region; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; -public class CommandFreeze extends ToggleCommand { +public class CommandFreeze extends RegionToggleCommand { public CommandFreeze(){ - super(false); - } - - public static ToggleCommand getInstance(){ - return getInstance(CommandFreeze.class); + super(); } @Override @@ -45,39 +50,75 @@ public class CommandFreeze extends ToggleCommand { String getDisableMessage(){ return "§aWelt aufgetaut"; } + @Override + String getNoRegionMessage() { + return "§cDu befindest dich derzeit in keiner Region"; + } + + @Override + boolean toggle(Region region) { + region.setFreeze(!region.isFreeze()); + return region.isFreeze(); + } + + @EventHandler + public void onEntitySpawn(EntitySpawnEvent e) { + Region.getRegion(e.getLocation(), region -> { + if (!region.isFreeze()) { + return; + } + if (e.getEntityType() == EntityType.FALLING_BLOCK) { + e.setCancelled(true); + } + }); + } @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onPistonExtend(BlockPistonExtendEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onPistonRetract(BlockPistonRetractEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onBlockGrow(BlockGrowEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onRedstoneEvent(BlockRedstoneEvent e){ - e.setNewCurrent(e.getOldCurrent()); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent()); + }); } @EventHandler public void onBlockDispense(BlockDispenseEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onInventoryMoveEvent(InventoryMoveItemEvent e){ - e.setCancelled(true); + Region.getRegion(e.getDestination().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index c6810f7..ae8960f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -20,12 +20,14 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.world.Region; import de.steamwar.core.TPSWatcher; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.util.List; @@ -33,10 +35,17 @@ public class CommandInfo implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + return false; + } + Player player = (Player) sender; + sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + CommandTNT.getTntMode().getName()); - sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); - sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); + Region.getRegion(player.getLocation(), region -> { + sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); + }, () -> { + sender.sendMessage(BauSystem.PREFIX + "§7Du bist in keiner Region."); + }); List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index f12afb7..6adcd6b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -45,28 +45,26 @@ public class CommandProtect implements CommandExecutor { return false; } - for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation()) && region.hasProtection()){ - try { - Schematic schem = null; - if(args.length > 0){ - schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if(schem == null){ - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return false; - } - } - region.protect(schem); - player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); - }catch(Exception e){ - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region"); - Bukkit.getLogger().log(Level.WARNING, "Failed protect", e); - } - return false; - } + Region region = Region.getRegion(player); + if (region == null || !region.hasProtection()) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); + return false; + } + try { + Schematic schem = null; + if(args.length > 0){ + schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); + if(schem == null){ + player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); + return false; + } + } + region.protect(schem); + player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + }catch(Exception e){ + player.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed protect", e); } - - player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index 353fd22..a75be05 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -45,29 +45,27 @@ public class CommandReset implements CommandExecutor { return false; } - for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation())){ - try { - if(args.length > 0){ - Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if(schem == null){ - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return false; - } - region.reset(schem); - }else{ - region.fastreset(); - } - player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); - }catch(Exception e){ - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); - Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); - } - return false; - } + Region region = Region.getRegion(player); + if (region == null) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); + return false; + } + try { + if(args.length > 0){ + Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); + if(schem == null){ + player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); + return false; + } + region.reset(schem); + }else{ + region.fastreset(); + } + player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + }catch(Exception e){ + player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); } - - player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 91eb203..c5ccad2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -36,12 +36,6 @@ import org.bukkit.event.entity.EntityExplodeEvent; public class CommandTNT implements CommandExecutor, Listener { - private static TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; - - public static TNTMode getTntMode() { - return tntMode; - } - public enum TNTMode { ON("§aan"), ONLY_TB("§7nur §eTestblock"), @@ -83,6 +77,10 @@ public class CommandTNT implements CommandExecutor, Listener { return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; } + private String getNoRegionMessage() { + return "§cDu befindest dich derzeit in keiner Region"; + } + @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { if (!(sender instanceof Player)) return false; @@ -93,74 +91,72 @@ public class CommandTNT implements CommandExecutor, Listener { return false; } + TNTMode requestedMode = null; + String requestedMessage = null; if (args.length != 0) { switch (args[0].toLowerCase()) { case "an": case "on": - tntMode = TNTMode.ON; - sendToActionBar(getEnableMessage()); - return false; + requestedMode = TNTMode.ON; + requestedMessage = getEnableMessage(); + break; case "aus": case "off": - tntMode = TNTMode.OFF; - sendToActionBar(getDisableMessage()); - return false; + requestedMode = TNTMode.OFF; + requestedMessage = getDisableMessage(); + break; case "testblock": case "tb": if (!Region.buildAreaEnabled()) break; - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); - return false; + requestedMode = TNTMode.ONLY_TB; + requestedMessage = getTestblockEnableMessage(); + break; default: break; } } - switch (tntMode) { - case ON: - case ONLY_TB: - tntMode = TNTMode.OFF; - sendToActionBar(getDisableMessage()); - break; - case OFF: - if (Region.buildAreaEnabled()) { - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); - } else { - tntMode = TNTMode.ON; - sendToActionBar(getEnableMessage()); - } - break; - } + TNTMode finalRequestedMode = requestedMode; + String finalRequestedMessage = requestedMessage; + Region.getRegion(player.getLocation(), region -> { + if (finalRequestedMode != null) { + region.setTntMode(finalRequestedMode); + RegionToggleCommand.actionBar(region, finalRequestedMessage); + return; + } + switch (region.getTntMode()) { + case ON: + case ONLY_TB: + region.setTntMode(TNTMode.OFF); + RegionToggleCommand.actionBar(region, getDisableMessage()); + break; + case OFF: + if (Region.buildAreaEnabled()) { + region.setTntMode(TNTMode.ONLY_TB); + RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); + } else { + region.setTntMode(TNTMode.ON); + RegionToggleCommand.actionBar(region, getEnableMessage()); + } + break; + } + }, () -> RegionToggleCommand.actionBar(player, getNoRegionMessage())); return false; } @EventHandler public void onExplode(EntityExplodeEvent event) { - switch (tntMode) { - case ON: - break; - case OFF: - event.blockList().clear(); - break; - case ONLY_TB: - boolean blocksDestroyed = event.blockList().removeIf(block -> { - for (Region region : Region.getRegions()) { - if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { - return true; - } - } - return false; - }); - if (blocksDestroyed) { - sendToActionBar(getDamageMessage()); - } - break; - } - } - - private void sendToActionBar(String message) { - Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message))); + event.blockList().removeIf(block -> { + Region region = Region.getRegion(block.getLocation()); + if (region == null) return false; + if (region.getTntMode() == TNTMode.OFF) return true; + if (region.getTntMode() == TNTMode.ON) return false; + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + RegionToggleCommand.actionBar(region, getDamageMessage()); + return true; + } + return false; + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index 6859231..e44d889 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -45,28 +45,26 @@ public class CommandTestblock implements CommandExecutor { return false; } - for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation()) && region.hasTestblock()){ - try { - Schematic schem = null; - if(args.length > 0){ - schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if(schem == null){ - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return false; - } - } - region.resetTestblock(schem); - player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); - }catch(Exception e){ - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); - Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); - } - return false; - } + Region region = Region.getRegion(player); + if (region == null || !region.hasTestblock()) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); + return false; + } + try { + Schematic schem = null; + if(args.length > 0){ + schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); + if(schem == null){ + player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); + return false; + } + } + region.resetTestblock(schem); + player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); + }catch(Exception e){ + player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); + Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); } - - player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java new file mode 100644 index 0000000..7aaff41 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -0,0 +1,83 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.world.Welt; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.server.v1_15_R1.BlockCactus; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +public abstract class RegionToggleCommand implements CommandExecutor, Listener { + + RegionToggleCommand() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) + return false; + Player player = (Player) sender; + + if (Welt.noPermission(player, Permission.world)){ + player.sendMessage(BauSystem.PREFIX + getNoPermMessage()); + return false; + } + + Region.getRegion(player.getLocation(), region -> { + if (toggle(region)) { + actionBar(region, getEnableMessage()); + } else { + actionBar(region, getDisableMessage()); + } + }, () -> actionBar(player, getNoRegionMessage())); + return false; + } + + public static void actionBar(Region region, String s) { + Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + } + + public static void actionBar(Player player, String s) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)); + } + + abstract String getNoRegionMessage(); + abstract String getNoPermMessage(); + abstract String getEnableMessage(); + abstract String getDisableMessage(); + + /** + * {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()} + */ + abstract boolean toggle(Region region); + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/ToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/ToggleCommand.java deleted file mode 100644 index 0551a80..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/ToggleCommand.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 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.commands; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.world.Welt; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; - -import java.util.HashMap; -import java.util.Map; - -public abstract class ToggleCommand implements CommandExecutor, Listener { - - private static Map, Boolean> enabled = new HashMap<>(); - private static Map, ToggleCommand> instance = new HashMap<>(); - - ToggleCommand(boolean on){ - enabled.put(getClass(), false); - if(on) - toggle(); - instance.put(getClass(), this); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) - return false; - Player player = (Player) sender; - - if (Welt.noPermission(player, Permission.world)){ - player.sendMessage(BauSystem.PREFIX + getNoPermMessage()); - return false; - } - - toggle(); - return false; - } - - static ToggleCommand getInstance(Class clazz){ - return instance.get(clazz); - } - - abstract String getNoPermMessage(); - abstract String getEnableMessage(); - abstract String getDisableMessage(); - - public boolean isOn(){ - return enabled.get(getClass()); - } - - public void toggle(){ - enabled.compute(getClass(), (clazz, value) -> !value); - if(enabled.get(getClass())){ - Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getEnableMessage()))); - }else{ - HandlerList.unregisterAll(this); - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getDisableMessage()))); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 8aaf994..3faa945 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -19,8 +19,6 @@ package de.steamwar.bausystem.world; -import de.steamwar.bausystem.commands.CommandFreeze; -import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.core.TPSWatcher; @@ -61,8 +59,12 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - strings.add("§eTNT§8: " + CommandTNT.getTntMode().getName()); - strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); + Region region = Region.getRegion(p); + if (region != null) { + strings.add("§eTNT§8: " + region.getTntMode().getName()); + strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); + strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); + } strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 82e9f96..3c170f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.world; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import de.steamwar.bausystem.commands.CommandTNT.TNTMode; import de.steamwar.core.Core; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; @@ -28,10 +29,12 @@ import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; import java.util.*; +import java.util.function.Consumer; import java.util.logging.Level; public class Region { @@ -39,10 +42,6 @@ public class Region { private static final List regions = new ArrayList<>(); private static boolean buildArea = false; - public static boolean buildAreaEnabled() { - return buildArea; - } - static{ YamlConfiguration config = new YamlConfiguration(); try { @@ -64,23 +63,125 @@ public class Region { } } + public static boolean buildAreaEnabled() { + return buildArea; + } + + public static Region getRegion(Player player) { + return getRegion(player.getLocation()); + } + + public static Region getRegion(Location location) { + for (Region region : regions) { + if (region.inRegion(location)) return region; + } + return null; + } + + public static void getRegion(Location location, Consumer regionConsumer) { + getRegion(location, regionConsumer, () -> {}); + } + + public static void getRegion(Location location, Consumer regionConsumer, Runnable noRegion) { + boolean b = true; + for (Region region : regions) { + if (region.inRegion(location)) { + regionConsumer.accept(region); + b = false; + } + } + if (b) { + noRegion.run(); + } + } + public static List getRegions(){ return regions; } + private static Region getRegionByName(String name) { + for (Region region : regions) { + if (region.name.equals(name)) return region; + } + return null; + } + + private final String name; private final int minX; private final int minY; private final int minZ; private final Prototype prototype; + private final String optionsLinkedWith; // nullable + private Region linkedRegion = null; // nullable + + private TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; + private boolean freeze = false; + private boolean fire = false; private Region(ConfigurationSection config){ + name = config.getName(); minX = config.getInt("minX"); minY = config.getInt("minY"); minZ = config.getInt("minZ"); prototype = Prototype.prototypes.get(config.getString("prototype")); + optionsLinkedWith = config.getString("optionsLinkedWith", null); regions.add(this); } + private void link() { + if (optionsLinkedWith != null && linkedRegion == null) { + linkedRegion = getRegionByName(optionsLinkedWith); + } + } + + public TNTMode getTntMode() { + return tntMode; + } + + public void setTntMode(TNTMode tntMode) { + this.tntMode = tntMode; + link(); + if (linkedRegion != null) { + linkedRegion.setTntModeOther(tntMode); + } + } + + private void setTntModeOther(TNTMode tntMode) { + this.tntMode = tntMode; + } + + public boolean isFreeze() { + return freeze; + } + + public void setFreeze(boolean freeze) { + this.freeze = freeze; + link(); + if (linkedRegion != null) { + linkedRegion.setFreezeOther(freeze); + } + } + + public void setFreezeOther(boolean freeze) { + this.freeze = freeze; + } + + public boolean isFire() { + return fire; + } + + public void setFire(boolean fire) { + this.fire = fire; + link(); + if (linkedRegion != null) { + linkedRegion.setFireOther(fire); + } + } + + public void setFireOther(boolean fire) { + this.fire = fire; + } + public boolean inRegion(Location l){ return prototype.inRegion(this, l); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index d0f2fc8..e50d7c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -20,8 +20,6 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.commands.CommandFire; -import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandScript; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.tracer.record.RecordStateMachine; @@ -153,6 +151,8 @@ public class ScriptListener implements Listener { index = ifJumpIndex; } continue; + default: + break; } PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command); @@ -235,6 +235,8 @@ public class ScriptListener implements Listener { case "--": add(scriptExecutor, args[0], -1); return; + default: + break; } setValue(scriptExecutor, args[0], args[1]); } @@ -280,17 +282,19 @@ public class ScriptListener implements Listener { } private static int getValue(ScriptExecutor scriptExecutor, String key) { + Region region = Region.getRegion(scriptExecutor.player); switch (key) { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; case "tnt": - return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; + return region == null || region.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; case "freeze": - return CommandFreeze.getInstance().isOn() ? 1 : 0; + return region == null || !region.isFreeze() ? 0 : 1; case "fire": - return CommandFire.getInstance().isOn() ? 1 : 0; + return region == null || !region.isFire() ? 0 : 1; + default: + return scriptExecutor.variables.getOrDefault(key, 0); } - return scriptExecutor.variables.getOrDefault(key, 0); } private static boolean isVariable(ScriptExecutor scriptExecutor, String key) { From 041741bc756d43551056019096d870d02fe20cb4 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 16:39:21 +0100 Subject: [PATCH 18/91] Fix CommandTNT Fix RegionToggleCommand --- .../bausystem/commands/CommandTNT.java | 51 ++++++++++--------- .../commands/RegionToggleCommand.java | 17 ++++--- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index c5ccad2..4230f93 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -116,31 +116,32 @@ public class CommandTNT implements CommandExecutor, Listener { } } - TNTMode finalRequestedMode = requestedMode; - String finalRequestedMessage = requestedMessage; - Region.getRegion(player.getLocation(), region -> { - if (finalRequestedMode != null) { - region.setTntMode(finalRequestedMode); - RegionToggleCommand.actionBar(region, finalRequestedMessage); - return; - } - switch (region.getTntMode()) { - case ON: - case ONLY_TB: - region.setTntMode(TNTMode.OFF); - RegionToggleCommand.actionBar(region, getDisableMessage()); - break; - case OFF: - if (Region.buildAreaEnabled()) { - region.setTntMode(TNTMode.ONLY_TB); - RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); - } else { - region.setTntMode(TNTMode.ON); - RegionToggleCommand.actionBar(region, getEnableMessage()); - } - break; - } - }, () -> RegionToggleCommand.actionBar(player, getNoRegionMessage())); + Region region = Region.getRegion(player.getLocation()); + if (region == null) { + RegionToggleCommand.actionBar(player, getNoRegionMessage()); + return false; + } + if (requestedMode != null) { + region.setTntMode(requestedMode); + RegionToggleCommand.actionBar(region, requestedMessage); + return false; + } + switch (region.getTntMode()) { + case ON: + case ONLY_TB: + region.setTntMode(TNTMode.OFF); + RegionToggleCommand.actionBar(region, getDisableMessage()); + break; + case OFF: + if (Region.buildAreaEnabled()) { + region.setTntMode(TNTMode.ONLY_TB); + RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); + } else { + region.setTntMode(TNTMode.ON); + RegionToggleCommand.actionBar(region, getEnableMessage()); + } + break; + } return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 7aaff41..6b01ea4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -52,13 +52,16 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { return false; } - Region.getRegion(player.getLocation(), region -> { - if (toggle(region)) { - actionBar(region, getEnableMessage()); - } else { - actionBar(region, getDisableMessage()); - } - }, () -> actionBar(player, getNoRegionMessage())); + Region region = Region.getRegion(player); + if (region == null) { + actionBar(player, getNoRegionMessage()); + return false; + } + if (toggle(region)) { + actionBar(region, getEnableMessage()); + } else { + actionBar(region, getDisableMessage()); + } return false; } From 4268647057c212498e25df63f1d67c8b21ea9f82 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 16:41:42 +0100 Subject: [PATCH 19/91] Fix CommandInfo --- .../src/de/steamwar/bausystem/commands/CommandInfo.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index ae8960f..3c31049 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -41,11 +41,12 @@ public class CommandInfo implements CommandExecutor { Player player = (Player) sender; sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - Region.getRegion(player.getLocation(), region -> { - sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); - }, () -> { + Region region = Region.getRegion(player); + if (region == null) { sender.sendMessage(BauSystem.PREFIX + "§7Du bist in keiner Region."); - }); + } else { + sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); + } List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); From 90d006346515ee281fb2044220447af8b7ca5783 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 17:10:45 +0100 Subject: [PATCH 20/91] Add other region to toggleable --- .../bausystem/commands/CommandFire.java | 14 +++++-- .../bausystem/commands/CommandFreeze.java | 35 +++++++++++++---- .../bausystem/commands/CommandInfo.java | 2 +- .../bausystem/commands/CommandTNT.java | 39 ++++++++++++++----- .../commands/RegionToggleCommand.java | 9 +++-- .../bausystem/world/BauScoreboard.java | 4 ++ .../de/steamwar/bausystem/world/Region.java | 11 ++++-- 7 files changed, 84 insertions(+), 30 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index bd640fb..009b2d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -42,10 +42,6 @@ public class CommandFire extends RegionToggleCommand { String getDisableMessage(){ return "§aFeuerschaden aktiviert"; } - @Override - String getNoRegionMessage() { - return "§cDu befindest dich derzeit in keiner Region"; - } @Override boolean toggle(Region region) { @@ -53,10 +49,18 @@ public class CommandFire extends RegionToggleCommand { return region.isFire(); } + @Override + boolean toggleGlobal() { + Region.NoRegion.fire = !Region.NoRegion.fire; + return Region.NoRegion.fire; + } + @EventHandler public void onFireDamage(BlockBurnEvent e) { Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFire()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.fire) e.setCancelled(true); }); } @@ -64,6 +68,8 @@ public class CommandFire extends RegionToggleCommand { public void onFireSpread(BlockSpreadEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFire()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.fire) e.setCancelled(true); }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 9a9c80f..cb6b5b9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -21,11 +21,7 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; @@ -50,10 +46,6 @@ public class CommandFreeze extends RegionToggleCommand { String getDisableMessage(){ return "§aWelt aufgetaut"; } - @Override - String getNoRegionMessage() { - return "§cDu befindest dich derzeit in keiner Region"; - } @Override boolean toggle(Region region) { @@ -61,6 +53,12 @@ public class CommandFreeze extends RegionToggleCommand { return region.isFreeze(); } + @Override + boolean toggleGlobal() { + Region.NoRegion.freeze = !Region.NoRegion.freeze; + return Region.NoRegion.freeze; + } + @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { Region.getRegion(e.getLocation(), region -> { @@ -70,6 +68,13 @@ public class CommandFreeze extends RegionToggleCommand { if (e.getEntityType() == EntityType.FALLING_BLOCK) { e.setCancelled(true); } + }, () -> { + if (!Region.NoRegion.freeze) { + return; + } + if (e.getEntityType() == EntityType.FALLING_BLOCK) { + e.setCancelled(true); + } }); } @@ -77,6 +82,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onPhysicsEvent(BlockPhysicsEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -84,6 +91,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onPistonExtend(BlockPistonExtendEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -91,6 +100,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onPistonRetract(BlockPistonRetractEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -98,6 +109,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onBlockGrow(BlockGrowEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -105,6 +118,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onRedstoneEvent(BlockRedstoneEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent()); + }, () -> { + if (Region.NoRegion.freeze) e.setNewCurrent(e.getOldCurrent()); }); } @@ -112,6 +127,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onBlockDispense(BlockDispenseEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -119,6 +136,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onInventoryMoveEvent(InventoryMoveItemEvent e){ Region.getRegion(e.getDestination().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 3c31049..fa3ea86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -43,7 +43,7 @@ public class CommandInfo implements CommandExecutor { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); Region region = Region.getRegion(player); if (region == null) { - sender.sendMessage(BauSystem.PREFIX + "§7Du bist in keiner Region."); + sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + Region.NoRegion.tnt.getName() + " §eFire§8: " + (Region.NoRegion.fire ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (Region.NoRegion.freeze ? "§aAN" : "§cAUS")); } else { sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 4230f93..9e44eb8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -23,8 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Welt; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -77,10 +75,6 @@ public class CommandTNT implements CommandExecutor, Listener { return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; } - private String getNoRegionMessage() { - return "§cDu befindest dich derzeit in keiner Region"; - } - @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { if (!(sender instanceof Player)) return false; @@ -118,13 +112,37 @@ public class CommandTNT implements CommandExecutor, Listener { Region region = Region.getRegion(player.getLocation()); if (region == null) { - RegionToggleCommand.actionBar(player, getNoRegionMessage()); + tntGlobalToggle(player, requestedMode, requestedMessage); return false; } + tntToggle(region, requestedMode, requestedMessage); + return false; + } + + private void tntGlobalToggle(Player player, TNTMode requestedMode, String requestedMessage) { + if (requestedMode != null && requestedMode != TNTMode.ONLY_TB) { + Region.NoRegion.tnt = requestedMode; + RegionToggleCommand.actionBar(player, requestedMessage); + return; + } + switch (Region.NoRegion.tnt) { + case ON: + case ONLY_TB: + Region.NoRegion.tnt = TNTMode.OFF; + RegionToggleCommand.actionBar(player, getDisableMessage()); + break; + case OFF: + Region.NoRegion.tnt = TNTMode.ON; + RegionToggleCommand.actionBar(player, getEnableMessage()); + break; + } + } + + private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { if (requestedMode != null) { region.setTntMode(requestedMode); RegionToggleCommand.actionBar(region, requestedMessage); - return false; + return; } switch (region.getTntMode()) { case ON: @@ -142,14 +160,15 @@ public class CommandTNT implements CommandExecutor, Listener { } break; } - return false; } @EventHandler public void onExplode(EntityExplodeEvent event) { event.blockList().removeIf(block -> { Region region = Region.getRegion(block.getLocation()); - if (region == null) return false; + if (region == null) { + return Region.NoRegion.tnt == TNTMode.OFF; + } if (region.getTntMode() == TNTMode.OFF) return true; if (region.getTntMode() == TNTMode.ON) return false; if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 6b01ea4..5661ec5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -27,7 +27,6 @@ import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Welt; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; -import net.minecraft.server.v1_15_R1.BlockCactus; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -54,7 +53,11 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { Region region = Region.getRegion(player); if (region == null) { - actionBar(player, getNoRegionMessage()); + if (toggleGlobal()) { + actionBar(player, getEnableMessage()); + } else { + actionBar(player, getDisableMessage()); + } return false; } if (toggle(region)) { @@ -73,7 +76,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)); } - abstract String getNoRegionMessage(); abstract String getNoPermMessage(); abstract String getEnableMessage(); abstract String getDisableMessage(); @@ -82,5 +84,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { * {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()} */ abstract boolean toggle(Region region); + abstract boolean toggleGlobal(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 3faa945..3a9ae2a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -64,6 +64,10 @@ public class BauScoreboard implements Listener { strings.add("§eTNT§8: " + region.getTntMode().getName()); strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); + } else { + strings.add("§eTNT§8: " + Region.NoRegion.tnt.getName()); + strings.add("§eFreeze§8: " + (Region.NoRegion.freeze ? "§aan" : "§caus")); + strings.add("§eFire§8: " + (Region.NoRegion.fire ? "§aaus" : "§can")); } strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 3c170f7..6388c0b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -42,6 +42,13 @@ public class Region { private static final List regions = new ArrayList<>(); private static boolean buildArea = false; + public static class NoRegion { + private NoRegion() {} + public static TNTMode tnt = TNTMode.OFF; + public static boolean fire = false; + public static boolean freeze = false; + } + static{ YamlConfiguration config = new YamlConfiguration(); try { @@ -78,10 +85,6 @@ public class Region { return null; } - public static void getRegion(Location location, Consumer regionConsumer) { - getRegion(location, regionConsumer, () -> {}); - } - public static void getRegion(Location location, Consumer regionConsumer, Runnable noRegion) { boolean b = true; for (Region region : regions) { From 1ddc58d1fbd0b583fa4d779c74be0b8acbdb23a6 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 17:22:22 +0100 Subject: [PATCH 21/91] Hotfix ScriptListener Script Book check --- .../src/de/steamwar/bausystem/world/ScriptListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index d0f2fc8..3fb474c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -55,7 +55,7 @@ public class ScriptListener implements Listener { if(item == null || isNoBook(item) || item.getItemMeta() == null) return; - if (CommandScript.BOOK.getItemMeta() != null && item.getItemMeta().getDisplayName().equals(CommandScript.BOOK.getItemMeta().getDisplayName())) { + if (CommandScript.BOOK.getItemMeta() != null && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(CommandScript.BOOK.getItemMeta().getDisplayName())) { return; } From ddcbec834e9fdd03f20ef85ff52cd43664b09e65 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 17:37:21 +0100 Subject: [PATCH 22/91] Fix last stuff --- .../bausystem/commands/CommandInfo.java | 2 +- .../bausystem/commands/CommandProtect.java | 2 +- .../bausystem/commands/CommandReset.java | 2 +- .../bausystem/commands/CommandTestblock.java | 2 +- .../commands/RegionToggleCommand.java | 2 +- .../bausystem/world/BauScoreboard.java | 2 +- .../de/steamwar/bausystem/world/Region.java | 64 ++++++------------- .../bausystem/world/ScriptListener.java | 2 +- 8 files changed, 25 insertions(+), 53 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index fa3ea86..fd8fc56 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -41,7 +41,7 @@ public class CommandInfo implements CommandExecutor { Player player = (Player) sender; sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null) { sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + Region.NoRegion.tnt.getName() + " §eFire§8: " + (Region.NoRegion.fire ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (Region.NoRegion.freeze ? "§aAN" : "§cAUS")); } else { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 6adcd6b..b6a34d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -45,7 +45,7 @@ public class CommandProtect implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null || !region.hasProtection()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index a75be05..934a383 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -45,7 +45,7 @@ public class CommandReset implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index e44d889..87ffbf3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -45,7 +45,7 @@ public class CommandTestblock implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null || !region.hasTestblock()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 5661ec5..49e36b8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -51,7 +51,7 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null) { if (toggleGlobal()) { actionBar(player, getEnableMessage()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 3a9ae2a..316cf00 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -59,7 +59,7 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - Region region = Region.getRegion(p); + Region region = Region.getRegion(p.getLocation()); if (region != null) { strings.add("§eTNT§8: " + region.getTntMode().getName()); strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 6388c0b..590e033 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -29,7 +29,6 @@ import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; @@ -74,10 +73,6 @@ public class Region { return buildArea; } - public static Region getRegion(Player player) { - return getRegion(player.getLocation()); - } - public static Region getRegion(Location location) { for (Region region : regions) { if (region.inRegion(location)) return region; @@ -93,20 +88,7 @@ public class Region { b = false; } } - if (b) { - noRegion.run(); - } - } - - public static List getRegions(){ - return regions; - } - - private static Region getRegionByName(String name) { - for (Region region : regions) { - if (region.name.equals(name)) return region; - } - return null; + if (b) noRegion.run(); } private final String name; @@ -131,9 +113,20 @@ public class Region { regions.add(this); } - private void link() { - if (optionsLinkedWith != null && linkedRegion == null) { - linkedRegion = getRegionByName(optionsLinkedWith); + private void setLinkedRegion(Consumer regionConsumer) { + if (optionsLinkedWith == null) { + return; + } + if (linkedRegion != null) { + regionConsumer.accept(linkedRegion); + return; + } + for (Region region : regions) { + if (region.name.equals(name)) { + linkedRegion = region; + regionConsumer.accept(linkedRegion); + return; + } } } @@ -143,14 +136,7 @@ public class Region { public void setTntMode(TNTMode tntMode) { this.tntMode = tntMode; - link(); - if (linkedRegion != null) { - linkedRegion.setTntModeOther(tntMode); - } - } - - private void setTntModeOther(TNTMode tntMode) { - this.tntMode = tntMode; + setLinkedRegion(region -> region.tntMode = tntMode); } public boolean isFreeze() { @@ -159,14 +145,7 @@ public class Region { public void setFreeze(boolean freeze) { this.freeze = freeze; - link(); - if (linkedRegion != null) { - linkedRegion.setFreezeOther(freeze); - } - } - - public void setFreezeOther(boolean freeze) { - this.freeze = freeze; + setLinkedRegion(region -> region.freeze = freeze); } public boolean isFire() { @@ -175,14 +154,7 @@ public class Region { public void setFire(boolean fire) { this.fire = fire; - link(); - if (linkedRegion != null) { - linkedRegion.setFireOther(fire); - } - } - - public void setFireOther(boolean fire) { - this.fire = fire; + setLinkedRegion(region -> region.fire = fire); } public boolean inRegion(Location l){ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 0bc9897..60c3121 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -282,7 +282,7 @@ public class ScriptListener implements Listener { } private static int getValue(ScriptExecutor scriptExecutor, String key) { - Region region = Region.getRegion(scriptExecutor.player); + Region region = Region.getRegion(scriptExecutor.player.getLocation()); switch (key) { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; From 56402bb0120d415714a90f03c8a62b7827060c9a Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:23:51 +0100 Subject: [PATCH 23/91] Optimize CommandTPSLimiter with accuracy --- .../bausystem/commands/CommandTPSLimiter.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 051d4f7..7d2e71f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; +import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -36,10 +37,14 @@ import org.bukkit.scheduler.BukkitTask; public class CommandTPSLimiter implements CommandExecutor { private static double currentTPSLimit = 20; - private static World world = Bukkit.getWorlds().get(0); private long lastTime = System.nanoTime(); private long currentTime = System.nanoTime(); + private static final long neededDelta = 50; + private static long neededDeltaFix = 50; + + private static World world = Bukkit.getWorlds().get(0); + private BukkitTask tpsLimiter = null; private boolean permissionCheck(Player player) { @@ -104,8 +109,13 @@ public class CommandTPSLimiter implements CommandExecutor { tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(world), 8), new VersionedRunnable(() -> TPSLimit_15.createTickCache(world), 14)); - for (int i = 0; i < (20 / currentTPSLimit); i++) { - sleepUntilNextTick(); + + double delay = 50 * (20 / currentTPSLimit); + int loops = (int)Math.ceil(delay / 50.0); + long sleepDelay = (long) delay / loops; + + for (int i = 0; i < loops; i++) { + sleepUntilNextTick(sleepDelay); VersionedRunnable.call(new VersionedRunnable(TPSLimit_12::sendTickPackets, 8), new VersionedRunnable(TPSLimit_15::sendTickPackets, 14)); } @@ -113,16 +123,12 @@ public class CommandTPSLimiter implements CommandExecutor { } } - private void sleepUntilNextTick() { + private void sleepUntilNextTick(long neededDelta) { lastTime = currentTime; currentTime = System.nanoTime(); long timeDelta = (currentTime - lastTime) / 1000000; - long neededDelta = 50; - - if (neededDelta - timeDelta < 0) { - return; - } + if (neededDelta - timeDelta < 0) return; try { Thread.sleep(neededDelta - timeDelta); From 47e268fb5400ef7e8889738b74eddfc50d7078aa Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:24:57 +0100 Subject: [PATCH 24/91] Optimize Imports --- .../src/de/steamwar/bausystem/commands/CommandTPSLimiter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 7d2e71f..4f27fe6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; -import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; From 55c5c3bda5ab7549a28a6e1cdfdacc02821c7ab7 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:25:36 +0100 Subject: [PATCH 25/91] Remove unused fields --- .../src/de/steamwar/bausystem/commands/CommandTPSLimiter.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 4f27fe6..0b9f4d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -39,9 +39,6 @@ public class CommandTPSLimiter implements CommandExecutor { private long lastTime = System.nanoTime(); private long currentTime = System.nanoTime(); - private static final long neededDelta = 50; - private static long neededDeltaFix = 50; - private static World world = Bukkit.getWorlds().get(0); private BukkitTask tpsLimiter = null; From 8bb76d656fc9a6394da756f9b2a4198ec054615b Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:31:55 +0100 Subject: [PATCH 26/91] Remove unused fields --- .../bausystem/commands/CommandTPSLimiter.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 0b9f4d7..97cee3a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -35,11 +35,15 @@ import org.bukkit.scheduler.BukkitTask; public class CommandTPSLimiter implements CommandExecutor { + private static final World WORLD = Bukkit.getWorlds().get(0); private static double currentTPSLimit = 20; + private long lastTime = System.nanoTime(); private long currentTime = System.nanoTime(); - private static World world = Bukkit.getWorlds().get(0); + private double delay = 0; + private int loops = 0; + private long sleepDelay = 0; private BukkitTask tpsLimiter = null; @@ -96,6 +100,10 @@ public class CommandTPSLimiter implements CommandExecutor { } private void tpsLimiter() { + delay = 50 * (20 / currentTPSLimit); + loops = (int)Math.ceil(delay / 50.0); + sleepDelay = (long) delay / loops; + if (currentTPSLimit == 20) { if (tpsLimiter == null) return; tpsLimiter.cancel(); @@ -103,12 +111,8 @@ public class CommandTPSLimiter implements CommandExecutor { } else { if (tpsLimiter != null) return; tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(world), 8), - new VersionedRunnable(() -> TPSLimit_15.createTickCache(world), 14)); - - double delay = 50 * (20 / currentTPSLimit); - int loops = (int)Math.ceil(delay / 50.0); - long sleepDelay = (long) delay / loops; + VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(WORLD), 8), + new VersionedRunnable(() -> TPSLimit_15.createTickCache(WORLD), 14)); for (int i = 0; i < loops; i++) { sleepUntilNextTick(sleepDelay); From fc275166cb135acfbba7de5da3d6aba8b86e5c87 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:58:12 +0100 Subject: [PATCH 27/91] Simplify math expressions --- .../de/steamwar/bausystem/commands/CommandTPSLimiter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 97cee3a..7a749c7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -100,9 +100,9 @@ public class CommandTPSLimiter implements CommandExecutor { } private void tpsLimiter() { - delay = 50 * (20 / currentTPSLimit); - loops = (int)Math.ceil(delay / 50.0); - sleepDelay = (long) delay / loops; + delay = 20 / currentTPSLimit; + loops = (int)Math.ceil(delay); + sleepDelay = (long) (50 * delay) / loops; if (currentTPSLimit == 20) { if (tpsLimiter == null) return; From 2d068abe3224678b58bd0a726d5168559b3630b1 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 11:20:42 +0100 Subject: [PATCH 28/91] Remove Redstone ore activation while freezed --- .../de/steamwar/bausystem/commands/CommandFreeze.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index cb6b5b9..507c454 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.world.Region; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; @@ -78,6 +79,15 @@ public class CommandFreeze extends RegionToggleCommand { }); } + @EventHandler + public void onEntityChangeBlock(EntityChangeBlockEvent e) { + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); + }); + } + @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { From 41c5b3dd551a20ce43bb6da457c732c4b6d999af Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 12:06:01 +0100 Subject: [PATCH 29/91] Rename GuiTraceShow inventory name --- .../steamwar/bausystem/gui/GuiTraceShow.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java index 48b588b..dc13bbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -39,16 +39,20 @@ import java.util.Map; public class GuiTraceShow { - private static final Map SHOW_MODE_PARAMETER_HASH_MAP = new HashMap<>(); + private static final Map ShowModeParameterMap = new HashMap<>(); + + private GuiTraceShow() { + + } public static void openGui(Player player) { ShowModeParameter playerShowMode = new ShowModeParameter(); playerShowMode.setInterpolate_Y(false); playerShowMode.setInterpolate_XZ(false); - SHOW_MODE_PARAMETER_HASH_MAP.put(player, playerShowMode); + ShowModeParameterMap.put(player, playerShowMode); - SWInventory swInventory = new SWInventory(player, 9, BauSystem.PREFIX + "ShowGUI"); - swInventory.addCloseCallback(clickType -> SHOW_MODE_PARAMETER_HASH_MAP.remove(player)); + SWInventory swInventory = new SWInventory(player, 9, "Trace Show GUI"); + swInventory.addCloseCallback(clickType -> ShowModeParameterMap.remove(player)); SWItem trace_show = new SWItem(Material.LIME_CONCRETE, "§aTraces Angezeigt", new ArrayList<>(), false, clickType -> {}); SWItem trace_hide = new SWItem(Material.RED_CONCRETE, "§cTraces Ausgeblendet", new ArrayList<>(), false, clickType -> {}); @@ -91,7 +95,7 @@ public class GuiTraceShow { } private static void toggleHideTNTinWaterExploded(Player player, SWInventory swInventory, SWItem swItem) { - ShowModeParameter showModeParameter = SHOW_MODE_PARAMETER_HASH_MAP.get(player); + ShowModeParameter showModeParameter = ShowModeParameterMap.get(player); showModeParameter.setWater(!showModeParameter.isWater()); show(player); @@ -101,7 +105,7 @@ public class GuiTraceShow { } private static void toggleInterpolateYPosition(Player player, SWInventory swInventory, SWItem swItem) { - ShowModeParameter showModeParameter = SHOW_MODE_PARAMETER_HASH_MAP.get(player); + ShowModeParameter showModeParameter = ShowModeParameterMap.get(player); showModeParameter.setInterpolate_Y(!showModeParameter.isInterpolate_Y()); show(player); @@ -111,7 +115,7 @@ public class GuiTraceShow { } private static void toggleInterpolateXZPosition(Player player, SWInventory swInventory, SWItem swItem) { - ShowModeParameter showModeParameter = SHOW_MODE_PARAMETER_HASH_MAP.get(player); + ShowModeParameter showModeParameter = ShowModeParameterMap.get(player); showModeParameter.setInterpolate_XZ(!showModeParameter.isInterpolate_XZ()); show(player); @@ -121,7 +125,7 @@ public class GuiTraceShow { } private static void show(Player player) { - ShowModeParameter showModeParameter = SHOW_MODE_PARAMETER_HASH_MAP.get(player); + ShowModeParameter showModeParameter = ShowModeParameterMap.get(player); ShowMode showMode; if (showModeParameter.isAdvanced()) { showMode = new Advanced(player, showModeParameter); From d66c102c2ee1113d6f51a03e5444f7263ad34eb7 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 14:51:59 +0100 Subject: [PATCH 30/91] Fix CommandFreeze for entity spawning and redstone ore activation --- .../steamwar/bausystem/commands/CommandFreeze.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 6443e32..c158459 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -19,8 +19,12 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.world.Region; +import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; public class CommandFreeze extends ToggleCommand { @@ -46,6 +50,16 @@ public class CommandFreeze extends ToggleCommand { return "§aWelt aufgetaut"; } + @EventHandler + public void onEntitySpawn(EntitySpawnEvent e) { + e.setCancelled(true); + } + + @EventHandler + public void onEntityChangeBlock(EntityChangeBlockEvent e) { + e.setCancelled(true); + } + @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ e.setCancelled(true); From 28b818f799f7ec7be59f38a101b6643a1daf4cb7 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 15:22:53 +0100 Subject: [PATCH 31/91] Fix pr stuff --- .../steamwar/bausystem/gui/GuiTraceShow.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java index dc13bbd..6fd07be 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -53,10 +53,7 @@ public class GuiTraceShow { SWInventory swInventory = new SWInventory(player, 9, "Trace Show GUI"); swInventory.addCloseCallback(clickType -> ShowModeParameterMap.remove(player)); - - SWItem trace_show = new SWItem(Material.LIME_CONCRETE, "§aTraces Angezeigt", new ArrayList<>(), false, clickType -> {}); - SWItem trace_hide = new SWItem(Material.RED_CONCRETE, "§cTraces Ausgeblendet", new ArrayList<>(), false, clickType -> {}); - setActiveShow(player, swInventory, trace_show, trace_hide); + setActiveShow(player, swInventory); SWItem water = new SWItem(Material.TNT, "§eWasser §7Positionen", Arrays.asList("§7Zeigt alles TNT, welches", "§7im Wasser explodiert ist."), false, clickType -> {}); swInventory.setItem(5, water); @@ -76,21 +73,21 @@ public class GuiTraceShow { swInventory.open(); } - private static void setActiveShow(Player player, SWInventory swInventory, SWItem shown, SWItem hidden) { + private static void setActiveShow(Player player, SWInventory swInventory) { if (TraceShowManager.hasActiveShow(player)) { - swInventory.setItem(1, shown); - swInventory.setCallback(1, clickType -> { + SWItem shown = new SWItem(Material.LIME_CONCRETE, "§aTraces angezeigt", new ArrayList<>(), false, clickType -> { TraceShowManager.hide(player); player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet"); - setActiveShow(player, swInventory, shown, hidden); + setActiveShow(player, swInventory); }); + swInventory.setItem(1, shown); } else { - swInventory.setItem(1, hidden); - swInventory.setCallback(1, clickType -> { + SWItem hidden = new SWItem(Material.RED_CONCRETE, "§cTraces ausgeblendet", new ArrayList<>(), false, clickType -> { show(player); player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); - setActiveShow(player, swInventory, shown, hidden); + setActiveShow(player, swInventory); }); + swInventory.setItem(1, hidden); } } From 200926d41d948005d17d3aea8a04ea75c2d6c677 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 27 Jan 2021 09:50:41 +0100 Subject: [PATCH 32/91] Fix merge conflicts --- .../de/steamwar/bausystem/commands/CommandFreeze.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index b3f05c6..507c454 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -88,16 +88,6 @@ public class CommandFreeze extends RegionToggleCommand { }); } - @EventHandler - public void onEntitySpawn(EntitySpawnEvent e) { - e.setCancelled(true); - } - - @EventHandler - public void onEntityChangeBlock(EntityChangeBlockEvent e) { - e.setCancelled(true); - } - @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { From 7be5700359979ff5283f0f806f32982fdee9573c Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 27 Jan 2021 09:51:14 +0100 Subject: [PATCH 33/91] Fix merge conflicts --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 507c454..53d6395 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -16,7 +16,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * / */ package de.steamwar.bausystem.commands; From 1a72a39b33aa165be8749389bb17332230b8bc78 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 27 Jan 2021 13:53:35 +0100 Subject: [PATCH 34/91] Merge Basic ShowMode and Advanced ShowMode to EntityShowMode Add EntityShowMode --- .../bausystem/commands/CommandTrace.java | 13 +- .../commands/CommandTraceTabCompleter.java | 5 +- .../steamwar/bausystem/gui/GuiTraceShow.java | 13 +- .../tracer/show/ShowModeParameter.java | 25 ++-- .../bausystem/tracer/show/mode/Advanced.java | 85 ------------- .../bausystem/tracer/show/mode/Basic.java | 54 -------- .../tracer/show/mode/EntityShowMode.java | 119 ++++++++++++++++++ 7 files changed, 140 insertions(+), 174 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/EntityShowMode.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 3b30892..8ca73f4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -26,8 +26,7 @@ import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.ShowModeParameter; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; -import de.steamwar.bausystem.tracer.show.mode.Advanced; -import de.steamwar.bausystem.tracer.show.mode.Basic; +import de.steamwar.bausystem.tracer.show.mode.EntityShowMode; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -90,14 +89,16 @@ public class CommandTrace implements CommandExecutor { break; case "show": if (args.length < 2) { - TraceShowManager.show(player, new Basic(player, new ShowModeParameter())); + TraceShowManager.show(player, new EntityShowMode(player, new ShowModeParameter())); + // TraceShowManager.show(player, new Basic(player, new ShowModeParameter())); } else { if (args[1].equalsIgnoreCase("gui")) { GuiTraceShow.openGui(player); return false; } - ShowModeParameter showModeParameter = ShowModeParameter.parseArguments(args, 2); - switch (args[1].toLowerCase()) { + ShowModeParameter showModeParameter = ShowModeParameter.parseArguments(args, 1); + TraceShowManager.show(player, new EntityShowMode(player, showModeParameter)); + /*switch (args[1].toLowerCase()) { case "advanced": TraceShowManager.show(player, new Advanced(player, showModeParameter)); break; @@ -106,7 +107,7 @@ public class CommandTrace implements CommandExecutor { default: TraceShowManager.show(player, new Basic(player, showModeParameter)); break; - } + }*/ } player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index e2930a2..609a936 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -39,9 +39,8 @@ public class CommandTraceTabCompleter implements TabCompleter { tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO), "start")); tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() != RecordStatus.IDLE && RecordStateMachine.getRecordStatus() != RecordStatus.IDLE_AUTO), "stop")); tabCompletes.add(new TabComplete((player, args) -> args.length == 1, "toggleauto", "auto", "show", "hide", "delete", "clear")); - tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "basic", "advanced", "gui")); - tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && (args[1].equalsIgnoreCase("basic") || args[1].equalsIgnoreCase("advanced")), "-water")); - tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && args[1].equalsIgnoreCase("advanced"), "-interpolate-xz", "-interpolate-y")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "gui", "-interpolate-xz", "-interpolate-y", "-water", "-advanced")); + tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && !args[1].equalsIgnoreCase("gui"), "-interpolate-xz", "-interpolate-y", "-water", "-advanced")); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java index 6fd07be..78e7a8a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -22,11 +22,9 @@ package de.steamwar.bausystem.gui; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.bausystem.tracer.show.ShowModeParameter; import de.steamwar.bausystem.tracer.show.TraceShowManager; -import de.steamwar.bausystem.tracer.show.mode.Advanced; -import de.steamwar.bausystem.tracer.show.mode.Basic; +import de.steamwar.bausystem.tracer.show.mode.EntityShowMode; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Material; @@ -122,14 +120,7 @@ public class GuiTraceShow { } private static void show(Player player) { - ShowModeParameter showModeParameter = ShowModeParameterMap.get(player); - ShowMode showMode; - if (showModeParameter.isAdvanced()) { - showMode = new Advanced(player, showModeParameter); - } else { - showMode = new Basic(player, showModeParameter); - } - TraceShowManager.show(player, showMode); + TraceShowManager.show(player, new EntityShowMode(player, ShowModeParameterMap.get(player))); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java index 153e580..e88c2c9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java @@ -24,9 +24,8 @@ package de.steamwar.bausystem.tracer.show; public class ShowModeParameter { private boolean water = false; - private boolean interpolate_SET = false; - private boolean interpolate_Y = true; - private boolean interpolate_XZ = true; + private boolean interpolate_Y = false; + private boolean interpolate_XZ = false; public ShowModeParameter() { @@ -71,12 +70,7 @@ public class ShowModeParameter { case "-interpolate-y": case "-interpolate_y": case "-y": - if (showModeParameter.interpolate_SET) { - showModeParameter.interpolate_Y = true; - } else { - showModeParameter.interpolate_XZ = false; - showModeParameter.interpolate_SET = true; - } + showModeParameter.interpolate_Y = true; break; case "-interpolatex": case "-interpolate-x": @@ -90,12 +84,13 @@ public class ShowModeParameter { case "-interpolate-xz": case "-interpolate_xz": case "-xz": - if (showModeParameter.interpolate_SET) { - showModeParameter.interpolate_XZ = true; - } else { - showModeParameter.interpolate_Y = false; - showModeParameter.interpolate_SET = true; - } + showModeParameter.interpolate_XZ = true; + break; + case "-advanced": + showModeParameter.interpolate_Y = true; + showModeParameter.interpolate_XZ = true; + break; + default: break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java deleted file mode 100644 index 49b5704..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.tracer.show.mode; - -import de.steamwar.bausystem.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.tracer.RoundedTNTPosition; -import de.steamwar.bausystem.tracer.TNTPosition; -import de.steamwar.bausystem.tracer.show.ShowModeParameter; -import org.bukkit.entity.Player; -import org.bukkit.util.Consumer; -import org.bukkit.util.Vector; - -import java.util.HashMap; -import java.util.Map; - -public class Advanced extends Basic { - - private final Map updateEntityMap = new HashMap<>(); - - public Advanced(Player player, ShowModeParameter showModeParameter) { - super(player, showModeParameter); - } - - @Override - public void show(TNTPosition position) { - super.show(position); - - if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { - for(TNTPosition pos : position.getRecord().getPositions()){ - applyOnPosition(pos, updatePointPosition -> - updateEntityMap.computeIfPresent(new RoundedTNTPosition(updatePointPosition), (p, point) -> point.hide(player, false) ? null : point)); - } - return; - } - - applyOnPosition(position, updatePointPosition -> - updateEntityMap.computeIfAbsent(new RoundedTNTPosition(updatePointPosition), pos -> createEntity(updatePointPosition, false)) - .display(player, position.isExploded())); - } - - @Override - public void hide() { - super.hide(); - updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); - updateEntityMap.clear(); - } - - private void applyOnPosition(TNTPosition position, Consumer function){ - if (position.getPreviousLocation() == null) return; - - if (showModeParameter.isInterpolate_Y()) { - Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); - if(!position.getLocation().equals(updatePointY)) - function.accept(updatePointY); - } - - if (showModeParameter.isInterpolate_XZ()){ - Vector movement = position.getLocation().clone().subtract(position.getPreviousLocation()); - Vector updatePointXZ = Math.abs(movement.getX()) > Math.abs(movement.getZ()) - ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) - : position.getLocation().clone().setX(position.getPreviousLocation().getX()); - if(!position.getLocation().equals(updatePointXZ)) - function.accept(updatePointXZ); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java deleted file mode 100644 index 475445e..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ /dev/null @@ -1,54 +0,0 @@ -package de.steamwar.bausystem.tracer.show.mode; - -import de.steamwar.bausystem.tracer.*; -import de.steamwar.bausystem.tracer.show.ShowMode; -import de.steamwar.bausystem.tracer.show.ShowModeParameter; -import de.steamwar.core.VersionedCallable; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import java.util.HashMap; -import java.util.Map; - -public class Basic implements ShowMode { - - protected final Player player; - protected final ShowModeParameter showModeParameter; - - private final Map tntEntityMap = new HashMap<>(); - - public Basic(Player player, ShowModeParameter showModeParameter) { - this.player = player; - this.showModeParameter = showModeParameter; - } - - @Override - public void show(TNTPosition position) { - if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { - for(TNTPosition pos : position.getRecord().getPositions()){ - RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(pos); - tntEntityMap.computeIfPresent(roundedTNTPosition, (p, tnt) -> tnt.hide(player, false) ? null : tnt); - } - return; - } - RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); - AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedTNTPosition, pos -> createEntity(position.getLocation(), true)); - entity.display(player, position.isExploded()); - } - - protected boolean checkWater(Vector position) { - return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(player.getWorld(), position), 8), - new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 14)); - } - - protected AbstractTraceEntity createEntity(Vector position, boolean tnt) { - return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, tnt), 8), - new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, tnt), 14)); - } - - @Override - public void hide() { - tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); - tntEntityMap.clear(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/EntityShowMode.java new file mode 100644 index 0000000..bd7e8d7 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/EntityShowMode.java @@ -0,0 +1,119 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.tracer.show.mode; + +import de.steamwar.bausystem.tracer.*; +import de.steamwar.bausystem.tracer.show.ShowMode; +import de.steamwar.bausystem.tracer.show.ShowModeParameter; +import de.steamwar.core.VersionedCallable; +import org.bukkit.entity.Player; +import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; + +import java.util.HashMap; +import java.util.Map; + +public class EntityShowMode implements ShowMode { + + protected final Player player; + protected final ShowModeParameter showModeParameter; + + private final Map tntEntityMap = new HashMap<>(); + private final Map updateEntityMap = new HashMap<>(); + + public EntityShowMode(Player player, ShowModeParameter showModeParameter) { + this.player = player; + this.showModeParameter = showModeParameter; + } + + @Override + public void show(TNTPosition position) { + if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { + // Basic + for (TNTPosition pos : position.getRecord().getPositions()) { + RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(pos); + tntEntityMap.computeIfPresent(roundedTNTPosition, (p, tnt) -> { + return tnt.hide(player, false) ? null : tnt; + }); + } + // Advanced + for (TNTPosition pos : position.getRecord().getPositions()) { + applyOnPosition(pos, updatePointPosition -> { + updateEntityMap.computeIfPresent(new RoundedTNTPosition(updatePointPosition), (p, point) -> { + return point.hide(player, false) ? null : point; + }); + }); + } + return; + } + + RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); + AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedTNTPosition, pos -> createEntity(position.getLocation(), true)); + entity.display(player, position.isExploded()); + + applyOnPosition(position, updatePointPosition -> { + updateEntityMap.computeIfAbsent(new RoundedTNTPosition(updatePointPosition), pos -> { + return createEntity(updatePointPosition, false); + }).display(player, position.isExploded()); + }); + } + + private boolean checkWater(Vector position) { + return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(player.getWorld(), position), 8), + new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 14)); + } + + private AbstractTraceEntity createEntity(Vector position, boolean tnt) { + return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, tnt), 8), + new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, tnt), 14)); + } + + private void applyOnPosition(TNTPosition position, Consumer function) { + if (position.getPreviousLocation() == null) return; + + if (showModeParameter.isInterpolate_Y()) { + Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); + if (!position.getLocation().equals(updatePointY)) { + function.accept(updatePointY); + } + } + + if (showModeParameter.isInterpolate_XZ()) { + Vector movement = position.getLocation().clone().subtract(position.getPreviousLocation()); + Vector updatePointXZ = Math.abs(movement.getX()) > Math.abs(movement.getZ()) + ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) + : position.getLocation().clone().setX(position.getPreviousLocation().getX()); + if (!position.getLocation().equals(updatePointXZ)) { + function.accept(updatePointXZ); + } + } + } + + @Override + public void hide() { + tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); + tntEntityMap.clear(); + updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); + updateEntityMap.clear(); + } + +} From 7f55dddd8ffbb6d2d2397adf12b919dd8ba9fd15 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 27 Jan 2021 13:56:40 +0100 Subject: [PATCH 35/91] Add '-a' as alias for '-advanced' to ShowModeParameter parsing --- .../src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java index e88c2c9..ad571d6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java @@ -87,6 +87,7 @@ public class ShowModeParameter { showModeParameter.interpolate_XZ = true; break; case "-advanced": + case "-a": showModeParameter.interpolate_Y = true; showModeParameter.interpolate_XZ = true; break; From c7584cd9520ed0eccaabe10ffd5193f5825eac12 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 27 Jan 2021 15:26:06 +0100 Subject: [PATCH 36/91] Fix pr stuff --- .../de/steamwar/bausystem/commands/CommandTrace.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 8ca73f4..3d30f71 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -90,7 +90,6 @@ public class CommandTrace implements CommandExecutor { case "show": if (args.length < 2) { TraceShowManager.show(player, new EntityShowMode(player, new ShowModeParameter())); - // TraceShowManager.show(player, new Basic(player, new ShowModeParameter())); } else { if (args[1].equalsIgnoreCase("gui")) { GuiTraceShow.openGui(player); @@ -98,16 +97,6 @@ public class CommandTrace implements CommandExecutor { } ShowModeParameter showModeParameter = ShowModeParameter.parseArguments(args, 1); TraceShowManager.show(player, new EntityShowMode(player, showModeParameter)); - /*switch (args[1].toLowerCase()) { - case "advanced": - TraceShowManager.show(player, new Advanced(player, showModeParameter)); - break; - case "basic": - case "default": - default: - TraceShowManager.show(player, new Basic(player, showModeParameter)); - break; - }*/ } player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); break; From 440717f1f5450e021636cf54245d757021a3e6ab Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 30 Jan 2021 11:22:43 +0100 Subject: [PATCH 37/91] Add ShowModeParameter 'advanced' --- .../steamwar/bausystem/commands/CommandTraceTabCompleter.java | 2 +- .../de/steamwar/bausystem/tracer/show/ShowModeParameter.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 609a936..47e9912 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -39,7 +39,7 @@ public class CommandTraceTabCompleter implements TabCompleter { tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO), "start")); tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() != RecordStatus.IDLE && RecordStateMachine.getRecordStatus() != RecordStatus.IDLE_AUTO), "stop")); tabCompletes.add(new TabComplete((player, args) -> args.length == 1, "toggleauto", "auto", "show", "hide", "delete", "clear")); - tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "gui", "-interpolate-xz", "-interpolate-y", "-water", "-advanced")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "gui", "-interpolate-xz", "-interpolate-y", "-water", "-advanced", "advanced")); tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && !args[1].equalsIgnoreCase("gui"), "-interpolate-xz", "-interpolate-y", "-water", "-advanced")); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java index ad571d6..7c4722d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java @@ -86,6 +86,7 @@ public class ShowModeParameter { case "-xz": showModeParameter.interpolate_XZ = true; break; + case "advanced": case "-advanced": case "-a": showModeParameter.interpolate_Y = true; From 6376ef7dd5e8e86089811db476f26145c51dda26 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 1 Feb 2021 13:42:19 +0100 Subject: [PATCH 38/91] Add Shift + Right Click Edit Sign --- BauSystem_Main/pom.xml | 7 ++ .../bausystem/world/RegionListener.java | 64 +++++++++++++++++++ BauSystem_Main/src/plugin.yml | 2 +- 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/pom.xml b/BauSystem_Main/pom.xml index 3aa54e7..cb63fc7 100644 --- a/BauSystem_Main/pom.xml +++ b/BauSystem_Main/pom.xml @@ -79,5 +79,12 @@ system ${main.basedir}/lib/WorldEdit-1.15.jar + + steamwar + ProtocolLib + 4.5.0 + system + ${main.basedir}/lib/ProtocolLib.jar + diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 0719a4f..a7641e7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -20,18 +20,33 @@ package de.steamwar.bausystem.world; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.BlockPosition; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.core.Core; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import com.comphenix.protocol.ProtocolLibrary; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +import java.util.logging.Level; + +import java.lang.reflect.InvocationTargetException; public class RegionListener implements Listener { @@ -98,4 +113,53 @@ public class RegionListener implements Listener { event.setLine(i, line); } } + + @EventHandler + public void editSign(PlayerInteractEvent event) { + if(event.getAction() != Action.RIGHT_CLICK_BLOCK || + !event.getClickedBlock().getType().name().contains("_SIGN") || + !event.getPlayer().isSneaking()) + return; + Player player = event.getPlayer(); + Sign sign = (Sign) event.getClickedBlock().getState(); + String[] lines = sign.getLines(); + for (int i = 0; i < lines.length; i++) { + sign.setLine(i, lines[i].replace('§', '&')); + } + sign.update(); + PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR); + signOpen.getBlockPositionModifier().write(0, new BlockPosition(event.getClickedBlock().getLocation().toVector())); + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, signOpen); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); + } + + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Client.UPDATE_SIGN) { + @Override + public void onPacketReceiving(PacketEvent event) { + if(!event.getPlayer().equals(player)) + return; + event.setCancelled(true); + Bukkit.getScheduler().runTask(BauSystem.getPlugin(), () -> { + PacketContainer packetContainer = event.getPacket(); + BlockPosition position = packetContainer.getBlockPositionModifier().read(0); + String[] lines = packetContainer.getStringArrays().read(0); + + Block signLoc = position.toLocation(player.getWorld()).getBlock(); + if(!signLoc.getType().name().contains("_SIGN")) + return; + + Sign sign = ((Sign) signLoc.getState()); + sign.setEditable(true); + for (int i = 0; i < lines.length; i++) { + sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i])); + } + sign.update(); + + ProtocolLibrary.getProtocolManager().removePacketListener(this); + }); + } + }); + } } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index bc85fb9..5460f05 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -1,7 +1,7 @@ name: BauSystem author: Lixfel version: "1.0" -depend: [WorldEdit, SpigotCore] +depend: [WorldEdit, SpigotCore, ProtocolLib] load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" From 7a89347248ebe1ca637947a7997539ff26c1d0f1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 1 Feb 2021 15:06:22 +0100 Subject: [PATCH 39/91] Fixing and Editing --- .../src/de/steamwar/bausystem/world/RegionListener.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index a7641e7..08d1bc9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -28,9 +28,12 @@ import com.comphenix.protocol.wrappers.BlockPosition; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; +import net.minecraft.server.v1_15_R1.PacketPlayOutOpenSignEditor; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import com.comphenix.protocol.ProtocolLibrary; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -117,9 +120,10 @@ public class RegionListener implements Listener { @EventHandler public void editSign(PlayerInteractEvent event) { if(event.getAction() != Action.RIGHT_CLICK_BLOCK || - !event.getClickedBlock().getType().name().contains("_SIGN") || + !event.getClickedBlock().getType().name().contains("SIGN") || !event.getPlayer().isSneaking()) return; + Player player = event.getPlayer(); Sign sign = (Sign) event.getClickedBlock().getState(); String[] lines = sign.getLines(); @@ -127,6 +131,7 @@ public class RegionListener implements Listener { sign.setLine(i, lines[i].replace('§', '&')); } sign.update(); + PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR); signOpen.getBlockPositionModifier().write(0, new BlockPosition(event.getClickedBlock().getLocation().toVector())); try { @@ -147,7 +152,7 @@ public class RegionListener implements Listener { String[] lines = packetContainer.getStringArrays().read(0); Block signLoc = position.toLocation(player.getWorld()).getBlock(); - if(!signLoc.getType().name().contains("_SIGN")) + if(!signLoc.getType().name().contains("SIGN")) return; Sign sign = ((Sign) signLoc.getState()); From faf31bc883453169184cb20275d51deb13b62b22 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 2 Feb 2021 14:59:41 +0100 Subject: [PATCH 40/91] Add 1.12 Support --- .../bausystem/world/RegionListener_12.java | 10 ++++++++++ BauSystem_15/pom.xml | 7 +++++++ .../bausystem/world/RegionListener_15.java | 20 +++++++++++++++++++ BauSystem_Main/pom.xml | 7 ------- .../bausystem/world/RegionListener.java | 19 +++--------------- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java index f88367f..12c6cc8 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java @@ -20,7 +20,12 @@ package de.steamwar.bausystem.world; import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import net.minecraft.server.v1_12_R1.BlockPosition; +import net.minecraft.server.v1_12_R1.PacketPlayOutOpenSignEditor; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; class RegionListener_12 { private RegionListener_12(){} @@ -33,4 +38,9 @@ class RegionListener_12 { return ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")).getWorldEdit().getPlatformManager() .getCommandManager().getDispatcher().get(command) != null; } + + static void openSignEditor(Player player, Location location) { + PacketPlayOutOpenSignEditor packet = new PacketPlayOutOpenSignEditor(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ())); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } } diff --git a/BauSystem_15/pom.xml b/BauSystem_15/pom.xml index cd2adb4..bcebe1e 100644 --- a/BauSystem_15/pom.xml +++ b/BauSystem_15/pom.xml @@ -50,5 +50,12 @@ BauSystem_API 1.0 + + steamwar + ProtocolLib + 4.5.0 + system + ${main.basedir}/lib/ProtocolLib.jar + diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java index 14a810e..fd22589 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java @@ -19,7 +19,17 @@ package de.steamwar.bausystem.world; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.BlockPosition; import com.sk89q.worldedit.WorldEdit; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; class RegionListener_15 { private RegionListener_15(){} @@ -31,4 +41,14 @@ class RegionListener_15 { command = command.toLowerCase(); return WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().containsCommand(command); } + + static void openSignEditor(Player player, Location location) { + PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR); + signOpen.getBlockPositionModifier().write(0, new BlockPosition(location.toVector())); + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, signOpen); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); + } + } } diff --git a/BauSystem_Main/pom.xml b/BauSystem_Main/pom.xml index cb63fc7..3aa54e7 100644 --- a/BauSystem_Main/pom.xml +++ b/BauSystem_Main/pom.xml @@ -79,12 +79,5 @@ system ${main.basedir}/lib/WorldEdit-1.15.jar - - steamwar - ProtocolLib - 4.5.0 - system - ${main.basedir}/lib/ProtocolLib.jar - diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 08d1bc9..691fa29 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -28,12 +28,10 @@ import com.comphenix.protocol.wrappers.BlockPosition; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; -import net.minecraft.server.v1_15_R1.PacketPlayOutOpenSignEditor; +import de.steamwar.core.VersionedRunnable; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import com.comphenix.protocol.ProtocolLibrary; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -47,10 +45,6 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; -import java.util.logging.Level; - -import java.lang.reflect.InvocationTargetException; - public class RegionListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) @@ -132,20 +126,14 @@ public class RegionListener implements Listener { } sign.update(); - PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR); - signOpen.getBlockPositionModifier().write(0, new BlockPosition(event.getClickedBlock().getLocation().toVector())); - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, signOpen); - } catch (InvocationTargetException e) { - Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); - } + VersionedRunnable.call(new VersionedRunnable(() -> RegionListener_12.openSignEditor(player, event.getClickedBlock().getLocation()), 12), + new VersionedRunnable(() -> RegionListener_15.openSignEditor(player, event.getClickedBlock().getLocation()), 15)); ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Client.UPDATE_SIGN) { @Override public void onPacketReceiving(PacketEvent event) { if(!event.getPlayer().equals(player)) return; - event.setCancelled(true); Bukkit.getScheduler().runTask(BauSystem.getPlugin(), () -> { PacketContainer packetContainer = event.getPacket(); BlockPosition position = packetContainer.getBlockPositionModifier().read(0); @@ -156,7 +144,6 @@ public class RegionListener implements Listener { return; Sign sign = ((Sign) signLoc.getState()); - sign.setEditable(true); for (int i = 0; i < lines.length; i++) { sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i])); } From 88b9ae0ec4b74ad4e563983ddb954343b2260b9b Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 11:12:27 +0100 Subject: [PATCH 41/91] Fix tnt spawning on redstone sources --- .../de/steamwar/bausystem/commands/CommandFreeze.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index c158459..8ab7445 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -19,7 +19,9 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.BauSystem; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; @@ -53,6 +55,11 @@ public class CommandFreeze extends ToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { e.setCancelled(true); + if (e.getEntityType() == EntityType.PRIMED_TNT) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1); + } } @EventHandler From 709e6f11dc78a2838a34cda46d6325400df7b614 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 11:13:33 +0100 Subject: [PATCH 42/91] Fix tnt spawning on redstone sources --- .../bausystem/commands/CommandFreeze.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 53d6395..4c1103e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -20,7 +20,10 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; @@ -65,15 +68,21 @@ public class CommandFreeze extends RegionToggleCommand { if (!region.isFreeze()) { return; } - if (e.getEntityType() == EntityType.FALLING_BLOCK) { - e.setCancelled(true); + e.setCancelled(true); + if (e.getEntityType() == EntityType.PRIMED_TNT) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1); } }, () -> { if (!Region.NoRegion.freeze) { return; } - if (e.getEntityType() == EntityType.FALLING_BLOCK) { - e.setCancelled(true); + e.setCancelled(true); + if (e.getEntityType() == EntityType.PRIMED_TNT) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1); } }); } From 7b4c0681d0715d4c92a21cc5bc96d2c5d9108764 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 14:30:59 +0100 Subject: [PATCH 43/91] Fix copyright --- .../bausystem/commands/CommandFreeze.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 4c1103e..67b7e19 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -1,26 +1,26 @@ /* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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 . - */ + This file is a part of the SteamWar software. + + Copyright (C) 2020 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.commands; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.commands.RegionToggleCommand; import de.steamwar.bausystem.world.Region; import org.bukkit.Bukkit; import org.bukkit.Material; From 16ad0ad5e62fdba7906aba2af4bb7afaa5759942 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 14:31:24 +0100 Subject: [PATCH 44/91] Optimize Imports --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 67b7e19..769ecd5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.commands.RegionToggleCommand; import de.steamwar.bausystem.world.Region; import org.bukkit.Bukkit; import org.bukkit.Material; From 168819e5c819da2f24e34626313ef810fd20b34f Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 15:38:12 +0100 Subject: [PATCH 45/91] Fix pr stuff --- .../de/steamwar/bausystem/commands/CommandFire.java | 4 ---- .../steamwar/bausystem/commands/CommandFreeze.java | 4 ---- .../de/steamwar/bausystem/commands/CommandTNT.java | 12 ++++++------ .../bausystem/commands/RegionToggleCommand.java | 10 +++++----- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 009b2d7..9c341d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -26,10 +26,6 @@ import org.bukkit.event.block.BlockSpreadEvent; public class CommandFire extends RegionToggleCommand { - public CommandFire() { - super(); - } - @Override String getNoPermMessage() { return "§cDu darfst hier nicht Feuerschaden (de-)aktivieren"; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 769ecd5..d456416 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -32,10 +32,6 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent; public class CommandFreeze extends RegionToggleCommand { - public CommandFreeze(){ - super(); - } - @Override String getNoPermMessage() { return "§cDu darfst diese Welt nicht einfrieren"; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 9e44eb8..2199bc2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -36,7 +36,7 @@ public class CommandTNT implements CommandExecutor, Listener { public enum TNTMode { ON("§aan"), - ONLY_TB("§7nur §eTestblock"), + ONLY_TB("§7Kein §eBaurahmen"), OFF("§caus"); private String name; @@ -112,28 +112,28 @@ public class CommandTNT implements CommandExecutor, Listener { Region region = Region.getRegion(player.getLocation()); if (region == null) { - tntGlobalToggle(player, requestedMode, requestedMessage); + tntGlobalToggle(requestedMode, requestedMessage); return false; } tntToggle(region, requestedMode, requestedMessage); return false; } - private void tntGlobalToggle(Player player, TNTMode requestedMode, String requestedMessage) { + private void tntGlobalToggle(TNTMode requestedMode, String requestedMessage) { if (requestedMode != null && requestedMode != TNTMode.ONLY_TB) { Region.NoRegion.tnt = requestedMode; - RegionToggleCommand.actionBar(player, requestedMessage); + RegionToggleCommand.actionBar(requestedMessage); return; } switch (Region.NoRegion.tnt) { case ON: case ONLY_TB: Region.NoRegion.tnt = TNTMode.OFF; - RegionToggleCommand.actionBar(player, getDisableMessage()); + RegionToggleCommand.actionBar(getDisableMessage()); break; case OFF: Region.NoRegion.tnt = TNTMode.ON; - RegionToggleCommand.actionBar(player, getEnableMessage()); + RegionToggleCommand.actionBar(getEnableMessage()); break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 49e36b8..6eba349 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -36,7 +36,7 @@ import org.bukkit.event.Listener; public abstract class RegionToggleCommand implements CommandExecutor, Listener { - RegionToggleCommand() { + public RegionToggleCommand() { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); } @@ -54,9 +54,9 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { Region region = Region.getRegion(player.getLocation()); if (region == null) { if (toggleGlobal()) { - actionBar(player, getEnableMessage()); + actionBar(getEnableMessage()); } else { - actionBar(player, getDisableMessage()); + actionBar(getDisableMessage()); } return false; } @@ -72,8 +72,8 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); } - public static void actionBar(Player player, String s) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)); + public static void actionBar(String s) { + Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); } abstract String getNoPermMessage(); From 4648186c1a864de2dd8663c1de48e4a1507d5cb6 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 15:39:06 +0100 Subject: [PATCH 46/91] Fix pr stuff --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 2199bc2..bc9e866 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -68,7 +68,7 @@ public class CommandTNT implements CommandExecutor, Listener { } private String getTestblockEnableMessage() { - return "§aTNT-Schaden am Testblock aktiviert"; + return "§aTNT-Schaden außerhalb Baurahmen aktiviert"; } private String getDamageMessage() { From d406ed7e66f6ac82c88fd786780429969a89c3c0 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 18:06:30 +0100 Subject: [PATCH 47/91] Fix CommandTNT for Region without Testblock --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 6 +++++- BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index bc9e866..e86ba40 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -140,6 +140,10 @@ public class CommandTNT implements CommandExecutor, Listener { private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { if (requestedMode != null) { + if (!region.hasTestblock() && requestedMode == TNTMode.ONLY_TB) { + requestedMode = TNTMode.ON; + requestedMessage = getEnableMessage(); + } region.setTntMode(requestedMode); RegionToggleCommand.actionBar(region, requestedMessage); return; @@ -151,7 +155,7 @@ public class CommandTNT implements CommandExecutor, Listener { RegionToggleCommand.actionBar(region, getDisableMessage()); break; case OFF: - if (Region.buildAreaEnabled()) { + if (Region.buildAreaEnabled() && region.hasTestblock()) { region.setTntMode(TNTMode.ONLY_TB); RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); } else { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 590e033..781a0b7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -110,6 +110,7 @@ public class Region { minZ = config.getInt("minZ"); prototype = Prototype.prototypes.get(config.getString("prototype")); optionsLinkedWith = config.getString("optionsLinkedWith", null); + if (!hasTestblock()) tntMode = TNTMode.OFF; regions.add(this); } From 475f93426c10b77f12be2a761369198fc38d0596 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 18:09:16 +0100 Subject: [PATCH 48/91] Simplify CommandTNT for Region without Testblock --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index e86ba40..c976f9a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -139,11 +139,7 @@ public class CommandTNT implements CommandExecutor, Listener { } private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { - if (requestedMode != null) { - if (!region.hasTestblock() && requestedMode == TNTMode.ONLY_TB) { - requestedMode = TNTMode.ON; - requestedMessage = getEnableMessage(); - } + if (requestedMode != null && region.hasTestblock()) { region.setTntMode(requestedMode); RegionToggleCommand.actionBar(region, requestedMessage); return; From 375885bbde4e2bf607d4514ce23fcf8d171af675 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 19:37:52 +0100 Subject: [PATCH 49/91] Fix Sound of TNT ignite with freeze enabled --- .../bausystem/commands/CommandFreeze.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index d456416..08097c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -60,24 +60,30 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { Region.getRegion(e.getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); + }); + } + + @EventHandler(ignoreCancelled = true) + public void onBlockCanBuild(BlockCanBuildEvent e) { + if (!e.isBuildable()) return; + Region.getRegion(e.getBlock().getLocation(), region -> { if (!region.isFreeze()) { return; } - e.setCancelled(true); - if (e.getEntityType() == EntityType.PRIMED_TNT) { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - e.getLocation().getBlock().setType(Material.TNT, false); - }, 1); + if (e.getMaterial() == Material.TNT) { + e.setBuildable(false); + e.getBlock().setType(Material.TNT, false); } }, () -> { if (!Region.NoRegion.freeze) { return; } - e.setCancelled(true); - if (e.getEntityType() == EntityType.PRIMED_TNT) { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - e.getLocation().getBlock().setType(Material.TNT, false); - }, 1); + if (e.getMaterial() == Material.TNT) { + e.setBuildable(false); + e.getBlock().setType(Material.TNT, false); } }); } From 5c73e5874d8cdf961bcdd9902e19a21d13e07827 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 19:41:00 +0100 Subject: [PATCH 50/91] Fix Sound of TNT ignite with freeze enabled --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 08097c3..9c2ddac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -66,7 +66,7 @@ public class CommandFreeze extends RegionToggleCommand { }); } - @EventHandler(ignoreCancelled = true) + @EventHandler public void onBlockCanBuild(BlockCanBuildEvent e) { if (!e.isBuildable()) return; Region.getRegion(e.getBlock().getLocation(), region -> { From 7cb2f224a2a5b25a5217da134c9d7115bc8344a7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 20:07:40 +0100 Subject: [PATCH 51/91] Fix freeze allow building of tnt --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 3 --- .../src/de/steamwar/bausystem/world/RegionListener.java | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 9c2ddac..4873c01 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -19,11 +19,8 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; import org.bukkit.event.entity.EntityChangeBlockEvent; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 0719a4f..3019aad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -29,7 +29,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -59,13 +59,13 @@ public class RegionListener implements Listener { } @EventHandler(priority = EventPriority.LOWEST) - public void onBlockPlace(BlockPlaceEvent e) { + public void onBlockCanBuild(BlockCanBuildEvent e) { Player p = e.getPlayer(); try{ if (Welt.noPermission(p, Permission.build)){ p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine Blöcke platzieren"); - e.setCancelled(true); + e.setBuildable(false); } }catch(NullPointerException ex){ //ignored, caused by worldedit brushes From 78c0e72178bfba86eef2ecfc1adb071bc8272c8c Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 20:21:31 +0100 Subject: [PATCH 52/91] Add plugin.yml --- BauSystem_Main/src/plugin.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index bc85fb9..4d17a57 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -1,10 +1,12 @@ name: BauSystem -author: Lixfel +author: [Lixfel, YoyoNow, Chaoscaot] version: "1.0" depend: [WorldEdit, SpigotCore] load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" +webside: www.steamwar.de +description: "So unseriös wie wir sind: BauSystem nur besser." commands: debugstick: From 5f0477e920e7a738d20cca633fb23c4b9ece7c86 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 20:25:23 +0100 Subject: [PATCH 53/91] Fix plugin.yml --- BauSystem_Main/src/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 74b9ef6..0c1df7e 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -5,7 +5,7 @@ depend: [WorldEdit, SpigotCore, ProtocolLib] load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" -webside: www.steamwar.de +website: "https://steamwar.de" description: "So unseriös wie wir sind: BauSystem nur besser." commands: From 607b1f155725836739f0c222823e65844709bea8 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 20:27:16 +0100 Subject: [PATCH 54/91] Fix plugin.yml --- BauSystem_Main/src/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 0c1df7e..5a10a50 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -1,5 +1,5 @@ name: BauSystem -author: [Lixfel, YoyoNow, Chaoscaot] +authors: [Lixfel, YoyoNow, Chaoscaot] version: "1.0" depend: [WorldEdit, SpigotCore, ProtocolLib] load: POSTWORLD From 828fb025aa73b825d9d6e8175b0c9126a0c6efc6 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 21:00:22 +0100 Subject: [PATCH 55/91] Simplify RegionSystem --- .../bausystem/commands/CommandFire.java | 10 --- .../bausystem/commands/CommandFreeze.java | 32 -------- .../bausystem/commands/CommandInfo.java | 6 +- .../bausystem/commands/CommandTNT.java | 26 ------ .../commands/RegionToggleCommand.java | 19 ++--- .../bausystem/world/BauScoreboard.java | 12 +-- .../de/steamwar/bausystem/world/Region.java | 81 ++++++++++++++++--- 7 files changed, 80 insertions(+), 106 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 9c341d0..8dcf312 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -45,18 +45,10 @@ public class CommandFire extends RegionToggleCommand { return region.isFire(); } - @Override - boolean toggleGlobal() { - Region.NoRegion.fire = !Region.NoRegion.fire; - return Region.NoRegion.fire; - } - @EventHandler public void onFireDamage(BlockBurnEvent e) { Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFire()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.fire) e.setCancelled(true); }); } @@ -64,8 +56,6 @@ public class CommandFire extends RegionToggleCommand { public void onFireSpread(BlockSpreadEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFire()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.fire) e.setCancelled(true); }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 4873c01..37c7a60 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -48,18 +48,10 @@ public class CommandFreeze extends RegionToggleCommand { return region.isFreeze(); } - @Override - boolean toggleGlobal() { - Region.NoRegion.freeze = !Region.NoRegion.freeze; - return Region.NoRegion.freeze; - } - @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { Region.getRegion(e.getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -74,14 +66,6 @@ public class CommandFreeze extends RegionToggleCommand { e.setBuildable(false); e.getBlock().setType(Material.TNT, false); } - }, () -> { - if (!Region.NoRegion.freeze) { - return; - } - if (e.getMaterial() == Material.TNT) { - e.setBuildable(false); - e.getBlock().setType(Material.TNT, false); - } }); } @@ -89,8 +73,6 @@ public class CommandFreeze extends RegionToggleCommand { public void onEntityChangeBlock(EntityChangeBlockEvent e) { Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -98,8 +80,6 @@ public class CommandFreeze extends RegionToggleCommand { public void onPhysicsEvent(BlockPhysicsEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -107,8 +87,6 @@ public class CommandFreeze extends RegionToggleCommand { public void onPistonExtend(BlockPistonExtendEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -116,8 +94,6 @@ public class CommandFreeze extends RegionToggleCommand { public void onPistonRetract(BlockPistonRetractEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -125,8 +101,6 @@ public class CommandFreeze extends RegionToggleCommand { public void onBlockGrow(BlockGrowEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -134,8 +108,6 @@ public class CommandFreeze extends RegionToggleCommand { public void onRedstoneEvent(BlockRedstoneEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent()); - }, () -> { - if (Region.NoRegion.freeze) e.setNewCurrent(e.getOldCurrent()); }); } @@ -143,8 +115,6 @@ public class CommandFreeze extends RegionToggleCommand { public void onBlockDispense(BlockDispenseEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -152,8 +122,6 @@ public class CommandFreeze extends RegionToggleCommand { public void onInventoryMoveEvent(InventoryMoveItemEvent e){ Region.getRegion(e.getDestination().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) e.setCancelled(true); }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index fd8fc56..980133b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -42,11 +42,7 @@ public class CommandInfo implements CommandExecutor { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); Region region = Region.getRegion(player.getLocation()); - if (region == null) { - sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + Region.NoRegion.tnt.getName() + " §eFire§8: " + (Region.NoRegion.fire ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (Region.NoRegion.freeze ? "§aAN" : "§cAUS")); - } else { - sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); - } + sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index c976f9a..84a9a5f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -111,33 +111,10 @@ public class CommandTNT implements CommandExecutor, Listener { } Region region = Region.getRegion(player.getLocation()); - if (region == null) { - tntGlobalToggle(requestedMode, requestedMessage); - return false; - } tntToggle(region, requestedMode, requestedMessage); return false; } - private void tntGlobalToggle(TNTMode requestedMode, String requestedMessage) { - if (requestedMode != null && requestedMode != TNTMode.ONLY_TB) { - Region.NoRegion.tnt = requestedMode; - RegionToggleCommand.actionBar(requestedMessage); - return; - } - switch (Region.NoRegion.tnt) { - case ON: - case ONLY_TB: - Region.NoRegion.tnt = TNTMode.OFF; - RegionToggleCommand.actionBar(getDisableMessage()); - break; - case OFF: - Region.NoRegion.tnt = TNTMode.ON; - RegionToggleCommand.actionBar(getEnableMessage()); - break; - } - } - private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { if (requestedMode != null && region.hasTestblock()) { region.setTntMode(requestedMode); @@ -166,9 +143,6 @@ public class CommandTNT implements CommandExecutor, Listener { public void onExplode(EntityExplodeEvent event) { event.blockList().removeIf(block -> { Region region = Region.getRegion(block.getLocation()); - if (region == null) { - return Region.NoRegion.tnt == TNTMode.OFF; - } if (region.getTntMode() == TNTMode.OFF) return true; if (region.getTntMode() == TNTMode.ON) return false; if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 6eba349..d07e013 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -52,14 +52,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { } Region region = Region.getRegion(player.getLocation()); - if (region == null) { - if (toggleGlobal()) { - actionBar(getEnableMessage()); - } else { - actionBar(getDisableMessage()); - } - return false; - } if (toggle(region)) { actionBar(region, getEnableMessage()); } else { @@ -69,11 +61,11 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { } public static void actionBar(Region region, String s) { - Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); - } - - public static void actionBar(String s) { - Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + if (Region.GlobalRegion.isGlobalRegion(region)) { + Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + } else { + Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + } } abstract String getNoPermMessage(); @@ -84,6 +76,5 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { * {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()} */ abstract boolean toggle(Region region); - abstract boolean toggleGlobal(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 316cf00..17873b7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -60,15 +60,9 @@ public class BauScoreboard implements Listener { strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); Region region = Region.getRegion(p.getLocation()); - if (region != null) { - strings.add("§eTNT§8: " + region.getTntMode().getName()); - strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); - strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); - } else { - strings.add("§eTNT§8: " + Region.NoRegion.tnt.getName()); - strings.add("§eFreeze§8: " + (Region.NoRegion.freeze ? "§aan" : "§caus")); - strings.add("§eFire§8: " + (Region.NoRegion.fire ? "§aaus" : "§can")); - } + strings.add("§eTNT§8: " + region.getTntMode().getName()); + strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); + strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 781a0b7..ff9f130 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -41,13 +41,6 @@ public class Region { private static final List regions = new ArrayList<>(); private static boolean buildArea = false; - public static class NoRegion { - private NoRegion() {} - public static TNTMode tnt = TNTMode.OFF; - public static boolean fire = false; - public static boolean freeze = false; - } - static{ YamlConfiguration config = new YamlConfiguration(); try { @@ -77,10 +70,10 @@ public class Region { for (Region region : regions) { if (region.inRegion(location)) return region; } - return null; + return GlobalRegion.getInstance(); } - public static void getRegion(Location location, Consumer regionConsumer, Runnable noRegion) { + public static void getRegion(Location location, Consumer regionConsumer) { boolean b = true; for (Region region : regions) { if (region.inRegion(location)) { @@ -88,7 +81,7 @@ public class Region { b = false; } } - if (b) noRegion.run(); + if (b) regionConsumer.accept(GlobalRegion.getInstance()); } private final String name; @@ -114,6 +107,16 @@ public class Region { regions.add(this); } + public Region(String name) { + this.name = name; + this.minX = 0; + this.minY = 0; + this.minZ = 0; + this.prototype = null; + this.optionsLinkedWith = null; + tntMode = TNTMode.OFF; + } + private void setLinkedRegion(Consumer regionConsumer) { if (optionsLinkedWith == null) { return; @@ -194,6 +197,64 @@ public class Region { prototype.protect(this, schem); } + public static class GlobalRegion extends Region { + + private static final GlobalRegion GLOBAL_REGION = new GlobalRegion(); + + public static GlobalRegion getInstance() { + return GLOBAL_REGION; + } + + public static boolean isGlobalRegion(Region region) { + return region == GLOBAL_REGION; + } + + public GlobalRegion() { + super("Global"); + } + + @Override + public boolean inRegion(Location l) { + return true; + } + + @Override + public boolean hasBuildRegion() { + return false; + } + + @Override + public boolean inBuildRegion(Location l) { + return false; + } + + @Override + public void fastreset() { + + } + + @Override + public boolean hasTestblock() { + return false; + } + + @Override + public void resetTestblock(Schematic schem) throws IOException, NoClipboardException { + + } + + @Override + public boolean hasProtection() { + return false; + } + + @Override + public void protect(Schematic schem) throws IOException, NoClipboardException { + + } + + } + public static class Prototype{ private static final Map prototypes = new HashMap<>(); From 97d626fcb3ef23eaaabf7e21fec2eda3f6c76132 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 21:08:59 +0100 Subject: [PATCH 56/91] Simplify RegionSystem --- .../bausystem/commands/CommandFire.java | 8 +-- .../bausystem/commands/CommandFreeze.java | 52 ++++++------------- .../de/steamwar/bausystem/world/Region.java | 26 ---------- 3 files changed, 18 insertions(+), 68 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 8dcf312..1b6f158 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -47,16 +47,12 @@ public class CommandFire extends RegionToggleCommand { @EventHandler public void onFireDamage(BlockBurnEvent e) { - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFire()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFire()) e.setCancelled(true); } @EventHandler public void onFireSpread(BlockSpreadEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFire()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFire()) e.setCancelled(true); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 37c7a60..2835e7c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -27,6 +27,8 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; +import java.sql.Ref; + public class CommandFreeze extends RegionToggleCommand { @Override @@ -50,78 +52,56 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { - Region.getRegion(e.getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onBlockCanBuild(BlockCanBuildEvent e) { if (!e.isBuildable()) return; - Region.getRegion(e.getBlock().getLocation(), region -> { - if (!region.isFreeze()) { - return; - } - if (e.getMaterial() == Material.TNT) { - e.setBuildable(false); - e.getBlock().setType(Material.TNT, false); - } - }); + if (!Region.getRegion(e.getBlock().getLocation()).isFreeze()) return; + if (e.getMaterial() == Material.TNT) { + e.setBuildable(false); + e.getBlock().setType(Material.TNT, false); + } } @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent e) { - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onPistonExtend(BlockPistonExtendEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onPistonRetract(BlockPistonRetractEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onBlockGrow(BlockGrowEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onRedstoneEvent(BlockRedstoneEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent()); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setNewCurrent(e.getOldCurrent()); } @EventHandler public void onBlockDispense(BlockDispenseEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onInventoryMoveEvent(InventoryMoveItemEvent e){ - Region.getRegion(e.getDestination().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getDestination().getLocation()).isFreeze()) e.setCancelled(true); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index ff9f130..28552ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -73,17 +73,6 @@ public class Region { return GlobalRegion.getInstance(); } - public static void getRegion(Location location, Consumer regionConsumer) { - boolean b = true; - for (Region region : regions) { - if (region.inRegion(location)) { - regionConsumer.accept(region); - b = false; - } - } - if (b) regionConsumer.accept(GlobalRegion.getInstance()); - } - private final String name; private final int minX; private final int minY; @@ -228,31 +217,16 @@ public class Region { return false; } - @Override - public void fastreset() { - - } - @Override public boolean hasTestblock() { return false; } - @Override - public void resetTestblock(Schematic schem) throws IOException, NoClipboardException { - - } - @Override public boolean hasProtection() { return false; } - @Override - public void protect(Schematic schem) throws IOException, NoClipboardException { - - } - } public static class Prototype{ From cf7ae0fa09e66e20aeafb699f70cde07762d3a65 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 21:10:59 +0100 Subject: [PATCH 57/91] Optimize Imports --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 2835e7c..2364e98 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -27,8 +27,6 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; -import java.sql.Ref; - public class CommandFreeze extends RegionToggleCommand { @Override From dfb67704537e9ec2497d65f2a11f7f6f1b097865 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 4 Feb 2021 09:55:39 +0100 Subject: [PATCH 58/91] Fix Freeze Exceptions --- .../bausystem/commands/CommandFreeze.java | 10 ++++++++ .../bausystem/world/RegionListener.java | 23 +++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 2364e98..5baa134 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -19,7 +19,10 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; +import de.steamwar.core.Core; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; @@ -55,6 +58,7 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onBlockCanBuild(BlockCanBuildEvent e) { + if (Core.getVersion() == 12) return; if (!e.isBuildable()) return; if (!Region.getRegion(e.getBlock().getLocation()).isFreeze()) return; if (e.getMaterial() == Material.TNT) { @@ -66,6 +70,12 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent e) { if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); + if (Core.getVersion() == 15) return; + if (e.isCancelled()) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getBlock().setType(Material.TNT, false); + }, 1L); + } } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 47d49c0..ac6825e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -38,10 +38,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockCanBuildEvent; -import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.block.*; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -72,8 +69,9 @@ public class RegionListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onBlockCanBuild(BlockCanBuildEvent e) { - Player p = e.getPlayer(); + if (Core.getVersion() == 12) return; + Player p = e.getPlayer(); try{ if (Welt.noPermission(p, Permission.build)){ p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine Blöcke platzieren"); @@ -84,6 +82,21 @@ public class RegionListener implements Listener { } } + @EventHandler(priority = EventPriority.LOWEST) + public void onBlockPlace(BlockPlaceEvent e) { + if (Core.getVersion() == 15) return; + + Player p = e.getPlayer(); + try{ + if (Welt.noPermission(p, Permission.build)){ + p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine Blöcke platzieren"); + e.setCancelled(true); + } + }catch(NullPointerException ex){ + //ignored, caused by worldedit brushes + } + } + private static final String[] shortcutCommands = {"//1", "//2", "//90", "//-90", "//180", "//p", "//c", "//flopy", "//floppy", "//flopyp", "//floppyp", "//u", "//r"}; private boolean isWorldEditCommand(String command) { From 180ab0f8a402110ef7620da3038c49fd1763eca7 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 4 Feb 2021 10:00:44 +0100 Subject: [PATCH 59/91] Fix Freeze Exceptions --- .../steamwar/bausystem/commands/CommandFreeze.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 5baa134..a366121 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -54,6 +54,12 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { if (Region.getRegion(e.getLocation()).isFreeze()) e.setCancelled(true); + if (Core.getVersion() == 15) return; + if (e.isCancelled()) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1L); + } } @EventHandler @@ -70,12 +76,6 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent e) { if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); - if (Core.getVersion() == 15) return; - if (e.isCancelled()) { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - e.getBlock().setType(Material.TNT, false); - }, 1L); - } } @EventHandler From 08ae54582038033c4723d252c171b81dc057c8b2 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 4 Feb 2021 10:06:26 +0100 Subject: [PATCH 60/91] Fix Freeze Exceptions --- .../bausystem/commands/CommandFreeze.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index a366121..ad268b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.world.Region; import de.steamwar.core.Core; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; import org.bukkit.event.entity.EntityChangeBlockEvent; @@ -53,12 +54,14 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { - if (Region.getRegion(e.getLocation()).isFreeze()) e.setCancelled(true); - if (Core.getVersion() == 15) return; - if (e.isCancelled()) { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - e.getLocation().getBlock().setType(Material.TNT, false); - }, 1L); + if (Region.getRegion(e.getLocation()).isFreeze()) { + e.setCancelled(true); + if (Core.getVersion() == 15) return; + if (e.getEntityType() == EntityType.PRIMED_TNT) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1L); + } } } From 8922e472bfc39a6158da958863b10479246f6db3 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 4 Feb 2021 10:09:49 +0100 Subject: [PATCH 61/91] Fix Freeze in 1.12 --- .../steamwar/bausystem/commands/CommandFreeze.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index ad268b1..edd616f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -54,14 +54,12 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { - if (Region.getRegion(e.getLocation()).isFreeze()) { - e.setCancelled(true); - if (Core.getVersion() == 15) return; - if (e.getEntityType() == EntityType.PRIMED_TNT) { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - e.getLocation().getBlock().setType(Material.TNT, false); - }, 1L); - } + if (!Region.getRegion(e.getLocation()).isFreeze()) return; + e.setCancelled(true); + if (Core.getVersion() == 12 && e.getEntityType() == EntityType.PRIMED_TNT) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1L); } } From 7a356b7f28aca6ee66b3b85595f138a550dfce0d Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 4 Feb 2021 10:25:54 +0100 Subject: [PATCH 62/91] Hotfix MovingTNTBlock --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index edd616f..f770e21 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -56,7 +56,7 @@ public class CommandFreeze extends RegionToggleCommand { public void onEntitySpawn(EntitySpawnEvent e) { if (!Region.getRegion(e.getLocation()).isFreeze()) return; e.setCancelled(true); - if (Core.getVersion() == 12 && e.getEntityType() == EntityType.PRIMED_TNT) { + if (e.getEntityType() == EntityType.PRIMED_TNT) { Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { e.getLocation().getBlock().setType(Material.TNT, false); }, 1L); From f8871d6a8e6e651f7766377c850315765725b5dd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 5 Feb 2021 18:45:35 +0100 Subject: [PATCH 63/91] Sign edit only with Empty hand --- .../src/de/steamwar/bausystem/world/RegionListener.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 47d49c0..306a9f1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -32,6 +32,7 @@ import de.steamwar.core.VersionedRunnable; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import com.comphenix.protocol.ProtocolLibrary; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -115,7 +116,9 @@ public class RegionListener implements Listener { public void editSign(PlayerInteractEvent event) { if(event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.getClickedBlock().getType().name().contains("SIGN") || - !event.getPlayer().isSneaking()) + !event.getPlayer().isSneaking() || + event.getItem() == null || + event.getItem().getType() != Material.AIR) return; Player player = event.getPlayer(); From dce3e96abfca07d267a6fda11af601c1e3d2b488 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 6 Feb 2021 13:17:42 +0100 Subject: [PATCH 64/91] Add Region.Prototype.extensionFront Add Region.Prototype.extensionBack Add Region.Prototype.extensionUp Add Region.Prototype.extensionSides --- .../src/de/steamwar/bausystem/world/Region.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 28552ac..cf7b8ff 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -240,6 +240,11 @@ public class Region { private final int offsetY; private final int offsetZ; + private final int extensionFront; + private final int extensionBack; + private final int extensionUp; + private final int extensionSides; + private final String schematic; private final boolean rotate; @@ -256,6 +261,10 @@ public class Region { offsetX = config.getInt("offsetX", 0); offsetY = config.getInt("offsetY", 0); offsetZ = config.getInt("offsetZ", 0); + extensionFront = config.getInt("extensionFront", 0); + extensionBack = config.getInt("extensionBack", 0); + extensionUp = config.getInt("extensionUp", 0); + extensionSides = config.getInt("extensionSides", 0); rotate = config.getBoolean("rotate", false); ConfigurationSection testblockSection = config.getConfigurationSection("testblock"); From 863f06673f5476ba43fc78ea66bce72ab7561a3a Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 6 Feb 2021 13:26:52 +0100 Subject: [PATCH 65/91] Add Region.ExtensionDirection Add Region.Prototype.extensionFrontDirection --- .../de/steamwar/bausystem/world/Region.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index cf7b8ff..45db098 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -229,6 +229,15 @@ public class Region { } + public enum ExtensionDirection { + + PositiveZ(), + NegativeZ(), + PositiveX(), + NegativeX() + + } + public static class Prototype{ private static final Map prototypes = new HashMap<>(); @@ -240,6 +249,7 @@ public class Region { private final int offsetY; private final int offsetZ; + private final ExtensionDirection extensionFrontDirection; private final int extensionFront; private final int extensionBack; private final int extensionUp; @@ -261,6 +271,28 @@ public class Region { offsetX = config.getInt("offsetX", 0); offsetY = config.getInt("offsetY", 0); offsetZ = config.getInt("offsetZ", 0); + String extDir = config.getString("extensionFrontDirection", null); + if (extDir == null) extensionFrontDirection = null; + else { + ExtensionDirection extDirection = null; + switch (extDir.toLowerCase()) { + case "positivex": + extDirection = ExtensionDirection.PositiveX; + break; + case "negativex": + extDirection = ExtensionDirection.NegativeX; + break; + case "positivez": + extDirection = ExtensionDirection.PositiveZ; + break; + case "negativez": + extDirection = ExtensionDirection.NegativeZ; + break; + default: + break; + } + extensionFrontDirection = extDirection; + } extensionFront = config.getInt("extensionFront", 0); extensionBack = config.getInt("extensionBack", 0); extensionUp = config.getInt("extensionUp", 0); From 9d07f192a770e6af376980191cd959614053446a Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 6 Feb 2021 15:15:52 +0100 Subject: [PATCH 66/91] Simplify Region --- .../de/steamwar/bausystem/world/Region.java | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 45db098..39eb0ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -231,10 +231,25 @@ public class Region { public enum ExtensionDirection { - PositiveZ(), - NegativeZ(), - PositiveX(), - NegativeX() + PositiveZ("positivez", "z+"), + NegativeZ("negativez", "z-"), + PositiveX("positivex", "x+"), + NegativeX("negativex", "x-"); + + private Set values; + + ExtensionDirection(String... values) { + this.values = new HashSet<>(Arrays.asList(values)); + } + + public static ExtensionDirection getByString(String value) { + if (value == null) return null; + value = value.toLowerCase(); + for (ExtensionDirection extensionDirection : values()) { + if (extensionDirection.values.contains(value)) return extensionDirection; + } + return null; + } } @@ -271,28 +286,7 @@ public class Region { offsetX = config.getInt("offsetX", 0); offsetY = config.getInt("offsetY", 0); offsetZ = config.getInt("offsetZ", 0); - String extDir = config.getString("extensionFrontDirection", null); - if (extDir == null) extensionFrontDirection = null; - else { - ExtensionDirection extDirection = null; - switch (extDir.toLowerCase()) { - case "positivex": - extDirection = ExtensionDirection.PositiveX; - break; - case "negativex": - extDirection = ExtensionDirection.NegativeX; - break; - case "positivez": - extDirection = ExtensionDirection.PositiveZ; - break; - case "negativez": - extDirection = ExtensionDirection.NegativeZ; - break; - default: - break; - } - extensionFrontDirection = extDirection; - } + extensionFrontDirection = ExtensionDirection.getByString(config.getString("extensionFrontDirection", null)); extensionFront = config.getInt("extensionFront", 0); extensionBack = config.getInt("extensionBack", 0); extensionUp = config.getInt("extensionUp", 0); From 7cfc8a959488c6bf64e206851d3399b118786056 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 6 Feb 2021 15:18:28 +0100 Subject: [PATCH 67/91] Simplify Region --- .../src/de/steamwar/bausystem/world/Region.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 39eb0ce..ee0907a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -230,21 +230,17 @@ public class Region { } public enum ExtensionDirection { - PositiveZ("positivez", "z+"), NegativeZ("negativez", "z-"), PositiveX("positivex", "x+"), NegativeX("negativex", "x-"); private Set values; - ExtensionDirection(String... values) { this.values = new HashSet<>(Arrays.asList(values)); } - public static ExtensionDirection getByString(String value) { - if (value == null) return null; - value = value.toLowerCase(); + private static ExtensionDirection getByString(String value) { for (ExtensionDirection extensionDirection : values()) { if (extensionDirection.values.contains(value)) return extensionDirection; } @@ -286,7 +282,7 @@ public class Region { offsetX = config.getInt("offsetX", 0); offsetY = config.getInt("offsetY", 0); offsetZ = config.getInt("offsetZ", 0); - extensionFrontDirection = ExtensionDirection.getByString(config.getString("extensionFrontDirection", null)); + extensionFrontDirection = ExtensionDirection.getByString(config.getString("extensionFrontDirection", "").toLowerCase()); extensionFront = config.getInt("extensionFront", 0); extensionBack = config.getInt("extensionBack", 0); extensionUp = config.getInt("extensionUp", 0); From 2950ddda36b63a841eb36c5279b296a23b951dfd Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 6 Feb 2021 15:36:23 +0100 Subject: [PATCH 68/91] Simplify Region --- .../de/steamwar/bausystem/world/Region.java | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index ee0907a..101eeba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -229,26 +229,6 @@ public class Region { } - public enum ExtensionDirection { - PositiveZ("positivez", "z+"), - NegativeZ("negativez", "z-"), - PositiveX("positivex", "x+"), - NegativeX("negativex", "x-"); - - private Set values; - ExtensionDirection(String... values) { - this.values = new HashSet<>(Arrays.asList(values)); - } - - private static ExtensionDirection getByString(String value) { - for (ExtensionDirection extensionDirection : values()) { - if (extensionDirection.values.contains(value)) return extensionDirection; - } - return null; - } - - } - public static class Prototype{ private static final Map prototypes = new HashMap<>(); @@ -260,11 +240,10 @@ public class Region { private final int offsetY; private final int offsetZ; - private final ExtensionDirection extensionFrontDirection; - private final int extensionFront; - private final int extensionBack; - private final int extensionUp; - private final int extensionSides; + private final int extensionPositiveZ; + private final int extensionNegativeZ; + private final int extensionPositiveY; + private final int extensionAxisX; private final String schematic; private final boolean rotate; @@ -282,11 +261,10 @@ public class Region { offsetX = config.getInt("offsetX", 0); offsetY = config.getInt("offsetY", 0); offsetZ = config.getInt("offsetZ", 0); - extensionFrontDirection = ExtensionDirection.getByString(config.getString("extensionFrontDirection", "").toLowerCase()); - extensionFront = config.getInt("extensionFront", 0); - extensionBack = config.getInt("extensionBack", 0); - extensionUp = config.getInt("extensionUp", 0); - extensionSides = config.getInt("extensionSides", 0); + extensionPositiveZ = config.getInt("extensionPositiveZ", 0); + extensionNegativeZ = config.getInt("extensionNegativeZ", 0); + extensionPositiveY = config.getInt("extensionPositiveY", 0); + extensionAxisX = config.getInt("extensionAxisX", 0); rotate = config.getBoolean("rotate", false); ConfigurationSection testblockSection = config.getConfigurationSection("testblock"); From 2fae702489e49b66b4c74b0bedfe1309069f3a6e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 6 Feb 2021 15:37:12 +0100 Subject: [PATCH 69/91] Fix Signedit --- .../src/de/steamwar/bausystem/world/RegionListener.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 306a9f1..1c7df86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -116,9 +116,9 @@ public class RegionListener implements Listener { public void editSign(PlayerInteractEvent event) { if(event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.getClickedBlock().getType().name().contains("SIGN") || - !event.getPlayer().isSneaking() || - event.getItem() == null || - event.getItem().getType() != Material.AIR) + !event.getPlayer().isSneaking()) + return; + if(event.getItem() != null || event.getItem().getType() != Material.AIR) return; Player player = event.getPlayer(); From fee6807d3b0de6f50f740cf8da74aa7fa1594757 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 6 Feb 2021 15:37:53 +0100 Subject: [PATCH 70/91] Fix Signedit --- .../src/de/steamwar/bausystem/world/RegionListener.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 1c7df86..20b4f3b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -116,9 +116,9 @@ public class RegionListener implements Listener { public void editSign(PlayerInteractEvent event) { if(event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.getClickedBlock().getType().name().contains("SIGN") || - !event.getPlayer().isSneaking()) - return; - if(event.getItem() != null || event.getItem().getType() != Material.AIR) + !event.getPlayer().isSneaking() || + event.getItem() != null || + event.getItem().getType() != Material.AIR) return; Player player = event.getPlayer(); From 76cf208379466a2787fa66b9180809a0b03d846d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 6 Feb 2021 15:43:50 +0100 Subject: [PATCH 71/91] Fix Signedit --- .../src/de/steamwar/bausystem/world/RegionListener.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 20b4f3b..35425ad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -117,8 +117,7 @@ public class RegionListener implements Listener { if(event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.getClickedBlock().getType().name().contains("SIGN") || !event.getPlayer().isSneaking() || - event.getItem() != null || - event.getItem().getType() != Material.AIR) + (event.getItem() != null && event.getItem().getType() != Material.AIR)) return; Player player = event.getPlayer(); From fb73fa6fce56777919f75864295265af28e81e2c Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 6 Feb 2021 17:08:01 +0100 Subject: [PATCH 72/91] Add CommandTNT with extension explode message --- .../steamwar/bausystem/commands/CommandTNT.java | 8 ++++++++ .../src/de/steamwar/bausystem/world/Region.java | 15 ++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 84a9a5f..6c556e9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -75,6 +75,10 @@ public class CommandTNT implements CommandExecutor, Listener { return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; } + private String getDamageExtensionMessage() { + return "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört"; + } + @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { if (!(sender instanceof Player)) return false; @@ -149,6 +153,10 @@ public class CommandTNT implements CommandExecutor, Listener { RegionToggleCommand.actionBar(region, getDamageMessage()); return true; } + if (region.hasBuildRegion() && region.inBuildRegionExtension(block.getLocation())) { + RegionToggleCommand.actionBar(region, getDamageExtensionMessage()); + return true; + } return false; }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 101eeba..0f3d682 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -162,6 +162,10 @@ public class Region { return prototype.buildArea.inRegion(this, l); } + public boolean inBuildRegionExtension(Location l) { + return prototype.buildArea.inRegionExtension(this, l); + } + public void fastreset(){ prototype.fastreset(this); } @@ -212,11 +216,6 @@ public class Region { return false; } - @Override - public boolean inBuildRegion(Location l) { - return false; - } - @Override public boolean hasTestblock() { return false; @@ -288,6 +287,12 @@ public class Region { inRange(l.getZ(), region.minZ + offsetZ, sizeZ); } + public boolean inRegionExtension(Region region, Location l) { + return inRange(l.getX(), region.minX + offsetX - extensionAxisX + 1, sizeX + extensionAxisX * 2 - 1) && + inRange(l.getY(), region.minY + offsetY, sizeY + extensionPositiveY - 1) && + inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ + 1, sizeZ + extensionNegativeZ - 1 + extensionPositiveZ); + } + public void fastreset(Region region){ File file = new File(schematic); int x = region.minX + offsetX + sizeX/2; From f151c6e69a5c91710ace70c27be643bc71a4f8f3 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 6 Feb 2021 21:44:00 +0100 Subject: [PATCH 73/91] Simplify CommandTNT methods --- .../bausystem/commands/CommandTNT.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 6c556e9..e3914ca 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -55,10 +55,6 @@ public class CommandTNT implements CommandExecutor, Listener { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); } - private String getNoPermMessage() { - return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"; - } - private String getEnableMessage() { return "§aTNT-Schaden aktiviert"; } @@ -71,21 +67,13 @@ public class CommandTNT implements CommandExecutor, Listener { return "§aTNT-Schaden außerhalb Baurahmen aktiviert"; } - private String getDamageMessage() { - return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; - } - - private String getDamageExtensionMessage() { - return "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört"; - } - @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { if (!(sender instanceof Player)) return false; Player player = (Player) sender; if (Welt.noPermission(player, Permission.world)) { - player.sendMessage(BauSystem.PREFIX + getNoPermMessage()); + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"); return false; } @@ -150,11 +138,11 @@ public class CommandTNT implements CommandExecutor, Listener { if (region.getTntMode() == TNTMode.OFF) return true; if (region.getTntMode() == TNTMode.ON) return false; if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { - RegionToggleCommand.actionBar(region, getDamageMessage()); + RegionToggleCommand.actionBar(region, "§cEine Explosion hätte Blöcke im Baubereich zerstört"); return true; } if (region.hasBuildRegion() && region.inBuildRegionExtension(block.getLocation())) { - RegionToggleCommand.actionBar(region, getDamageExtensionMessage()); + RegionToggleCommand.actionBar(region, "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört"); return true; } return false; From fc44167ea0bda4bdddd80876330c6d4f401c6a65 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 6 Feb 2021 21:47:48 +0100 Subject: [PATCH 74/91] Add tnt message with OFF mode --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index e3914ca..d528f37 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -135,7 +135,6 @@ public class CommandTNT implements CommandExecutor, Listener { public void onExplode(EntityExplodeEvent event) { event.blockList().removeIf(block -> { Region region = Region.getRegion(block.getLocation()); - if (region.getTntMode() == TNTMode.OFF) return true; if (region.getTntMode() == TNTMode.ON) return false; if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { RegionToggleCommand.actionBar(region, "§cEine Explosion hätte Blöcke im Baubereich zerstört"); @@ -145,7 +144,7 @@ public class CommandTNT implements CommandExecutor, Listener { RegionToggleCommand.actionBar(region, "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört"); return true; } - return false; + return region.getTntMode() == TNTMode.OFF; }); } From 05aa50d8f3d6c42421c8d8f290cc9afed2ce6d10 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 8 Feb 2021 17:57:46 +0100 Subject: [PATCH 75/91] Fix Typo --- BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 6a7e214..ec74e09 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -144,7 +144,7 @@ public class Detonator implements Listener { } else { locs.add(new Detoloader.DetonatorActivation(detoloader.getActivation(), event.getClickedBlock().getLocation())); } - print(detoloader.addBack ? "§e" + detoloader.getBlock() + " getsetzt" : + print(detoloader.addBack ? "§e" + detoloader.getBlock() + " gesetzt" : detoloader.getBlock(), detoloader.addBack); } break; From a41602bd379c0d0a3078cf90f1f4c4ffbdbeef78 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 18:40:43 +0100 Subject: [PATCH 76/91] Add TPS warping to TPSLimit --- .../steamwar/bausystem/world/TPSLimit_15.java | 34 ++++++++++ .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../bausystem/commands/CommandInfo.java | 27 ++++++-- .../bausystem/commands/CommandTPSLimiter.java | 9 ++- .../CommandTPSLimiterTabComplete.java | 4 +- .../bausystem/world/BauScoreboard.java | 11 +++- .../de/steamwar/bausystem/world/TPSUtils.java | 62 +++++++++++++++++++ 7 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java new file mode 100644 index 0000000..039ef29 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java @@ -0,0 +1,34 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.world; + +import net.minecraft.server.v1_15_R1.SystemUtils; + +import java.util.function.LongSupplier; + +public class TPSLimit_15 { + + public static void init(LongSupplier longSupplier) { + SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong(); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 96bde54..01d66dd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -106,6 +106,7 @@ public class BauSystem extends JavaPlugin implements Listener { new AFKStopper(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); + TPSUtils.init(); } public static BauSystem getPlugin() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 980133b..c3455c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.world.TPSUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; @@ -55,12 +56,26 @@ public class CommandInfo implements CommandExecutor { } sender.sendMessage(membermessage.toString()); - sender.sendMessage(BauSystem.PREFIX + "TPS:§e" + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)); + if (TPSUtils.isWarping()) { + sender.sendMessage(BauSystem.PREFIX + "TPS:§e" + + " " + getTps(TPSWatcher.TPSType.ONE_SECOND) + + " " + getTps(TPSWatcher.TPSType.TEN_SECONDS)); + } else { + sender.sendMessage(BauSystem.PREFIX + "TPS:§e" + + " " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND) + + " " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS) + + " " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE) + + " " + TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES) + + " " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)); + } return false; } + + private double getTps(TPSWatcher.TPSType tpsType) { + if (TPSUtils.isWarping()) { + return TPSWatcher.getTPS(tpsType, Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20)); + } + return TPSWatcher.getTPS(tpsType); + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 7a749c7..badb079 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -21,7 +21,9 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.TPSUtils; import de.steamwar.bausystem.world.Welt; +import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -77,7 +79,7 @@ public class CommandTPSLimiter implements CommandExecutor { try { double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.')); - if (tpsLimitDouble < 0.5 || tpsLimitDouble > 20) { + if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSUtils.isWarpAllowed() ? 40 : 20)) { sendInvalidArgumentMessage(player); return false; } @@ -104,7 +106,8 @@ public class CommandTPSLimiter implements CommandExecutor { loops = (int)Math.ceil(delay); sleepDelay = (long) (50 * delay) / loops; - if (currentTPSLimit == 20) { + TPSUtils.setTPS(currentTPSLimit); + if (currentTPSLimit >= 20) { if (tpsLimiter == null) return; tpsLimiter.cancel(); tpsLimiter = null; @@ -139,7 +142,7 @@ public class CommandTPSLimiter implements CommandExecutor { } public static double getCurrentTPSLimit() { - return currentTPSLimit; + return (double)Math.round(currentTPSLimit * 10.0D) / 10.0D; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java index 9b401ee..8db0904 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.world.TPSUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -30,6 +31,7 @@ import java.util.List; public class CommandTPSLimiterTabComplete implements TabCompleter { private List arguments = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"); + private List argumentsWarped = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"); @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { @@ -37,7 +39,7 @@ public class CommandTPSLimiterTabComplete implements TabCompleter { return new ArrayList<>(); } List validArguments = new ArrayList<>(arguments.size()); - for (String s : arguments) { + for (String s : TPSUtils.isWarpAllowed() ? argumentsWarped : arguments) { if (s.startsWith(args[0])) { validArguments.add(s); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 17873b7..c510a2d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -73,7 +73,7 @@ public class BauScoreboard implements Listener { } strings.add("§4"); - strings.add("§eTPS§8: " + tpsColor() + TPSWatcher.getTPS() + tpsLimit()); + strings.add("§eTPS§8: " + tpsColor() + getTps() + tpsLimit()); int i = strings.size(); HashMap result = new HashMap<>(); @@ -87,7 +87,7 @@ public class BauScoreboard implements Listener { } private String tpsColor() { - double tps = TPSWatcher.getTPS(); + double tps = getTps(); if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) { return "§a"; } @@ -104,4 +104,11 @@ public class BauScoreboard implements Listener { return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } + private double getTps() { + if (TPSUtils.isWarping()) { + return TPSWatcher.getTPS(Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20)); + } + return TPSWatcher.getTPS(); + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java new file mode 100644 index 0000000..2733a80 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java @@ -0,0 +1,62 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.world; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.VersionedRunnable; +import org.bukkit.Bukkit; + +public class TPSUtils { + + private TPSUtils() { + throw new IllegalStateException("Utility Class"); + } + + private static boolean warp = true; + private static long nanoOffset = 0; + private static long nanoDOffset = 0; + + public static void init() { + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + nanoOffset += nanoDOffset; + }, 1, 1); + VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), + new VersionedRunnable(() -> TPSLimit_15.init(() -> nanoOffset), 15)); + } + + public static void setTPS(double tps) { + double d = 50 - (50 / (tps / 20.0)); + long nanos = (long) (d * 1000000); + if (nanos < 0) nanos = 0; + if (nanos > 25000000) nanos = 25000000; + nanoDOffset = nanos; + } + + public static boolean isWarpAllowed() { + return warp; + } + + public static boolean isWarping() { + return nanoDOffset > 0; + } + +} From de2f4a1c53a0fd221e86c99c1004bbc800c54ff2 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 20:56:18 +0100 Subject: [PATCH 77/91] Add VersionedRunnable to CommandDebugStick --- .../bausystem/commands/CommandDebugStick.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDebugStick.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDebugStick.java index 0e5feb1..74e9f66 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDebugStick.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDebugStick.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; -import de.steamwar.core.Core; +import de.steamwar.core.VersionedRunnable; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -42,14 +42,8 @@ public class CommandDebugStick implements CommandExecutor { return false; } - switch(Core.getVersion()){ - case 15: - CommandDebugStick_15.giveStick(player); - break; - case 12: - default: - player.sendMessage(BauSystem.PREFIX + "§cDen Debugstick gibt es nicht in der 1.12."); - } + VersionedRunnable.call(new VersionedRunnable(() -> player.sendMessage(BauSystem.PREFIX + "§cDen Debugstick gibt es nicht in der 1.12."), 8), + new VersionedRunnable(() -> CommandDebugStick_15.giveStick(player), 15)); return false; } } From 461e6d17a0a3574a8eb878ef06552180ce46b0b7 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 21:02:19 +0100 Subject: [PATCH 78/91] Add VersionedRunnable to AutoLoader --- .../de/steamwar/bausystem/world/AutoLoader.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java index 6763ac7..1b83664 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; -import de.steamwar.core.Core; import de.steamwar.core.VersionedCallable; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -225,12 +224,8 @@ public class AutoLoader extends IAutoLoader implements Listener { @Override boolean setRedstone(Location location, boolean active){ - switch(Core.getVersion()){ - case 15: - return AutoLoader_15.setRedstone(location, active); - default: - return AutoLoader_12.setRedstone(location, active); - } + return VersionedCallable.call(new VersionedCallable<>(() -> AutoLoader_12.setRedstone(location, active), 8), + new VersionedCallable<>(() -> AutoLoader_15.setRedstone(location, active), 15)); } @Override @@ -256,12 +251,8 @@ public class AutoLoader extends IAutoLoader implements Listener { @Override public boolean perform() { - switch(Core.getVersion()){ - case 15: - return AutoLoader_15.tntPlaceActionPerform(location); - default: - return AutoLoader_12.tntPlaceActionPerform(location); - } + return VersionedCallable.call(new VersionedCallable<>(() -> AutoLoader_12.tntPlaceActionPerform(location), 8), + new VersionedCallable<>(() -> AutoLoader_15.tntPlaceActionPerform(location), 15)); } @Override From 9dc5c535f5f3b659fa40e63f9d5465cb35ee5380 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 21:02:31 +0100 Subject: [PATCH 79/91] Add VersionedRunnable to Region --- .../de/steamwar/bausystem/world/Region.java | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 0f3d682..e7a6007 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -21,7 +21,7 @@ package de.steamwar.bausystem.world; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.commands.CommandTNT.TNTMode; -import de.steamwar.core.Core; +import de.steamwar.core.VersionedRunnable; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -298,14 +298,8 @@ public class Region { int x = region.minX + offsetX + sizeX/2; int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ/2; - switch(Core.getVersion()){ - case 12: - Region_12.paste(file, x, y, z, rotate); - break; - case 15: - default: - Region_15.fastpaste(file, x, y, z, rotate); - } + VersionedRunnable.call(new VersionedRunnable(() -> Region_12.paste(file, x, y, z, rotate), 8), + new VersionedRunnable(() -> Region_15.fastpaste(file, x, y, z, rotate), 15)); } public void reset(Region region, Schematic schem) throws IOException, NoClipboardException { @@ -345,25 +339,13 @@ public class Region { } private static void paste(File file, int x, int y, int z, boolean rotate){ //Type of protect - switch(Core.getVersion()){ - case 12: - Region_12.paste(file, x, y, z, rotate); - break; - case 15: - default: - Region_15.paste(file, x, y, z, rotate); - } + VersionedRunnable.call(new VersionedRunnable(() -> Region_12.paste(file, x, y, z, rotate), 8), + new VersionedRunnable(() -> Region_15.paste(file, x, y, z, rotate), 15)); } private static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ - switch(Core.getVersion()){ - case 12: - Region_12.paste(clipboard, x, y, z, rotate); - break; - case 15: - default: - Region_15.paste(clipboard, x, y, z, rotate); - } + VersionedRunnable.call(new VersionedRunnable(() -> Region_12.paste(clipboard, x, y, z, rotate), 8), + new VersionedRunnable(() -> Region_15.paste(clipboard, x, y, z, rotate), 15)); } } } From d45c39c528b6119584a9c584a46c6290dd38781d Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 21:02:47 +0100 Subject: [PATCH 80/91] Add VersionedRunnable to RegionListener --- .../de/steamwar/bausystem/world/RegionListener.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index cb1fa12..64f5cf0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.world; import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; @@ -28,10 +29,10 @@ import com.comphenix.protocol.wrappers.BlockPosition; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import de.steamwar.core.VersionedRunnable; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import com.comphenix.protocol.ProtocolLibrary; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -105,13 +106,8 @@ public class RegionListener implements Listener { if(command.startsWith(shortcut)) return true; - switch(Core.getVersion()){ - case 12: - return RegionListener_12.isWorldEditCommand(command); - case 15: - default: - return RegionListener_15.isWorldEditCommand(command); - } + return VersionedCallable.call(new VersionedCallable<>(() -> RegionListener_12.isWorldEditCommand(command), 8), + new VersionedCallable<>(() -> RegionListener_15.isWorldEditCommand(command), 15)); } @EventHandler From 1696aa4e546dc3ed2910040e04d4e188961b95f3 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 21:03:00 +0100 Subject: [PATCH 81/91] Add VersionedRunnable to ScriptListener --- .../de/steamwar/bausystem/world/ScriptListener.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 60c3121..07cffe3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -23,7 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.commands.CommandScript; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.tracer.record.RecordStateMachine; -import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -72,13 +72,8 @@ public class ScriptListener implements Listener { } private boolean isNoBook(ItemStack item){ - switch(Core.getVersion()){ - case 12: - return ScriptListener_12.isNoBook(item); - case 15: - default: - return ScriptListener_15.isNoBook(item); - } + return VersionedCallable.call(new VersionedCallable<>(() -> ScriptListener_12.isNoBook(item), 8), + new VersionedCallable<>(() -> ScriptListener_15.isNoBook(item), 15)); } private static class ScriptExecutor { From 5372f8440951719012f7e7325ef170b56abe55e6 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 9 Feb 2021 21:07:24 +0100 Subject: [PATCH 82/91] Optimize CommandInfo --- .../bausystem/commands/CommandInfo.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index c3455c4..7783971 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -56,18 +56,16 @@ public class CommandInfo implements CommandExecutor { } sender.sendMessage(membermessage.toString()); - if (TPSUtils.isWarping()) { - sender.sendMessage(BauSystem.PREFIX + "TPS:§e" + - " " + getTps(TPSWatcher.TPSType.ONE_SECOND) + - " " + getTps(TPSWatcher.TPSType.TEN_SECONDS)); - } else { - sender.sendMessage(BauSystem.PREFIX + "TPS:§e" + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)); + StringBuilder tpsMessage = new StringBuilder(); + tpsMessage.append(BauSystem.PREFIX).append("TPS:§e"); + tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND)); + tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS)); + if (!TPSUtils.isWarping()) { + tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE)); + tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES)); + tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)); } + sender.sendMessage(tpsMessage.toString()); return false; } From 97926c08d5f5dee37a02c3e2f4a3ddcb4e9cb335 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 9 Feb 2021 21:14:52 +0100 Subject: [PATCH 83/91] Optimize TPSLimit_15 Optimize CommandInfo Optimize CommandTPSLimiter Optimize CommandTPSLimiterTabComplete Optimize BauScoreboard Optimize TPSUtils --- .../steamwar/bausystem/world/TPSLimit_15.java | 1 - .../bausystem/commands/CommandInfo.java | 9 ++------- .../bausystem/commands/CommandTPSLimiter.java | 2 +- .../commands/CommandTPSLimiterTabComplete.java | 6 ++++-- .../steamwar/bausystem/world/BauScoreboard.java | 11 ++--------- .../de/steamwar/bausystem/world/TPSUtils.java | 17 +++++++++-------- 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java index 039ef29..452bc74 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java @@ -16,7 +16,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * / */ package de.steamwar.bausystem.world; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 7783971..6043e74 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -32,6 +32,8 @@ import org.bukkit.entity.Player; import java.util.List; +import static de.steamwar.bausystem.world.TPSUtils.getTps; + public class CommandInfo implements CommandExecutor { @Override @@ -69,11 +71,4 @@ public class CommandInfo implements CommandExecutor { return false; } - private double getTps(TPSWatcher.TPSType tpsType) { - if (TPSUtils.isWarping()) { - return TPSWatcher.getTPS(tpsType, Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20)); - } - return TPSWatcher.getTPS(tpsType); - } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index badb079..350b421 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -98,7 +98,7 @@ public class CommandTPSLimiter implements CommandExecutor { } private void sendInvalidArgumentMessage(Player player) { - player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 0,5 und 20, und 'default' erlaubt."); + player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 0,5 und " + (TPSUtils.isWarpAllowed() ? 40 : 20) + ", und 'default' erlaubt."); } private void tpsLimiter() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java index 8db0904..035055d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java @@ -31,7 +31,9 @@ import java.util.List; public class CommandTPSLimiterTabComplete implements TabCompleter { private List arguments = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"); - private List argumentsWarped = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"); + public CommandTPSLimiterTabComplete() { + if (TPSUtils.isWarpAllowed()) arguments.addAll(Arrays.asList("21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40")); + } @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { @@ -39,7 +41,7 @@ public class CommandTPSLimiterTabComplete implements TabCompleter { return new ArrayList<>(); } List validArguments = new ArrayList<>(arguments.size()); - for (String s : TPSUtils.isWarpAllowed() ? argumentsWarped : arguments) { + for (String s : arguments) { if (s.startsWith(args[0])) { validArguments.add(s); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index c510a2d..0a93414 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -73,7 +73,7 @@ public class BauScoreboard implements Listener { } strings.add("§4"); - strings.add("§eTPS§8: " + tpsColor() + getTps() + tpsLimit()); + strings.add("§eTPS§8: " + tpsColor() + TPSUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); int i = strings.size(); HashMap result = new HashMap<>(); @@ -87,7 +87,7 @@ public class BauScoreboard implements Listener { } private String tpsColor() { - double tps = getTps(); + double tps = TPSUtils.getTps(TPSWatcher.TPSType.ONE_SECOND); if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) { return "§a"; } @@ -104,11 +104,4 @@ public class BauScoreboard implements Listener { return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } - private double getTps() { - if (TPSUtils.isWarping()) { - return TPSWatcher.getTPS(Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20)); - } - return TPSWatcher.getTPS(); - } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java index 2733a80..0c38b78 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java @@ -16,12 +16,13 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * / */ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.commands.CommandTPSLimiter; +import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import org.bukkit.Bukkit; @@ -36,19 +37,14 @@ public class TPSUtils { private static long nanoDOffset = 0; public static void init() { - Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - nanoOffset += nanoDOffset; - }, 1, 1); + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1); VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), new VersionedRunnable(() -> TPSLimit_15.init(() -> nanoOffset), 15)); } public static void setTPS(double tps) { double d = 50 - (50 / (tps / 20.0)); - long nanos = (long) (d * 1000000); - if (nanos < 0) nanos = 0; - if (nanos > 25000000) nanos = 25000000; - nanoDOffset = nanos; + nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 25000000)); } public static boolean isWarpAllowed() { @@ -59,4 +55,9 @@ public class TPSUtils { return nanoDOffset > 0; } + public static double getTps(TPSWatcher.TPSType tpsType) { + if (TPSUtils.isWarping()) return TPSWatcher.getTPS(tpsType, Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20)); + return TPSWatcher.getTPS(tpsType); + } + } From 813b8803b4326cba46719cff4e40869d5adc3b03 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 9 Feb 2021 21:20:36 +0100 Subject: [PATCH 84/91] Fix CommandTPSLimiterTabComplete --- .../bausystem/commands/CommandTPSLimiterTabComplete.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java index 035055d..14401a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java @@ -30,7 +30,7 @@ import java.util.List; public class CommandTPSLimiterTabComplete implements TabCompleter { - private List arguments = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"); + private List arguments = new ArrayList<>(Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")); public CommandTPSLimiterTabComplete() { if (TPSUtils.isWarpAllowed()) arguments.addAll(Arrays.asList("21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40")); } From 88028286767cf987935aa6a4321edb834550a817 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 11 Feb 2021 19:39:06 +0100 Subject: [PATCH 85/91] Fix pr stuff --- .../bausystem/world/{TPSLimit_15.java => TPSUtils_15.java} | 2 +- .../de/steamwar/bausystem/commands/CommandTPSLimiter.java | 1 - .../bausystem/commands/CommandTPSLimiterTabComplete.java | 1 + .../src/de/steamwar/bausystem/world/TPSUtils.java | 6 ++++-- 4 files changed, 6 insertions(+), 4 deletions(-) rename BauSystem_15/src/de/steamwar/bausystem/world/{TPSLimit_15.java => TPSUtils_15.java} (97%) diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/TPSUtils_15.java similarity index 97% rename from BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java rename to BauSystem_15/src/de/steamwar/bausystem/world/TPSUtils_15.java index 452bc74..4cfeaac 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/TPSLimit_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/TPSUtils_15.java @@ -24,7 +24,7 @@ import net.minecraft.server.v1_15_R1.SystemUtils; import java.util.function.LongSupplier; -public class TPSLimit_15 { +public class TPSUtils_15 { public static void init(LongSupplier longSupplier) { SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 350b421..f997911 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.TPSUtils; import de.steamwar.bausystem.world.Welt; -import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java index 14401a5..00dc116 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java @@ -31,6 +31,7 @@ import java.util.List; public class CommandTPSLimiterTabComplete implements TabCompleter { private List arguments = new ArrayList<>(Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")); + public CommandTPSLimiterTabComplete() { if (TPSUtils.isWarpAllowed()) arguments.addAll(Arrays.asList("21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40")); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java index 0c38b78..563e01a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java @@ -37,9 +37,11 @@ public class TPSUtils { private static long nanoDOffset = 0; public static void init() { - Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1); VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), - new VersionedRunnable(() -> TPSLimit_15.init(() -> nanoOffset), 15)); + new VersionedRunnable(() -> { + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1); + TPSUtils_15.init(() -> nanoOffset); + }, 15)); } public static void setTPS(double tps) { From 778e5565c525a26580f367ce16790a3c76eb5df2 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 12 Feb 2021 11:08:18 +0100 Subject: [PATCH 86/91] Optimize Imports --- .../src/de/steamwar/bausystem/commands/TPSLimit_12.java | 2 -- .../src/de/steamwar/bausystem/commands/TPSLimit_15.java | 1 - 2 files changed, 3 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java b/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java index b2ebadc..4cd4c22 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java @@ -28,9 +28,7 @@ import org.bukkit.entity.FallingBlock; import org.bukkit.entity.TNTPrimed; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; class TPSLimit_12 { diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java index a1621dc..2860e2a 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java @@ -29,7 +29,6 @@ import org.bukkit.entity.TNTPrimed; import java.util.ArrayList; import java.util.List; -import java.util.Set; class TPSLimit_15 { From 2610359d670c29639f9dfeb3e9a1c69d369944e3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 13 Feb 2021 09:33:01 +0100 Subject: [PATCH 87/91] Improve Give Commands --- .../steamwar/bausystem/commands/CommandDebugStick_15.java | 5 ++++- .../de/steamwar/bausystem/commands/CommandDetonator.java | 6 +++++- .../src/de/steamwar/bausystem/commands/CommandSkull.java | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java index ec1560c..88e5b3b 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java @@ -27,6 +27,9 @@ class CommandDebugStick_15 { private CommandDebugStick_15(){} static void giveStick(Player player){ - player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK, 1)); + if(player.getInventory().getItemInMainHand().getType() == Material.AIR) + player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK)); + else + player.getInventory().addItem(new ItemStack(Material.DEBUG_STICK)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 52bc21e..4446023 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Welt; +import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -62,7 +63,10 @@ public class CommandDetonator implements CommandExecutor { case "wand": case "detonator": case "item": - player.getInventory().setItemInMainHand(Detonator.WAND); + if(player.getInventory().getItemInMainHand().getType() == Material.AIR) + player.getInventory().setItemInMainHand(Detonator.WAND); + else + player.getInventory().addItem(Detonator.WAND); player.updateInventory(); Detonator.getDetonator(player); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java index 0208ca7..9a0ca95 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; +import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -46,7 +47,11 @@ public class CommandSkull implements CommandExecutor { assert sm != null; sm.setDisplayName("§e" + args[0] + "§8s Kopf"); is.setItemMeta(sm); - p.getInventory().setItemInMainHand(is); + if(p.getInventory().getItemInMainHand().getType() == Material.AIR) + p.getInventory().setItemInMainHand(is); + else + p.getInventory().addItem(is); + return false; } } From 7025dabd8a4b0ec2604fffaced4cb6a986857c8b Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 14 Feb 2021 11:19:46 +0100 Subject: [PATCH 88/91] Fix GuiTraceShow --- .../src/de/steamwar/bausystem/tracer/TNTTracer_12.java | 8 ++++++++ .../src/de/steamwar/bausystem/tracer/TNTTracer_15.java | 8 ++++++++ .../src/de/steamwar/bausystem/gui/GuiTraceShow.java | 9 +++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 52daf91..bfed2bb 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -34,4 +34,12 @@ public class TNTTracer_12 { return material == Material.WATER || material == Material.STATIONARY_WATER; } + public static Material getTraceShowMaterial() { + return Material.CONCRETE; + } + + public static Material getTraceHideMaterial() { + return Material.CONCRETE; + } + } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 16be514..ace2691 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -44,4 +44,12 @@ public class TNTTracer_15 { return ((Waterlogged) data).isWaterlogged(); } + public static Material getTraceShowMaterial() { + return Material.LIME_CONCRETE; + } + + public static Material getTraceHideMaterial() { + return Material.RED_CONCRETE; + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java index 78e7a8a..56b0fa3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -22,9 +22,12 @@ package de.steamwar.bausystem.gui; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.TNTTracer_12; +import de.steamwar.bausystem.tracer.TNTTracer_15; import de.steamwar.bausystem.tracer.show.ShowModeParameter; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.tracer.show.mode.EntityShowMode; +import de.steamwar.core.VersionedCallable; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Material; @@ -73,14 +76,16 @@ public class GuiTraceShow { private static void setActiveShow(Player player, SWInventory swInventory) { if (TraceShowManager.hasActiveShow(player)) { - SWItem shown = new SWItem(Material.LIME_CONCRETE, "§aTraces angezeigt", new ArrayList<>(), false, clickType -> { + Material showMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_12::getTraceShowMaterial, 8), new VersionedCallable<>(TNTTracer_15::getTraceShowMaterial, 14)); + SWItem shown = new SWItem(showMaterial, (byte) 5, "§aTraces angezeigt", new ArrayList<>(), false, clickType -> { TraceShowManager.hide(player); player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet"); setActiveShow(player, swInventory); }); swInventory.setItem(1, shown); } else { - SWItem hidden = new SWItem(Material.RED_CONCRETE, "§cTraces ausgeblendet", new ArrayList<>(), false, clickType -> { + Material hideMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_12::getTraceHideMaterial, 8), new VersionedCallable<>(TNTTracer_15::getTraceHideMaterial, 14)); + SWItem hidden = new SWItem(hideMaterial, (byte) 14, "§cTraces ausgeblendet", new ArrayList<>(), false, clickType -> { show(player); player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); setActiveShow(player, swInventory); From 311c41383b64c65ddb19660a2e313496122aa7b7 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 14 Feb 2021 14:45:30 +0100 Subject: [PATCH 89/91] Fix GuiTraceShow --- .../src/de/steamwar/bausystem/tracer/TNTTracer_12.java | 4 ++++ .../src/de/steamwar/bausystem/tracer/TNTTracer_15.java | 4 ++++ .../src/de/steamwar/bausystem/gui/GuiTraceShow.java | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index bfed2bb..4f1ed78 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -42,4 +42,8 @@ public class TNTTracer_12 { return Material.CONCRETE; } + public static Material getTraceXZMaterial() { + return Material.STEP; + } + } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index ace2691..20ef07f 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -52,4 +52,8 @@ public class TNTTracer_15 { return Material.RED_CONCRETE; } + public static Material getTraceXZMaterial() { + return Material.QUARTZ_SLAB; + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java index 56b0fa3..c3625f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -60,7 +60,8 @@ public class GuiTraceShow { swInventory.setItem(5, water); swInventory.setCallback(5, clickType -> toggleHideTNTinWaterExploded(player, swInventory, water)); - SWItem interpolateY = new SWItem(Material.QUARTZ_STAIRS, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse."), false, clickType -> {}); + Material xzMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_12::getTraceXZMaterial, 8), new VersionedCallable<>(TNTTracer_15::getTraceXZMaterial, 14)); + SWItem interpolateY = new SWItem(xzMaterial, (byte) 7, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse."), false, clickType -> {}); swInventory.setItem(6, interpolateY); swInventory.setCallback(6, clickType -> toggleInterpolateYPosition(player, swInventory, interpolateY)); From 870bbd94f0f65bb8158e1d19974880937b4cb51c Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 14 Feb 2021 18:09:08 +0100 Subject: [PATCH 90/91] Fix pr stuff --- .../src/de/steamwar/bausystem/gui/GuiTraceShow.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java index c3625f7..07f1886 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -60,12 +60,12 @@ public class GuiTraceShow { swInventory.setItem(5, water); swInventory.setCallback(5, clickType -> toggleHideTNTinWaterExploded(player, swInventory, water)); - Material xzMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_12::getTraceXZMaterial, 8), new VersionedCallable<>(TNTTracer_15::getTraceXZMaterial, 14)); - SWItem interpolateY = new SWItem(xzMaterial, (byte) 7, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse."), false, clickType -> {}); + SWItem interpolateY = new SWItem(Material.QUARTZ_STAIRS, (byte) 7, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse."), false, clickType -> {}); swInventory.setItem(6, interpolateY); swInventory.setCallback(6, clickType -> toggleInterpolateYPosition(player, swInventory, interpolateY)); - SWItem interpolateXZ = new SWItem(Material.QUARTZ_SLAB, "§eInterpolation §7XZ-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der XZ-Achse."), false, clickType -> {}); + Material xzMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_12::getTraceXZMaterial, 8), new VersionedCallable<>(TNTTracer_15::getTraceXZMaterial, 14)); + SWItem interpolateXZ = new SWItem(xzMaterial, "§eInterpolation §7XZ-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der XZ-Achse."), false, clickType -> {}); swInventory.setItem(7, interpolateXZ); swInventory.setCallback(7, clickType -> toggleInterpolateXZPosition(player, swInventory, interpolateXZ)); // Water Bucket (-water) From 5aaa1aaa38e963d9fc7618ee5a604dc0ac13756f Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 15 Feb 2021 10:37:20 +0100 Subject: [PATCH 91/91] Fix pr stuff --- .../src/de/steamwar/bausystem/gui/GuiTraceShow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java index 07f1886..8331f02 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/gui/GuiTraceShow.java @@ -60,12 +60,12 @@ public class GuiTraceShow { swInventory.setItem(5, water); swInventory.setCallback(5, clickType -> toggleHideTNTinWaterExploded(player, swInventory, water)); - SWItem interpolateY = new SWItem(Material.QUARTZ_STAIRS, (byte) 7, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse."), false, clickType -> {}); + SWItem interpolateY = new SWItem(Material.QUARTZ_STAIRS, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse."), false, clickType -> {}); swInventory.setItem(6, interpolateY); swInventory.setCallback(6, clickType -> toggleInterpolateYPosition(player, swInventory, interpolateY)); Material xzMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_12::getTraceXZMaterial, 8), new VersionedCallable<>(TNTTracer_15::getTraceXZMaterial, 14)); - SWItem interpolateXZ = new SWItem(xzMaterial, "§eInterpolation §7XZ-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der XZ-Achse."), false, clickType -> {}); + SWItem interpolateXZ = new SWItem(xzMaterial, (byte) 7, "§eInterpolation §7XZ-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der XZ-Achse."), false, clickType -> {}); swInventory.setItem(7, interpolateXZ); swInventory.setCallback(7, clickType -> toggleInterpolateXZPosition(player, swInventory, interpolateXZ)); // Water Bucket (-water)