From 85a8dae7a9a885e2225839483d49a2fd53c8e71f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 May 2023 20:40:40 +0200 Subject: [PATCH 01/23] Add Gradle Plugin Signed-off-by: Chaoscaot --- build.gradle | 193 +----------------------------------------------- settings.gradle | 9 +++ 2 files changed, 10 insertions(+), 192 deletions(-) diff --git a/build.gradle b/build.gradle index 653fbc20..48c8df51 100644 --- a/build.gradle +++ b/build.gradle @@ -16,10 +16,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - - -import org.apache.tools.ant.taskdefs.condition.Os - plugins { // Adding the base plugin fixes the following gradle warnings in IntelliJ: // @@ -32,43 +28,12 @@ plugins { id 'application' id 'com.github.johnrengelman.shadow' version '5.0.0' -} - -ext.swdep = { s -> - if (file("${rootDir}/lib/${s}.jar").exists()) { - return files("${rootDir}/lib/${s}.jar") - } else { - if (s.contains("-")) { - return "de.steamwar:${s.toLowerCase().replace('-', ':')}" - } else { - return "de.steamwar:${s.toLowerCase()}:RELEASE" - } - } + id 'de.steamwar.gradle' version 'RELEASE' } group 'de.steamwar' version '' -Properties steamwarProperties = new Properties() -if (file("steamwar.properties").exists()) { - steamwarProperties.load(file("steamwar.properties").newDataInputStream()) -} - -ext { - buildName = 'BauSystem2.0' - artifactName = 'bausystem2.0' - - uberJarName = "${buildName}-all.jar" - jarName = "${artifactName}.jar" - libs = "${buildDir}/libs" - - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - operatingSystem = "windows" - } else { - operatingSystem = "unix" - } -} - compileJava.options.encoding = 'UTF-8' compileJava.options.compilerArgs << '-parameter' @@ -96,14 +61,6 @@ allprojects { maven { url = uri('https://libraries.minecraft.net') } - - maven { - url = uri('https://steamwar.de/maven/') - credentials { - username = steamwarProperties.getProperty("maven.username") - password = steamwarProperties.getProperty("maven.password") - } - } } } @@ -117,151 +74,3 @@ dependencies { } } } - -task buildProject { - description 'Build this project' - group "Steamwar" - - dependsOn build -} - -task finalizeProject { - description 'Finalize this project' - group "Steamwar" - - doLast { - if ("${buildDir}" == null) { - return - } - delete fileTree("${libs}").matching { - exclude("${uberJarName}") - } - file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName)) - } -} -build.finalizedBy(finalizeProject) - -if (steamwarProperties.containsKey("hostname")) { - String hostname = steamwarProperties.get("hostname") - - String type = steamwarProperties.getOrDefault("type", "Bau19") - String world = steamwarProperties.getOrDefault("world", "") - String pluginFolder = steamwarProperties.getOrDefault("pluginFolder", "") - - task uploadProject { - description 'Upload this project' - group "Steamwar" - - doLast { - await(shell("scp ${libs}/${jarName} ${hostname}:${pluginFolder}")) - if (steamwarProperties.getOrDefault("directStart", "false") == "false" && !answer("Start ${server} server?")) { - return - } - serverStart(type, hostname, world, pluginFolder) - } - } - uploadProject.dependsOn(buildProject) - - task startDevServer { - description 'Start the DevServer' - group "Steamwar" - - doLast { - serverStart(server, "", hostname) - } - } -} - -private def await(Process proc) { - def out = new StringBuilder() - def err = new StringBuilder() - proc.waitForProcessOutput(out, err) - return [out, err, proc.exitValue()] -} - -private def shell(String command) { - if (operatingSystem == "unix") { - return ['bash', '-c', command].execute() - } else { - return ["cmd", "/c", command].execute() - } -} - -private def serverStart(String type, String hostname, String worldName, String pluginFolder) { - def proc = shell("ssh -t ${hostname} \"./binarys/dev.py ${type} -w ${worldName} -p ${pluginFolder}\"") - - Set strings = new HashSet<>() - File file = new File("${projectDir}/ignoredlog"); - if (file.exists()) { - new BufferedReader(new InputStreamReader(new FileInputStream(file))).readLines().forEach({ s -> - strings.add(s) - }) - } - - Thread outputThread = new Thread({ - Reader reader = proc.getInputStream().newReader(); - Writer writer = System.out.newWriter(); - try { - while (proc.alive) { - String s = reader.readLine() - if (s == null) { - return - } - if (strings.stream().anyMatch({check -> s.contains(check)})) { - continue - } - writer.write(s + "\n") - writer.flush() - } - } catch (IOException e) { - // Ignored - } - }) - outputThread.setName("${type} - OutputThread") - outputThread.start() - - Writer writer - Thread inputThread = new Thread({ - Reader reader = System.in.newReader() - writer = proc.getOutputStream().newWriter() - try { - while (proc.alive) { - String s = reader.readLine() - writer.write(s + "\n") - writer.flush() - } - } catch (IOException e) { - // Ignored - } - }) - inputThread.setName("${type} - InputThread") - inputThread.start() - - gradle.buildFinished { buildResult -> - if (!proc.alive) { - return - } - writer = proc.getOutputStream().newWriter() - writer.write("stop\n") - writer.flush() - awaitClose(proc, outputThread, inputThread) - } - awaitClose(proc, outputThread, inputThread) -}; - -private static def awaitClose(Process proc, Thread outputThread, Thread inputThread) { - while (proc.alive) { - Thread.sleep(10) - } - proc.closeStreams() - outputThread.interrupt() - inputThread.interrupt() -} - -private def answer(String question) { - while (System.in.available() > 0) System.in.read() - println(question) - boolean valid = "Yy".contains(((char) System.in.read()).toString()) - while (System.in.available() > 0) System.in.read() - return valid -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7c452a9c..5e22de72 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,6 +17,15 @@ * along with this program. If not, see . */ +pluginManagement { + repositories { + gradlePluginPortal() + maven { + url 'https://steamwar.de/maven/' + } + } +} + rootProject.name = 'BauSystem2.0' file('.').listFiles().each { From 5d56f4238da3a61cb7040cb5b52d3a737e715328 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 12 Jun 2023 21:43:42 +0200 Subject: [PATCH 02/23] Add ShieldPrinting help messages Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 12 ++++++++++++ BauSystem_Main/src/BauSystem_de.properties | 12 ++++++++++++ .../shieldprinting/ShieldPrintingCommand.java | 11 +++++++++++ 3 files changed, 35 insertions(+) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 448fd952..44fd1772 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -524,6 +524,18 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server # Shield Printing +SHIELD_PRINTING_HELP_START = §8/§eshieldprinting start §8- §7Starts the shield printing +SHIELD_PRINTING_HELP_COPY = §8/§eshieldprinting copy §8- §7Copies the shield configuration +SHIELD_PRINTING_HELP_APPLY = §8/§eshieldprinting apply §8- §7Applies the shield configuration +SHIELD_PRINTING_HELP_STOP = §8/§eshieldprinting stop §8- §7Stops the shield printing +SHIELD_PRINTING_HELP_STEP_1 = §81. §7Paste the schematic you want to use +SHIELD_PRINTING_HELP_STEP_2 = §82. §7Start the shield printing with §8/§eshieldprinting start +SHIELD_PRINTING_HELP_STEP_3 = §83. §7Wait until the shield printing is finished +SHIELD_PRINTING_HELP_STEP_4 = §84. §7Edit the shields if necessary +SHIELD_PRINTING_HELP_STEP_5 = §85. §7Copy the shields printing with §8/§eshieldprinting copy +SHIELD_PRINTING_HELP_STEP_6 = §86. §7Paste the original schematic +SHIELD_PRINTING_HELP_STEP_7 = §87. §7Apply the shield printing with §8/§eshieldprinting apply + SHIELD_PRINTING_NO_REGION = §cYou are not in a region. SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 804afa46..9730a04b 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -516,6 +516,18 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server # Shield Printing +SHIELD_PRINTING_HELP_START = §8/§eshieldprinting start §8- §7Starte das Schild drucken +SHIELD_PRINTING_HELP_COPY = §8/§eshieldprinting copy §8- §7Kopiert die Schilder +SHIELD_PRINTING_HELP_APPLY = §8/§eshieldprinting apply §8- §7Wendet die Schilder an +SHIELD_PRINTING_HELP_STOP = §8/§eshieldprinting stop §8- §7Stoppt das Schild drucken +SHIELD_PRINTING_HELP_STEP_1 = §81. §7Füge die Schematic in die Welt ein +SHIELD_PRINTING_HELP_STEP_2 = §82. §7Starte das Schild drucken mit §8/§eshieldprinting start +SHIELD_PRINTING_HELP_STEP_3 = §83. §7Warte bis alle Schilde ausgefahren sind +SHIELD_PRINTING_HELP_STEP_4 = §84. §7Editiere die Schilde wenn nötig +SHIELD_PRINTING_HELP_STEP_5 = §85. §7Kopiere das gedruckte mit §8/§eshieldprinting copy +SHIELD_PRINTING_HELP_STEP_6 = §86. §7Füge die originale Schematic wieder ein +SHIELD_PRINTING_HELP_STEP_7 = §87. §7Wende das gedruckte mit §8/§eshieldprinting apply§7 an + SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java index a72443f5..34b912c2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -38,6 +38,17 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { public ShieldPrintingCommand() { super("shieldprinting"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_START"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_COPY"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_APPLY"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_STOP"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_1"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_2"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_3"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_4"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_5"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_6"); + addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_7"); } static final Map SHIELD_PRINTING_MAP = new HashMap<>(); From 0ebfaae4c17340d6fb33229218ad55571983f896 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 13 Jun 2023 22:34:58 +0200 Subject: [PATCH 03/23] Fix typo --- BauSystem_Main/src/BauSystem_de.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 9730a04b..89e8f48a 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -1304,7 +1304,7 @@ WARP_EXISTS=§7Ein Warp mit dem namen §e{0} §7existiert bereits WARP_NAME_RESERVED=§7Du kannst nicht §c{0} §7als name für einen Warp nutzen WARP_CREATED=§7Der Warp §e{0} §7wurde erstellt WARP_DELETE_HOVER=§e{0} §7löschen -WARP_DELETED=§e{0} §7wurde gelöcht +WARP_DELETED=§e{0} §7wurde gelöscht WARP_TELEPORT_HOVER=§7Zu §e{0} §7teleportieren WARP_MATERIAL_CHOOSE=Material auswählen WARP_GUI_NAME=Warps From 3d4468ef8cbeb070be1de2252870c759b25ad4c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 14 Jun 2023 17:03:29 +0200 Subject: [PATCH 04/23] Add Tracer to global Region Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 - BauSystem_Main/src/BauSystem_de.properties | 1 - .../features/tracer/TraceCommand.java | 6 --- .../tracer/TraceScoreboardElement.java | 14 +++++-- .../features/tracer/record/Recorder.java | 39 ++----------------- 5 files changed, 15 insertions(+), 46 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 44fd1772..6b641c33 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -763,7 +763,6 @@ TRACE_MESSAGE_ISOLATE = §aTNT-positions isolated TRACE_MESSAGE_UNISOLATE = §cTNT-positions hidden TRACE_MESSAGE_CLICK_ISOLATE = §eClick to §aisolate§8/§cunisolate TRACE_MESSAGE_DISALLOWED = §cYou are not allowed to use the TNT-Tracer here -TRACE_MESSAGE_NO_REGION = §cYou are not in a region TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Starts recording of all TNT-positions TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Starts a single recording of all TNT-positions diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 9730a04b..3e788236 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -735,7 +735,6 @@ TRACE_MESSAGE_ISOLATE = §aTNT-Positionen isoliert TRACE_MESSAGE_UNISOLATE = §cTNT-Positionen ausgeblendet TRACE_MESSAGE_CLICK_ISOLATE = §eKlicken zum §aisolieren§8/§causblenden TRACE_MESSAGE_DISALLOWED = §cDu darfst hier nicht den TNT-Tracer nutzen -TRACE_MESSAGE_NO_REGION = §cDu bist in keiner Region TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Startet eine einzelne Aufnahme aller TNT-Positionen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index b79d08f0..f18147f3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.features.tracer.gui.TraceGui; import de.steamwar.bausystem.features.tracer.record.*; import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.*; -import de.steamwar.bausystem.features.tracer.show.EntityShowMode; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.command.PreviousArguments; @@ -262,11 +261,6 @@ public class TraceCommand extends SWCommand { messageSender.send("TRACE_MESSAGE_DISALLOWED", player); return false; } - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - messageSender.send("TRACE_MESSAGE_NO_REGION", player); - return false; - } return true; }; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java index 5e955824..87ae3876 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java @@ -21,12 +21,15 @@ package de.steamwar.bausystem.features.tracer; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.StoredRecords; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; +import java.util.List; + @Linked public class TraceScoreboardElement implements ScoreboardElement { @@ -45,9 +48,14 @@ public class TraceScoreboardElement implements ScoreboardElement { String traceScore = Recorder.INSTANCE.get(region).scoreboard(p); if (traceScore != null) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore; - } else if (!(Recorder.INSTANCE.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { - return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p); } - return null; + List records = StoredRecords.getRecords(region); + if (records.isEmpty()) { + return null; + } + if (records.stream().allMatch(record -> record.getTnt().isEmpty())) { + return null; + } + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 85d2ef2a..3a0bfe7b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -27,7 +27,6 @@ import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -37,7 +36,9 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Collectors; @Linked @@ -49,36 +50,6 @@ public class Recorder implements Listener { INSTANCE = this; } - public static class NoopTraceRecorder implements TraceRecorder { - @Override - public String scoreboard(Player player) { - return null; - } - - @Override - public void spawn(TNTPrimed tntPrimed) { - } - - @Override - public void tick(TNTPrimed tntPrimed) { - } - - @Override - public void explode(TNTPrimed tntPrimed, boolean b) { - } - - @Override - public String scriptState() { - return "OFF"; - } - - @Override - public long scriptTime() { - return 0; - } - } - private static final NoopTraceRecorder NOOP = new NoopTraceRecorder(); - private static class DisabledTracerRecorder implements TraceRecorder { @Override public String scoreboard(Player player) { @@ -115,8 +86,6 @@ public class Recorder implements Listener { instance = this; } - private final World world = Bukkit.getWorlds().get(0); - private Map regionTraceRecorderMap = new HashMap<>(); private Map tntTraceRecorderMap = new HashMap<>(); @@ -125,7 +94,7 @@ public class Recorder implements Listener { } public TraceRecorder get(Region region) { - return regionTraceRecorderMap.getOrDefault(region, region.isGlobal() ? NOOP : DISABLED); + return regionTraceRecorderMap.getOrDefault(region, DISABLED); } public void set(Region region, TraceRecorder traceRecorder) { From e01d551a211b9c18699d6d052db27fc5929911cf Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 14 Jun 2023 17:12:09 +0200 Subject: [PATCH 05/23] Update LoaderMovement Signed-off-by: yoyosource --- .../bausystem/features/tracer/TracerBauGuiItem.java | 4 ---- .../bausystem/features/tracer/show/TraceShowManager.java | 6 ------ 2 files changed, 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TracerBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TracerBauGuiItem.java index d309b132..5df27f45 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TracerBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TracerBauGuiItem.java @@ -46,10 +46,6 @@ public class TracerBauGuiItem extends BauGuiItem { @Override public ItemStack getItem(Player player) { Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return SWUtils.setCustomModelData(new SWItem(Material.OBSERVER, BauSystem.MESSAGE.parse("TRACE_GUI_ITEM_NAME", player), Collections.emptyList(), false, clickType -> { - }), 1).getItemStack(); - } return SWUtils.setCustomModelData(new SWItem(Material.OBSERVER, BauSystem.MESSAGE.parse("TRACE_GUI_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("TRACE_GUI_ITEM_LORE", player, Recorder.INSTANCE.get(region).scoreboard(player))), false, clickType -> { }), 1).getItemStack(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java index 44ac27c5..5cebaa1c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java @@ -47,9 +47,6 @@ public class TraceShowManager implements Listener { hide(player); Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return; - } Map> regionalShowModes = showModes.computeIfAbsent(region, __ -> new HashMap<>()); regionalShowModes.put(player, traceShowMode); StoredRecords.show(region, player, traceShowMode); @@ -57,9 +54,6 @@ public class TraceShowManager implements Listener { public static void hide(Player player) { Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return; - } Map> regionalShowModes = showModes.get(region); if (regionalShowModes == null) { return; From 8a5c3b164788b575bf12edd2a0cfdde31c51181d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 15 Jun 2023 22:49:38 +0200 Subject: [PATCH 06/23] Add unlimited TPS and better AFKStopperListener Signed-off-by: yoyosource --- .../features/tpslimit/TPSLimitCommand.java | 16 ++++-- .../features/tpslimit/TPSLimitUtils.java | 4 +- .../features/tpslimit/TPSWarpUtils.java | 3 +- .../features/world/AFKStopperListener.java | 50 +++++++++++++------ 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java index 778b6f82..20259a4c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java @@ -31,20 +31,28 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; @Linked public class TPSLimitCommand extends SWCommand implements Enable { - private final List tabCompletions = new ArrayList<>(Arrays.asList("0,5", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")); + private final List tabCompletions = new ArrayList<>(); + + static final int MAX_TPS = Integer.MAX_VALUE; public TPSLimitCommand() { super("tpslimit"); + tabCompletions.add("0,5"); + for (int i = 0; i <= 20; i++) { + tabCompletions.add(i + ""); + } if (TPSWarpUtils.isWarpAllowed()) { for (int i = 20; i <= 60; i += 5) { tabCompletions.add(i + ""); } + for (int i = 60; i <= 240; i += 10) { + tabCompletions.add(i + ""); + } } if (FreezeUtils.freezeEnabled) { tabCompletions.add("0"); @@ -79,7 +87,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { sendNewTPSLimitMessage(true); return; } - if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) { + if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20)) { sendInvalidArgumentMessage(p); return; } @@ -121,6 +129,6 @@ public class TPSLimitCommand extends SWCommand implements Enable { } private void sendInvalidArgumentMessage(Player player) { - BauSystem.MESSAGE.send("TPSLIMIT_INVALID", player, TPSWarpUtils.isWarpAllowed() ? 60 : 20, FreezeUtils.freezeEnabled ? BauSystem.MESSAGE.parse("TPSLIMIT_INVALID_FROZEN", player) : ""); + BauSystem.MESSAGE.send("TPSLIMIT_INVALID", player, TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20, FreezeUtils.freezeEnabled ? BauSystem.MESSAGE.parse("TPSLIMIT_INVALID_FROZEN", player) : ""); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index abb28103..6e333f03 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -32,6 +32,8 @@ import org.bukkit.scheduler.BukkitTask; import java.util.function.BiFunction; +import static de.steamwar.bausystem.features.tpslimit.TPSLimitCommand.MAX_TPS; + @UtilityClass public class TPSLimitUtils { @@ -88,7 +90,7 @@ public class TPSLimitUtils { @SuppressWarnings("unused") public static void setTPS(double d) { if (d < 0.5) d = 0.5; - if (d > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) d = (TPSWarpUtils.isWarpAllowed() ? 60 : 20); + if (d > (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20)) d = (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20); currentTPSLimit = d; tpsLimiter(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java index b6f4fa9a..d268ccf6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java @@ -40,7 +40,8 @@ public class TPSWarpUtils { public static void setTPS(double tps) { double d = 50 - (50 / (tps / 20.0)); - nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000)); + // nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000)); + nanoDOffset = (long) (d * 1000000); if (nanoDOffset == 0) { if (bukkitTask == null) return; bukkitTask.cancel(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index 426d26bc..799ccba8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -30,30 +30,48 @@ import org.bukkit.event.player.PlayerMoveEvent; @Linked public class AFKStopperListener implements Listener { + // CPU > 50% + // RAM > 60% + private int minutesAfk = 0; public AFKStopperListener() { - Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { - switch (minutesAfk) { - case 5: - if (Bukkit.getOnlinePlayers().isEmpty()) { - Bukkit.shutdown(); - return; - } - for (Player p : Bukkit.getOnlinePlayers()) { - p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p)); - } - break; - case 4: - BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE"); - default: - minutesAfk++; + Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getInstance(), () -> { + double load = RamUsage.getLoad(); + double usage = RamUsage.getUsage(); + // System.out.println("CPU: " + load + " RAM: " + usage); + if (load < 50.0 && usage < 0.6) { + minutesAfk = 0; + return; } + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + switch (minutesAfk) { + case 5: + if (Bukkit.getOnlinePlayers().isEmpty()) { + Bukkit.shutdown(); + return; + } + for (Player p : Bukkit.getOnlinePlayers()) { + p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p)); + } + break; + case 4: + BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE"); + default: + minutesAfk++; + } + }, 1); }, 1200, 1200); //every minute } @EventHandler public void onPlayerMove(PlayerMoveEvent event) { - minutesAfk = 0; + if (event.getTo() == null) return; + if (event.getFrom().getPitch() != event.getTo().getPitch()) { + minutesAfk = 0; + } + if (event.getFrom().getYaw() != event.getTo().getYaw()) { + minutesAfk = 0; + } } } From 567f88c916dbe6efddd3b48611fabae8310565d3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 16 Jun 2023 19:40:09 +0200 Subject: [PATCH 07/23] Update RamUsage Signed-off-by: yoyosource --- .../features/world/AFKStopperListener.java | 38 +++++++++---------- .../bausystem/features/world/RamUsage.java | 28 ++++++++++++++ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index 799ccba8..ec539714 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -36,31 +36,27 @@ public class AFKStopperListener implements Listener { private int minutesAfk = 0; public AFKStopperListener() { - Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getInstance(), () -> { - double load = RamUsage.getLoad(); - double usage = RamUsage.getUsage(); + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { // System.out.println("CPU: " + load + " RAM: " + usage); - if (load < 50.0 && usage < 0.6) { + if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) { minutesAfk = 0; return; } - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - switch (minutesAfk) { - case 5: - if (Bukkit.getOnlinePlayers().isEmpty()) { - Bukkit.shutdown(); - return; - } - for (Player p : Bukkit.getOnlinePlayers()) { - p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p)); - } - break; - case 4: - BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE"); - default: - minutesAfk++; - } - }, 1); + switch (minutesAfk) { + case 5: + if (Bukkit.getOnlinePlayers().isEmpty()) { + Bukkit.shutdown(); + return; + } + for (Player p : Bukkit.getOnlinePlayers()) { + p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p)); + } + break; + case 4: + BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE"); + default: + minutesAfk++; + } }, 1200, 1200); //every minute } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index 9f5a1fcd..711a574c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -28,7 +28,31 @@ public class RamUsage { private File meminfo = new File("/proc/meminfo"); + private double usage = 0D; + private double load = 0D; + + static { + Thread thread = new Thread(() -> { + while (true) { + usage = _getUsage(); + load = _getLoad(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + }); + thread.setDaemon(true); + thread.setName("RamUsage"); + thread.start(); + } + public static double getUsage() { + return usage; + } + + private static double _getUsage() { try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) { String memTotal = bufferedReader.readLine().replaceAll(" +", " "); bufferedReader.readLine(); @@ -43,6 +67,10 @@ public class RamUsage { } public static double getLoad() { + return load; + } + + private static double _getLoad() { try { Process process = new ProcessBuilder("bash", "-c", "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start(); process.waitFor(); From 8f1fa7c2d6bef3cc01c54813e6b8f9b63f65253b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Jun 2023 11:17:54 +0200 Subject: [PATCH 08/23] Hotfix LoaderLever Signed-off-by: yoyosource --- .../features/loader/elements/impl/LoaderLever.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java index 911daf57..3afa4f04 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java @@ -52,11 +52,11 @@ public class LoaderLever extends LoaderInteractionElement Date: Sat, 17 Jun 2023 11:47:12 +0200 Subject: [PATCH 09/23] Add some debug infos Signed-off-by: yoyosource --- .../bausystem/features/world/RamUsage.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index 711a574c..17b632cc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -28,16 +28,28 @@ public class RamUsage { private File meminfo = new File("/proc/meminfo"); + private double usageSelf = 0D; private double usage = 0D; private double load = 0D; + public static void init() { + } + static { Thread thread = new Thread(() -> { while (true) { + long maxMemory = Runtime.getRuntime().maxMemory(); + long totalMemory = Runtime.getRuntime().totalMemory(); + long freeMemory = Runtime.getRuntime().freeMemory(); + long usedMemory = totalMemory - freeMemory; + usageSelf = usedMemory / (double) totalMemory; + double usageSelfByMax = usedMemory / (double) maxMemory; + System.out.println("Self: " + usageSelf + "/" + usageSelfByMax + /* " " + maxMemory + " " + totalMemory + " " + freeMemory + " " + usedMemory + */ " Ram: " + usage + " CPU: " + load); + usage = _getUsage(); load = _getLoad(); try { - Thread.sleep(1000); + Thread.sleep(2000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } From 4d4e13ad53388c65139b968af1e18a073b04238f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Jun 2023 11:47:32 +0200 Subject: [PATCH 10/23] Fix timeout Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/world/RamUsage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index 17b632cc..ee4fa0d2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -49,7 +49,7 @@ public class RamUsage { usage = _getUsage(); load = _getLoad(); try { - Thread.sleep(2000); + Thread.sleep(10000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } From a950640aae6e7e13b99ae346dedd6127b063eae5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Jun 2023 12:18:51 +0200 Subject: [PATCH 11/23] Disable System.out messages Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/world/RamUsage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index ee4fa0d2..a4451fda 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -44,12 +44,12 @@ public class RamUsage { long usedMemory = totalMemory - freeMemory; usageSelf = usedMemory / (double) totalMemory; double usageSelfByMax = usedMemory / (double) maxMemory; - System.out.println("Self: " + usageSelf + "/" + usageSelfByMax + /* " " + maxMemory + " " + totalMemory + " " + freeMemory + " " + usedMemory + */ " Ram: " + usage + " CPU: " + load); + // System.out.println("Self: " + usageSelf + "/" + usageSelfByMax + /* " " + maxMemory + " " + totalMemory + " " + freeMemory + " " + usedMemory + */ " Ram: " + usage + " CPU: " + load); usage = _getUsage(); load = _getLoad(); try { - Thread.sleep(10000); + Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } From b52283afa3f76520ab449a55f7a3dd7771151477 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Jun 2023 17:13:46 +0200 Subject: [PATCH 12/23] Update and hopefully fix the persisting issue Signed-off-by: yoyosource --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 2 ++ .../de/steamwar/bausystem/features/world/RamUsage.java | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 1d1e6362..23293543 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.configplayer.Config; +import de.steamwar.bausystem.features.world.RamUsage; import de.steamwar.bausystem.region.loader.PrototypeLoader; import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.Updater; @@ -73,6 +74,7 @@ public class BauSystem extends JavaPlugin implements Listener { new Updater(RegionLoader.file, RegionLoader::load); LinkageUtils.link(); + RamUsage.init(); // This could disable any watchdog stuff. We need to investigate if this is a problem. /* diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index a4451fda..6cf1600a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.world; import lombok.experimental.UtilityClass; import java.io.*; +import java.util.concurrent.locks.LockSupport; @UtilityClass public class RamUsage { @@ -48,11 +49,8 @@ public class RamUsage { usage = _getUsage(); load = _getLoad(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + Thread.yield(); + LockSupport.parkNanos(1000000000L); } }); thread.setDaemon(true); From 9a4aa3281a1e7a31fd6f185726e29b815c6f8bc3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Jun 2023 17:47:13 +0200 Subject: [PATCH 13/23] Remove load calculation Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/world/RamUsage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index 6cf1600a..e5024bef 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -48,7 +48,7 @@ public class RamUsage { // System.out.println("Self: " + usageSelf + "/" + usageSelfByMax + /* " " + maxMemory + " " + totalMemory + " " + freeMemory + " " + usedMemory + */ " Ram: " + usage + " CPU: " + load); usage = _getUsage(); - load = _getLoad(); + // load = _getLoad(); Thread.yield(); LockSupport.parkNanos(1000000000L); } From 1337ec8ddf859e262ac164ccfb8c6495552574dc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Jun 2023 18:18:45 +0200 Subject: [PATCH 14/23] Update load usage calculation Signed-off-by: yoyosource --- .../bausystem/features/world/RamUsage.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index e5024bef..1d187444 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -28,6 +28,7 @@ import java.util.concurrent.locks.LockSupport; public class RamUsage { private File meminfo = new File("/proc/meminfo"); + private File stat = new File("/proc/stat"); private double usageSelf = 0D; private double usage = 0D; @@ -48,7 +49,7 @@ public class RamUsage { // System.out.println("Self: " + usageSelf + "/" + usageSelfByMax + /* " " + maxMemory + " " + totalMemory + " " + freeMemory + " " + usedMemory + */ " Ram: " + usage + " CPU: " + load); usage = _getUsage(); - // load = _getLoad(); + load = _getLoad(); Thread.yield(); LockSupport.parkNanos(1000000000L); } @@ -80,21 +81,40 @@ public class RamUsage { return load; } + private long lastCpuSecond = -1; + private long lastCpuForth = -1; + private long lastCpuFifth = -1; + private static double _getLoad() { - try { - Process process = new ProcessBuilder("bash", "-c", "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start(); - process.waitFor(); - return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(stat)))) { + String[] strings = bufferedReader.readLine().split(" "); + + long cpuSecond = Long.parseLong(strings[2]); + long cpuForth = Long.parseLong(strings[4]); + long cpuFifth = Long.parseLong(strings[5]); + + if (lastCpuSecond == -1) { + lastCpuSecond = cpuSecond; + lastCpuForth = cpuForth; + lastCpuFifth = cpuFifth; + return 0D; + } + + long cpuSecondDiff = cpuSecond - lastCpuSecond; + long cpuForthDiff = cpuForth - lastCpuForth; + long cpuSixthDiff = cpuFifth - lastCpuFifth; + + lastCpuSecond = cpuSecond; + lastCpuForth = cpuForth; + lastCpuFifth = cpuFifth; + + return (cpuSecondDiff + cpuForthDiff) / (double) (cpuSecondDiff + cpuForthDiff + cpuSixthDiff); } catch (IOException e) { return 1D; - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return 1D; } } private static long getNumber(String s) { return Long.parseLong(s.split(" ")[1]); } - } From 949f7d1aebf4abc30732b317ac4dcc7f32b603b2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Jun 2023 20:09:02 +0200 Subject: [PATCH 15/23] Fix some stuff Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java index d268ccf6..f470a871 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java @@ -41,7 +41,7 @@ public class TPSWarpUtils { public static void setTPS(double tps) { double d = 50 - (50 / (tps / 20.0)); // nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000)); - nanoDOffset = (long) (d * 1000000); + nanoDOffset = Math.max(0, (long) (d * 1000000)); if (nanoDOffset == 0) { if (bukkitTask == null) return; bukkitTask.cancel(); From 1b28b377e28135d320c7347dcc01e85337b9e1b2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Jun 2023 17:19:00 +0200 Subject: [PATCH 16/23] Add ShowModeParameterType.MICROMOTION Signed-off-by: yoyosource --- .../bausystem/features/tracer/show/EntityShowMode.java | 5 ++++- .../steamwar/bausystem/features/tracer/show/Record.java | 8 ++++++++ .../bausystem/features/tracer/show/ShowModeParameter.java | 5 +++++ .../features/tracer/show/ShowModeParameterType.java | 4 +++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java index 6f61a08e..0828ce73 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -29,7 +29,6 @@ import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.Material; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -85,6 +84,10 @@ public class EntityShowMode implements ShowMode { return; } + if (showModeParameter.isMicroMotion() && !position.getRecord().isHasMicroMotion()) { + return; + } + if (showModeParameter.isExplodeOnly()) { if (position.isExploded()) { generatePositions(position, false, false); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java index 71b19f1d..08bc6561 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java @@ -75,6 +75,9 @@ public class Record { @Setter private boolean inBuildArea = false; + @Getter + private boolean hasMicroMotion = false; + public TNTRecord(long offset, Region region) { this.offset = offset; this.region = region; @@ -90,6 +93,11 @@ public class Record { public void explode(TNTPrimed tntPrimed) { add(tntPrimed, false, true); + Vector velocity = tntPrimed.getVelocity(); + if (velocity.getY() != 0) return; + if (velocity.getX() > 0.001 || velocity.getZ() > 0.001) return; + if (velocity.getX() == 0 && velocity.getZ() == 0) return; + hasMicroMotion = true; } private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java index 4babe506..802c1eba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java @@ -32,6 +32,7 @@ public class ShowModeParameter { private boolean count = false; private boolean buildDestroyOnly = false; private boolean ticksSinceStart = false; + private boolean microMotion = false; public void enableWater() { this.water = true; @@ -68,4 +69,8 @@ public class ShowModeParameter { public void enableTicksSinceStart() { this.ticksSinceStart = true; } + + public void enableMicroMotion() { + this.microMotion = true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java index a80a3633..897fcff6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java @@ -41,7 +41,9 @@ public enum ShowModeParameterType { TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT", "TICKS_SINCE_START"), COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "TICKS", "TICKS_SINCE_START"), BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"), - TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"); + TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"), + MICROMOTION(ShowModeParameter::enableMicroMotion, Arrays.asList("-micromotion", "-micro", "-m"), "COUNT"), + ; @Getter private final Consumer showModeParameterConsumer; From 8ef7bafa224e1a43c111fe01e7721a2cfc2d4665 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Jun 2023 17:58:52 +0200 Subject: [PATCH 17/23] Fix MicroMotion detector in Trace Signed-off-by: yoyosource --- .../features/tracer/show/Record.java | 26 ++++++++++++++----- .../tracer/show/ShowModeParameterType.java | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java index 08bc6561..82844113 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java @@ -48,7 +48,7 @@ public class Record { } public TNTRecord spawn(long offset) { - TNTRecord record = new TNTRecord(offset, region); + TNTRecord record = new TNTRecord(this, offset, region); tnt.add(record); return record; } @@ -57,11 +57,26 @@ public class Record { tnt.clear(); } + private void checkMicroMotion() { + for (TNTRecord tntRecord : tnt) { + List positions = tntRecord.positions; + if (positions.isEmpty()) continue; + TNTPosition position = positions.get(positions.size() - 1); + + Vector velocity = position.getVelocity(); + if (velocity.getY() == 0 && (velocity.getX() != 0 || velocity.getZ() != 0) && (Math.abs(velocity.getX()) < 0.001 || Math.abs(velocity.getZ()) < 0.001)) { + tntRecord.hasMicroMotion = true; + } + } + } + public static class TNTRecord { @Getter private final UUID id = UUID.randomUUID(); + private Record record; + @Getter private final long offset; @@ -78,7 +93,8 @@ public class Record { @Getter private boolean hasMicroMotion = false; - public TNTRecord(long offset, Region region) { + public TNTRecord(Record record, long offset, Region region) { + this.record = record; this.offset = offset; this.region = region; } @@ -93,11 +109,7 @@ public class Record { public void explode(TNTPrimed tntPrimed) { add(tntPrimed, false, true); - Vector velocity = tntPrimed.getVelocity(); - if (velocity.getY() != 0) return; - if (velocity.getX() > 0.001 || velocity.getZ() > 0.001) return; - if (velocity.getX() == 0 && velocity.getZ() == 0) return; - hasMicroMotion = true; + record.checkMicroMotion(); } private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java index 897fcff6..a4f83958 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java @@ -42,7 +42,7 @@ public enum ShowModeParameterType { COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "TICKS", "TICKS_SINCE_START"), BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"), TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"), - MICROMOTION(ShowModeParameter::enableMicroMotion, Arrays.asList("-micromotion", "-micro", "-m"), "COUNT"), + MICROMOTION(ShowModeParameter::enableMicroMotion, Arrays.asList("-micromotion", "-micro", "-m")), ; @Getter From 65cf7ffe77861179aa25fddf64f8e158c9293e2c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Jun 2023 18:20:21 +0200 Subject: [PATCH 18/23] Auto reshow on MicroMotion Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/tracer/show/Record.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java index 82844113..09d0e832 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java @@ -65,6 +65,9 @@ public class Record { Vector velocity = position.getVelocity(); if (velocity.getY() == 0 && (velocity.getX() != 0 || velocity.getZ() != 0) && (Math.abs(velocity.getX()) < 0.001 || Math.abs(velocity.getZ()) < 0.001)) { + if (!tntRecord.hasMicroMotion) { + positions.forEach(tntPosition -> TraceShowManager.show(region, tntPosition)); + } tntRecord.hasMicroMotion = true; } } From a317891685c9da232afb57c12fb8bbed1521f7b7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Jun 2023 18:42:11 +0200 Subject: [PATCH 19/23] Auto reshow on MicroMotion Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 22 +-- BauSystem_Main/src/BauSystem_de.properties | 19 +-- .../features/cannon/CannonDetector.java | 99 ++++++++++++ .../bausystem/features/cannon/CannonKey.java | 33 ++++ .../features/cannon/depth/Depth.java | 110 ++++++++++++++ .../features/cannon/depth/DepthManager.java | 48 ++++++ .../testblock/blockcounter/BlockCount.java | 4 +- .../testblock/depthcounter/CountMode.java | 36 ----- .../testblock/depthcounter/Depth.java | 131 ---------------- .../testblock/depthcounter/DepthCounter.java | 142 ------------------ .../depthcounter/DepthCounterCommand.java | 57 ------- .../depthcounter/DepthCounterListener.java | 57 ------- .../bausystem/region/RegionUtils.java | 23 ++- 13 files changed, 319 insertions(+), 462 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonKey.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/DepthManager.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/CountMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 6b641c33..b3dc6618 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -701,26 +701,16 @@ KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 cannons BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Toggle on/off BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Toggles BlockCounter on BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Toggles BlockCounter off -BLOCK_COUNTER_MESSAGE = §7Counter §8> §e{0} §7Blocks §e{1} §7TNT §e{2} §7Blocks/TNT §e{3} §7Blocks/tick -BLOCK_COUNTER_MESSAGE_SECOND = §7Counter §8> §e{0} §7Blocks §e{1} §7TNT §e{2} §7Blocks/TNT §e{3} §7Blocks/s +BLOCK_COUNTER_MESSAGE = §7Damage §8> §e{0} §7Blocks §e{1} §7TNT §e{2} §7Blocks/TNT §e{3} §7Blocks/tick +BLOCK_COUNTER_MESSAGE_SECOND = §7Damage §8> §e{0} §7Blocks §e{1} §7TNT §e{2} §7Blocks/TNT §e{3} §7Blocks/s BLOCK_COUNTER_ENABLE = §7BlockCounter activated BLOCK_COUNTER_DISABLE = §7BlockCounter deactivated # DepthCounter -DEPTH_COUNTER_COMMAND_ENABLE_HELP = §8/§edepthcounter enable §8- §7Activate the depth-counter -DEPTH_COUNTER_COMMAND_DISABLE_HELP = §8/§edepthcounter disable §8- §7Deactivate the depth-counter -DEPTH_COUNTER_COMMAND_INFO_HELP = §8/§edepthcounter info §8- §7Lists active counting modes -DEPTH_COUNTER_COMMAND_TOGGLE_HELP = §8/§edepthcounter toggle §8<§7CountMode§8> §8- §7Toggle counting modes -DEPTH_COUNTER_ENABLE_MESSAGE = §7You activated the depth-counter -DEPTH_COUNTER_DISABLE_MESSAGE = §7You deactivated the depth-counter -DEPTH_COUNTER_ACTIVE_MESSAGE = §7Active couting modes: §e{0}§8. -DEPTH_COUNTER_MESSAGE = §7Damage §8> §7{0} -DEPTH_COUNTER_HIGHLIGHT = §e -DEPTH_COUNTER_SEPARATOR = §7 §7 -DEPTH_COUNTER_X = X: {0} -DEPTH_COUNTER_Y = Y: {0} -DEPTH_COUNTER_Z = Z: {0} -DEPTH_COUNTER_TNT = §7TNT§8: §e{0} +DEPTH_COUNTER_MESSAGE = §7Depth §8> §7 +DEPTH_COUNTER_COUNT = {0}{1}§8×{2}{3}§8×{4}{5} +DEPTH_COUNTER_HOVER = §7X§8ק7Y§8ק7Z +DEPTH_COUNTER_TNT = §7 TNT§8: §e{0} # TPSLimit TICK_STEP_HELP = §8/§etick step §8<§7Ticks§8> §8- §7Step n ticks diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 571d9b8f..a9cf35f5 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -673,26 +673,13 @@ KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 Kanonnen BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Schalte den BlockCounter aus -BLOCK_COUNTER_MESSAGE = §7Counter §8> §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/tick -BLOCK_COUNTER_MESSAGE_SECOND = §7Counter §8> §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/s +BLOCK_COUNTER_MESSAGE = §7Schaden §8> §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/tick +BLOCK_COUNTER_MESSAGE_SECOND = §7Schaden §8> §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/s BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht # DepthCounter -DEPTH_COUNTER_COMMAND_ENABLE_HELP = §8/§edepthcounter enable §8- §7Aktiviere den Tiefenzähler -DEPTH_COUNTER_COMMAND_DISABLE_HELP = §8/§edepthcounter disable §8- §7Deaktiviere den Tiefenzähler -DEPTH_COUNTER_COMMAND_INFO_HELP = §8/§edepthcounter info §8- §7Zähle aktive Zählmodi auf -DEPTH_COUNTER_COMMAND_TOGGLE_HELP = §8/§edepthcounter toggle §8<§7CountMode§8> §8- §7Stelle einzelne Zählmodi ein -DEPTH_COUNTER_ENABLE_MESSAGE = §7Du hast den Tiefenzähler aktiviert. -DEPTH_COUNTER_DISABLE_MESSAGE = §7Du hast den Tiefenzähler deaktiviert. -DEPTH_COUNTER_ACTIVE_MESSAGE = §7Aktive Zählmodi: §e{0}§8. -DEPTH_COUNTER_MESSAGE = §7Schaden §8> §7{0} -DEPTH_COUNTER_HIGHLIGHT = §e -DEPTH_COUNTER_SEPARATOR = §7 §7 -DEPTH_COUNTER_X = X: {0} -DEPTH_COUNTER_Y = Y: {0} -DEPTH_COUNTER_Z = Z: {0} -DEPTH_COUNTER_TNT = §7TNT§8: §e{0} +DEPTH_COUNTER_MESSAGE = §7Tiefe §8> §7 # TPSLimit TICK_STEP_HELP = §8/§etick step §8<§7Ticks§8> §8- §7Spule n Ticks vor diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java new file mode 100644 index 00000000..801b5aca --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java @@ -0,0 +1,99 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.cannon; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.cannon.depth.Depth; +import de.steamwar.bausystem.features.cannon.depth.DepthManager; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.linkage.Linked; +import org.bukkit.Bukkit; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Linked +public class CannonDetector implements Listener { + + private Map velocities = new HashMap<>(); + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + if (!(event.getEntity() instanceof TNTPrimed)) { + return; + } + + TNTPrimed tnt = (TNTPrimed) event.getEntity(); + DepthManager.update(tnt, event.blockList()); + + List tnts = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class) + .stream() + .filter(entity -> entity != tnt) + .filter(entity -> entity.getFuseTicks() > 1) + .filter(entity -> entity.getLocation().distance(event.getLocation()) <= 8) + .collect(Collectors.toList()); + + if (tnts.isEmpty()) { + return; + } + + boolean isEmpty = velocities.isEmpty(); + tnts.forEach(tntPrimed -> { + velocities.put(tntPrimed, tntPrimed.getVelocity().clone()); + }); + + if (!isEmpty) { + return; + } + + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + Map> grouped = new HashMap<>(); + velocities.forEach((tntPrimed, vector) -> { + grouped.computeIfAbsent(new CannonKey(round(tntPrimed.getLocation().toVector()), round(vector)), ignored -> new ArrayList<>()).add(tntPrimed); + }); + grouped.forEach((cannonKey, tntPrimeds) -> { + if (tntPrimeds.size() <= 5) return; + Region region = Region.getRegion(tntPrimeds.get(0).getLocation()); + if (region.isGlobal()) return; + if (!region.hasType(RegionType.TESTBLOCK)) return; + Depth depth = new Depth(region); + DepthManager.init(tntPrimeds, depth); + }); + velocities.clear(); + }, 1); + } + + private Vector round(Vector vector) { + vector.multiply(10000); + vector.setX(Math.round(vector.getX())); + vector.setY(Math.round(vector.getY())); + vector.setZ(Math.round(vector.getZ())); + return vector; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonKey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonKey.java new file mode 100644 index 00000000..73270eab --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonKey.java @@ -0,0 +1,33 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.cannon; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import org.bukkit.util.Vector; + +@AllArgsConstructor +@EqualsAndHashCode +@Getter +public final class CannonKey { + private Vector locationVector; + private Vector velocityVector; +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java new file mode 100644 index 00000000..506b6e93 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java @@ -0,0 +1,110 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.cannon.depth; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class Depth { + + private Region region; + private Vector minVector = null; + private Vector maxVector = null; + private int tntCount = 0; + + public Depth(Region region) { + this.region = region; + } + + public void update(List blocks) { + List blocksList = blocks.stream() + .filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) + .collect(Collectors.toList()); + if (blocksList.isEmpty()) return; + tntCount++; + for (Block block : blocksList) { + internalUpdate(block); + } + } + + public void finish() { + if (maxVector == null || minVector == null) return; + Vector dimensions = maxVector.subtract(minVector); + dimensions.setX(Math.abs(dimensions.getX())); + dimensions.setY(Math.abs(dimensions.getY())); + dimensions.setZ(Math.abs(dimensions.getZ())); + + RegionUtils.message(region, player -> { + player.spigot().sendMessage(getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, tntCount)); + }); + } + + private void internalUpdate(Block block) { + if (minVector == null) { + minVector = block.getLocation().toVector(); + } + minVector.setX(Math.min(minVector.getX(), block.getX())); + minVector.setY(Math.min(minVector.getY(), block.getY())); + minVector.setZ(Math.min(minVector.getZ(), block.getZ())); + + if (maxVector == null) { + maxVector = block.getLocation().toVector(); + } + maxVector.setX(Math.max(maxVector.getX(), block.getX())); + maxVector.setY(Math.max(maxVector.getY(), block.getY())); + maxVector.setZ(Math.max(maxVector.getZ(), block.getZ())); + } + + private static BaseComponent[] getMessage(Player player, int x, int y, int z, int tntCount) { + final Set dimensions = new HashSet<>(); + dimensions.add(x); + dimensions.add(y); + dimensions.add(z); + + int max = getMax(dimensions); + + TextComponent headerComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_MESSAGE", player)); + + TextComponent depthComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_COUNT", player, x == max ? "§e" : "§7", x, y == max ? "§e" : "§7", y, z == max ? "§e" : "§7", z)); + depthComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_HOVER", player))})); + + TextComponent tntComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_TNT", player, tntCount)); + + return new BaseComponent[]{headerComponent, depthComponent, tntComponent}; + } + + private static int getMax(Set values) { + return values.stream().max(Integer::compare).orElse(0); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/DepthManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/DepthManager.java new file mode 100644 index 00000000..21789d7b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/DepthManager.java @@ -0,0 +1,48 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.cannon.depth; + +import lombok.experimental.UtilityClass; +import org.bukkit.block.Block; +import org.bukkit.entity.TNTPrimed; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@UtilityClass +public class DepthManager { + + private Map depths = new HashMap<>(); + + public void init(List list, Depth depth) { + for (TNTPrimed tnt : list) { + depths.putIfAbsent(tnt, depth); + } + } + + public void update(TNTPrimed tnt, List blocks) { + Depth depth = depths.remove(tnt); + if (depth == null) return; + depth.update(blocks); + if (depths.containsValue(depth)) return; + depth.finish(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java index 8e63bd90..e99a31be 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java @@ -57,7 +57,9 @@ public class BlockCount { toRemove.add(blockCount.region); if (count > 10) { - RegionUtils.message(blockCount.region, player -> BlockCounter.getMessage(player, blockCount.count, blockCount.tntCount, blockCount.tick, blockCount.lastUpdate)); + RegionUtils.message(blockCount.region, player -> { + return BlockCounter.getMessage(player, blockCount.count, blockCount.tntCount, blockCount.tick, blockCount.lastUpdate); + }); } } toRemove.forEach(BlockCounter.blockCountMap::remove); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/CountMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/CountMode.java deleted file mode 100644 index 1dfb795b..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/CountMode.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.testblock.depthcounter; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - - -public enum CountMode { - - X, - Y, - Z; - - public static Set ALL() { - return new HashSet<>(Arrays.asList(values())); - } -} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java deleted file mode 100644 index 52999a45..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.testblock.depthcounter; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.tpslimit.TPSUtils; -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.RegionUtils; -import org.bukkit.Bukkit; -import org.bukkit.block.Block; -import org.bukkit.scheduler.BukkitTask; -import org.bukkit.util.Vector; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class Depth { - - private static BukkitTask bukkitTask = null; - - private Region region; - private int tntCount = 1; - private Vector minVector = null; - private Vector maxVector = null; - - private long lastUpdate = TPSUtils.currentTick.get(); - - public Depth(Region region, List blocks) { - if (blocks.isEmpty()) { - throw new SecurityException(); - } - this.region = region; - blocks.forEach(block -> { - if (minVector == null) { - minVector = DepthCounter.blockVector(block.getLocation().toVector()); - maxVector = DepthCounter.blockVector(block.getLocation().toVector()); - } else { - internalUpdate(block); - } - }); - - if (bukkitTask == null) { - bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { - Set toRemove = new HashSet<>(); - for (Set value : DepthCounter.depthMap.values()) { - value.forEach(depth -> { - if (TPSUtils.currentTick.get() - depth.lastUpdate < 10) { - return; - } - - Vector dimensions = depth.maxVector.subtract(depth.minVector); - dimensions.setX(Math.abs(dimensions.getX())); - dimensions.setY(Math.abs(dimensions.getY())); - dimensions.setZ(Math.abs(dimensions.getZ())); - - if (depth.tntCount > 4 && dimensions.getX() != 0 && dimensions.getY() != 0 && dimensions.getZ() != 0) { - RegionUtils.message(depth.region, player -> DepthCounter.getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, depth.tntCount)); - } - - Set depthSet = DepthCounter.depthMap.get(depth.region); - if (depthSet == null) { - return; - } - toRemove.add(depth); - }); - } - toRemove.forEach(depth -> { - Set depthSet = DepthCounter.depthMap.get(depth.region); - depthSet.remove(depth); - if (depthSet.isEmpty()) { - DepthCounter.depthMap.remove(depth.region); - } - }); - - if (DepthCounter.depthMap.isEmpty()) { - bukkitTask.cancel(); - bukkitTask = null; - } - }, 2, 2); - } - } - - public boolean update(List blocks) { - double totalBlastResistanceBroken = blocks.stream().filter(block -> { - Vector vector = DepthCounter.blockVector(block.getLocation().toVector()); - return vector.getX() >= minVector.getX() - && vector.getY() >= minVector.getY() - && vector.getZ() >= minVector.getZ() - && vector.getX() <= maxVector.getX() - && vector.getY() <= maxVector.getY() - && vector.getZ() <= maxVector.getZ(); - }).filter(block -> block.getType().isBlock()) - .mapToDouble(block -> block.getType().getBlastResistance()) - .sum(); - if (totalBlastResistanceBroken < 18) { - return false; - } - lastUpdate = TPSUtils.currentTick.get(); - blocks.forEach(this::internalUpdate); - tntCount++; - return true; - } - - private void internalUpdate(Block block) { - minVector.setX(Math.min(minVector.getX(), block.getX())); - minVector.setY(Math.min(minVector.getY(), block.getY())); - minVector.setZ(Math.min(minVector.getZ(), block.getZ())); - - maxVector.setX(Math.max(maxVector.getX(), block.getX())); - maxVector.setY(Math.max(maxVector.getY(), block.getY())); - maxVector.setZ(Math.max(maxVector.getZ(), block.getZ())); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java deleted file mode 100644 index 551fa2d6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.testblock.depthcounter; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.configplayer.Config; -import de.steamwar.bausystem.region.Region; -import lombok.experimental.UtilityClass; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; -import yapion.hierarchy.types.YAPIONObject; - -import java.util.*; -import java.util.stream.Collectors; - -@UtilityClass -public class DepthCounter { - - public final Map> depthMap = new HashMap<>(); - - private static final YAPIONObject DEFAULT = new YAPIONObject().add("X", "").add("Y", "").add("Z", ""); - - public void toggleMode(final Player p, final CountMode countMode) { - if (isActive(p, countMode)) { - removeMode(p, countMode); - } else { - addMode(p, countMode); - } - } - - public boolean isActive(final Player p, final CountMode countMode) { - return Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).containsKey(countMode.name()); - } - - public void addMode(final Player p, final CountMode countMode) { - if (!isActive(p, countMode)) { - Config.getInstance().get(p).getObject("depth-counter").add(countMode.name(), ""); - } - } - - public void removeMode(final Player p, final CountMode countMode) { - if (isActive(p, countMode)) { - Config.getInstance().get(p).getObject("depth-counter").remove(countMode.name()); - } - } - - public void setModes(final Player p, final Set countModes) { - YAPIONObject yapionObject = new YAPIONObject(); - countModes.forEach(countMode -> yapionObject.put(countMode.name(), "")); - Config.getInstance().get(p).put("depth-counter", yapionObject); - } - - public void removePlayer(final Player p) { - Config.getInstance().get(p).put("depth-counter", new YAPIONObject()); - } - - public Vector blockVector(Vector vector) { - return new Vector(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); - } - - public Set getModes(Player p) { - Set countModes = new HashSet<>(); - Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).forEach((s, yapionAnyType) -> { - countModes.add(CountMode.valueOf(s)); - }); - return countModes.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new)); - } - - public boolean hasModes(Player p) { - return !getModes(p).isEmpty(); - } - - public int getMax(int... values) { - return Arrays.stream(values).max().orElse(0); - } - - public int getMax(Set values) { - return values.stream().max(Integer::compare).orElse(0); - } - - public String getMessage(Player player, int x, int y, int z, int tntCount) { - final boolean xActive = DepthCounter.isActive(player, CountMode.X); - final boolean yActive = DepthCounter.isActive(player, CountMode.Y); - final boolean zActive = DepthCounter.isActive(player, CountMode.Z); - - if (!xActive && !yActive && !zActive) { - return null; - } - - final Set dimensions = new HashSet<>(); - if (xActive) { - dimensions.add(x); - } - if (yActive) { - dimensions.add(y); - } - if (zActive) { - dimensions.add(z); - } - - int max = getMax(dimensions); - - StringBuilder st = new StringBuilder(); - if (xActive) { - st.append(x == max ? BauSystem.MESSAGE.parse("DEPTH_COUNTER_HIGHLIGHT", player) : "") - .append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_X", player, x)) - .append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_SEPARATOR", player)); - } - - if (yActive) { - st.append(y == max ? BauSystem.MESSAGE.parse("DEPTH_COUNTER_HIGHLIGHT", player) : "") - .append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_Y", player, y)) - .append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_SEPARATOR", player)); - } - - if (zActive) { - st.append(z == max ? BauSystem.MESSAGE.parse("DEPTH_COUNTER_HIGHLIGHT", player) : "") - .append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_Z", player, z)) - .append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_SEPARATOR", player)); - } - - st.append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_TNT", player, tntCount)); - return BauSystem.MESSAGE.parse("DEPTH_COUNTER_MESSAGE", player, st.toString()); - } -} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterCommand.java deleted file mode 100644 index b8fd1e6c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.testblock.depthcounter; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.command.SWCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.entity.Player; - -@Linked -public class DepthCounterCommand extends SWCommand { - - public DepthCounterCommand() { - super("depthcounter", "depthcount", "dcounter", "dcount"); - } - - @Register(value = "toggle", description = "DEPTH_COUNTER_COMMAND_TOGGLE_HELP") - public void toggleCommand(Player p, CountMode countMode) { - DepthCounter.toggleMode(p, countMode); - BauSystem.MESSAGE.send("DEPTH_COUNTER_ACTIVE_MESSAGE", p, DepthCounter.getModes(p).toString()); - } - - @Register(value = "enable", description = "DEPTH_COUNTER_COMMAND_ENABLE_HELP") - public void enableCommand(Player p) { - DepthCounter.setModes(p, CountMode.ALL()); - BauSystem.MESSAGE.send("DEPTH_COUNTER_ENABLE_MESSAGE", p); - BauSystem.MESSAGE.send("DEPTH_COUNTER_ACTIVE_MESSAGE", p, DepthCounter.getModes(p).toString()); - } - - @Register(value = "disable", description = "DEPTH_COUNTER_COMMAND_DISABLE_HELP") - public void disableCommand(Player p) { - DepthCounter.removePlayer(p); - BauSystem.MESSAGE.send("DEPTH_COUNTER_DISABLE_MESSAGE", p); - } - - @Register(value = "info", description = "DEPTH_COUNTER_COMMAND_INFO_HELP") - public void infoCommand(Player p) { - BauSystem.MESSAGE.send("DEPTH_COUNTER_ACTIVE_MESSAGE", p, DepthCounter.getModes(p).toString()); - } -} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java deleted file mode 100644 index c48142d2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.testblock.depthcounter; - -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.linkage.Linked; -import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityExplodeEvent; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -@Linked -public class DepthCounterListener implements Listener { - - @EventHandler - public void onEntityExplode(EntityExplodeEvent event) { - Region region = Region.getRegion(event.getLocation()); - List blockList = event.blockList(); - blockList = blockList.stream().filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)).collect(Collectors.toList()); - if (blockList.isEmpty()) { - return; - } - - DepthCounter.depthMap.putIfAbsent(region, new HashSet<>()); - Set depthSet = DepthCounter.depthMap.get(region); - for (Depth depth : depthSet) { - if (depth.update(blockList)) { - return; - } - } - depthSet.add(new Depth(region, blockList)); - } -} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java index 45eeeec1..3f81b60a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java @@ -33,6 +33,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.io.File; +import java.util.function.Consumer; import java.util.function.Function; @@ -61,13 +62,23 @@ public class RegionUtils { .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) .forEach(player -> { - String message = function.apply(player); - if (message == null) { - return; - } + String message = function.apply(player); + if (message == null) { + return; + } - player.sendMessage(message); - }); + player.sendMessage(message); + }); + } + + public static void message(Region region, Consumer function) { + Bukkit.getOnlinePlayers() + .stream() + .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) + .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) + .forEach(player -> { + function.accept(player); + }); } static EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) { From 6c6b17eb30312c66dca1021ba32002d71108e82f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 20 Jun 2023 17:56:26 +0200 Subject: [PATCH 20/23] Fix tpslimit 0 with all necessary features Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/BauSystem.java | 50 +++++++++++++++++++ .../features/autostart/AutostartListener.java | 4 +- .../features/cannon/CannonDetector.java | 2 +- .../bausystem/features/loader/Loader.java | 2 +- .../features/loader/LoaderRecorder.java | 12 ++--- .../loader/elements/impl/LoaderMovement.java | 2 +- .../loader/elements/impl/LoaderTNT.java | 2 +- .../loader/elements/impl/LoaderTicks.java | 2 +- .../loader/elements/impl/LoaderWait.java | 2 +- .../features/loadtimer/Loadtimer.java | 14 +++--- .../redstonetester/RedstonetesterUtils.java | 8 +-- .../shieldprinting/ShieldPrinting.java | 7 +-- .../features/simulator/TNTSimulator.java | 2 +- .../testblock/blockcounter/BlockCount.java | 10 ++-- .../bausystem/features/tpslimit/TPSUtils.java | 4 ++ .../tracer/record/AutoTraceRecorder.java | 10 ++-- .../features/tracer/record/Recorder.java | 2 +- .../tracer/record/SimpleTraceRecorder.java | 8 +-- .../features/tracer/show/StoredRecords.java | 2 +- 19 files changed, 97 insertions(+), 48 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 23293543..0d38af4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -21,6 +21,10 @@ package de.steamwar.bausystem; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.configplayer.Config; +import de.steamwar.bausystem.features.tpslimit.FreezeUtils; +import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; import de.steamwar.bausystem.features.world.RamUsage; import de.steamwar.bausystem.region.loader.PrototypeLoader; import de.steamwar.bausystem.region.loader.RegionLoader; @@ -32,11 +36,16 @@ import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; import java.util.logging.Level; public class BauSystem extends JavaPlugin implements Listener { @@ -123,4 +132,45 @@ public class BauSystem extends JavaPlugin implements Listener { } })); } + + public static BukkitTask runTaskLater(Plugin plugin, Runnable runnable, long delay) { + return new BukkitRunnable() { + private int counter = 1; + + @Override + public void run() { + if (FreezeUtils.isFrozen()) return; + if (counter >= delay) { + runnable.run(); + cancel(); + return; + } + counter++; + } + }.runTaskTimer(plugin, 0, 1); + } + + public static BukkitTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) { + return new BukkitRunnable() { + private int counter = 1; + private boolean first = true; + + @Override + public void run() { + if (FreezeUtils.isFrozen()) return; + if (counter >= (first ? delay : period)) { + first = false; + runnable.run(); + counter = 1; + return; + } + counter++; + } + }.runTaskTimer(plugin, 0, 1); + } + + public static void runTaskTimer(Plugin plugin, Consumer consumer, long delay, long period) { + AtomicReference task = new AtomicReference<>(); + task.set(runTaskTimer(plugin, () -> consumer.accept(task.get()), delay, period)); + } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 8d254a3a..66f53359 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -88,7 +88,7 @@ public class AutostartListener implements Listener { } else { BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_START", player); } - regionStartTime.put(region, TPSUtils.currentTick.get()); + regionStartTime.put(region, TPSUtils.currentRealTick.get()); } @EventHandler @@ -101,7 +101,7 @@ public class AutostartListener implements Listener { if (!regionStartTime.containsKey(region)) return; if (!region.hasType(RegionType.TESTBLOCK)) return; if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return; - long tickDiff = TPSUtils.currentTick.get() - regionStartTime.remove(region); + long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region); RegionUtils.message(region, player -> { return BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_RESULT1", player, new SimpleDateFormat(BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_DATE_PATTERN", player)).format(new Date(tickDiff * 50))); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java index 801b5aca..09893fd5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java @@ -72,7 +72,7 @@ public class CannonDetector implements Listener { return; } - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + BauSystem.runTaskLater(BauSystem.getInstance(), () -> { Map> grouped = new HashMap<>(); velocities.forEach((tntPrimed, vector) -> { grouped.computeIfAbsent(new CannonKey(round(tntPrimed.getLocation().toVector()), round(vector)), ignored -> new ArrayList<>()).add(tntPrimed); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index 6b61f14f..58ac95a6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -71,7 +71,7 @@ public class Loader implements Listener { if (currentElement >= elements.size()) { currentElement = 0; if (totalDelay == 0) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1); + BauSystem.runTaskLater(BauSystem.getInstance(), this::next, 1); return; } totalDelay = 0; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java index f42ad0db..a0734231 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java @@ -46,7 +46,7 @@ public class LoaderRecorder implements Listener { private Player player; private List loaderElementList; - private long lastInteraction = TPSUtils.currentTick.get(); + private long lastInteraction = TPSUtils.currentRealTick.get(); public LoaderRecorder(Player player, List loaderElementList) { this.player = player; @@ -63,15 +63,15 @@ public class LoaderRecorder implements Listener { private void addWaitTime(boolean last) { if (loaderElementList.isEmpty()) { - lastInteraction = TPSUtils.currentTick.get(); + lastInteraction = TPSUtils.currentRealTick.get(); return; } if (loaderElementList.get(loaderElementList.size() - 1) instanceof LoaderWait) { return; } - long diff = TPSUtils.currentTick.get() - lastInteraction; + long diff = TPSUtils.currentRealTick.get() - lastInteraction; if (last && diff > 160) diff = 160; - lastInteraction = TPSUtils.currentTick.get(); + lastInteraction = TPSUtils.currentRealTick.get(); loaderElementList.add(new LoaderWait(diff)); } @@ -165,10 +165,10 @@ public class LoaderRecorder implements Listener { Long startTime = blockSet.remove(fromBlock.getLocation()); LoaderMovement loaderMovement = movementSet.remove(fromBlock.getLocation()); if (loaderMovement != null && startTime != null) { - loaderMovement.setInitialTicks(TPSUtils.currentTick.get() - startTime); + loaderMovement.setInitialTicks(TPSUtils.currentRealTick.get() - startTime); } - blockSet.put(toBlock.getLocation(), TPSUtils.currentTick.get()); + blockSet.put(toBlock.getLocation(), TPSUtils.currentRealTick.get()); addWaitTime(false); loaderMovement = null; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java index 55c41fd7..3bc9ebff 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java @@ -112,7 +112,7 @@ public class LoaderMovement extends LoaderInteractionElement= 0) { boolean finalWaitFor = waitFor; - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + BauSystem.runTaskLater(BauSystem.getInstance(), () -> { if (blockData instanceof AnaloguePowerable) { AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData; analoguePowerable.setPower(0); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java index 6c95bf71..be2fb913 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java @@ -49,7 +49,7 @@ public class LoaderTNT implements LoaderElement { public void execute(Runnable nextAction) { Block block = location.getBlock(); if (block.getType() != Material.AIR && block.getType() != Material.WATER) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1); + BauSystem.runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1); return; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java index 098d29ea..e770c258 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java @@ -87,7 +87,7 @@ public class LoaderTicks extends LoaderInteractionElement { + BauSystem.runTaskLater(BauSystem.getInstance(), () -> { powerable.setPowered(false); location.getBlock().setBlockData(powerable, true); update(powerable); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java index 0c694a87..527ee624 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java @@ -58,7 +58,7 @@ public class LoaderWait implements LoaderElement, Listener { nextAction.run(); return; } - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), nextAction, delay); + BauSystem.runTaskLater(BauSystem.getInstance(), nextAction, delay); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadtimer/Loadtimer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadtimer/Loadtimer.java index c321faba..116edba5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadtimer/Loadtimer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadtimer/Loadtimer.java @@ -65,9 +65,9 @@ public class Loadtimer implements Listener { this.region = region; this.stage = Stage.WAITING; Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + task = BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { if (stage == Stage.COUNTING) { - long timeSinceStart = TPSUtils.currentTick.get() - start; + long timeSinceStart = TPSUtils.currentRealTick.get() - start; long timeSinceHalf = timeSinceStart / 2; double timeSec = (timeSinceStart / 20d); String sec = new DecimalFormat("#.#").format(timeSec); @@ -119,7 +119,7 @@ public class Loadtimer implements Listener { public void onTntPlace(BlockPlaceEvent event) { if (stage == Stage.WAITING) { this.stage = Stage.COUNTING; - this.start = TPSUtils.currentTick.get(); + this.start = TPSUtils.currentRealTick.get(); } if (stage == Stage.COUNTING) { @@ -146,9 +146,9 @@ public class Loadtimer implements Listener { public void onTntSpawn() { if ((stage == Stage.COUNTING || stage == Stage.ACTIVATED)) { stage = Stage.IGNITION; - ignite = TPSUtils.currentTick.get(); + ignite = TPSUtils.currentRealTick.get(); if (activate == -1) - activate = TPSUtils.currentTick.get(); + activate = TPSUtils.currentRealTick.get(); if (finishOnActive) { stage = Stage.END; print(); @@ -160,14 +160,14 @@ public class Loadtimer implements Listener { public void onTntExplode(EntityExplodeEvent event) { if (region.inRegion(event.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION) && stage == Stage.IGNITION) { stage = Stage.END; - explode = TPSUtils.currentTick.get(); + explode = TPSUtils.currentRealTick.get(); print(); delete(); } } private void setActivate() { - activate = TPSUtils.currentTick.get(); + activate = TPSUtils.currentRealTick.get(); stage = Stage.ACTIVATED; if (finishOnActive) { print(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterUtils.java index 128c79ae..a70b143b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/redstonetester/RedstonetesterUtils.java @@ -89,18 +89,18 @@ public class RedstonetesterUtils { tick = null; return; } - if (TPSUtils.currentTick.get() - lastTick > 100) { + if (TPSUtils.currentRealTick.get() - lastTick > 100) { tick = null; } if (loc1.equals(location)) { - lastTick = TPSUtils.currentTick.get(); + lastTick = TPSUtils.currentRealTick.get(); if (tick == null) { - tick = TPSUtils.currentTick.get(); + tick = TPSUtils.currentRealTick.get(); } return; } if (tick != null && loc2.equals(location)) { - BauSystem.MESSAGE.send("RT_RESULT", player, (TPSUtils.currentTick.get() - tick), ((TPSUtils.currentTick.get() - tick) / 2.0)); + BauSystem.MESSAGE.send("RT_RESULT", player, (TPSUtils.currentRealTick.get() - tick), ((TPSUtils.currentRealTick.get() - tick) / 2.0)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index ea3b0fbc..5f093e7d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; -import de.steamwar.bausystem.utils.bossbar.RegionedBossbar; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -38,13 +37,9 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.block.EntityBlockFormEvent; -import org.bukkit.event.entity.EntityAirChangeEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; @@ -57,7 +52,7 @@ public class ShieldPrinting implements Listener { private static final World WORLD = Bukkit.getWorlds().get(0); static { - Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> { shieldPrinting.fallingBlocks.replaceAll((entity, location) -> { if (entity.isDead()) return null; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 46d9779a..d1a71b95 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -245,7 +245,7 @@ public class TNTSimulator { }); AtomicInteger currentTick = new AtomicInteger(0); - Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> { + BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> { int tick = currentTick.get(); if (tick > maxTick.get()) bukkitTask.cancel(); currentTick.incrementAndGet(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java index e99a31be..84853b8c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java @@ -40,18 +40,18 @@ public class BlockCount { private Region region; private int count = 0; private int tntCount = 0; - private final long tick = TPSUtils.currentTick.get(); + private final long tick = TPSUtils.currentRealTick.get(); - private long lastUpdate = TPSUtils.currentTick.get(); + private long lastUpdate = TPSUtils.currentRealTick.get(); public BlockCount(Region region) { this.region = region; if (bukkitTask == null) { - bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + bukkitTask = BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { Set toRemove = new HashSet<>(); for (BlockCount blockCount : BlockCounter.blockCountMap.values()) { - if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 60) { + if (TPSUtils.currentRealTick.get() - blockCount.lastUpdate < 60) { continue; } toRemove.add(blockCount.region); @@ -74,6 +74,6 @@ public class BlockCount { public void update(List blocks) { count += blocks.size(); tntCount++; - lastUpdate = TPSUtils.currentTick.get(); + lastUpdate = TPSUtils.currentRealTick.get(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java index 7a2e3a0e..d920b5fa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java @@ -31,7 +31,11 @@ public class TPSUtils { private static long ticksSinceServerStart = 0; public static final Supplier currentTick = () -> ticksSinceServerStart; // This is intended as Supplier + private static long realTicksSinceServerStart = 0; + public static final Supplier currentRealTick = () -> realTicksSinceServerStart; // This is intended as Supplier + static { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> ticksSinceServerStart++, 1, 1); + BauSystem.runTaskTimer(BauSystem.getInstance(), () -> realTicksSinceServerStart++, 1, 1); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java index 2af4146b..f0eeab8c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java @@ -32,7 +32,7 @@ import java.util.function.Supplier; public abstract class AutoTraceRecorder implements TraceRecorder { protected boolean recording = false; - private long startTime = TPSUtils.currentTick.get(); + private long startTime = TPSUtils.currentRealTick.get(); private long lastExplosion = 0; private final Map recordMap = new HashMap<>(); @@ -40,7 +40,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder { private Supplier recordSupplier; private Record.TNTRecord getRecord(TNTPrimed tntPrimed) { - return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentTick.get() - startTime)); + return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentRealTick.get() - startTime)); } protected abstract String getInactivityMessage(); @@ -51,7 +51,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder { @Override public final String scoreboard(Player player) { if (recording) { - return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player); + return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentRealTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player); } else { return BauSystem.MESSAGE.parse(getInactivityMessage(), player); } @@ -59,7 +59,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder { private void startRecording() { lastExplosion = 0; - startTime = TPSUtils.currentTick.get(); + startTime = TPSUtils.currentRealTick.get(); record = recordSupplier.get(); recording = true; } @@ -130,6 +130,6 @@ public abstract class AutoTraceRecorder implements TraceRecorder { @Override public long scriptTime() { - return TPSUtils.currentTick.get() - startTime; + return TPSUtils.currentRealTick.get() - startTime; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 3a0bfe7b..7dd12060 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -129,7 +129,7 @@ public class Recorder implements Listener { } { - Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { tick(); tntTraceRecorderMap.keySet() .stream() diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java index 79e984aa..1077f59a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java @@ -31,13 +31,13 @@ import java.util.function.Supplier; public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { - private final long startTime = TPSUtils.currentTick.get(); + private final long startTime = TPSUtils.currentRealTick.get(); private final Map recordMap = new HashMap<>(); private Record record; @Override public String scoreboard(Player player) { - return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player); + return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentRealTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player); } @Override @@ -51,7 +51,7 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { } private Record.TNTRecord getRecord(TNTPrimed tntPrimed) { - return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentTick.get() - startTime)); + return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentRealTick.get() - startTime)); } @Override @@ -79,6 +79,6 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { @Override public long scriptTime() { - return TPSUtils.currentTick.get() - startTime; + return TPSUtils.currentRealTick.get() - startTime; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java index ce90aad7..993e4fdd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java @@ -42,7 +42,7 @@ public class StoredRecords { private static final Map> records = new HashMap<>(); static { - Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { replayLoops.forEach((region, playerSupplierMap) -> { playerSupplierMap.forEach((player, integerSupplier) -> { int tick = integerSupplier.get(); From 4b4b623fee7752cbc24cf9ca068e08d985aa4d74 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 26 Jun 2023 20:59:31 +0200 Subject: [PATCH 21/23] Hotfix NPE in FreezeListener Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/region/FreezeListener.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java index d810ce61..10beca8f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java @@ -100,7 +100,9 @@ public class FreezeListener implements Listener, ScoreboardElement { @EventHandler public void onInventoryMoveEvent(InventoryMoveItemEvent e) { - if (Region.getRegion(e.getDestination().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) { + if (e.getDestination().getLocation() != null && Region.getRegion(e.getDestination().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) { + e.setCancelled(true); + } else if (e.getSource().getLocation() != null && Region.getRegion(e.getSource().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) { e.setCancelled(true); } } From 65e425ebdbf8cdcd13068c26ed3503e0b15a0023 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Jul 2023 21:18:25 +0200 Subject: [PATCH 22/23] Hotfix KillcheckerVisualizer bossbar progress Signed-off-by: yoyosource --- .../bausystem/features/killchecker/KillcheckerVisualizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index ff21d13b..6d4b8af2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -293,7 +293,7 @@ public class KillcheckerVisualizer { private void updateBossBar(Player player) { BauSystemBossbar bossbar = bossBarService.get(player, region, "killchecker"); bossbar.setTitle(BauSystem.MESSAGE.parse("KILLCHECKER_BOSSBAR", player, kills, ((int) (percent * 1000) / 10.0), cannonCount)); - bossbar.setProgress(percent); + bossbar.setProgress(Math.min(Math.max(percent, 0), 1)); if (percent >= 0.35) { bossbar.setColor(BarColor.RED); From 9062bc698e48aa60418f72e7b64bf88b7d4d9bf8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Jul 2023 21:25:43 +0200 Subject: [PATCH 23/23] Hotfix LaufbauState Signed-off-by: yoyosource --- .../features/slaves/laufbau/states/LaufbauState.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/LaufbauState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/LaufbauState.java index 88041527..6ece3e22 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/LaufbauState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/LaufbauState.java @@ -36,13 +36,13 @@ public interface LaufbauState { default String eta(Player p, long start, int done, int total) { if (total == 0) return ""; long elapsed = System.currentTimeMillis() - start; - long eta = (long) (elapsed / (done / (double) total) - elapsed); + long eta = ((long) (elapsed / (done / (double) total) - elapsed)) * 1000000; if (eta > 86399999999999L) { return LocalTime.ofNanoOfDay(86399999999999L).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p))); } if (eta < 0) { return LocalTime.ofNanoOfDay(0).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p))); } - return LocalTime.ofNanoOfDay(eta * 1000000).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p))); + return LocalTime.ofNanoOfDay(eta).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p))); } }