From dc79b80cc0a547966c69829efeb5e67d70ebe4dc Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 19 Nov 2020 13:00:12 +0100 Subject: [PATCH 01/46] Initial TNT-Tracer --- .../bausystem/tracernew/DataHolder.java | 37 +++++++++++++ .../bausystem/tracernew/TraceHolder.java | 4 ++ .../tracernew/data/RecordStatus.java | 26 +++++++++ .../bausystem/tracernew/data/TNTTrace.java | 4 ++ .../tracernew/recorder/RecordManager.java | 4 ++ .../tracernew/recorder/TNTRecorder.java | 53 +++++++++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/TraceHolder.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/RecordStatus.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/TNTTrace.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java new file mode 100644 index 0000000..e449674 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java @@ -0,0 +1,37 @@ +package de.steamwar.bausystem.tracernew; + +import de.steamwar.bausystem.tracernew.data.RecordStatus; +import org.bukkit.Bukkit; +import org.bukkit.World; + +public class DataHolder { + + public static final World world = Bukkit.getWorlds().get(0); + + public static RecordStatus status = RecordStatus.IDLE; + + public static boolean isRecording() { + return status == RecordStatus.RECORD || status == RecordStatus.RECORD_AUTO; + } + + public static boolean isRecordingAuto() { + return status == RecordStatus.RECORD_AUTO; + } + + public static boolean isRecordingNotAuto() { + return status == RecordStatus.RECORD; + } + + public static boolean isIdle() { + return status == RecordStatus.IDLE || status == RecordStatus.IDLE_AUTO; + } + + public static boolean isIdleAuto() { + return status == RecordStatus.IDLE_AUTO; + } + + public static boolean isIdleNotAuto() { + return status == RecordStatus.IDLE; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/TraceHolder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/TraceHolder.java new file mode 100644 index 0000000..6d1115b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/TraceHolder.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.tracernew; + +public class TraceHolder { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/RecordStatus.java new file mode 100644 index 0000000..7da8547 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/RecordStatus.java @@ -0,0 +1,26 @@ +package de.steamwar.bausystem.tracernew.data; + +public enum RecordStatus { + + RECORD("§aan", true), + RECORD_AUTO("§aan", true), + IDLE("§caus", false), + IDLE_AUTO("§eauto", false); + + String name; + boolean tracing; + + RecordStatus(String value, boolean tracing) { + this.name = value; + this.tracing = tracing; + } + + public String getName() { + return name; + } + + public boolean isTracing() { + return tracing; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/TNTTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/TNTTrace.java new file mode 100644 index 0000000..0f58dbf --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/TNTTrace.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.tracernew.data; + +public class TNTTrace { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java new file mode 100644 index 0000000..c2d0830 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java @@ -0,0 +1,4 @@ +package de.steamwar.bausystem.tracernew.recorder; + +public class RecordManager { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java new file mode 100644 index 0000000..d6f1806 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java @@ -0,0 +1,53 @@ +package de.steamwar.bausystem.tracernew.recorder; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.TraceListener; +import de.steamwar.bausystem.tracernew.DataHolder; +import org.bukkit.Bukkit; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitTask; + +import java.util.stream.Stream; + +import static de.steamwar.bausystem.tracer.recorder.RecordManager.stopAuto; + +public class TNTRecorder { + + private static BukkitTask task = null; + public static long recordStart = System.currentTimeMillis(); + public static long lastExplosion = System.currentTimeMillis(); + + static void update() { + if (task == null) return; + if (!DataHolder.isRecordingAuto()) return; + lastExplosion = System.currentTimeMillis(); + } + + static void startRecording() { + if (task != null) return; + recordStart = System.currentTimeMillis(); + lastExplosion = System.currentTimeMillis(); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1); + run(); + } + + static void stopRecording() { + if (task == null) return; + task.cancel(); + task = null; + } + + private static void run() { + DataHolder.world.getEntitiesByClass(TNTPrimed.class).stream() + Stream tntPrimedStream = DataHolder.world.getEntities() + .stream() + .filter(e -> e instanceof TNTPrimed) + .map(e -> (TNTPrimed)e); + TraceListener.onTick(tntPrimedStream); + + if (DataHolder.isRecordingAuto() && System.currentTimeMillis() - lastExplosion > 4500) { + stopAuto(); + } + } + +} From d7e13f2be2fca3c793f3c348004e5aef12e465a5 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 20 Nov 2020 15:26:11 +0100 Subject: [PATCH 02/46] Add ExplodeListener --- .../bausystem/tracernew/DataHolder.java | 8 ++ .../tracernew/recorder/ExplodeListener.java | 22 +++++ .../tracernew/recorder/RecordManager.java | 83 +++++++++++++++++++ .../tracernew/recorder/TNTRecorder.java | 12 ++- 4 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/ExplodeListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java index e449674..c9c1bbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java @@ -1,5 +1,6 @@ package de.steamwar.bausystem.tracernew; +import de.steamwar.bausystem.commands.CommandTPSLimiter; import de.steamwar.bausystem.tracernew.data.RecordStatus; import org.bukkit.Bukkit; import org.bukkit.World; @@ -9,6 +10,13 @@ public class DataHolder { public static final World world = Bukkit.getWorlds().get(0); public static RecordStatus status = RecordStatus.IDLE; + public static long recordStart = System.currentTimeMillis(); + public static long lastExplosion = System.currentTimeMillis(); + + public static boolean isAutoStop() { + if (!isRecordingAuto()) return false; + return System.currentTimeMillis() - lastExplosion > (20.0 / CommandTPSLimiter.getCurrentTPSLimit()) * 50 * 80; + } public static boolean isRecording() { return status == RecordStatus.RECORD || status == RecordStatus.RECORD_AUTO; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/ExplodeListener.java new file mode 100644 index 0000000..e0ed975 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/ExplodeListener.java @@ -0,0 +1,22 @@ +package de.steamwar.bausystem.tracernew.recorder; + +import de.steamwar.bausystem.tracernew.DataHolder; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +public class ExplodeListener implements Listener { + + public void onEntityExplode(EntityExplodeEvent event) { + if (!(event.getEntity() instanceof TNTPrimed)) + return; + + if (DataHolder.isRecordingAuto()) + RecordManager.stopAuto(); + if (DataHolder.isIdleAuto()) + RecordManager.updateAuto(); + + + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java index c2d0830..87389ad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java @@ -1,4 +1,87 @@ package de.steamwar.bausystem.tracernew.recorder; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.TraceManager; +import de.steamwar.bausystem.tracernew.DataHolder; +import de.steamwar.bausystem.tracernew.data.RecordStatus; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import static de.steamwar.bausystem.tracernew.recorder.TNTRecorder.*; + public class RecordManager { + + public static void recordCommands(Player player, String[] args) { + switch (args[0].toLowerCase()) { + case "start": + start(); + player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet"); + break; + case "stop": + stop(); + player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); + break; + case "auto": + case "toggleauto": + toggleAuto(); + if (DataHolder.isIdleNotAuto() || DataHolder.isRecordingNotAuto()) { + player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert"); + } else { + player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert"); + } + break; + } + } + + private static void toggleAuto() { + switch (DataHolder.status) { + case IDLE: + DataHolder.status = RecordStatus.IDLE_AUTO; + break; + case RECORD: + DataHolder.status = RecordStatus.RECORD_AUTO; + break; + case IDLE_AUTO: + DataHolder.status = RecordStatus.IDLE; + break; + case RECORD_AUTO: + DataHolder.status = RecordStatus.RECORD; + break; + default: + break; + } + } + + public static void start() { + DataHolder.status = RecordStatus.RECORD; + TraceManager.startFrame(); + startRecording(); + } + + public static void startAuto() { + DataHolder.status = RecordStatus.RECORD_AUTO; + Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet"))); + TraceManager.startFrame(); + startRecording(); + } + + public static void updateAuto() { + update(); + } + + public static void stop() { + DataHolder.status = RecordStatus.IDLE; + stopRecording(); + TraceManager.stopFrame(); + } + + static void stopAuto() { + DataHolder.status = RecordStatus.IDLE_AUTO; + Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt"))); + stopRecording(); + TraceManager.stopFrame(); + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java index d6f1806..e5ea32a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java @@ -9,24 +9,22 @@ import org.bukkit.scheduler.BukkitTask; import java.util.stream.Stream; -import static de.steamwar.bausystem.tracer.recorder.RecordManager.stopAuto; +import static de.steamwar.bausystem.tracernew.recorder.RecordManager.stopAuto; public class TNTRecorder { private static BukkitTask task = null; - public static long recordStart = System.currentTimeMillis(); - public static long lastExplosion = System.currentTimeMillis(); static void update() { if (task == null) return; if (!DataHolder.isRecordingAuto()) return; - lastExplosion = System.currentTimeMillis(); + DataHolder.lastExplosion = System.currentTimeMillis(); } static void startRecording() { if (task != null) return; - recordStart = System.currentTimeMillis(); - lastExplosion = System.currentTimeMillis(); + DataHolder.recordStart = System.currentTimeMillis(); + DataHolder.lastExplosion = System.currentTimeMillis(); task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1); run(); } @@ -45,7 +43,7 @@ public class TNTRecorder { .map(e -> (TNTPrimed)e); TraceListener.onTick(tntPrimedStream); - if (DataHolder.isRecordingAuto() && System.currentTimeMillis() - lastExplosion > 4500) { + if (DataHolder.isAutoStop()) { stopAuto(); } } From daad65b1d7ebed0101c69b86f62dfef36b6059a6 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 4 Dec 2020 22:49:21 +0100 Subject: [PATCH 03/46] Add RecordManager --- .../steamwar/bausystem/tracernew/recorder/RecordManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java index 87389ad..eb8efc4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java @@ -13,6 +13,10 @@ import static de.steamwar.bausystem.tracernew.recorder.TNTRecorder.*; public class RecordManager { + private RecordManager() { + throw new IllegalStateException("Utility class"); + } + public static void recordCommands(Player player, String[] args) { switch (args[0].toLowerCase()) { case "start": From bb92dc51db0ca4557a919feb6b5c4f5875985464 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 5 Dec 2020 21:33:48 +0100 Subject: [PATCH 04/46] Add basic Trace System --- .../bausystem/tracer/TNTTracer_12.java | 30 --- .../bausystem/tracer/TraceTNT_12.java | 53 +++++ .../bausystem/tracer/TNTTracer_15.java | 30 --- .../bausystem/tracer/TraceTNT_15.java | 37 +++ .../bausystem/tracer/ReflectionsUtils.java | 39 +++ .../src/de/steamwar/bausystem/BauSystem.java | 10 +- .../bausystem/commands/CommandTrace.java | 30 ++- .../commands/CommandTraceTabCompleter.java | 5 +- .../bausystem/tracer/ExplodeListener.java | 19 ++ .../bausystem/tracer/RecordManager.java | 87 +++++++ .../data => tracer}/RecordStatus.java | 2 +- .../bausystem/tracer/ShowManager.java | 225 ------------------ .../steamwar/bausystem/tracer/TNTTrace.java | 112 --------- .../steamwar/bausystem/tracer/TNTTracer.java | 125 ---------- .../bausystem/tracer/TNTTracerGUI.java | 99 -------- .../steamwar/bausystem/tracer/TraceCache.java | 170 ------------- .../bausystem/tracer/TraceListener.java | 73 ------ .../bausystem/tracer/TraceManager.java | 107 +++------ .../steamwar/bausystem/tracer/TraceTNT.java | 97 ++++++++ .../tracer/recorder/RecordManager.java | 136 ----------- .../tracer/recorder/TNTRecorder.java | 70 ------ .../bausystem/tracernew/DataHolder.java | 45 ---- .../bausystem/tracernew/TraceHolder.java | 4 - .../bausystem/tracernew/data/TNTTrace.java | 4 - .../tracernew/recorder/ExplodeListener.java | 22 -- .../tracernew/recorder/RecordManager.java | 91 ------- .../tracernew/recorder/TNTRecorder.java | 51 ---- .../bausystem/world/BauScoreboard.java | 14 +- 28 files changed, 393 insertions(+), 1394 deletions(-) delete mode 100644 BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java create mode 100644 BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java rename BauSystem_Main/src/de/steamwar/bausystem/{tracernew/data => tracer}/RecordStatus.java (90%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/ShowManager.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTrace.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracerGUI.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceCache.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceListener.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/RecordManager.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/TNTRecorder.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/TraceHolder.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/TNTTrace.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/ExplodeListener.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java deleted file mode 100644 index 7f7ad45..0000000 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import org.bukkit.Material; - -class TNTTracer_12 { - private TNTTracer_12(){} - - static Material getMaterial(){ - return Material.STAINED_GLASS; - } -} diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java new file mode 100644 index 0000000..5079f69 --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java @@ -0,0 +1,53 @@ +package de.steamwar.bausystem.tracer; + +import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntity; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public class TraceTNT_12 { + + // public PacketPlayOutSpawnEntity(Entity var1, int var2, int var3) { + // this.a = var1.getId(); + // this.b = var1.getUniqueID(); + // this.c = var1.locX; + // this.d = var1.locY; + // this.e = var1.locZ; + // this.i = MathHelper.d(var1.pitch * 256.0F / 360.0F); + // this.j = MathHelper.d(var1.yaw * 256.0F / 360.0F); + // this.k = var2; + // this.l = var3; + // double var4 = 3.9D; + // this.f = (int)(MathHelper.a(var1.motX, -3.9D, 3.9D) * 8000.0D); + // this.g = (int)(MathHelper.a(var1.motY, -3.9D, 3.9D) * 8000.0D); + // this.h = (int)(MathHelper.a(var1.motZ, -3.9D, 3.9D) * 8000.0D); + // } + + static void showTNT(int entityID, Player player, float... position) { + PacketPlayOutSpawnEntity spawnEntity = new PacketPlayOutSpawnEntity(); + ReflectionsUtils.setField("a", spawnEntity, entityID); + ReflectionsUtils.setField("b", spawnEntity, UUID.randomUUID()); + ReflectionsUtils.setField("c", spawnEntity, position[0]); + ReflectionsUtils.setField("d", spawnEntity, position[1]); + ReflectionsUtils.setField("e", spawnEntity, position[2]); + ReflectionsUtils.setField("i", spawnEntity, 0); + ReflectionsUtils.setField("j", spawnEntity, 0); + // EntityType + ReflectionsUtils.setField("k", spawnEntity, 0); + ReflectionsUtils.setField("l", spawnEntity, 0); + ReflectionsUtils.setField("f", spawnEntity, 0); + ReflectionsUtils.setField("g", spawnEntity, 0); + ReflectionsUtils.setField("h", spawnEntity, 0); + + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(spawnEntity); + } + + static void hideTNT(int entityID, Player player, float... position) { + PacketPlayOutEntityDestroy deleteEntity = new PacketPlayOutEntityDestroy(entityID); + + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(deleteEntity); + } + +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java deleted file mode 100644 index f88d841..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import org.bukkit.Material; - -class TNTTracer_15 { - private TNTTracer_15(){} - - static Material getMaterial(boolean updatePoint){ - return updatePoint ? Material.LIME_STAINED_GLASS : Material.RED_STAINED_GLASS; - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java new file mode 100644 index 0000000..148f27d --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java @@ -0,0 +1,37 @@ +package de.steamwar.bausystem.tracer; + +import net.minecraft.server.v1_15_R1.EntityTypes; +import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public class TraceTNT_15 { + + static void showTNT(int entityID, Player player, float... position) { + PacketPlayOutSpawnEntity spawnEntity = new PacketPlayOutSpawnEntity(); + ReflectionsUtils.setField("a", spawnEntity, entityID); + ReflectionsUtils.setField("b", spawnEntity, UUID.randomUUID()); + ReflectionsUtils.setField("c", spawnEntity, position[0]); + ReflectionsUtils.setField("d", spawnEntity, position[1]); + ReflectionsUtils.setField("e", spawnEntity, position[2]); + ReflectionsUtils.setField("i", spawnEntity, 0); + ReflectionsUtils.setField("j", spawnEntity, 0); + ReflectionsUtils.setField("k", spawnEntity, EntityTypes.FALLING_BLOCK); + ReflectionsUtils.setField("l", spawnEntity, 0); + ReflectionsUtils.setField("f", spawnEntity, 0); + ReflectionsUtils.setField("g", spawnEntity, 0); + ReflectionsUtils.setField("h", spawnEntity, 0); + + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(spawnEntity); + } + + static void hideTNT(int entityID, Player player, float... position) { + PacketPlayOutEntityDestroy deleteEntity = new PacketPlayOutEntityDestroy(entityID); + + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(deleteEntity); + } + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java new file mode 100644 index 0000000..236e5c7 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java @@ -0,0 +1,39 @@ +package de.steamwar.bausystem.tracer; + +import java.lang.reflect.Field; +import java.util.LinkedHashMap; +import java.util.Map; + +public class ReflectionsUtils { + + private static Map fieldMap = new LinkedHashMap() { + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > 100; + } + }; + + @SuppressWarnings({"java:S3011"}) + static void setField(String fieldName, Object object, Object fieldValue) { + String cacheName = object.getClass().getTypeName() + ":" + fieldName; + Field field; + if (fieldMap.containsKey(cacheName)) { + field = fieldMap.get(cacheName); + } else { + try { + field = object.getClass().getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + return; + } + fieldMap.put(cacheName, field); + } + + field.setAccessible(true); + try { + field.set(object, fieldValue); + } catch (IllegalAccessException e) { + + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 267533f..7c4de53 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -20,9 +20,7 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.commands.*; -import de.steamwar.bausystem.tracer.ShowManager; -import de.steamwar.bausystem.tracer.TNTTracer; -import de.steamwar.bausystem.tracer.TraceListener; +import de.steamwar.bausystem.tracer.ExplodeListener; import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; import de.steamwar.core.Core; @@ -134,10 +132,10 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); - Bukkit.getPluginManager().registerEvents(new TraceListener(), this); + Bukkit.getPluginManager().registerEvents(new ExplodeListener(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); new AFKStopper(); - TNTTracer.init(); + // TNTTracer.init(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); } @@ -182,7 +180,7 @@ public class BauSystem extends JavaPlugin implements Listener { Player p = e.getPlayer(); p.setOp(true); - ShowManager.add(p); + // ShowManager.add(p); if (Core.getVersion() == 15) Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 430c3ab..3b0cb63 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -21,9 +21,8 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.tracer.ShowManager; +import de.steamwar.bausystem.tracer.RecordManager; import de.steamwar.bausystem.tracer.TraceManager; -import de.steamwar.bausystem.tracer.recorder.RecordManager; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -69,19 +68,27 @@ public class CommandTrace implements CommandExecutor { switch (args[0].toLowerCase()) { case "start": + RecordManager.commandStart(); + break; case "stop": + RecordManager.commandStop(); + break; case "toggleauto": case "auto": - RecordManager.tracer(player, args); + RecordManager.commandAuto(); break; case "show": + TraceManager.commandShow(player); + break; case "hide": + TraceManager.commandHide(player); + break; case "toggleshow": case "interpolate": case "distance": - if (tracer(player, args)) { + /*if (tracer(player, args)) { help(player); - } + }*/ break; case "list": case "gui": @@ -99,7 +106,7 @@ public class CommandTrace implements CommandExecutor { } private boolean delete(Player player, String[] args) { - if (args.length == 2) { + /*if (args.length == 2) { try { TraceManager.delete(Integer.parseInt(args[1])); player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + args[1] + " gelöscht"); @@ -108,15 +115,16 @@ public class CommandTrace implements CommandExecutor { } catch (NumberFormatException e) { return true; } - } - TraceManager.deleteAll(); + }*/ + TraceManager.commandDelete(); + // TraceManager.deleteAll(); player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); - ShowManager.globalDirty(); + // ShowManager.globalDirty(); return false; } - public boolean tracer(Player player, String[] args) { + /*public boolean tracer(Player player, String[] args) { ShowManager.ShowStatus showStatus = ShowManager.showMap.get(player.getUniqueId().toString()); showStatus.dirty = true; switch (args[0].toLowerCase()) { @@ -240,5 +248,5 @@ public class CommandTrace implements CommandExecutor { return true; } return false; - } + }*/ } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index b97fa39..ef0ace0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -19,7 +19,8 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.tracer.recorder.RecordManager; +import de.steamwar.bausystem.tracer.RecordManager; +import de.steamwar.bausystem.tracer.RecordStatus; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -39,7 +40,7 @@ public class CommandTraceTabCompleter implements TabCompleter { private List tracerTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); - if (RecordManager.getStatus() == RecordManager.Status.IDLE || RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO) { + if (RecordManager.getRecordStatus() == RecordStatus.IDLE || RecordManager.getRecordStatus() == RecordStatus.IDLE_AUTO) { tabComplete.add("start"); } else { tabComplete.add("stop"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java new file mode 100644 index 0000000..de2654d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java @@ -0,0 +1,19 @@ +package de.steamwar.bausystem.tracer; + +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +public class ExplodeListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onEntityExplode(EntityExplodeEvent event) { + if (!(event.getEntity() instanceof TNTPrimed)) return; + + RecordManager.tntExplode(); + TraceManager.tntExplode((TNTPrimed) event.getEntity()); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java new file mode 100644 index 0000000..24ad350 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java @@ -0,0 +1,87 @@ +package de.steamwar.bausystem.tracer; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.commands.CommandTPSLimiter; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitTask; + +public class RecordManager { + + private static final World world = Bukkit.getWorlds().get(0); + + private static RecordStatus recordStatus = RecordStatus.IDLE; + + private static BukkitTask recorder = null; + private static long startTime = 0; + private static long lastExplosion = 0; + + public static void commandStart() { + recordStatus = RecordStatus.RECORD; + recordStart(); + } + + public static void commandStop() { + recordStatus = RecordStatus.IDLE; + recordStop(); + } + + public static void commandAuto() { + if (recordStatus != RecordStatus.IDLE) { + return; + } + if (recordStatus == RecordStatus.IDLE_AUTO) { + recordStatus = RecordStatus.IDLE; + } else { + recordStatus = RecordStatus.IDLE_AUTO; + } + } + + public static void tntExplode() { + if (recordStatus == RecordStatus.RECORD_AUTO) { + lastExplosion = System.currentTimeMillis(); + return; + } + if (recordStatus != RecordStatus.IDLE_AUTO) { + return; + } + lastExplosion = System.currentTimeMillis(); + recordStatus = RecordStatus.RECORD_AUTO; + recordStart(); + } + + private static void recordStart() { + if (recorder != null) return; + startTime = System.currentTimeMillis(); + recorder = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + world.getEntitiesByClass(TNTPrimed.class).forEach(TraceManager::tntAdd); + recordAutoStop(); + }, 1, 1); + } + + private static void recordStop() { + if (recorder == null) return; + recorder.cancel(); + recorder = null; + startTime = 0; + TraceManager.recordStop(); + } + + private static void recordAutoStop() { + if (recordStatus != RecordStatus.RECORD_AUTO) return; + if (System.currentTimeMillis() - lastExplosion > (20.0 / CommandTPSLimiter.getCurrentTPSLimit()) * 50 * 80) { + recordStatus = RecordStatus.IDLE_AUTO; + recordStop(); + } + } + + public static RecordStatus getRecordStatus() { + return recordStatus; + } + + public static long getStartTime() { + return startTime; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java similarity index 90% rename from BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/RecordStatus.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java index 7da8547..eee5ad5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java @@ -1,4 +1,4 @@ -package de.steamwar.bausystem.tracernew.data; +package de.steamwar.bausystem.tracer; public enum RecordStatus { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/ShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/ShowManager.java deleted file mode 100644 index 9514990..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/ShowManager.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import java.util.*; - -public class ShowManager { - - public enum DisplayMode { - NONE, - Y_AXIS, - ALL - } - - public enum DisplayType { - Particle, - Block - } - - public enum ShowSelection { - NONE, - SELECTIVE, - ALL - } - - - public interface Mode { - void run(int tntID); - } - - public interface ModeChoose { - boolean run(int tntID); - } - - - public static class ShowStatus { - - private ShowSelection showSelection = ShowSelection.NONE; - public DisplayType displayType = DisplayType.Particle; - public DisplayMode displayMode = DisplayMode.ALL; - - public boolean dirty = true; - private int count = 0; - - private Set selected = new HashSet<>(); - - private void clear() { - if (showSelection == ShowSelection.NONE) return; - selected.clear(); - } - - public void show() { - showSelection = ShowSelection.ALL; - } - - public void hide() { - clear(); - showSelection = ShowSelection.NONE; - } - - public void addSelection(int id) { - if (showSelection == ShowSelection.ALL) return; - if (showSelection == ShowSelection.NONE) showSelection = ShowSelection.SELECTIVE; - TraceManager.getFrame(id).forEach(i -> selected.add(i)); - if (selected.size() == TraceManager.getAllTraces().size()) { - showSelection = ShowSelection.ALL; - clear(); - } - } - - public void removeSelection(int id) { - if (showSelection == ShowSelection.NONE) return; - if (showSelection == ShowSelection.ALL) selected = TraceManager.getAllTraces(); - TraceManager.getFrame(id).forEach(i -> selected.remove(i)); - showSelection = ShowSelection.SELECTIVE; - if (selected.isEmpty()) showSelection = ShowSelection.NONE; - } - - public boolean toggleSelection(int id) { - if (showSelection == ShowSelection.NONE) { - addSelection(id); - return true; - } - if (showSelection == ShowSelection.ALL) { - removeSelection(id); - return false; - } - if (selected.contains(id)) { - removeSelection(id); - return false; - } else { - addSelection(id); - return true; - } - } - - public DisplayType getDisplayType() { - return displayType; - } - - public DisplayMode getDisplayMode() { - return displayMode; - } - - public LinkedList getTraces() { - if (showSelection == ShowSelection.NONE) return new LinkedList<>(); - Set tntIDs; - if (showSelection == ShowSelection.ALL) { - tntIDs = TraceManager.getAllTraces(); - } else { - tntIDs = selected; - } - - LinkedList traces = new LinkedList<>(); - for (int traceId : tntIDs) { - TNTTrace trace = TraceManager.getTrace(traceId); - if (trace == null) continue; - traces.add(trace); - } - return traces; - } - - public boolean isDirty() { - if (displayType == DisplayType.Block) { - count++; - } - if (count >= 10) { - count = 0; - return true; - } - if (dirty) { - dirty = false; - return true; - } - return false; - } - - public double slopeHeight = 7.0; - - private int size = 0; - - private TraceCache.Loc loc = null; - - public double getShowRadius() { - double maxRadius = 80.0; - if (showSelection == ShowSelection.NONE) return maxRadius; - if (showSelection == ShowSelection.ALL) size = TraceManager.getAllTraces().size(); - if (showSelection == ShowSelection.SELECTIVE) size = selected.size(); - if (size == 0) return maxRadius; - double minRadius = 20.0; - if (size >= 950) return minRadius; - - double slope = -(size / slopeHeight) + 85; - return Math.min(Math.max(slope, minRadius), maxRadius); - } - - public void setSlope(double slope) { - double minSlope = 3.0; - double maxSlope = 11.0; - slopeHeight = Math.min(Math.max(slope, minSlope), maxSlope); - } - - public void move(Player player) { - if (loc != null && !loc.remove(player, 4)) { - return; - } - Location location = player.getLocation(); - loc = new TraceCache.Loc((float) location.getX(), (float) location.getY(), (float) location.getZ()); - dirty = true; - } - - } - - public static Map showMap = new HashMap<>(); - - public static void add(Player p) { - showMap.put(p.getUniqueId().toString(), new ShowStatus()); - } - - public static ShowStatus get(Player p) { - if (!showMap.containsKey(p.getUniqueId().toString())) add(p); - return showMap.get(p.getUniqueId().toString()); - } - - public static void traceAdd() { - for (Map.Entry entry : showMap.entrySet()) { - if (entry.getValue().showSelection == ShowSelection.ALL) { - entry.getValue().dirty = true; - } - } - } - - public static void traceRemove(int id) { - for (Map.Entry entry : showMap.entrySet()) { - entry.getValue().removeSelection(id); - } - } - - public static void globalDirty() { - for (Map.Entry entry : showMap.entrySet()) { - entry.getValue().dirty = true; - } - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTrace.java deleted file mode 100644 index 6c7b770..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTrace.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import org.bukkit.Location; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class TNTTrace { - - private final int frameID; - - private int index = 0; - private float[] positions = new float[240]; - - private Set posSet = new HashSet<>(); - private Set posYSet = new HashSet<>(); - private Set posXYZSet = new HashSet<>(); - - TNTTrace(int frameID) { - this.frameID = frameID; - } - - void addLocation(Location location) { - if (index >= positions.length) { - positions = Arrays.copyOf(positions, positions.length + 3); - } - positions[index] = (float)location.getX(); - positions[index + 1] = (float)location.getY(); - positions[index + 2] = (float)location.getZ(); - index += 3; - } - - private int size() { - return index / 3; - } - - public int length() { - return size(); - } - - private int realLength() { - return positions.length; - } - - int getFrameID() { - return frameID; - } - - void cleanUp() { - positions = Arrays.copyOf(positions, index); - ShowManager.traceAdd(); - - for (int i = 0; i < length(); i++) { - posSet.add(new TraceCache.Loc(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2])); - } - - for (int i = 0; i < realLength() - 3; i += 3) { - float x1 = positions[i]; - float y1 = positions[i + 1]; - float z1 = positions[i + 2]; - - float x2 = positions[i + 3]; - float y2 = positions[i + 4]; - float z2 = positions[i + 5]; - - if (isDifferent(y2, y1)) { - TraceCache.Loc loc = new TraceCache.Loc(x1, y2, z1); - posYSet.add(loc); - posXYZSet.add(loc); - } - if (Math.abs(x2 - x1) > Math.abs(z2 - z1)) { - if (isDifferent(x2, x1)) posXYZSet.add(new TraceCache.Loc(x2, y2, z1)); - } else { - if (isDifferent(z2, z1)) posXYZSet.add(new TraceCache.Loc(x1, y2, z2)); - } - } - } - - Set locs() { - return posSet; - } - - Set locsUpdate(ShowManager.DisplayMode displayMode) { - if (displayMode == ShowManager.DisplayMode.NONE) return new HashSet<>(); - if (displayMode == ShowManager.DisplayMode.Y_AXIS) return posYSet; - return posXYZSet; - } - - private static boolean isDifferent(float d1, float d2) { - return (d2 - d1) * (d2 - d1) >= 0.01; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java deleted file mode 100644 index a7ea71b..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.core.Core; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.entity.Player; - -import java.util.Set; - -public class TNTTracer { - private TNTTracer(){} - - static final boolean DEBUG = false; - - private static final Object synchronizer = new Object(); - private static final TraceCache traceCache = new TraceCache(); - - public static void init(){ - Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer::run, 0, 20); - } - - private static void run() { - for (Player p : Bukkit.getOnlinePlayers()) { - if (DEBUG) { - String actionBar = "§e" + TraceManager.getAllTraces().size() + " §cTraces §e" + ShowManager.get(p).getShowRadius() + " §cRadius"; - p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar)); - } - - boolean dirty = ShowManager.get(p).isDirty(); - if (ShowManager.get(p).getDisplayType() == ShowManager.DisplayType.Block && !dirty) { - continue; - } - Set toHide = traceCache.update(p, dirty); - Set toShow = traceCache.get(p); - - hideBlockTraces(toHide, p); - showTraces(toShow, ShowManager.get(p).getDisplayType(), p); - } - } - - private static void hideBlockTraces(Set locs, Player player) { - if (locs.isEmpty()) return; - - for (TraceCache.Loc l : locs) { - hideBlock(player, l.x, l.y - 0.49F, l.z); - } - } - - private static void showTraces(Set locs, ShowManager.DisplayType displayMode, Player player) { - if (locs.isEmpty()) return; - - for (TraceCache.Loc l : locs) { - if (displayMode == ShowManager.DisplayType.Block) { - showBlock(player, l.x, l.y - 0.49F, l.z, getMaterial(l), (l.updatePoint ? (byte) 5 : (byte) 14)); - } else { - showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY)); - } - } - } - - private static Material getMaterial(TraceCache.Loc l){ - switch(Core.getVersion()){ - case 15: - return TNTTracer_15.getMaterial(l.updatePoint); - default: - return TNTTracer_12.getMaterial(); - } - } - - private static void showCorner(Player player, float x, float y, float z, Particle particle) { - player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); - - player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); - } - - private static void showBlock(Player p, float x, float y, float z, Material block, byte b) { - if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) { - p.sendBlockChange(makeLocation(x, y, z), block, b); - } - } - - private static void hideBlock(Player p, float x, float y, float z) { - if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) { - p.sendBlockChange(makeLocation(x, y, z), Material.AIR, (byte) 0); - } - } - - private static final Location location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); - private static Location makeLocation(float x, float y, float z) { - location.setX(x); - location.setY(y); - location.setZ(z); - return location; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracerGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracerGUI.java deleted file mode 100644 index e011e48..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracerGUI.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -public class TNTTracerGUI { - - /*private static GuiCallbackTNTFrame guiCallbackTNTFrame; - private static GuiCallbackTNTTrace guiCallbackTNTTrace; - private static GuiCallbackRecording guiCallbackRecording; - - private static Inventory getEmpty(String title) { - Inventory inventory = Bukkit.createInventory(null, 54, title); - ItemStack i1 = createItem(Material.LIGHT_GRAY_STAINED_GLASS_PANE, false, ""); - for (int i = 0; i < 9; i++) { - inventory.setItem(i, i1); - } - ItemStack i2 = createItem(Material.RED_STAINED_GLASS, false, ""); - for (int i = 9; i < 54; i++) { - inventory.setItem(i, i2); - } - return inventory; - } - - public static ItemStack createItem(Material material, boolean selected, String name, String... lore) { - ItemStack item = new ItemStack(material, 1); - ItemMeta im = item.getItemMeta(); - - if (im == null) return item; - if (name == null) name = "§f"; - if (name.isEmpty()) name = "§f"; - im.setDisplayName(name); - if (selected) { - im.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true); - } - im.addItemFlags(ItemFlag.HIDE_ENCHANTS); - - if (lore != null) { - List lorelist = Arrays.asList(lore); - im.setLore(lorelist); - } - - item.setItemMeta(im); - return item; - } - - private static void frameControls(Inventory inventory, int page, int allPages) { - inventory.setItem(1, createItem(Material.HONEYCOMB, false, "§eShow§8/§eHide")); - inventory.setItem(4, createItem(Material.BARRIER, false, "§eClear ausgewählte Positionen")); - inventory.setItem(5, createItem(Material.OBSERVER, false, "§eToggle AUTO-Trace")); - inventory.setItem(6, guiCallbackRecording.run()); - inventory.setItem(8, createItem(Material.PAPER, false, "§7PAGE §e§l" + page + "§8/§e§l" + allPages)); - } - - private static Inventory getFrameInventory(Player p, int page) { - ItemStack[] items = guiCallbackTNTFrame.run(p); - - Inventory inventory = getEmpty("§7§lTRACE §8- §e§lAufnahmen"); - if (items.length == 0) { - frameControls(inventory, page + 1, 1); - } else { - frameControls(inventory, page + 1, items.length / 45 + (items.length % 45 == 0 ? 0 : 1)); - } - return inventory; - } - - public static void init(GuiCallbackTNTFrame guiCallbackTNTFrame, GuiCallbackTNTTrace guiCallbackTNTTrace, GuiCallbackRecording guiCallbackRecording) { - TNTTracerGUI_15.guiCallbackTNTFrame = guiCallbackTNTFrame; - TNTTracerGUI_15.guiCallbackTNTTrace = guiCallbackTNTTrace; - TNTTracerGUI_15.guiCallbackRecording = guiCallbackRecording; - } - - public enum Menu { - FRAME, - TRACE, - BLOCK - } - - public static void show(Player p, int page, Menu menu) { - - }*/ - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceCache.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceCache.java deleted file mode 100644 index 1f094cb..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceCache.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import org.bukkit.entity.Player; - -import java.util.*; - -public class TraceCache { - - private static final Set empty = new HashSet<>(); - private Map> playerMap = new HashMap<>(); - private Map playerDisplayMap = new HashMap<>(); - - public Set get(Player player) { - return playerMap.getOrDefault(player.getUniqueId().toString(), empty); - } - - Set update(Player player, boolean dirty) { - if (!dirty) return empty; - String key = player.getUniqueId().toString(); - Set locOld; - ShowManager.DisplayType displayMode; - if (!playerMap.containsKey(key)) { - locOld = new HashSet<>(); - displayMode = getDisplayType(player); - } else { - locOld = playerMap.get(key); - displayMode = playerDisplayMap.get(key); - } - - Set locSet = new HashSet<>(); - updatePoints(player).forEach(loc -> { - loc.updatePoint = true; - locSet.add(loc); - }); - updateLocations(player).forEach(loc -> { - loc.updatePoint = false; - locSet.add(loc); - }); - - playerMap.put(key, locSet); - ShowManager.DisplayType currentMode = getDisplayType(player); - playerDisplayMap.put(key, currentMode); - - if (currentMode == ShowManager.DisplayType.Particle && displayMode == ShowManager.DisplayType.Block) return locOld; - if (currentMode == ShowManager.DisplayType.Block) return diff(locOld, locSet); - return empty; - } - - public static class Loc { - final float x; - final float y; - final float z; - - private final float dx; - private final float dy; - private final float dz; - - boolean updatePoint = false; - - public Loc(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - this.dx = round(x); - this.dy = round(y); - this.dz = round(z); - } - - private static float round(float toRound) { - final int roundNumber = 10; - float r = (toRound * roundNumber); - float t = r - (int) r; - if (t >= 0.5) { - return (((float)(int)r) + 1) / roundNumber; - } else { - return (((float)(int)r) + 0) / roundNumber; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Loc)) return false; - Loc loc = (Loc) o; - return Float.compare(loc.dx, dx) == 0 && - Float.compare(loc.dy, dy) == 0 && - Float.compare(loc.dz, dz) == 0; - } - - @Override - public int hashCode() { - return Objects.hash(dx, dy, dz); - } - - @Override - public String toString() { - return "Loc{" + - "x=" + x + - ", y=" + y + - ", z=" + z + - '}'; - } - - public boolean remove(Player player, double radius) { - double x = player.getLocation().getX(); - double y = player.getLocation().getY(); - double z = player.getLocation().getZ(); - - double dx = (this.x - x) * (this.x - x); - double dy = (this.y - y) * (this.y - y); - double dz = (this.z - z) * (this.z - z); - - return (dx + dy + dz) > radius * radius; - } - } - - private Set diff(Set locOld, Set locNew) { - if (locOld.isEmpty()) return empty; - if (locNew.isEmpty()) return locOld; - for (Loc l : locNew) { - locOld.remove(l); - } - return locOld; - } - - private Set updateLocations(Player player) { - Iterator traces = ShowManager.get(player).getTraces().descendingIterator(); - Set locSet = new HashSet<>(); - while (traces.hasNext()) { - locSet.addAll(traces.next().locs()); - } - double radius = ShowManager.get(player).getShowRadius(); - locSet.removeIf(loc -> loc.remove(player, radius)); - return locSet; - } - - private Set updatePoints(Player player) { - Iterator traces = ShowManager.get(player).getTraces().descendingIterator(); - Set locSet = new HashSet<>(); - while (traces.hasNext()) { - locSet.addAll(traces.next().locsUpdate(ShowManager.get(player).getDisplayMode())); - } - double radius = ShowManager.get(player).getShowRadius(); - locSet.removeIf(loc -> loc.remove(player, radius)); - return locSet; - } - - private ShowManager.DisplayType getDisplayType(Player player) { - return ShowManager.get(player).getDisplayType(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceListener.java deleted file mode 100644 index be87341..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceListener.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import de.steamwar.bausystem.tracer.recorder.RecordManager; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.player.PlayerMoveEvent; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - -public class TraceListener implements Listener { - - private static final Map tntMap = new HashMap<>(); - - public static void onTick(Stream tntPrimedStream) { - tntPrimedStream.forEach(tnt -> { - TNTTrace trace; - if (!tntMap.containsKey(tnt)) { - trace = TraceManager.createTrace(); - if (trace == null) return; - tntMap.put(tnt, trace); - } else { - trace = tntMap.get(tnt); - } - trace.addLocation(tnt.getLocation()); - }); - } - - @EventHandler - public void onEntityExplode(EntityExplodeEvent event) { - if (!(event.getEntity() instanceof TNTPrimed)) - return; - - if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO) - RecordManager.startAuto(); - if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO) - RecordManager.updateAuto(); - - TNTTrace trace = tntMap.remove((TNTPrimed) event.getEntity()); - if (trace != null) - trace.cleanUp(); - } - - - @EventHandler - public void playerMove(PlayerMoveEvent event) { - Player p = event.getPlayer(); - ShowManager.get(p).move(p); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java index 1491610..9826b76 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java @@ -1,101 +1,48 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - package de.steamwar.bausystem.tracer; -import java.util.*; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; public class TraceManager { - private TraceManager(){} - private static Map> frameMap = new HashMap<>(); - private static Map traceMap = new HashMap<>(); + private static Map traceTNTMap = new HashMap<>(); + private static Set traceTNTSet = new HashSet<>(); - private static int currentFrame; - - private static int currentID = 0; - private static synchronized int generateID() { - return currentID++; + public static void recordStop() { + traceTNTMap.clear(); } - public static void startFrame() { - currentFrame = generateID(); - frameMap.put(currentFrame, new ArrayList<>()); + public static void tntExplode(TNTPrimed tntPrimed) { + if (!traceTNTMap.containsKey(tntPrimed)) return; + traceTNTMap.remove(tntPrimed).explosion(tntPrimed); } - public static TNTTrace createTrace() { - if (!frameMap.containsKey(currentFrame)) return null; - TNTTrace trace = new TNTTrace(currentFrame); - int id = generateID(); - traceMap.put(id, trace); - frameMap.get(currentFrame).add(id); - return trace; + public static void tntAdd(TNTPrimed tntPrimed) { + TraceTNT traceTNT = new TraceTNT(tntPrimed); + traceTNTMap.put(tntPrimed, traceTNT); + traceTNTSet.add(traceTNT); } - public static TNTTrace getTrace(int id) { - return traceMap.get(id); + public static void commandDelete() { + traceTNTMap.clear(); + traceTNTSet.clear(); } - public static Set getAllTraces() { - return traceMap.keySet(); + public static int getRecordSize() { + return traceTNTMap.size(); } - public static List getFrame(int frameID) { - return new ArrayList<>(frameMap.getOrDefault(frameID, new ArrayList<>())); + public static void commandShow(Player player) { + traceTNTSet.forEach(traceTNT -> traceTNT.showTrace(player)); } - public static int currentFrameSize() { - if (!frameMap.containsKey(currentFrame)) return 0; - return frameMap.get(currentFrame).size(); + public static void commandHide(Player player) { + traceTNTSet.forEach(traceTNT -> traceTNT.hideTrace(player)); } - public static void stopFrame() { - testRemoveFrame(currentFrame); - } - - private static void testRemoveFrame(int frame){ - if (!frameMap.containsKey(frame) || !frameMap.get(frame).isEmpty()) - return; - frameMap.remove(frame); - } - - public static void deleteAll() { - for (Integer integer : new HashSet<>(traceMap.keySet())) { - delete(integer); - } - } - - public static void delete(int id) { - TNTTrace trace = traceMap.remove(id); - if(trace == null){ - List frame = frameMap.get(id); - if(frame == null) - return; - - for(int t : new HashSet<>(frame)){ - delete(t); - } - return; - } - int frameID = trace.getFrameID(); - ShowManager.traceRemove(id); - if (frameMap.containsKey(frameID)) frameMap.get(frameID).remove((Integer) id); - testRemoveFrame(frameID); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java new file mode 100644 index 0000000..78f4de9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java @@ -0,0 +1,97 @@ +package de.steamwar.bausystem.tracer; + +import de.steamwar.core.Core; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; + +import java.util.function.Consumer; + +public class TraceTNT { + + private static int traceID = 0; + + private int id = traceID++; + private float[] source = new float[3]; + private float[] explosion = new float[3]; + private int index = 0; + private float[] position = new float[240]; + private float[] velocity = new float[240]; + + public TraceTNT(TNTPrimed tntPrimed) { + source[0] = (float) tntPrimed.getLocation().getX(); + source[1] = (float) tntPrimed.getLocation().getY(); + source[2] = (float) tntPrimed.getLocation().getZ(); + } + + public void explosion(TNTPrimed tntPrimed) { + explosion[0] = (float) tntPrimed.getLocation().getX(); + explosion[1] = (float) tntPrimed.getLocation().getY(); + explosion[2] = (float) tntPrimed.getLocation().getZ(); + } + + public void add(TNTPrimed tntPrimed) { + if (index > position.length) return; + position[index + 0] = (float) tntPrimed.getLocation().getX(); + position[index + 1] = (float) tntPrimed.getLocation().getY(); + position[index + 2] = (float) tntPrimed.getLocation().getZ(); + velocity[index + 0] = (float) tntPrimed.getVelocity().getX(); + velocity[index + 1] = (float) tntPrimed.getVelocity().getY(); + velocity[index + 2] = (float) tntPrimed.getVelocity().getZ(); + index += 3; + } + + public long size() { + long size = 0; + + // id: + size += 32; + + // index: + size += 32; + + // source: + size += source.length * 32; + + // explosion: + size += explosion.length * 32; + + // position: + size += position.length * 32; + + // velocity: + size += velocity.length * 32; + + return size; + } + + public void showTrace(Player player) { + int entityID = Integer.MAX_VALUE - id * 200; + + tnt(entityID, player, source, TraceTNT_15::showTNT, TraceTNT_12::showTNT); + } + + public void hideTrace(Player player) { + int entityID = Integer.MAX_VALUE - id * 200; + + tnt(entityID, player, source, TraceTNT_15::hideTNT, TraceTNT_12::hideTNT); + } + + private void tnt(int entityID, Player player, float[] position, VersionConsumer version15, VersionConsumer versionDefault) { + if (position.length != 3) return; + switch (Core.getVersion()) { + case 15: + version15.accept(entityID, player, position); + break; + default: + versionDefault.accept(entityID, player, position); + break; + } + } + + private interface VersionConsumer { + + void accept(K k, V v, S s); + + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/RecordManager.java deleted file mode 100644 index 0e7d55b..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/RecordManager.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer.recorder; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.tracer.TraceManager; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import static de.steamwar.bausystem.tracer.recorder.TNTRecorder.*; - -public class RecordManager { - - static Status status = Status.IDLE; - - static final World world = Bukkit.getWorlds().get(0); - - public static void tracer(Player player, String[] args) { - switch (args[0].toLowerCase()) { - case "start": - start(); - player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet"); - break; - case "stop": - stop(); - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); - break; - case "auto": - case "toggleauto": - toggleAuto(); - if (status == Status.IDLE || status == Status.RECORD) { - player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert"); - } else { - player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert"); - } - break; - } - } - - private static void toggleAuto() { - switch (status) { - case IDLE: - status = Status.IDLE_AUTO; - break; - case RECORD: - status = Status.RECORD_AUTO; - break; - case IDLE_AUTO: - status = Status.IDLE; - break; - case RECORD_AUTO: - status = Status.RECORD; - break; - default: - break; - } - } - - public static Status getStatus() { - return status; - } - - private static void start() { - status = Status.RECORD; - TraceManager.startFrame(); - startRecording(); - } - - public static void startAuto() { - status = Status.RECORD_AUTO; - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet"))); - TraceManager.startFrame(); - startRecording(); - } - - public static void updateAuto() { - update(); - } - - private static void stop() { - status = Status.IDLE; - stopRecording(); - TraceManager.stopFrame(); - } - - static void stopAuto() { - status = Status.IDLE_AUTO; - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt"))); - stopRecording(); - TraceManager.stopFrame(); - } - - public enum Status { - RECORD("§aan", true), - RECORD_AUTO("§aan", true), - IDLE("§caus", false), - IDLE_AUTO("§eauto", false); - - String value; - boolean tracing; - - Status(String value, boolean tracing) { - this.value = value; - this.tracing = tracing; - } - - public String getValue() { - return value; - } - - public boolean isTracing() { - return tracing; - } - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/TNTRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/TNTRecorder.java deleted file mode 100644 index e51b936..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/TNTRecorder.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer.recorder; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.tracer.TraceListener; -import org.bukkit.Bukkit; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.scheduler.BukkitTask; - -import java.util.stream.Stream; - -import static de.steamwar.bausystem.tracer.recorder.RecordManager.stopAuto; - -public class TNTRecorder { - - private static BukkitTask task = null; - public static long recordStart = System.currentTimeMillis(); - public static long lastExplosion = System.currentTimeMillis(); - - static void update() { - if (task == null) return; - if (RecordManager.status != RecordManager.Status.RECORD_AUTO) return; - lastExplosion = System.currentTimeMillis(); - } - - static void startRecording() { - if (task != null) return; - recordStart = System.currentTimeMillis(); - lastExplosion = System.currentTimeMillis(); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1); - run(); - } - - static void stopRecording() { - if (task == null) return; - task.cancel(); - task = null; - } - - private static void run() { - Stream tntPrimedStream = RecordManager.world.getEntities() - .stream() - .filter(e -> e instanceof TNTPrimed) - .map(e -> (TNTPrimed)e); - TraceListener.onTick(tntPrimedStream); - - if (RecordManager.status == RecordManager.Status.RECORD_AUTO && System.currentTimeMillis() - lastExplosion > 4500) { - stopAuto(); - } - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java deleted file mode 100644 index c9c1bbd..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.steamwar.bausystem.tracernew; - -import de.steamwar.bausystem.commands.CommandTPSLimiter; -import de.steamwar.bausystem.tracernew.data.RecordStatus; -import org.bukkit.Bukkit; -import org.bukkit.World; - -public class DataHolder { - - public static final World world = Bukkit.getWorlds().get(0); - - public static RecordStatus status = RecordStatus.IDLE; - public static long recordStart = System.currentTimeMillis(); - public static long lastExplosion = System.currentTimeMillis(); - - public static boolean isAutoStop() { - if (!isRecordingAuto()) return false; - return System.currentTimeMillis() - lastExplosion > (20.0 / CommandTPSLimiter.getCurrentTPSLimit()) * 50 * 80; - } - - public static boolean isRecording() { - return status == RecordStatus.RECORD || status == RecordStatus.RECORD_AUTO; - } - - public static boolean isRecordingAuto() { - return status == RecordStatus.RECORD_AUTO; - } - - public static boolean isRecordingNotAuto() { - return status == RecordStatus.RECORD; - } - - public static boolean isIdle() { - return status == RecordStatus.IDLE || status == RecordStatus.IDLE_AUTO; - } - - public static boolean isIdleAuto() { - return status == RecordStatus.IDLE_AUTO; - } - - public static boolean isIdleNotAuto() { - return status == RecordStatus.IDLE; - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/TraceHolder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/TraceHolder.java deleted file mode 100644 index 6d1115b..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/TraceHolder.java +++ /dev/null @@ -1,4 +0,0 @@ -package de.steamwar.bausystem.tracernew; - -public class TraceHolder { -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/TNTTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/TNTTrace.java deleted file mode 100644 index 0f58dbf..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/data/TNTTrace.java +++ /dev/null @@ -1,4 +0,0 @@ -package de.steamwar.bausystem.tracernew.data; - -public class TNTTrace { -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/ExplodeListener.java deleted file mode 100644 index e0ed975..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/ExplodeListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.steamwar.bausystem.tracernew.recorder; - -import de.steamwar.bausystem.tracernew.DataHolder; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityExplodeEvent; - -public class ExplodeListener implements Listener { - - public void onEntityExplode(EntityExplodeEvent event) { - if (!(event.getEntity() instanceof TNTPrimed)) - return; - - if (DataHolder.isRecordingAuto()) - RecordManager.stopAuto(); - if (DataHolder.isIdleAuto()) - RecordManager.updateAuto(); - - - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java deleted file mode 100644 index eb8efc4..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/RecordManager.java +++ /dev/null @@ -1,91 +0,0 @@ -package de.steamwar.bausystem.tracernew.recorder; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.tracer.TraceManager; -import de.steamwar.bausystem.tracernew.DataHolder; -import de.steamwar.bausystem.tracernew.data.RecordStatus; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import static de.steamwar.bausystem.tracernew.recorder.TNTRecorder.*; - -public class RecordManager { - - private RecordManager() { - throw new IllegalStateException("Utility class"); - } - - public static void recordCommands(Player player, String[] args) { - switch (args[0].toLowerCase()) { - case "start": - start(); - player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet"); - break; - case "stop": - stop(); - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); - break; - case "auto": - case "toggleauto": - toggleAuto(); - if (DataHolder.isIdleNotAuto() || DataHolder.isRecordingNotAuto()) { - player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert"); - } else { - player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert"); - } - break; - } - } - - private static void toggleAuto() { - switch (DataHolder.status) { - case IDLE: - DataHolder.status = RecordStatus.IDLE_AUTO; - break; - case RECORD: - DataHolder.status = RecordStatus.RECORD_AUTO; - break; - case IDLE_AUTO: - DataHolder.status = RecordStatus.IDLE; - break; - case RECORD_AUTO: - DataHolder.status = RecordStatus.RECORD; - break; - default: - break; - } - } - - public static void start() { - DataHolder.status = RecordStatus.RECORD; - TraceManager.startFrame(); - startRecording(); - } - - public static void startAuto() { - DataHolder.status = RecordStatus.RECORD_AUTO; - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet"))); - TraceManager.startFrame(); - startRecording(); - } - - public static void updateAuto() { - update(); - } - - public static void stop() { - DataHolder.status = RecordStatus.IDLE; - stopRecording(); - TraceManager.stopFrame(); - } - - static void stopAuto() { - DataHolder.status = RecordStatus.IDLE_AUTO; - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt"))); - stopRecording(); - TraceManager.stopFrame(); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java deleted file mode 100644 index e5ea32a..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracernew/recorder/TNTRecorder.java +++ /dev/null @@ -1,51 +0,0 @@ -package de.steamwar.bausystem.tracernew.recorder; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.tracer.TraceListener; -import de.steamwar.bausystem.tracernew.DataHolder; -import org.bukkit.Bukkit; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.scheduler.BukkitTask; - -import java.util.stream.Stream; - -import static de.steamwar.bausystem.tracernew.recorder.RecordManager.stopAuto; - -public class TNTRecorder { - - private static BukkitTask task = null; - - static void update() { - if (task == null) return; - if (!DataHolder.isRecordingAuto()) return; - DataHolder.lastExplosion = System.currentTimeMillis(); - } - - static void startRecording() { - if (task != null) return; - DataHolder.recordStart = System.currentTimeMillis(); - DataHolder.lastExplosion = System.currentTimeMillis(); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1); - run(); - } - - static void stopRecording() { - if (task == null) return; - task.cancel(); - task = null; - } - - private static void run() { - DataHolder.world.getEntitiesByClass(TNTPrimed.class).stream() - Stream tntPrimedStream = DataHolder.world.getEntities() - .stream() - .filter(e -> e instanceof TNTPrimed) - .map(e -> (TNTPrimed)e); - TraceListener.onTick(tntPrimedStream); - - if (DataHolder.isAutoStop()) { - stopAuto(); - } - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 117a4ee..8f71247 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -22,9 +22,8 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; +import de.steamwar.bausystem.tracer.RecordManager; import de.steamwar.bausystem.tracer.TraceManager; -import de.steamwar.bausystem.tracer.recorder.RecordManager; -import de.steamwar.bausystem.tracer.recorder.TNTRecorder; import de.steamwar.core.TPSWatcher; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; @@ -62,14 +61,14 @@ public class BauScoreboard implements Listener { strings.add("§2"); strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); - strings.add("§eTrace§8: " + RecordManager.getStatus().getValue()); + strings.add("§eTrace§8: " + RecordManager.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); - if (RecordManager.getStatus().isTracing()) { + if (RecordManager.getRecordStatus().isTracing()) { strings.add("§3"); - strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(TNTRecorder.recordStart))); + strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(RecordManager.getStartTime()))); strings.add("§eTicks§8: §7" + traceTicks()); - strings.add("§eAnzahl TNT§8: §7" + TraceManager.currentFrameSize()); + strings.add("§eAnzahl TNT§8: §7" + TraceManager.getRecordSize()); } strings.add("§4"); @@ -83,7 +82,7 @@ public class BauScoreboard implements Listener { } private long traceTicks() { - return (System.currentTimeMillis() - TNTRecorder.recordStart) / 50; + return (System.currentTimeMillis() - RecordManager.getStartTime()) / 50; } private String tpsColor() { @@ -103,4 +102,5 @@ public class BauScoreboard implements Listener { } return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } + } From 599c6049be2a4c515a06e220661fc6d358b5f654 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 16 Dec 2020 16:27:08 +0100 Subject: [PATCH 05/46] Add Trace Record System --- .../src/de/steamwar/bausystem/BauSystem.java | 3 +- .../bausystem/commands/CommandTrace.java | 2 +- .../commands/CommandTraceTabCompleter.java | 2 +- .../bausystem/tracer/ExplodeListener.java | 20 +++++++ .../steamwar/bausystem/tracer/Position.java | 43 ++++++++++++++ .../bausystem/tracer/RecordStatus.java | 19 ++++++ .../bausystem/tracer/TraceManager.java | 19 ++++++ .../steamwar/bausystem/tracer/TraceTNT.java | 19 ++++++ .../bausystem/tracer/record/DataHolder.java | 34 +++++++++++ .../tracer/record/ExplodeListener.java | 58 +++++++++++++++++++ .../tracer/{ => record}/RecordManager.java | 25 +++++++- .../bausystem/tracer/record/RecordTrace.java | 57 ++++++++++++++++++ .../bausystem/world/BauScoreboard.java | 2 +- 13 files changed, 297 insertions(+), 6 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java rename BauSystem_Main/src/de/steamwar/bausystem/tracer/{ => record}/RecordManager.java (70%) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 4472b16..341fd31 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -20,7 +20,7 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.commands.*; -import de.steamwar.bausystem.tracer.ExplodeListener; +import de.steamwar.bausystem.tracer.record.ExplodeListener; import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; import de.steamwar.core.Core; @@ -120,6 +120,7 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new ScriptListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); + // Bukkit.getPluginManager().registerEvents(new ExplodeListener(), this); Bukkit.getPluginManager().registerEvents(new ExplodeListener(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); new AFKStopper(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 3b0cb63..c600b5b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.tracer.RecordManager; +import de.steamwar.bausystem.tracer.record.RecordManager; import de.steamwar.bausystem.tracer.TraceManager; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index ef0ace0..5a34af2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.tracer.RecordManager; +import de.steamwar.bausystem.tracer.record.RecordManager; import de.steamwar.bausystem.tracer.RecordStatus; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java index de2654d..6a3540e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java @@ -1,5 +1,25 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; +import de.steamwar.bausystem.tracer.record.RecordManager; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java new file mode 100644 index 0000000..0e17c9f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java @@ -0,0 +1,43 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer; + +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; + +public class Position { + + private Vector location; + private Vector vector; + + public Position(Entity entity) { + location = entity.getLocation().toVector(); + vector = entity.getVelocity(); + } + + @Override + public String toString() { + return "Position{" + + "location=" + location + + ", vector=" + vector + + '}'; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java index eee5ad5..d2da29f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; public enum RecordStatus { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java index 9826b76..8840b57 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java index 78f4de9..8a7e6e3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; import de.steamwar.core.Core; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java new file mode 100644 index 0000000..f43a466 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java @@ -0,0 +1,34 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer.record; + +import org.bukkit.entity.TNTPrimed; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DataHolder { + + public static Map recordTraceMap = new HashMap<>(); + public static List finished = new ArrayList<>(); + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java new file mode 100644 index 0000000..f8693c0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java @@ -0,0 +1,58 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer.record; + +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +public class ExplodeListener implements Listener { + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + if (!(event.getEntity() instanceof TNTPrimed)) return; + TNTPrimed tntPrimed = (TNTPrimed) event.getEntity(); + + RecordManager.tntExplode(); + if (!RecordManager.getRecordStatus().isTracing()) { + return; + } + + explode(tntPrimed); + } + + static void add(TNTPrimed tntPrimed) { + get(tntPrimed).add(tntPrimed); + } + + static void explode(TNTPrimed tntPrimed) { + get(tntPrimed).explode(tntPrimed); + DataHolder.finished.add(DataHolder.recordTraceMap.remove(tntPrimed)); + } + + private static RecordTrace get(TNTPrimed tntPrimed) { + if (!DataHolder.recordTraceMap.containsKey(tntPrimed)) { + DataHolder.recordTraceMap.put(tntPrimed, new RecordTrace(tntPrimed)); + } + return DataHolder.recordTraceMap.get(tntPrimed); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java similarity index 70% rename from BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java index 24ad350..ba7a848 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java @@ -1,7 +1,28 @@ -package de.steamwar.bausystem.tracer; +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer.record; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.commands.CommandTPSLimiter; +import de.steamwar.bausystem.tracer.RecordStatus; +import de.steamwar.bausystem.tracer.TraceManager; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.TNTPrimed; @@ -55,7 +76,7 @@ public class RecordManager { if (recorder != null) return; startTime = System.currentTimeMillis(); recorder = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - world.getEntitiesByClass(TNTPrimed.class).forEach(TraceManager::tntAdd); + world.getEntitiesByClass(TNTPrimed.class).forEach(ExplodeListener::add); recordAutoStop(); }, 1, 1); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java new file mode 100644 index 0000000..415c4ca --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java @@ -0,0 +1,57 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer.record; + +import de.steamwar.bausystem.tracer.Position; +import org.bukkit.entity.TNTPrimed; + +import java.util.ArrayList; +import java.util.List; + +public class RecordTrace { + + private Position startPosition; + private Position explosionPosition; + private List positionList = new ArrayList<>(160); + + public RecordTrace(TNTPrimed tntPrimed) { + startPosition = new Position(tntPrimed); + } + + public RecordTrace add(TNTPrimed tntPrimed) { + positionList.add(new Position(tntPrimed)); + return this; + } + + public RecordTrace explode(TNTPrimed tntPrimed) { + explosionPosition = new Position(tntPrimed); + return this; + } + + @Override + public String toString() { + return "RecordTrace{" + + "startPosition=" + startPosition + + ", explosionPosition=" + explosionPosition + + ", positionList=" + positionList + + '}'; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 8f71247..a924ffc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; -import de.steamwar.bausystem.tracer.RecordManager; +import de.steamwar.bausystem.tracer.record.RecordManager; import de.steamwar.bausystem.tracer.TraceManager; import de.steamwar.core.TPSWatcher; import de.steamwar.scoreboard.SWScoreboard; From 19ee52aee52e095dc2e457c477844a61860c53ba Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 17 Dec 2020 19:43:30 +0100 Subject: [PATCH 06/46] Add ExplodeListener Add RecordManager Add RecordTrace Add ShowTrace basics Add TNTEntity basics --- .../steamwar/bausystem/tracer/Position.java | 8 ++++++ .../bausystem/tracer/record/DataHolder.java | 5 ---- .../tracer/record/ExplodeListener.java | 19 +++++++++++--- .../tracer/record/RecordManager.java | 2 +- .../bausystem/tracer/show/ShowTrace.java | 11 ++++++++ .../bausystem/tracer/show/TNTEntity.java | 25 +++++++++++++++++++ .../bausystem/world/BauScoreboard.java | 5 +++- 7 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowTrace.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java index 0e17c9f..c5c0fa9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java @@ -32,6 +32,14 @@ public class Position { vector = entity.getVelocity(); } + public Vector getLocation() { + return location; + } + + public Vector getVector() { + return vector; + } + @Override public String toString() { return "Position{" + diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java index f43a466..0ce980e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java @@ -19,16 +19,11 @@ package de.steamwar.bausystem.tracer.record; -import org.bukkit.entity.TNTPrimed; - import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class DataHolder { - public static Map recordTraceMap = new HashMap<>(); public static List finished = new ArrayList<>(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java index f8693c0..8f08e19 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java @@ -24,8 +24,13 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; +import java.util.HashMap; +import java.util.Map; + public class ExplodeListener implements Listener { + private static Map recordTraceMap = new HashMap<>(); + @EventHandler public void onEntityExplode(EntityExplodeEvent event) { if (!(event.getEntity() instanceof TNTPrimed)) return; @@ -45,14 +50,20 @@ public class ExplodeListener implements Listener { static void explode(TNTPrimed tntPrimed) { get(tntPrimed).explode(tntPrimed); - DataHolder.finished.add(DataHolder.recordTraceMap.remove(tntPrimed)); + RecordTrace recordTrace = recordTraceMap.remove(tntPrimed); + // System.out.println(recordTrace); + DataHolder.finished.add(recordTrace); } private static RecordTrace get(TNTPrimed tntPrimed) { - if (!DataHolder.recordTraceMap.containsKey(tntPrimed)) { - DataHolder.recordTraceMap.put(tntPrimed, new RecordTrace(tntPrimed)); + if (!recordTraceMap.containsKey(tntPrimed)) { + recordTraceMap.put(tntPrimed, new RecordTrace(tntPrimed)); } - return DataHolder.recordTraceMap.get(tntPrimed); + return recordTraceMap.get(tntPrimed); + } + + public static int size() { + return recordTraceMap.size(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java index ba7a848..fb90ee5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java @@ -49,7 +49,7 @@ public class RecordManager { } public static void commandAuto() { - if (recordStatus != RecordStatus.IDLE) { + if (recordStatus != RecordStatus.IDLE && recordStatus != RecordStatus.IDLE_AUTO) { return; } if (recordStatus == RecordStatus.IDLE_AUTO) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowTrace.java new file mode 100644 index 0000000..ea78894 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowTrace.java @@ -0,0 +1,11 @@ +package de.steamwar.bausystem.tracer.show; + +import de.steamwar.bausystem.tracer.record.RecordTrace; + +public class ShowTrace { + + public ShowTrace(RecordTrace recordTrace) { + + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java new file mode 100644 index 0000000..8a6cde4 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java @@ -0,0 +1,25 @@ +package de.steamwar.bausystem.tracer.show; + +import de.steamwar.bausystem.tracer.Position; +import net.minecraft.server.v1_15_R1.*; + +public class TNTEntity extends EntityFallingBlock { + + private Position position; + + public TNTEntity(World world, Position position) { + super(world, position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + this.position = position; + + this.setNoGravity(true); + this.ticksLived = -12000; + this.dropItem = false; + this.setCustomNameVisible(true); + } + + @Override + public void move(EnumMoveType enummovetype, Vec3D vec3d) { + + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index a924ffc..59fa73e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -22,8 +22,11 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; +import de.steamwar.bausystem.tracer.record.DataHolder; +import de.steamwar.bausystem.tracer.record.ExplodeListener; import de.steamwar.bausystem.tracer.record.RecordManager; import de.steamwar.bausystem.tracer.TraceManager; +import de.steamwar.bausystem.tracer.record.RecordTrace; import de.steamwar.core.TPSWatcher; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; @@ -68,7 +71,7 @@ public class BauScoreboard implements Listener { strings.add("§3"); strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(RecordManager.getStartTime()))); strings.add("§eTicks§8: §7" + traceTicks()); - strings.add("§eAnzahl TNT§8: §7" + TraceManager.getRecordSize()); + strings.add("§eAnzahl TNT§8: §7" + ExplodeListener.size()); } strings.add("§4"); From 2ecd71baebc380a1f06f38bf911f897f39083d56 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 17 Dec 2020 20:06:43 +0100 Subject: [PATCH 07/46] Simplify version dependant --- .../bausystem/tracer/TNTEntity_12.java | 24 ++++ .../bausystem/tracer/TraceTNT_12.java | 53 -------- .../bausystem/tracer/TNTEntity_15.java | 24 ++++ .../bausystem/tracer/TraceTNT_15.java | 37 ------ .../bausystem/tracer/ReflectionsUtils.java | 39 ------ .../bausystem/tracer/TNTPosition.java | 32 +++++ .../bausystem/commands/CommandTrace.java | 5 +- .../bausystem/tracer/ExplodeListener.java | 39 ------ .../steamwar/bausystem/tracer/Position.java | 51 -------- .../bausystem/tracer/TraceManager.java | 67 ---------- .../steamwar/bausystem/tracer/TraceTNT.java | 116 ------------------ .../tracer/record/ExplodeListener.java | 1 - .../tracer/record/RecordManager.java | 4 +- .../bausystem/tracer/record/RecordTrace.java | 20 +-- .../bausystem/tracer/show/TNTEntity.java | 10 +- .../bausystem/world/BauScoreboard.java | 3 - 16 files changed, 99 insertions(+), 426 deletions(-) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java delete mode 100644 BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java new file mode 100644 index 0000000..c196d6e --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -0,0 +1,24 @@ +package de.steamwar.bausystem.tracer; + +import net.minecraft.server.v1_12_R1.*; + +public class TNTEntity_12 extends EntityFallingBlock { + + private TNTPosition position; + + public TNTEntity_12(World world, TNTPosition position) { + super(world, position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + this.position = position; + + this.setNoGravity(true); + this.ticksLived = -12000; + this.dropItem = false; + this.setCustomNameVisible(true); + } + + @Override + public void move(EnumMoveType enummovetype, double dx, double dy, double dz) { + + } + +} diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java deleted file mode 100644 index 5079f69..0000000 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.steamwar.bausystem.tracer; - -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntity; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -import java.util.UUID; - -public class TraceTNT_12 { - - // public PacketPlayOutSpawnEntity(Entity var1, int var2, int var3) { - // this.a = var1.getId(); - // this.b = var1.getUniqueID(); - // this.c = var1.locX; - // this.d = var1.locY; - // this.e = var1.locZ; - // this.i = MathHelper.d(var1.pitch * 256.0F / 360.0F); - // this.j = MathHelper.d(var1.yaw * 256.0F / 360.0F); - // this.k = var2; - // this.l = var3; - // double var4 = 3.9D; - // this.f = (int)(MathHelper.a(var1.motX, -3.9D, 3.9D) * 8000.0D); - // this.g = (int)(MathHelper.a(var1.motY, -3.9D, 3.9D) * 8000.0D); - // this.h = (int)(MathHelper.a(var1.motZ, -3.9D, 3.9D) * 8000.0D); - // } - - static void showTNT(int entityID, Player player, float... position) { - PacketPlayOutSpawnEntity spawnEntity = new PacketPlayOutSpawnEntity(); - ReflectionsUtils.setField("a", spawnEntity, entityID); - ReflectionsUtils.setField("b", spawnEntity, UUID.randomUUID()); - ReflectionsUtils.setField("c", spawnEntity, position[0]); - ReflectionsUtils.setField("d", spawnEntity, position[1]); - ReflectionsUtils.setField("e", spawnEntity, position[2]); - ReflectionsUtils.setField("i", spawnEntity, 0); - ReflectionsUtils.setField("j", spawnEntity, 0); - // EntityType - ReflectionsUtils.setField("k", spawnEntity, 0); - ReflectionsUtils.setField("l", spawnEntity, 0); - ReflectionsUtils.setField("f", spawnEntity, 0); - ReflectionsUtils.setField("g", spawnEntity, 0); - ReflectionsUtils.setField("h", spawnEntity, 0); - - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(spawnEntity); - } - - static void hideTNT(int entityID, Player player, float... position) { - PacketPlayOutEntityDestroy deleteEntity = new PacketPlayOutEntityDestroy(entityID); - - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(deleteEntity); - } - -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java new file mode 100644 index 0000000..cf9984a --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -0,0 +1,24 @@ +package de.steamwar.bausystem.tracer; + +import net.minecraft.server.v1_15_R1.*; + +public class TNTEntity_15 extends EntityFallingBlock { + + private TNTPosition position; + + public TNTEntity_15(World world, TNTPosition position) { + super(world, position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + this.position = position; + + this.setNoGravity(true); + this.ticksLived = -12000; + this.dropItem = false; + this.setCustomNameVisible(true); + } + + @Override + public void move(EnumMoveType enummovetype, Vec3D vec3d) { + + } + +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java deleted file mode 100644 index 148f27d..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.steamwar.bausystem.tracer; - -import net.minecraft.server.v1_15_R1.EntityTypes; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -import java.util.UUID; - -public class TraceTNT_15 { - - static void showTNT(int entityID, Player player, float... position) { - PacketPlayOutSpawnEntity spawnEntity = new PacketPlayOutSpawnEntity(); - ReflectionsUtils.setField("a", spawnEntity, entityID); - ReflectionsUtils.setField("b", spawnEntity, UUID.randomUUID()); - ReflectionsUtils.setField("c", spawnEntity, position[0]); - ReflectionsUtils.setField("d", spawnEntity, position[1]); - ReflectionsUtils.setField("e", spawnEntity, position[2]); - ReflectionsUtils.setField("i", spawnEntity, 0); - ReflectionsUtils.setField("j", spawnEntity, 0); - ReflectionsUtils.setField("k", spawnEntity, EntityTypes.FALLING_BLOCK); - ReflectionsUtils.setField("l", spawnEntity, 0); - ReflectionsUtils.setField("f", spawnEntity, 0); - ReflectionsUtils.setField("g", spawnEntity, 0); - ReflectionsUtils.setField("h", spawnEntity, 0); - - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(spawnEntity); - } - - static void hideTNT(int entityID, Player player, float... position) { - PacketPlayOutEntityDestroy deleteEntity = new PacketPlayOutEntityDestroy(entityID); - - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(deleteEntity); - } - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java deleted file mode 100644 index 236e5c7..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.steamwar.bausystem.tracer; - -import java.lang.reflect.Field; -import java.util.LinkedHashMap; -import java.util.Map; - -public class ReflectionsUtils { - - private static Map fieldMap = new LinkedHashMap() { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > 100; - } - }; - - @SuppressWarnings({"java:S3011"}) - static void setField(String fieldName, Object object, Object fieldValue) { - String cacheName = object.getClass().getTypeName() + ":" + fieldName; - Field field; - if (fieldMap.containsKey(cacheName)) { - field = fieldMap.get(cacheName); - } else { - try { - field = object.getClass().getDeclaredField(fieldName); - } catch (NoSuchFieldException e) { - return; - } - fieldMap.put(cacheName, field); - } - - field.setAccessible(true); - try { - field.set(object, fieldValue); - } catch (IllegalAccessException e) { - - } - } - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java new file mode 100644 index 0000000..ab1bb1a --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java @@ -0,0 +1,32 @@ +package de.steamwar.bausystem.tracer; + +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; + +public class TNTPosition { + + private Vector location; + private Vector vector; + + public TNTPosition(Entity entity) { + location = entity.getLocation().toVector(); + vector = entity.getVelocity(); + } + + public Vector getLocation() { + return location; + } + + public Vector getVector() { + return vector; + } + + @Override + public String toString() { + return "Position{" + + "location=" + location + + ", vector=" + vector + + '}'; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index c600b5b..ff78c90 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordManager; -import de.steamwar.bausystem.tracer.TraceManager; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -78,10 +77,10 @@ public class CommandTrace implements CommandExecutor { RecordManager.commandAuto(); break; case "show": - TraceManager.commandShow(player); + // TraceManager.commandShow(player); break; case "hide": - TraceManager.commandHide(player); + // TraceManager.commandHide(player); break; case "toggleshow": case "interpolate": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java deleted file mode 100644 index 6a3540e..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import de.steamwar.bausystem.tracer.record.RecordManager; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityExplodeEvent; - -public class ExplodeListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onEntityExplode(EntityExplodeEvent event) { - if (!(event.getEntity() instanceof TNTPrimed)) return; - - RecordManager.tntExplode(); - TraceManager.tntExplode((TNTPrimed) event.getEntity()); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java deleted file mode 100644 index c5c0fa9..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/Position.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import org.bukkit.entity.Entity; -import org.bukkit.util.Vector; - -public class Position { - - private Vector location; - private Vector vector; - - public Position(Entity entity) { - location = entity.getLocation().toVector(); - vector = entity.getVelocity(); - } - - public Vector getLocation() { - return location; - } - - public Vector getVector() { - return vector; - } - - @Override - public String toString() { - return "Position{" + - "location=" + location + - ", vector=" + vector + - '}'; - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java deleted file mode 100644 index 8840b57..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class TraceManager { - - private static Map traceTNTMap = new HashMap<>(); - private static Set traceTNTSet = new HashSet<>(); - - public static void recordStop() { - traceTNTMap.clear(); - } - - public static void tntExplode(TNTPrimed tntPrimed) { - if (!traceTNTMap.containsKey(tntPrimed)) return; - traceTNTMap.remove(tntPrimed).explosion(tntPrimed); - } - - public static void tntAdd(TNTPrimed tntPrimed) { - TraceTNT traceTNT = new TraceTNT(tntPrimed); - traceTNTMap.put(tntPrimed, traceTNT); - traceTNTSet.add(traceTNT); - } - - public static void commandDelete() { - traceTNTMap.clear(); - traceTNTSet.clear(); - } - - public static int getRecordSize() { - return traceTNTMap.size(); - } - - public static void commandShow(Player player) { - traceTNTSet.forEach(traceTNT -> traceTNT.showTrace(player)); - } - - public static void commandHide(Player player) { - traceTNTSet.forEach(traceTNT -> traceTNT.hideTrace(player)); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java deleted file mode 100644 index 8a7e6e3..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import de.steamwar.core.Core; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; - -import java.util.function.Consumer; - -public class TraceTNT { - - private static int traceID = 0; - - private int id = traceID++; - private float[] source = new float[3]; - private float[] explosion = new float[3]; - private int index = 0; - private float[] position = new float[240]; - private float[] velocity = new float[240]; - - public TraceTNT(TNTPrimed tntPrimed) { - source[0] = (float) tntPrimed.getLocation().getX(); - source[1] = (float) tntPrimed.getLocation().getY(); - source[2] = (float) tntPrimed.getLocation().getZ(); - } - - public void explosion(TNTPrimed tntPrimed) { - explosion[0] = (float) tntPrimed.getLocation().getX(); - explosion[1] = (float) tntPrimed.getLocation().getY(); - explosion[2] = (float) tntPrimed.getLocation().getZ(); - } - - public void add(TNTPrimed tntPrimed) { - if (index > position.length) return; - position[index + 0] = (float) tntPrimed.getLocation().getX(); - position[index + 1] = (float) tntPrimed.getLocation().getY(); - position[index + 2] = (float) tntPrimed.getLocation().getZ(); - velocity[index + 0] = (float) tntPrimed.getVelocity().getX(); - velocity[index + 1] = (float) tntPrimed.getVelocity().getY(); - velocity[index + 2] = (float) tntPrimed.getVelocity().getZ(); - index += 3; - } - - public long size() { - long size = 0; - - // id: - size += 32; - - // index: - size += 32; - - // source: - size += source.length * 32; - - // explosion: - size += explosion.length * 32; - - // position: - size += position.length * 32; - - // velocity: - size += velocity.length * 32; - - return size; - } - - public void showTrace(Player player) { - int entityID = Integer.MAX_VALUE - id * 200; - - tnt(entityID, player, source, TraceTNT_15::showTNT, TraceTNT_12::showTNT); - } - - public void hideTrace(Player player) { - int entityID = Integer.MAX_VALUE - id * 200; - - tnt(entityID, player, source, TraceTNT_15::hideTNT, TraceTNT_12::hideTNT); - } - - private void tnt(int entityID, Player player, float[] position, VersionConsumer version15, VersionConsumer versionDefault) { - if (position.length != 3) return; - switch (Core.getVersion()) { - case 15: - version15.accept(entityID, player, position); - break; - default: - versionDefault.accept(entityID, player, position); - break; - } - } - - private interface VersionConsumer { - - void accept(K k, V v, S s); - - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java index 8f08e19..3472624 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java @@ -51,7 +51,6 @@ public class ExplodeListener implements Listener { static void explode(TNTPrimed tntPrimed) { get(tntPrimed).explode(tntPrimed); RecordTrace recordTrace = recordTraceMap.remove(tntPrimed); - // System.out.println(recordTrace); DataHolder.finished.add(recordTrace); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java index fb90ee5..9e8de6c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.tracer.record; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.commands.CommandTPSLimiter; import de.steamwar.bausystem.tracer.RecordStatus; -import de.steamwar.bausystem.tracer.TraceManager; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.TNTPrimed; @@ -86,7 +85,8 @@ public class RecordManager { recorder.cancel(); recorder = null; startTime = 0; - TraceManager.recordStop(); + // TODO: fix + // TraceManager.recordStop(); } private static void recordAutoStop() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java index 415c4ca..caf3eb7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.tracer.record; -import de.steamwar.bausystem.tracer.Position; +import de.steamwar.bausystem.tracer.TNTPosition; import org.bukkit.entity.TNTPrimed; import java.util.ArrayList; @@ -27,30 +27,30 @@ import java.util.List; public class RecordTrace { - private Position startPosition; - private Position explosionPosition; - private List positionList = new ArrayList<>(160); + private TNTPosition startTNTPosition; + private TNTPosition explosionTNTPosition; + private List TNTPositionList = new ArrayList<>(160); public RecordTrace(TNTPrimed tntPrimed) { - startPosition = new Position(tntPrimed); + startTNTPosition = new TNTPosition(tntPrimed); } public RecordTrace add(TNTPrimed tntPrimed) { - positionList.add(new Position(tntPrimed)); + TNTPositionList.add(new TNTPosition(tntPrimed)); return this; } public RecordTrace explode(TNTPrimed tntPrimed) { - explosionPosition = new Position(tntPrimed); + explosionTNTPosition = new TNTPosition(tntPrimed); return this; } @Override public String toString() { return "RecordTrace{" + - "startPosition=" + startPosition + - ", explosionPosition=" + explosionPosition + - ", positionList=" + positionList + + "startPosition=" + startTNTPosition + + ", explosionPosition=" + explosionTNTPosition + + ", positionList=" + TNTPositionList + '}'; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java index 8a6cde4..8679439 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java @@ -1,15 +1,15 @@ package de.steamwar.bausystem.tracer.show; -import de.steamwar.bausystem.tracer.Position; +import de.steamwar.bausystem.tracer.TNTPosition; import net.minecraft.server.v1_15_R1.*; public class TNTEntity extends EntityFallingBlock { - private Position position; + private TNTPosition TNTPosition; - public TNTEntity(World world, Position position) { - super(world, position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); - this.position = position; + public TNTEntity(World world, TNTPosition TNTPosition) { + super(world, TNTPosition.getLocation().getX(), TNTPosition.getLocation().getY(), TNTPosition.getLocation().getZ(), Blocks.TNT.getBlockData()); + this.TNTPosition = TNTPosition; this.setNoGravity(true); this.ticksLived = -12000; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 59fa73e..c6ce573 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -22,11 +22,8 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; -import de.steamwar.bausystem.tracer.record.DataHolder; import de.steamwar.bausystem.tracer.record.ExplodeListener; import de.steamwar.bausystem.tracer.record.RecordManager; -import de.steamwar.bausystem.tracer.TraceManager; -import de.steamwar.bausystem.tracer.record.RecordTrace; import de.steamwar.core.TPSWatcher; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; From ba7888eb564f717f527d88a3b5f3c73c391df1c2 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 18 Dec 2020 22:38:31 +0100 Subject: [PATCH 08/46] Lixfels trace changes --- .../bausystem/tracer/TNTPosition.java | 7 - .../src/de/steamwar/bausystem/BauSystem.java | 3 - .../bausystem/commands/CommandTrace.java | 170 ++---------------- .../commands/CommandTraceTabCompleter.java | 6 +- .../tracer/record/RecordManager.java | 108 ----------- .../tracer/record/RecordStateMachine.java | 90 ++++++++++ .../tracer/{ => record}/RecordStatus.java | 2 +- .../bausystem/tracer/record/RecordTrace.java | 57 ------ .../bausystem/tracer/record/Recorder.java | 86 +++++++++ ...odeListener.java => TraceAutoHandler.java} | 60 ++++--- .../bausystem/tracer/show/Record.java | 79 ++++++++ .../bausystem/tracer/show/ShowMode.java | 8 + .../bausystem/tracer/show/ShowTrace.java | 11 -- .../StoredRecords.java} | 17 +- .../tracer/show/TraceShowManager.java | 53 ++++++ .../bausystem/world/BauScoreboard.java | 17 +- 16 files changed, 384 insertions(+), 390 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java rename BauSystem_Main/src/de/steamwar/bausystem/tracer/{ => record}/RecordStatus.java (96%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java rename BauSystem_Main/src/de/steamwar/bausystem/tracer/record/{ExplodeListener.java => TraceAutoHandler.java} (51%) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowTrace.java rename BauSystem_Main/src/de/steamwar/bausystem/tracer/{record/DataHolder.java => show/StoredRecords.java} (66%) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java index ab1bb1a..2a65f6c 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java @@ -6,26 +6,19 @@ import org.bukkit.util.Vector; public class TNTPosition { private Vector location; - private Vector vector; public TNTPosition(Entity entity) { location = entity.getLocation().toVector(); - vector = entity.getVelocity(); } public Vector getLocation() { return location; } - public Vector getVector() { - return vector; - } - @Override public String toString() { return "Position{" + "location=" + location + - ", vector=" + vector + '}'; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 341fd31..6d7dd7b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.commands.*; -import de.steamwar.bausystem.tracer.record.ExplodeListener; import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; import de.steamwar.core.Core; @@ -120,8 +119,6 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new ScriptListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); - // Bukkit.getPluginManager().registerEvents(new ExplodeListener(), this); - Bukkit.getPluginManager().registerEvents(new ExplodeListener(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); new AFKStopper(); // TNTTracer.init(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index ff78c90..e6c9e96 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -21,7 +21,8 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.tracer.record.RecordManager; +import de.steamwar.bausystem.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -67,185 +68,34 @@ public class CommandTrace implements CommandExecutor { switch (args[0].toLowerCase()) { case "start": - RecordManager.commandStart(); + RecordStateMachine.commandStart(); break; case "stop": - RecordManager.commandStop(); + RecordStateMachine.commandStop(); break; case "toggleauto": case "auto": - RecordManager.commandAuto(); + RecordStateMachine.commandAuto(); + break; + case "clear": + case "delete": + StoredRecords.clear(); + player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); break; case "show": - // TraceManager.commandShow(player); break; case "hide": - // TraceManager.commandHide(player); break; case "toggleshow": case "interpolate": case "distance": - /*if (tracer(player, args)) { - help(player); - }*/ break; case "list": case "gui": - // player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau"); - break; - case "delete": - if (delete(player, args)) { - help(player); - } break; default: help(player); } return false; } - - private boolean delete(Player player, String[] args) { - /*if (args.length == 2) { - try { - TraceManager.delete(Integer.parseInt(args[1])); - player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + args[1] + " gelöscht"); - ShowManager.globalDirty(); - return false; - } catch (NumberFormatException e) { - return true; - } - }*/ - TraceManager.commandDelete(); - // TraceManager.deleteAll(); - player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); - // ShowManager.globalDirty(); - return false; - } - - - /*public boolean tracer(Player player, String[] args) { - ShowManager.ShowStatus showStatus = ShowManager.showMap.get(player.getUniqueId().toString()); - showStatus.dirty = true; - switch (args[0].toLowerCase()) { - case "show": - showStatus.show(); - if (args.length == 2) { - return tracerShow(player, showStatus, args); - } - player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); - break; - case "distance": - if (args.length != 2) { - return true; - } - if (args[1].equalsIgnoreCase("default")) { - ShowManager.get(player).setSlope(7.0); - player.sendMessage(BauSystem.PREFIX + "§aAnzeige Distanz auf " + ShowManager.get(player).slopeHeight + " gesetzt"); - return false; - } - try { - double radius = Double.parseDouble(args[1]); - radius = (double)(int)(radius * 10) / 10; - ShowManager.get(player).setSlope(radius); - player.sendMessage(BauSystem.PREFIX + "§aAnzeige Distanz auf " + ShowManager.get(player).slopeHeight + " gesetzt"); - return false; - } catch (NumberFormatException e) { - return true; - } - case "hide": - showStatus.hide(); - if (args.length == 2) { - return traceID(player, args[1], showStatus::removeSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} versteckt"}); - } - player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen versteckt"); - break; - case "toggleshow": - if (args.length == 2) { - return traceID(player, args[1], showStatus::toggleSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} angezeigt"}, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} versteckt"}); - } - return true; - case "interpolate": - if (args.length == 2) { - return tracerInterpolate(player, showStatus, args); - } - return true; - default: - break; - } - return false; - } - - private boolean tracerShow(Player player, ShowManager.ShowStatus showStatus, String[] args) { - switch (args[1].toLowerCase()) { - case "block": - case "blocks": - showStatus.displayType = ShowManager.DisplayType.Block; - player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Blöcke, angezeigt"); - break; - case "particle": - case "particles": - case "default": - showStatus.displayType = ShowManager.DisplayType.Particle; - player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Partikel, angezeigt"); - break; - default: - return traceID(player, args[1], showStatus::addSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} angezeigt"}); - } - return false; - } - - private boolean tracerInterpolate(Player player, ShowManager.ShowStatus showStatus, String[] args) { - switch (args[1].toLowerCase()) { - case "none": - showStatus.displayMode = ShowManager.DisplayMode.NONE; - player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §enone §agesetzt"); - break; - case "yaxis": - case "y": - showStatus.displayMode = ShowManager.DisplayMode.Y_AXIS; - player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eyaxis §agesetzt"); - break; - case "all": - case "allaxis": - case "xyz": - case "default": - showStatus.displayMode = ShowManager.DisplayMode.ALL; - player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eall §agesetzt"); - break; - default: - return true; - } - return false; - } - - - private boolean traceID(Player player, String number, ShowManager.Mode mode, String[] messages) { - try { - mode.run(Integer.parseInt(number)); - for (String s : messages) { - player.sendMessage(s.replace("{}", number)); - } - } catch (NumberFormatException e) { - return true; - } - return false; - } - - private boolean traceID(Player player, String number, ShowManager.ModeChoose mode, String[] messagesTrue, String[] messagesFalse) { - try { - boolean result = mode.run(Integer.parseInt(number)); - if (result) { - for (String s : messagesTrue) { - player.sendMessage(s.replace("{}", number)); - } - } else { - for (String s : messagesFalse) { - player.sendMessage(s.replace("{}", number)); - } - } - } catch (NumberFormatException e) { - return true; - } - return false; - }*/ } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 5a34af2..9c32567 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -19,8 +19,8 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.tracer.record.RecordManager; -import de.steamwar.bausystem.tracer.RecordStatus; +import de.steamwar.bausystem.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.tracer.record.RecordStatus; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -40,7 +40,7 @@ public class CommandTraceTabCompleter implements TabCompleter { private List tracerTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); - if (RecordManager.getRecordStatus() == RecordStatus.IDLE || RecordManager.getRecordStatus() == RecordStatus.IDLE_AUTO) { + if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { tabComplete.add("start"); } else { tabComplete.add("stop"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java deleted file mode 100644 index 9e8de6c..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordManager.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer.record; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.commands.CommandTPSLimiter; -import de.steamwar.bausystem.tracer.RecordStatus; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.scheduler.BukkitTask; - -public class RecordManager { - - private static final World world = Bukkit.getWorlds().get(0); - - private static RecordStatus recordStatus = RecordStatus.IDLE; - - private static BukkitTask recorder = null; - private static long startTime = 0; - private static long lastExplosion = 0; - - public static void commandStart() { - recordStatus = RecordStatus.RECORD; - recordStart(); - } - - public static void commandStop() { - recordStatus = RecordStatus.IDLE; - recordStop(); - } - - public static void commandAuto() { - if (recordStatus != RecordStatus.IDLE && recordStatus != RecordStatus.IDLE_AUTO) { - return; - } - if (recordStatus == RecordStatus.IDLE_AUTO) { - recordStatus = RecordStatus.IDLE; - } else { - recordStatus = RecordStatus.IDLE_AUTO; - } - } - - public static void tntExplode() { - if (recordStatus == RecordStatus.RECORD_AUTO) { - lastExplosion = System.currentTimeMillis(); - return; - } - if (recordStatus != RecordStatus.IDLE_AUTO) { - return; - } - lastExplosion = System.currentTimeMillis(); - recordStatus = RecordStatus.RECORD_AUTO; - recordStart(); - } - - private static void recordStart() { - if (recorder != null) return; - startTime = System.currentTimeMillis(); - recorder = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - world.getEntitiesByClass(TNTPrimed.class).forEach(ExplodeListener::add); - recordAutoStop(); - }, 1, 1); - } - - private static void recordStop() { - if (recorder == null) return; - recorder.cancel(); - recorder = null; - startTime = 0; - // TODO: fix - // TraceManager.recordStop(); - } - - private static void recordAutoStop() { - if (recordStatus != RecordStatus.RECORD_AUTO) return; - if (System.currentTimeMillis() - lastExplosion > (20.0 / CommandTPSLimiter.getCurrentTPSLimit()) * 50 * 80) { - recordStatus = RecordStatus.IDLE_AUTO; - recordStop(); - } - } - - public static RecordStatus getRecordStatus() { - return recordStatus; - } - - public static long getStartTime() { - return startTime; - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java new file mode 100644 index 0000000..5086697 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java @@ -0,0 +1,90 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer.record; + +public class RecordStateMachine { + private RecordStateMachine(){} + + private static final TraceAutoHandler autoHandler = new TraceAutoHandler(); + + private static RecordStatus recordStatus = RecordStatus.IDLE; + private static Recorder recorder = null; + + public static void commandStart() { + recordStatus = RecordStatus.RECORD; + autoHandler.disable(); + recordStart(); + } + + public static void commandStop() { + recordStatus = RecordStatus.IDLE; + autoHandler.disable(); + recordStop(); + } + + public static void commandAuto() { + if (recordStatus.isTracing()) + return; + + if (recordStatus == RecordStatus.IDLE_AUTO) { + recordStatus = RecordStatus.IDLE; + autoHandler.disable(); + } else { + recordStatus = RecordStatus.IDLE_AUTO; + autoHandler.enable(); + } + } + + static void autoRecord(){ + recordStatus = RecordStatus.RECORD_AUTO; + recordStart(); + } + + static void autoIdle(){ + recordStatus = RecordStatus.IDLE_AUTO; + recordStop(); + } + + private static void recordStart() { + if(recordStatus.isTracing()) + return; + + recorder = new Recorder(); + } + + private static void recordStop() { + if(!recordStatus.isTracing()) + return; + + recorder.stopRecording(); + } + + public static RecordStatus getRecordStatus() { + return recordStatus; + } + + public static int size(){ + return recorder.size(); + } + + public static long getStartTime(){ + return recorder.getStartTime(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java index d2da29f..45cbec3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ -package de.steamwar.bausystem.tracer; +package de.steamwar.bausystem.tracer.record; public enum RecordStatus { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java deleted file mode 100644 index caf3eb7..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordTrace.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer.record; - -import de.steamwar.bausystem.tracer.TNTPosition; -import org.bukkit.entity.TNTPrimed; - -import java.util.ArrayList; -import java.util.List; - -public class RecordTrace { - - private TNTPosition startTNTPosition; - private TNTPosition explosionTNTPosition; - private List TNTPositionList = new ArrayList<>(160); - - public RecordTrace(TNTPrimed tntPrimed) { - startTNTPosition = new TNTPosition(tntPrimed); - } - - public RecordTrace add(TNTPrimed tntPrimed) { - TNTPositionList.add(new TNTPosition(tntPrimed)); - return this; - } - - public RecordTrace explode(TNTPrimed tntPrimed) { - explosionTNTPosition = new TNTPosition(tntPrimed); - return this; - } - - @Override - public String toString() { - return "RecordTrace{" + - "startPosition=" + startTNTPosition + - ", explosionPosition=" + explosionTNTPosition + - ", positionList=" + TNTPositionList + - '}'; - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java new file mode 100644 index 0000000..c161253 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -0,0 +1,86 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer.record; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.show.Record; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.scheduler.BukkitTask; + +import java.util.HashMap; +import java.util.Map; + +public class Recorder implements Listener { + + private static final World world = Bukkit.getWorlds().get(0); + + private final Map recordMap = new HashMap<>(); + private final BukkitTask task; + private final Record record; + + Recorder(){ + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1); + record = new Record(); + } + + void stopRecording(){ + HandlerList.unregisterAll(this); + task.cancel(); + } + + int size() { + return record.size(); + } + + long getStartTime() { + return record.getStartTime(); + } + + private void run() { + world.getEntitiesByClass(TNTPrimed.class).forEach(tntPrimed -> get(tntPrimed).add(tntPrimed)); + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + if (!(event.getEntity() instanceof TNTPrimed)) + return; + TNTPrimed tntPrimed = (TNTPrimed) event.getEntity(); + + get(tntPrimed).explode(tntPrimed); + recordMap.remove(tntPrimed); + } + + private Record.TNTRecord get(TNTPrimed tntPrimed) { + Record.TNTRecord tntRecord = recordMap.get(tntPrimed); + if(tntRecord != null) + return tntRecord; + + tntRecord = this.record.spawn(); + recordMap.put(tntPrimed, tntRecord); + return tntRecord; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/TraceAutoHandler.java similarity index 51% rename from BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/record/TraceAutoHandler.java index 3472624..ed93e28 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/ExplodeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/TraceAutoHandler.java @@ -19,50 +19,52 @@ package de.steamwar.bausystem.tracer.record; +import de.steamwar.bausystem.BauSystem; +import org.bukkit.Bukkit; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.scheduler.BukkitTask; -import java.util.HashMap; -import java.util.Map; +public class TraceAutoHandler implements Listener { + /* This listener handles the en- and disabling of the Tracer in AUTO mode */ -public class ExplodeListener implements Listener { + private BukkitTask task; + private int lastExplosion = 0; // Time since the last explosion in ticks - private static Map recordTraceMap = new HashMap<>(); + public void enable(){ + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + } + + public void disable(){ + HandlerList.unregisterAll(this); + if(task != null){ + task.cancel(); + task = null; + } + } @EventHandler public void onEntityExplode(EntityExplodeEvent event) { - if (!(event.getEntity() instanceof TNTPrimed)) return; - TNTPrimed tntPrimed = (TNTPrimed) event.getEntity(); - - RecordManager.tntExplode(); - if (!RecordManager.getRecordStatus().isTracing()) { + if (!(event.getEntity() instanceof TNTPrimed)) return; + + lastExplosion = 0; + if(task == null){ + RecordStateMachine.autoRecord(); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1); } - - explode(tntPrimed); } - static void add(TNTPrimed tntPrimed) { - get(tntPrimed).add(tntPrimed); - } + private void run(){ + lastExplosion++; - static void explode(TNTPrimed tntPrimed) { - get(tntPrimed).explode(tntPrimed); - RecordTrace recordTrace = recordTraceMap.remove(tntPrimed); - DataHolder.finished.add(recordTrace); - } - - private static RecordTrace get(TNTPrimed tntPrimed) { - if (!recordTraceMap.containsKey(tntPrimed)) { - recordTraceMap.put(tntPrimed, new RecordTrace(tntPrimed)); + if (lastExplosion > 80) { + RecordStateMachine.autoIdle(); + task.cancel(); + task = null; } - return recordTraceMap.get(tntPrimed); } - - public static int size() { - return recordTraceMap.size(); - } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java new file mode 100644 index 0000000..531927e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java @@ -0,0 +1,79 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer.show; + +import de.steamwar.bausystem.tracer.TNTPosition; +import org.bukkit.entity.TNTPrimed; + +import java.util.ArrayList; +import java.util.List; + +public class Record { + + private final long startTime; + private final List tnt = new ArrayList<>(); + + public int size(){ + return tnt.size(); + } + + public long getStartTime(){ + return startTime; + } + + public void showAll(ShowMode mode) { + for(TNTRecord record : tnt) + record.showAll(mode); + } + + /* The following methods should only be called by a recorder */ + public Record(){ + startTime = System.currentTimeMillis(); + StoredRecords.add(this); + } + + public TNTRecord spawn(){ + TNTRecord record = new TNTRecord(); + tnt.add(record); + return record; + } + + public static class TNTRecord { + private final List positions = new ArrayList<>(41); + private boolean exploded = false; + + public void showAll(ShowMode mode){ + for(TNTPosition position : positions) + mode.show(position); + } + + /* The following methods should only be called by a recorder */ + public void add(TNTPrimed tntPrimed) { + TNTPosition position = new TNTPosition(tntPrimed); + positions.add(position); + TraceShowManager.show(position); + } + + public void explode(TNTPrimed tntPrimed) { + exploded = true; + add(tntPrimed); + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java new file mode 100644 index 0000000..c3ad9da --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java @@ -0,0 +1,8 @@ +package de.steamwar.bausystem.tracer.show; + +import de.steamwar.bausystem.tracer.TNTPosition; + +public interface ShowMode { + void show(TNTPosition position); + void hide(); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowTrace.java deleted file mode 100644 index ea78894..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowTrace.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.steamwar.bausystem.tracer.show; - -import de.steamwar.bausystem.tracer.record.RecordTrace; - -public class ShowTrace { - - public ShowTrace(RecordTrace recordTrace) { - - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java similarity index 66% rename from BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java index 0ce980e..259bbab 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/DataHolder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java @@ -17,13 +17,24 @@ along with this program. If not, see . */ -package de.steamwar.bausystem.tracer.record; +package de.steamwar.bausystem.tracer.show; import java.util.ArrayList; import java.util.List; -public class DataHolder { +public class StoredRecords { + private static final List records = new ArrayList<>(); - public static List finished = new ArrayList<>(); + public static void add(Record record){ + records.add(record); + } + public static void showAll(ShowMode mode){ + for(Record record : records) record.showAll(mode); + } + + public static void clear(){ + records.clear(); + TraceShowManager.clear(); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java new file mode 100644 index 0000000..a739434 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -0,0 +1,53 @@ +package de.steamwar.bausystem.tracer.show; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.TNTPosition; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.Map; + +public class TraceShowManager implements Listener { + private TraceShowManager(){} + + private static final Map showModes = new HashMap<>(); + + public static void show(Player player){ + hide(player); + ShowMode showMode; + StoredRecords.showAll(showMode); + } + + public static void hide(Player player){ + ShowMode showMode = showModes.remove(player); + if(showMode == null) + return; + showMode.hide(); + } + + /* Only to be called by record */ + static void show(TNTPosition tnt){ + for(ShowMode mode : showModes.values()) + mode.show(tnt); + } + + /* Only to be called by StoredRecords */ + static void clear(){ + for(ShowMode mode : showModes.values()) + mode.hide(); + } + + /* Internal if player leaves*/ + static{ + Bukkit.getPluginManager().registerEvents(new TraceShowManager(), BauSystem.getPlugin()); + } + + @EventHandler + public void onLeave(PlayerQuitEvent event){ + showModes.remove(event.getPlayer()); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index c6ce573..c15abc1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -22,8 +22,7 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; -import de.steamwar.bausystem.tracer.record.ExplodeListener; -import de.steamwar.bausystem.tracer.record.RecordManager; +import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.core.TPSWatcher; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; @@ -33,7 +32,10 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; public class BauScoreboard implements Listener { @@ -61,14 +63,13 @@ public class BauScoreboard implements Listener { strings.add("§2"); strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); - strings.add("§eTrace§8: " + RecordManager.getRecordStatus().getName()); + strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); - if (RecordManager.getRecordStatus().isTracing()) { + if (RecordStateMachine.getRecordStatus().isTracing()) { strings.add("§3"); - strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(RecordManager.getStartTime()))); strings.add("§eTicks§8: §7" + traceTicks()); - strings.add("§eAnzahl TNT§8: §7" + ExplodeListener.size()); + strings.add("§eAnzahl TNT§8: §7" + RecordStateMachine.size()); } strings.add("§4"); @@ -82,7 +83,7 @@ public class BauScoreboard implements Listener { } private long traceTicks() { - return (System.currentTimeMillis() - RecordManager.getStartTime()) / 50; + return (System.currentTimeMillis() - RecordStateMachine.getStartTime()) / 50; } private String tpsColor() { From 33584589a5000146c335522899b53fefd565c56a Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 14:42:50 +0100 Subject: [PATCH 09/46] Start BasicShowMode --- .../bausystem/tracer/TNTEntity_12.java | 29 +++++++++++-- .../bausystem/tracer/TNTEntity_15.java | 30 ++++++++++++-- .../bausystem/tracer/AbstractTNTEntity.java | 13 ++++++ .../tracer/show/mode/BasicShowMode.java | 41 +++++++++++++++++++ 4 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java index c196d6e..f6b1dd3 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -1,19 +1,26 @@ package de.steamwar.bausystem.tracer; -import net.minecraft.server.v1_12_R1.*; +import net.minecraft.server.v1_12_R1.Blocks; +import net.minecraft.server.v1_12_R1.EntityFallingBlock; +import net.minecraft.server.v1_12_R1.EnumMoveType; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.bukkit.entity.Player; -public class TNTEntity_12 extends EntityFallingBlock { +public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { private TNTPosition position; - public TNTEntity_12(World world, TNTPosition position) { - super(world, position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + public TNTEntity_12(World world, TNTPosition position, Player player) { + super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); + + display(player); } @Override @@ -21,4 +28,18 @@ public class TNTEntity_12 extends EntityFallingBlock { } + @Override + public AbstractTNTEntity display(Player player) { + return this; + } + + @Override + public AbstractTNTEntity hide(Player player) { + return this; + } + + @Override + public void remove() { + killEntity(); + } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index cf9984a..d1474af 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -1,19 +1,27 @@ package de.steamwar.bausystem.tracer; -import net.minecraft.server.v1_15_R1.*; +import net.minecraft.server.v1_15_R1.Blocks; +import net.minecraft.server.v1_15_R1.EntityFallingBlock; +import net.minecraft.server.v1_15_R1.EnumMoveType; +import net.minecraft.server.v1_15_R1.Vec3D; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.entity.Player; -public class TNTEntity_15 extends EntityFallingBlock { +public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { private TNTPosition position; - public TNTEntity_15(World world, TNTPosition position) { - super(world, position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + public TNTEntity_15(World world, TNTPosition position, Player player) { + super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); + + display(player); } @Override @@ -21,4 +29,18 @@ public class TNTEntity_15 extends EntityFallingBlock { } + @Override + public AbstractTNTEntity display(Player player) { + return this; + } + + @Override + public AbstractTNTEntity hide(Player player) { + return this; + } + + @Override + public void remove() { + killEntity(); + } } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java new file mode 100644 index 0000000..89c7dd3 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java @@ -0,0 +1,13 @@ +package de.steamwar.bausystem.tracer; + +import org.bukkit.entity.Player; + +public interface AbstractTNTEntity { + + AbstractTNTEntity display(Player player); + + AbstractTNTEntity hide(Player player); + + void remove(); + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java new file mode 100644 index 0000000..0d704f6 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java @@ -0,0 +1,41 @@ +package de.steamwar.bausystem.tracer.show.mode; + +import de.steamwar.bausystem.tracer.AbstractTNTEntity; +import de.steamwar.bausystem.tracer.TNTEntity_12; +import de.steamwar.bausystem.tracer.TNTEntity_15; +import de.steamwar.bausystem.tracer.TNTPosition; +import de.steamwar.bausystem.tracer.show.ShowMode; +import de.steamwar.core.Core; +import org.bukkit.entity.Player; + +import java.util.HashSet; +import java.util.Set; + +public class BasicShowMode implements ShowMode { + + private final Player player; + + private Set tntEntitySet = new HashSet<>(); + + public BasicShowMode(Player player) { + this.player = player; + } + + @Override + public void show(TNTPosition position) { + switch (Core.getVersion()) { + case 12: + tntEntitySet.add(new TNTEntity_12(player.getWorld(), position, player)); + break; + default: + tntEntitySet.add(new TNTEntity_15(player.getWorld(), position, player)); + break; + } + } + + @Override + public void hide() { + tntEntitySet.forEach(abstractTNTEntity -> abstractTNTEntity.hide(player)); + } + +} From 4824893d792f1556e5bad53927e1278409db031b Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 17:49:35 +0100 Subject: [PATCH 10/46] Add BasicShowMode --- .../bausystem/tracer/TNTEntity_12.java | 14 ++++++++--- .../bausystem/tracer/TNTEntity_15.java | 19 +++++++++++--- .../bausystem/tracer/ReflectionUtils.java | 13 ++++++++++ .../bausystem/tracer/show/TNTEntity.java | 25 ------------------- .../tracer/show/TraceShowManager.java | 3 ++- .../tracer/show/mode/BasicShowMode.java | 4 ++- 6 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java index f6b1dd3..72d7136 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -1,10 +1,9 @@ package de.steamwar.bausystem.tracer; -import net.minecraft.server.v1_12_R1.Blocks; -import net.minecraft.server.v1_12_R1.EntityFallingBlock; -import net.minecraft.server.v1_12_R1.EnumMoveType; +import net.minecraft.server.v1_12_R1.*; import org.bukkit.World; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { @@ -30,6 +29,15 @@ public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity display(Player player) { + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); + ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); + ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); + ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); + return this; } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index d1474af..c5a4d2a 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -1,11 +1,9 @@ package de.steamwar.bausystem.tracer; -import net.minecraft.server.v1_15_R1.Blocks; -import net.minecraft.server.v1_15_R1.EntityFallingBlock; -import net.minecraft.server.v1_15_R1.EnumMoveType; -import net.minecraft.server.v1_15_R1.Vec3D; +import net.minecraft.server.v1_15_R1.*; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { @@ -31,11 +29,23 @@ public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity display(Player player) { + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this); + ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); + ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); + ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); + return this; } @Override public AbstractTNTEntity hide(Player player) { + PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); + return this; } @@ -43,4 +53,5 @@ public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntit public void remove() { killEntity(); } + } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java new file mode 100644 index 0000000..88d125a --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java @@ -0,0 +1,13 @@ +package de.steamwar.bausystem.tracer; + +public class ReflectionUtils { + + static void setValue(String field, Object object, Object value) { + try { + object.getClass().getDeclaredField(field).set(object, value); + } catch (NoSuchFieldException | IllegalAccessException e) { + + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java deleted file mode 100644 index 8679439..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TNTEntity.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.steamwar.bausystem.tracer.show; - -import de.steamwar.bausystem.tracer.TNTPosition; -import net.minecraft.server.v1_15_R1.*; - -public class TNTEntity extends EntityFallingBlock { - - private TNTPosition TNTPosition; - - public TNTEntity(World world, TNTPosition TNTPosition) { - super(world, TNTPosition.getLocation().getX(), TNTPosition.getLocation().getY(), TNTPosition.getLocation().getZ(), Blocks.TNT.getBlockData()); - this.TNTPosition = TNTPosition; - - this.setNoGravity(true); - this.ticksLived = -12000; - this.dropItem = false; - this.setCustomNameVisible(true); - } - - @Override - public void move(EnumMoveType enummovetype, Vec3D vec3d) { - - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index a739434..f8ec581 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.tracer.show; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.tracer.TNTPosition; +import de.steamwar.bausystem.tracer.show.mode.BasicShowMode; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -18,7 +19,7 @@ public class TraceShowManager implements Listener { public static void show(Player player){ hide(player); - ShowMode showMode; + ShowMode showMode = new BasicShowMode(player); StoredRecords.showAll(showMode); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java index 0d704f6..85a378e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java @@ -25,7 +25,7 @@ public class BasicShowMode implements ShowMode { public void show(TNTPosition position) { switch (Core.getVersion()) { case 12: - tntEntitySet.add(new TNTEntity_12(player.getWorld(), position, player)); + // tntEntitySet.add(new TNTEntity_12(player.getWorld(), position, player)); break; default: tntEntitySet.add(new TNTEntity_15(player.getWorld(), position, player)); @@ -36,6 +36,8 @@ public class BasicShowMode implements ShowMode { @Override public void hide() { tntEntitySet.forEach(abstractTNTEntity -> abstractTNTEntity.hide(player)); + tntEntitySet.forEach(AbstractTNTEntity::remove); + tntEntitySet.clear(); } } From de9c79240a748de203940bec9045590e399f27eb Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 18:16:23 +0100 Subject: [PATCH 11/46] Add BasicShowMode --- .../bausystem/tracer/TNTEntity_12.java | 6 ++-- .../bausystem/tracer/TNTEntity_15.java | 8 +++-- .../bausystem/commands/CommandTrace.java | 3 ++ .../tracer/record/RecordStateMachine.java | 29 +++++++++---------- .../bausystem/tracer/record/Recorder.java | 6 ++-- .../bausystem/tracer/show/Record.java | 14 ++++----- .../bausystem/tracer/show/StoredRecords.java | 10 ++++--- .../tracer/show/TraceShowManager.java | 20 ++++++------- 8 files changed, 51 insertions(+), 45 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java index 72d7136..e69ef24 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -8,11 +8,8 @@ import org.bukkit.entity.Player; public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { - private TNTPosition position; - public TNTEntity_12(World world, TNTPosition position, Player player) { super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); - this.position = position; this.setNoGravity(true); this.ticksLived = -12000; @@ -35,6 +32,9 @@ public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntit ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index c5a4d2a..f421f5c 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -8,11 +8,8 @@ import org.bukkit.entity.Player; public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { - private TNTPosition position; - public TNTEntity_15(World world, TNTPosition position, Player player) { super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); - this.position = position; this.setNoGravity(true); this.ticksLived = -12000; @@ -29,12 +26,17 @@ public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity display(Player player) { + System.out.println("SHOW: " + player + " " + locX() + " " + locY() + " " + locZ()); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index e6c9e96..983f726 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.StoredRecords; +import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -83,8 +84,10 @@ public class CommandTrace implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); break; case "show": + TraceShowManager.show(player); break; case "hide": + TraceShowManager.hide(player); break; case "toggleshow": case "interpolate": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java index 5086697..7a1e25e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java @@ -20,7 +20,8 @@ package de.steamwar.bausystem.tracer.record; public class RecordStateMachine { - private RecordStateMachine(){} + private RecordStateMachine() { + } private static final TraceAutoHandler autoHandler = new TraceAutoHandler(); @@ -28,15 +29,15 @@ public class RecordStateMachine { private static Recorder recorder = null; public static void commandStart() { - recordStatus = RecordStatus.RECORD; autoHandler.disable(); recordStart(); + recordStatus = RecordStatus.RECORD; } public static void commandStop() { - recordStatus = RecordStatus.IDLE; autoHandler.disable(); recordStop(); + recordStatus = RecordStatus.IDLE; } public static void commandAuto() { @@ -52,27 +53,23 @@ public class RecordStateMachine { } } - static void autoRecord(){ - recordStatus = RecordStatus.RECORD_AUTO; + static void autoRecord() { recordStart(); + recordStatus = RecordStatus.RECORD_AUTO; } - static void autoIdle(){ - recordStatus = RecordStatus.IDLE_AUTO; + static void autoIdle() { recordStop(); + recordStatus = RecordStatus.IDLE_AUTO; } private static void recordStart() { - if(recordStatus.isTracing()) - return; - + if (recordStatus.isTracing()) return; recorder = new Recorder(); } private static void recordStop() { - if(!recordStatus.isTracing()) - return; - + if (!recordStatus.isTracing()) return; recorder.stopRecording(); } @@ -80,11 +77,13 @@ public class RecordStateMachine { return recordStatus; } - public static int size(){ + public static int size() { + if (recorder == null) return 0; return recorder.size(); } - public static long getStartTime(){ + public static long getStartTime() { + if (recorder == null) return 0; return recorder.getStartTime(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java index c161253..8aeaa43 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -41,13 +41,13 @@ public class Recorder implements Listener { private final BukkitTask task; private final Record record; - Recorder(){ + Recorder() { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1); record = new Record(); } - void stopRecording(){ + void stopRecording() { HandlerList.unregisterAll(this); task.cancel(); } @@ -76,7 +76,7 @@ public class Recorder implements Listener { private Record.TNTRecord get(TNTPrimed tntPrimed) { Record.TNTRecord tntRecord = recordMap.get(tntPrimed); - if(tntRecord != null) + if (tntRecord != null) return tntRecord; tntRecord = this.record.spawn(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java index 531927e..b829d50 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java @@ -30,26 +30,26 @@ public class Record { private final long startTime; private final List tnt = new ArrayList<>(); - public int size(){ + public int size() { return tnt.size(); } - public long getStartTime(){ + public long getStartTime() { return startTime; } public void showAll(ShowMode mode) { - for(TNTRecord record : tnt) + for (TNTRecord record : tnt) record.showAll(mode); } /* The following methods should only be called by a recorder */ - public Record(){ + public Record() { startTime = System.currentTimeMillis(); StoredRecords.add(this); } - public TNTRecord spawn(){ + public TNTRecord spawn() { TNTRecord record = new TNTRecord(); tnt.add(record); return record; @@ -59,8 +59,8 @@ public class Record { private final List positions = new ArrayList<>(41); private boolean exploded = false; - public void showAll(ShowMode mode){ - for(TNTPosition position : positions) + public void showAll(ShowMode mode) { + for (TNTPosition position : positions) mode.show(position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java index 259bbab..a7ce3c5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java @@ -23,18 +23,20 @@ import java.util.ArrayList; import java.util.List; public class StoredRecords { + private static final List records = new ArrayList<>(); - public static void add(Record record){ + public static void add(Record record) { records.add(record); } - public static void showAll(ShowMode mode){ - for(Record record : records) record.showAll(mode); + public static void showAll(ShowMode mode) { + for (Record record : records) record.showAll(mode); } - public static void clear(){ + public static void clear() { records.clear(); TraceShowManager.clear(); } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index f8ec581..c931eed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -13,42 +13,42 @@ import java.util.HashMap; import java.util.Map; public class TraceShowManager implements Listener { - private TraceShowManager(){} + private TraceShowManager() {} private static final Map showModes = new HashMap<>(); - public static void show(Player player){ + public static void show(Player player) { hide(player); ShowMode showMode = new BasicShowMode(player); StoredRecords.showAll(showMode); } - public static void hide(Player player){ + public static void hide(Player player) { ShowMode showMode = showModes.remove(player); - if(showMode == null) + if (showMode == null) return; showMode.hide(); } /* Only to be called by record */ - static void show(TNTPosition tnt){ - for(ShowMode mode : showModes.values()) + static void show(TNTPosition tnt) { + for (ShowMode mode : showModes.values()) mode.show(tnt); } /* Only to be called by StoredRecords */ - static void clear(){ - for(ShowMode mode : showModes.values()) + static void clear() { + for (ShowMode mode : showModes.values()) mode.hide(); } /* Internal if player leaves*/ - static{ + static { Bukkit.getPluginManager().registerEvents(new TraceShowManager(), BauSystem.getPlugin()); } @EventHandler - public void onLeave(PlayerQuitEvent event){ + public void onLeave(PlayerQuitEvent event) { showModes.remove(event.getPlayer()); } } From 5149faa62691b28d7d8a31537152210ba6a58864 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 18:18:02 +0100 Subject: [PATCH 12/46] Add BasicShowMode --- BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index f421f5c..2bf0278 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -26,7 +26,7 @@ public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity display(Player player) { - System.out.println("SHOW: " + player + " " + locX() + " " + locY() + " " + locZ()); + // System.out.println("SHOW: " + player + " " + locX() + " " + locY() + " " + locZ()); PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); From d00d0ad512718944bb6d04c19efef22467e2f394 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 20:01:26 +0100 Subject: [PATCH 13/46] Add BasicShowMode --- .../de/steamwar/bausystem/tracer/TNTEntity_12.java | 6 ++++++ .../de/steamwar/bausystem/tracer/TNTEntity_15.java | 14 +++++--------- .../steamwar/bausystem/tracer/ReflectionUtils.java | 9 +++++++-- .../steamwar/bausystem/commands/CommandTrace.java | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java index e69ef24..edfb52f 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -8,8 +8,11 @@ import org.bukkit.entity.Player; public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { + private TNTPosition position; + public TNTEntity_12(World world, TNTPosition position, Player player) { super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + this.position = position; this.setNoGravity(true); this.ticksLived = -12000; @@ -27,6 +30,9 @@ public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); + ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getLocation().getX()); + ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getLocation().getY()); + ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getLocation().getZ()); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index 2bf0278..6a49013 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -8,8 +8,12 @@ import org.bukkit.entity.Player; public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { + private static final Vec3D ZERO = new Vec3D(0, 0, 0); + private TNTPosition position; + public TNTEntity_15(World world, TNTPosition position, Player player) { super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + this.position = position; this.setNoGravity(true); this.ticksLived = -12000; @@ -26,17 +30,9 @@ public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity display(Player player) { - // System.out.println("SHOW: " + player + " " + locX() + " " + locY() + " " + locZ()); - - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this); - ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); - ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); - ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.TNT.getBlockData()), ZERO); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); - PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java index 88d125a..5fc0946 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java @@ -1,12 +1,17 @@ package de.steamwar.bausystem.tracer; +import java.lang.reflect.Field; + public class ReflectionUtils { + @SuppressWarnings({"java:S3011"}) static void setValue(String field, Object object, Object value) { try { - object.getClass().getDeclaredField(field).set(object, value); + Field f = object.getClass().getDeclaredField(field); + f.setAccessible(true); + f.set(object, value); } catch (NoSuchFieldException | IllegalAccessException e) { - + e.printStackTrace(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 983f726..44f65d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -65,7 +65,7 @@ public class CommandTrace implements CommandExecutor { return false; } - if (!permissionCheck(player)) return false; + // if (!permissionCheck(player)) return false; switch (args[0].toLowerCase()) { case "start": From c1e9fe5664584866f3812499ec7177ea40cff5eb Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 20:01:59 +0100 Subject: [PATCH 14/46] Add Permission check --- .../src/de/steamwar/bausystem/commands/CommandTrace.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 44f65d4..983f726 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -65,7 +65,7 @@ public class CommandTrace implements CommandExecutor { return false; } - // if (!permissionCheck(player)) return false; + if (!permissionCheck(player)) return false; switch (args[0].toLowerCase()) { case "start": From 1dd0bd74182b0d1fb955a655da483fd181ba8e29 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 20:11:02 +0100 Subject: [PATCH 15/46] Add Copyright Notice --- .../bausystem/tracer/TNTEntityFactory_12.java | 31 +++++++++++++++++++ .../bausystem/tracer/TNTEntity_12.java | 25 ++++++++++++++- .../bausystem/tracer/TNTEntityFactory_15.java | 31 +++++++++++++++++++ .../bausystem/tracer/TNTEntity_15.java | 21 ++++++++++++- .../bausystem/tracer/AbstractTNTEntity.java | 19 ++++++++++++ .../bausystem/tracer/ReflectionUtils.java | 19 ++++++++++++ .../bausystem/tracer/TNTPosition.java | 19 ++++++++++++ .../tracer/show/mode/BasicShowMode.java | 9 ++---- 8 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntityFactory_12.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntityFactory_15.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntityFactory_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntityFactory_12.java new file mode 100644 index 0000000..794fbc4 --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntityFactory_12.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +public class TNTEntityFactory_12 { + + public static AbstractTNTEntity create(World world, TNTPosition tntPosition, Player player) { + return new TNTEntity_12(world, tntPosition, player); + } + +} diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java index edfb52f..1412fad 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; import net.minecraft.server.v1_12_R1.*; @@ -6,7 +25,7 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { +class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { private TNTPosition position; @@ -49,6 +68,9 @@ public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity hide(Player player) { + PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); + return this; } @@ -56,4 +78,5 @@ public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntit public void remove() { killEntity(); } + } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntityFactory_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntityFactory_15.java new file mode 100644 index 0000000..0fc1ac8 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntityFactory_15.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.tracer; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +public class TNTEntityFactory_15 { + + public static AbstractTNTEntity create(World world, TNTPosition tntPosition, Player player) { + return new TNTEntity_15(world, tntPosition, player); + } + +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index 6a49013..f53c11d 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; import net.minecraft.server.v1_15_R1.*; @@ -6,7 +25,7 @@ import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { +class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { private static final Vec3D ZERO = new Vec3D(0, 0, 0); private TNTPosition position; diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java index 89c7dd3..d39751f 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; import org.bukkit.entity.Player; diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java index 5fc0946..0aac017 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; import java.lang.reflect.Field; diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java index 2a65f6c..12708e6 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer; import org.bukkit.entity.Entity; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java index 85a378e..8819135 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java @@ -1,9 +1,6 @@ package de.steamwar.bausystem.tracer.show.mode; -import de.steamwar.bausystem.tracer.AbstractTNTEntity; -import de.steamwar.bausystem.tracer.TNTEntity_12; -import de.steamwar.bausystem.tracer.TNTEntity_15; -import de.steamwar.bausystem.tracer.TNTPosition; +import de.steamwar.bausystem.tracer.*; import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.core.Core; import org.bukkit.entity.Player; @@ -25,10 +22,10 @@ public class BasicShowMode implements ShowMode { public void show(TNTPosition position) { switch (Core.getVersion()) { case 12: - // tntEntitySet.add(new TNTEntity_12(player.getWorld(), position, player)); + tntEntitySet.add(TNTEntityFactory_12.create(player.getWorld(), position, player)); break; default: - tntEntitySet.add(new TNTEntity_15(player.getWorld(), position, player)); + tntEntitySet.add(TNTEntityFactory_15.create(player.getWorld(), position, player)); break; } } From 4b358d07eb2d71444859f0b60e28ba5bf847489f Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 20:17:29 +0100 Subject: [PATCH 16/46] Add hide System WIP --- BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java | 2 +- BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java index 1412fad..ce11c08 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -68,7 +68,7 @@ class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { @Override public AbstractTNTEntity hide(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); + PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); return this; diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index f53c11d..00de470 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -60,7 +60,7 @@ class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { @Override public AbstractTNTEntity hide(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); + PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); return this; From efb153521137391d165112c12cb29817f0a01f64 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 12:11:59 +0100 Subject: [PATCH 17/46] Add BasicNoWater show mode Add UpdateEntity_12 Add UpdateEntity_15 Add Advanced show mode WIP Fix Recorder --- .../bausystem/tracer/TNTTracer_12.java | 16 +++- ...{TNTEntity_12.java => TraceEntity_12.java} | 8 +- .../bausystem/tracer/UpdateEntity_12.java | 84 +++++++++++++++++++ .../bausystem/tracer/TNTTracer_15.java | 16 +++- ...{TNTEntity_15.java => TraceEntity_15.java} | 8 +- .../bausystem/tracer/UpdateEntity_15.java | 76 +++++++++++++++++ ...NTEntity.java => AbstractTraceEntity.java} | 6 +- .../bausystem/commands/CommandTrace.java | 6 +- .../commands/CommandTraceTabCompleter.java | 14 +--- .../bausystem/tracer/record/Recorder.java | 5 ++ .../tracer/show/TraceShowManager.java | 28 ++++++- .../bausystem/tracer/show/mode/Advanced.java | 25 ++++++ .../bausystem/tracer/show/mode/Basic.java | 81 ++++++++++++++++++ .../tracer/show/mode/BasicNoWater.java | 61 ++++++++++++++ .../tracer/show/mode/BasicShowMode.java | 40 --------- 15 files changed, 399 insertions(+), 75 deletions(-) rename BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntityFactory_15.java => BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java (57%) rename BauSystem_12/src/de/steamwar/bausystem/tracer/{TNTEntity_12.java => TraceEntity_12.java} (91%) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java rename BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntityFactory_12.java => BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java (58%) rename BauSystem_15/src/de/steamwar/bausystem/tracer/{TNTEntity_15.java => TraceEntity_15.java} (90%) create mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java rename BauSystem_API/src/de/steamwar/bausystem/tracer/{AbstractTNTEntity.java => AbstractTraceEntity.java} (86%) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntityFactory_15.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java similarity index 57% rename from BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntityFactory_15.java rename to BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 0fc1ac8..94dc43d 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntityFactory_15.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -19,13 +19,23 @@ package de.steamwar.bausystem.tracer; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; -public class TNTEntityFactory_15 { +public class TNTTracer_12 { - public static AbstractTNTEntity create(World world, TNTPosition tntPosition, Player player) { - return new TNTEntity_15(world, tntPosition, player); + public static AbstractTraceEntity createTNT(World world, TNTPosition tntPosition, Player player) { + return new TraceEntity_12(world, tntPosition, player); + } + + public static AbstractTraceEntity createUpdatePoint(World world, TNTPosition tntPosition, Player player) { + return new UpdateEntity_12(world, tntPosition, player); + } + + public static boolean inWater(World world, TNTPosition tntPosition) { + Material material = tntPosition.getLocation().toLocation(world).getBlock().getType(); + return material == Material.WATER || material == Material.STATIONARY_WATER; } } diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java similarity index 91% rename from BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java rename to BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index ce11c08..59ed8bd 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -25,11 +25,11 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { +class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { private TNTPosition position; - public TNTEntity_12(World world, TNTPosition position, Player player) { + public TraceEntity_12(World world, TNTPosition position, Player player) { super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); this.position = position; @@ -47,7 +47,7 @@ class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { } @Override - public AbstractTNTEntity display(Player player) { + public AbstractTraceEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getLocation().getX()); ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getLocation().getY()); @@ -67,7 +67,7 @@ class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { } @Override - public AbstractTNTEntity hide(Player player) { + public AbstractTraceEntity hide(Player player) { PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java new file mode 100644 index 0000000..2cd3272 --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java @@ -0,0 +1,84 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.tracer; + +import net.minecraft.server.v1_12_R1.*; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +class UpdateEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { + + private TNTPosition position; + + public UpdateEntity_12(World world, TNTPosition position, Player player) { + super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.STAINED_GLASS.getBlockData()); + this.position = position; + + this.setNoGravity(true); + this.ticksLived = -12000; + this.dropItem = false; + this.setCustomNameVisible(true); + + display(player); + } + + @Override + public void move(EnumMoveType enummovetype, double dx, double dy, double dz) { + + } + + @Override + public AbstractTraceEntity display(Player player) { + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); + ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getLocation().getX()); + ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getLocation().getY()); + ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getLocation().getZ()); + ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); + ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); + ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + + PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); + + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); + + return this; + } + + @Override + public AbstractTraceEntity hide(Player player) { + PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); + + return this; + } + + @Override + public void remove() { + killEntity(); + } + +} diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntityFactory_12.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java similarity index 58% rename from BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntityFactory_12.java rename to BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 794fbc4..823ea7a 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntityFactory_12.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -19,13 +19,23 @@ package de.steamwar.bausystem.tracer; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; -public class TNTEntityFactory_12 { +public class TNTTracer_15 { - public static AbstractTNTEntity create(World world, TNTPosition tntPosition, Player player) { - return new TNTEntity_12(world, tntPosition, player); + public static AbstractTraceEntity createTNT(World world, TNTPosition tntPosition, Player player) { + return new TraceEntity_15(world, tntPosition, player); + } + + public static AbstractTraceEntity createUpdatePoint(World world, TNTPosition tntPosition, Player player) { + return new UpdateEntity_15(world, tntPosition, player); + } + + public static boolean inWater(World world, TNTPosition tntPosition) { + Material material = tntPosition.getLocation().toLocation(world).getBlock().getType(); + return material == Material.WATER; } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java similarity index 90% rename from BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java rename to BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 00de470..303a191 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -25,12 +25,12 @@ import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { +class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { private static final Vec3D ZERO = new Vec3D(0, 0, 0); private TNTPosition position; - public TNTEntity_15(World world, TNTPosition position, Player player) { + public TraceEntity_15(World world, TNTPosition position, Player player) { super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); this.position = position; @@ -48,7 +48,7 @@ class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { } @Override - public AbstractTNTEntity display(Player player) { + public AbstractTraceEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.TNT.getBlockData()), ZERO); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); @@ -59,7 +59,7 @@ class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { } @Override - public AbstractTNTEntity hide(Player player) { + public AbstractTraceEntity hide(Player player) { PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java new file mode 100644 index 0000000..8fa1f70 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java @@ -0,0 +1,76 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.tracer; + +import net.minecraft.server.v1_15_R1.*; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +class UpdateEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { + + private static final Vec3D ZERO = new Vec3D(0, 0, 0); + private TNTPosition position; + + public UpdateEntity_15(World world, TNTPosition position, Player player) { + super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + this.position = position; + + this.setNoGravity(true); + this.ticksLived = -12000; + this.dropItem = false; + this.setCustomNameVisible(true); + + display(player); + } + + @Override + public void move(EnumMoveType enummovetype, Vec3D vec3d) { + + } + + @Override + public AbstractTraceEntity display(Player player) { + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); + + return this; + } + + @Override + public AbstractTraceEntity hide(Player player) { + PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); + + return this; + } + + @Override + public void remove() { + killEntity(); + } + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java similarity index 86% rename from BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java rename to BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java index d39751f..1ff6886 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java @@ -21,11 +21,11 @@ package de.steamwar.bausystem.tracer; import org.bukkit.entity.Player; -public interface AbstractTNTEntity { +public interface AbstractTraceEntity { - AbstractTNTEntity display(Player player); + AbstractTraceEntity display(Player player); - AbstractTNTEntity hide(Player player); + AbstractTraceEntity hide(Player player); void remove(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 983f726..f553a2d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -84,15 +84,11 @@ public class CommandTrace implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); break; case "show": - TraceShowManager.show(player); + TraceShowManager.show(player, args); break; case "hide": TraceShowManager.hide(player); break; - case "toggleshow": - case "interpolate": - case "distance": - break; case "list": case "gui": break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 9c32567..1f3a699 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -21,6 +21,8 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.record.RecordStatus; +import de.steamwar.bausystem.tracer.show.mode.Basic; +import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -47,21 +49,13 @@ public class CommandTraceTabCompleter implements TabCompleter { } tabComplete.add("toggleauto"); tabComplete.add("auto"); - tabComplete.add("toggleshow"); tabComplete.add("show"); if (args[0].equalsIgnoreCase("show") && args.length == 2) { - return manageList(new ArrayList<>(Arrays.asList("block", "particle")), args, 1); + return manageList(new ArrayList<>(Arrays.asList("water", "nowater", "no_water", "removedwater", "removed_water", "basic", "default")), args, 1); } tabComplete.add("hide"); tabComplete.add("delete"); - tabComplete.add("interpolate"); - if (args[0].equalsIgnoreCase("interpolate") && args.length == 2) { - return manageList(new ArrayList<>(Arrays.asList("all", "yaxis", "none")), args, 1); - } - tabComplete.add("distance"); - if (args[0].equalsIgnoreCase("distance") && args.length == 2) { - return manageList(new ArrayList<>(Arrays.asList("3", "4", "5", "6", "7", "8", "9", "10", "11", "default")), args, 1); - } + tabComplete.add("clear"); //tabComplete.add("gui"); //tabComplete.add("list"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java index 8aeaa43..ea0252e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -45,6 +45,11 @@ public class Recorder implements Listener { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1); record = new Record(); + + // To trace TNT initial positions with AutoTracer + if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { + run(); + } } void stopRecording() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index c931eed..c9fb65f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -2,7 +2,8 @@ package de.steamwar.bausystem.tracer.show; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.tracer.TNTPosition; -import de.steamwar.bausystem.tracer.show.mode.BasicShowMode; +import de.steamwar.bausystem.tracer.show.mode.Basic; +import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -17,9 +18,30 @@ public class TraceShowManager implements Listener { private static final Map showModes = new HashMap<>(); - public static void show(Player player) { + public static void show(Player player, String[] args) { hide(player); - ShowMode showMode = new BasicShowMode(player); + + ShowMode showMode; + if (args.length < 2) { + showMode = new Basic(player); + } else { + switch (args[1].toLowerCase()) { + case "water": + case "nowater": + case "no_water": + case "removedwater": + case "removed_water": + showMode = new BasicNoWater(player); + break; + case "basic": + case "default": + default: + showMode = new Basic(player); + break; + } + } + + showModes.put(player, showMode); StoredRecords.showAll(showMode); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java new file mode 100644 index 0000000..61afa4a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -0,0 +1,25 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.tracer.show.mode; + +public class Advanced { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java new file mode 100644 index 0000000..de1e69b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -0,0 +1,81 @@ +package de.steamwar.bausystem.tracer.show.mode; + +import de.steamwar.bausystem.tracer.*; +import de.steamwar.bausystem.tracer.show.ShowMode; +import de.steamwar.core.Core; +import org.bukkit.entity.Player; + +import java.util.*; + +public class Basic implements ShowMode { + + private final Player player; + + private Map tntEntityMap = new HashMap<>(); + + public Basic(Player player) { + this.player = player; + } + + @Override + public void show(TNTPosition position) { + RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); + if (tntEntityMap.containsKey(roundedTNTPosition)) { + return; + } + + switch (Core.getVersion()) { + case 12: + tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player)); + break; + default: + tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player)); + break; + } + } + + @Override + public void hide() { + tntEntityMap.forEach((roundedTNTPosition, abstractTNTEntity) -> { + abstractTNTEntity.hide(player); + abstractTNTEntity.remove(); + }); + tntEntityMap.clear(); + } + + private static class RoundedTNTPosition { + + private static final int factor = 10; + + private int x; + private int y; + private int z; + + private RoundedTNTPosition(TNTPosition tntPosition) { + this(tntPosition.getLocation().getX(), tntPosition.getLocation().getY(), tntPosition.getLocation().getZ()); + } + + private RoundedTNTPosition(double x, double y, double z) { + this.x = (int)(x * factor); + this.y = (int)(y * factor); + this.z = (int)(z * factor); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof RoundedTNTPosition)) return false; + RoundedTNTPosition that = (RoundedTNTPosition) o; + return x == that.x && + y == that.y && + z == that.z; + } + + @Override + public int hashCode() { + return Objects.hash(x, y, z); + } + + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java new file mode 100644 index 0000000..c51ab87 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java @@ -0,0 +1,61 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.tracer.show.mode; + +import de.steamwar.bausystem.tracer.TNTPosition; +import de.steamwar.bausystem.tracer.TNTTracer_12; +import de.steamwar.bausystem.tracer.TNTTracer_15; +import de.steamwar.core.Core; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + +public class BasicNoWater extends Basic { + + private static final World world = Bukkit.getWorlds().get(0); + + public BasicNoWater(Player player) { + super(player); + } + + @Override + public void show(TNTPosition position) { + boolean b; + switch (Core.getVersion()) { + case 12: + b = TNTTracer_12.inWater(world, position); + break; + default: + b = TNTTracer_15.inWater(world, position); + break; + } + if (!b) { + super.show(position); + } + } + + @Override + public void hide() { + super.hide(); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java deleted file mode 100644 index 8819135..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java +++ /dev/null @@ -1,40 +0,0 @@ -package de.steamwar.bausystem.tracer.show.mode; - -import de.steamwar.bausystem.tracer.*; -import de.steamwar.bausystem.tracer.show.ShowMode; -import de.steamwar.core.Core; -import org.bukkit.entity.Player; - -import java.util.HashSet; -import java.util.Set; - -public class BasicShowMode implements ShowMode { - - private final Player player; - - private Set tntEntitySet = new HashSet<>(); - - public BasicShowMode(Player player) { - this.player = player; - } - - @Override - public void show(TNTPosition position) { - switch (Core.getVersion()) { - case 12: - tntEntitySet.add(TNTEntityFactory_12.create(player.getWorld(), position, player)); - break; - default: - tntEntitySet.add(TNTEntityFactory_15.create(player.getWorld(), position, player)); - break; - } - } - - @Override - public void hide() { - tntEntitySet.forEach(abstractTNTEntity -> abstractTNTEntity.hide(player)); - tntEntitySet.forEach(AbstractTNTEntity::remove); - tntEntitySet.clear(); - } - -} From 3f040e6130759cf909369e9e8bedfc31a749442b Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 12:57:50 +0100 Subject: [PATCH 18/46] Add Advanced Add AdvancedNoWater Add RoundedTNTPosition --- .../bausystem/tracer/TraceEntity_12.java | 3 + .../bausystem/tracer/TraceEntity_15.java | 3 + .../bausystem/tracer/RoundedTNTPosition.java | 65 ++++++++++++ .../bausystem/tracer/TNTPosition.java | 20 +++- .../commands/CommandTraceTabCompleter.java | 2 +- .../bausystem/tracer/show/Record.java | 7 +- .../tracer/show/TraceShowManager.java | 15 ++- .../bausystem/tracer/show/mode/Advanced.java | 98 ++++++++++++++++++- .../tracer/show/mode/AdvancedNoWater.java | 56 +++++++++++ .../bausystem/tracer/show/mode/Basic.java | 44 +-------- .../tracer/show/mode/BasicNoWater.java | 5 - 11 files changed, 266 insertions(+), 52 deletions(-) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 59ed8bd..14c2565 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -37,6 +37,9 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); + if (position.isExploded()) { + this.setCustomName("Exploded"); + } display(player); } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 303a191..738f5dd 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -38,6 +38,9 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); + if (position.isExploded()) { + this.setCustomName(new ChatComponentText("Exploded")); + } display(player); } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java new file mode 100644 index 0000000..a38459b --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java @@ -0,0 +1,65 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.tracer; + +import org.bukkit.util.Vector; + +import java.util.Objects; + +public class RoundedTNTPosition { + + private static final int factor = 10; + + private int x; + private int y; + private int z; + + public RoundedTNTPosition(TNTPosition tntPosition) { + this(tntPosition.getLocation().getX(), tntPosition.getLocation().getY(), tntPosition.getLocation().getZ()); + } + + public RoundedTNTPosition(Vector vector) { + this(vector.getX(), vector.getY(), vector.getZ()); + } + + public RoundedTNTPosition(double x, double y, double z) { + this.x = (int)(x * factor); + this.y = (int)(y * factor); + this.z = (int)(z * factor); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof RoundedTNTPosition)) return false; + RoundedTNTPosition that = (RoundedTNTPosition) o; + return x == that.x && + y == that.y && + z == that.z; + } + + @Override + public int hashCode() { + return Objects.hash(x, y, z); + } + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java index 12708e6..5c47ed6 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java @@ -25,15 +25,33 @@ import org.bukkit.util.Vector; public class TNTPosition { private Vector location; + private TNTPosition previous; + private boolean exploded; - public TNTPosition(Entity entity) { + public TNTPosition(Entity entity, TNTPosition previous, boolean exploded) { location = entity.getLocation().toVector(); + this.previous = previous; + this.exploded = exploded; + } + + public TNTPosition(Vector vector) { + location = vector; + this.previous = null; + this.exploded = false; } public Vector getLocation() { return location; } + public TNTPosition getPrevious() { + return previous; + } + + public boolean isExploded() { + return exploded; + } + @Override public String toString() { return "Position{" + diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 1f3a699..28b9a62 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -51,7 +51,7 @@ public class CommandTraceTabCompleter implements TabCompleter { tabComplete.add("auto"); tabComplete.add("show"); if (args[0].equalsIgnoreCase("show") && args.length == 2) { - return manageList(new ArrayList<>(Arrays.asList("water", "nowater", "no_water", "removedwater", "removed_water", "basic", "default")), args, 1); + return manageList(new ArrayList<>(Arrays.asList("nowater", "basic", "default", "advanced")), args, 1); } tabComplete.add("hide"); tabComplete.add("delete"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java index b829d50..9b4a93c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java @@ -66,7 +66,12 @@ public class Record { /* The following methods should only be called by a recorder */ public void add(TNTPrimed tntPrimed) { - TNTPosition position = new TNTPosition(tntPrimed); + TNTPosition position; + if (positions.isEmpty()) { + position = new TNTPosition(tntPrimed, null, exploded); + } else { + position = new TNTPosition(tntPrimed, positions.get(positions.size() - 1), exploded); + } positions.add(position); TraceShowManager.show(position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index c9fb65f..420125e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -2,6 +2,8 @@ package de.steamwar.bausystem.tracer.show; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.tracer.TNTPosition; +import de.steamwar.bausystem.tracer.show.mode.Advanced; +import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater; import de.steamwar.bausystem.tracer.show.mode.Basic; import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import org.bukkit.Bukkit; @@ -26,13 +28,18 @@ public class TraceShowManager implements Listener { showMode = new Basic(player); } else { switch (args[1].toLowerCase()) { - case "water": case "nowater": - case "no_water": - case "removedwater": - case "removed_water": + case "basic-nowater": + case "basicnowater": showMode = new BasicNoWater(player); break; + case "advanced": + showMode = new Advanced(player); + break; + case "advanced-nowater": + case "advancednowater": + showMode = new AdvancedNoWater(player); + break; case "basic": case "default": default: diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 61afa4a..034bcc4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -21,5 +21,101 @@ package de.steamwar.bausystem.tracer.show.mode; -public class Advanced { +import de.steamwar.bausystem.tracer.*; +import de.steamwar.bausystem.tracer.show.ShowMode; +import de.steamwar.core.Core; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.HashMap; +import java.util.Map; + +public class Advanced implements ShowMode { + + private final Player player; + + private Map tntEntityMap = new HashMap<>(); + private Map updateEntityMap = new HashMap<>(); + + public Advanced(Player player) { + this.player = player; + } + + @Override + public void show(TNTPosition position) { + RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); + if (tntEntityMap.containsKey(roundedTNTPosition)) { + return; + } + + switch (Core.getVersion()) { + case 12: + tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player)); + break; + default: + tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player)); + break; + } + + if (position.getPrevious() == null) return; + + Vector vector = position.getLocation().clone().subtract(position.getPrevious().getLocation()); + Vector updatePointY = position.getPrevious().getLocation().clone().setY(position.getLocation().getY()); + Vector updatePointXZ; + if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) { + updatePointXZ = updatePointY.clone().setX(position.getLocation().getX()); + } else { + updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); + } + + System.out.println(updatePointY); + System.out.println(updatePointXZ); + + if (!position.getLocation().equals(updatePointY)) { + RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointY); + if (updateEntityMap.containsKey(updatePointPosition)) { + return; + } + + switch (Core.getVersion()) { + case 12: + updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY), player)); + break; + default: + updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY), player)); + break; + } + } + if (!position.getLocation().equals(updatePointXZ)) { + RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ); + if (updateEntityMap.containsKey(updatePointPosition)) { + return; + } + + switch (Core.getVersion()) { + case 12: + updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ), player)); + break; + default: + updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ), player)); + break; + } + } + } + + @Override + public void hide() { + tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { + abstractTraceEntity.hide(player); + abstractTraceEntity.remove(); + }); + tntEntityMap.clear(); + + updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { + abstractTraceEntity.hide(player); + abstractTraceEntity.remove(); + }); + updateEntityMap.clear(); + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java new file mode 100644 index 0000000..9e1a932 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java @@ -0,0 +1,56 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.tracer.show.mode; + +import de.steamwar.bausystem.tracer.TNTPosition; +import de.steamwar.bausystem.tracer.TNTTracer_12; +import de.steamwar.bausystem.tracer.TNTTracer_15; +import de.steamwar.core.Core; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + +public class AdvancedNoWater extends Advanced { + + private static final World world = Bukkit.getWorlds().get(0); + + public AdvancedNoWater(Player player) { + super(player); + } + + @Override + public void show(TNTPosition position) { + boolean b; + switch (Core.getVersion()) { + case 12: + b = TNTTracer_12.inWater(world, position); + break; + default: + b = TNTTracer_15.inWater(world, position); + break; + } + if (!b) { + super.show(position); + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java index de1e69b..e72d2ab 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -5,7 +5,8 @@ import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.core.Core; import org.bukkit.entity.Player; -import java.util.*; +import java.util.HashMap; +import java.util.Map; public class Basic implements ShowMode { @@ -36,46 +37,11 @@ public class Basic implements ShowMode { @Override public void hide() { - tntEntityMap.forEach((roundedTNTPosition, abstractTNTEntity) -> { - abstractTNTEntity.hide(player); - abstractTNTEntity.remove(); + tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { + abstractTraceEntity.hide(player); + abstractTraceEntity.remove(); }); tntEntityMap.clear(); } - private static class RoundedTNTPosition { - - private static final int factor = 10; - - private int x; - private int y; - private int z; - - private RoundedTNTPosition(TNTPosition tntPosition) { - this(tntPosition.getLocation().getX(), tntPosition.getLocation().getY(), tntPosition.getLocation().getZ()); - } - - private RoundedTNTPosition(double x, double y, double z) { - this.x = (int)(x * factor); - this.y = (int)(y * factor); - this.z = (int)(z * factor); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RoundedTNTPosition)) return false; - RoundedTNTPosition that = (RoundedTNTPosition) o; - return x == that.x && - y == that.y && - z == that.z; - } - - @Override - public int hashCode() { - return Objects.hash(x, y, z); - } - - } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java index c51ab87..8f9e2f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java @@ -53,9 +53,4 @@ public class BasicNoWater extends Basic { } } - @Override - public void hide() { - super.hide(); - } - } From 79ee79926053c6395cea93c4ff0af2b2f87e259a Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 12:59:39 +0100 Subject: [PATCH 19/46] Add CommandTrace messages --- .../src/de/steamwar/bausystem/commands/CommandTrace.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index f553a2d..5267cce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -70,13 +70,16 @@ public class CommandTrace implements CommandExecutor { switch (args[0].toLowerCase()) { case "start": RecordStateMachine.commandStart(); + player.sendMessage(BauSystem.PREFIX + "§aTNT-Tracer gestartet"); break; case "stop": RecordStateMachine.commandStop(); + player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); break; case "toggleauto": case "auto": RecordStateMachine.commandAuto(); + player.sendMessage(BauSystem.PREFIX + "§eTNT-Tracer auf Auto gestellt"); break; case "clear": case "delete": @@ -85,9 +88,11 @@ public class CommandTrace implements CommandExecutor { break; case "show": TraceShowManager.show(player, args); + player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); break; case "hide": TraceShowManager.hide(player); + player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet"); break; case "list": case "gui": From 7798ddc5d79bf00b9c50fcef1b1c8aa330a5f8dd Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 13:00:07 +0100 Subject: [PATCH 20/46] Remove Logging Messages --- .../src/de/steamwar/bausystem/tracer/show/mode/Advanced.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 034bcc4..dcb3163 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -68,9 +68,6 @@ public class Advanced implements ShowMode { updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); } - System.out.println(updatePointY); - System.out.println(updatePointXZ); - if (!position.getLocation().equals(updatePointY)) { RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointY); if (updateEntityMap.containsKey(updatePointPosition)) { From 0ffafaf95c3b95f5d8ac367eba5991ab18b1cfe4 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 13:02:43 +0100 Subject: [PATCH 21/46] Fix CommandTraceTabCompleter --- .../steamwar/bausystem/commands/CommandTraceTabCompleter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 28b9a62..3b362a9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -51,7 +51,7 @@ public class CommandTraceTabCompleter implements TabCompleter { tabComplete.add("auto"); tabComplete.add("show"); if (args[0].equalsIgnoreCase("show") && args.length == 2) { - return manageList(new ArrayList<>(Arrays.asList("nowater", "basic", "default", "advanced")), args, 1); + return manageList(new ArrayList<>(Arrays.asList("nowater", "basic", "default", "advanced", "advanced-nowater")), args, 1); } tabComplete.add("hide"); tabComplete.add("delete"); From f554f595f8b4c1bf35906eb7d452c1b892078c5c Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 13:25:43 +0100 Subject: [PATCH 22/46] Optimize Imports --- .../steamwar/bausystem/commands/CommandTraceTabCompleter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 3b362a9..486a08d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -21,8 +21,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.record.RecordStatus; -import de.steamwar.bausystem.tracer.show.mode.Basic; -import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; From 5a881be7469f409049a4107eb7728d3a280a0e2b Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 13:32:10 +0100 Subject: [PATCH 23/46] Simplify Advanced --- .../bausystem/tracer/show/mode/Advanced.java | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index dcb3163..84dd2de 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.*; -import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.core.Core; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -30,32 +29,20 @@ import org.bukkit.util.Vector; import java.util.HashMap; import java.util.Map; -public class Advanced implements ShowMode { +public class Advanced extends Basic { private final Player player; - private Map tntEntityMap = new HashMap<>(); private Map updateEntityMap = new HashMap<>(); public Advanced(Player player) { + super(player); this.player = player; } @Override public void show(TNTPosition position) { - RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); - if (tntEntityMap.containsKey(roundedTNTPosition)) { - return; - } - - switch (Core.getVersion()) { - case 12: - tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player)); - break; - default: - tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player)); - break; - } + super.show(position); if (position.getPrevious() == null) return; @@ -102,11 +89,7 @@ public class Advanced implements ShowMode { @Override public void hide() { - tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { - abstractTraceEntity.hide(player); - abstractTraceEntity.remove(); - }); - tntEntityMap.clear(); + super.hide(); updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { abstractTraceEntity.hide(player); From 62d223b470f76fb9f42cf93e8f94109129085b8d Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 18:49:35 +0100 Subject: [PATCH 24/46] Simplify TNTPosition --- .../de/steamwar/bausystem/tracer/TNTPosition.java | 12 ++++++------ .../steamwar/bausystem/commands/CommandTrace.java | 15 ++++++++------- .../de/steamwar/bausystem/tracer/show/Record.java | 7 +------ .../bausystem/tracer/show/mode/Advanced.java | 8 ++++---- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java index 5c47ed6..8922696 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java @@ -25,18 +25,18 @@ import org.bukkit.util.Vector; public class TNTPosition { private Vector location; - private TNTPosition previous; + private Vector velocity; private boolean exploded; - public TNTPosition(Entity entity, TNTPosition previous, boolean exploded) { + public TNTPosition(Entity entity, boolean exploded) { location = entity.getLocation().toVector(); - this.previous = previous; + velocity = entity.getVelocity(); this.exploded = exploded; } public TNTPosition(Vector vector) { location = vector; - this.previous = null; + this.velocity = null; this.exploded = false; } @@ -44,8 +44,8 @@ public class TNTPosition { return location; } - public TNTPosition getPrevious() { - return previous; + public Vector getVelocity() { + return velocity; } public boolean isExploded() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 5267cce..7245237 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -24,6 +24,10 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; +import de.steamwar.bausystem.tracer.show.mode.Advanced; +import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater; +import de.steamwar.bausystem.tracer.show.mode.Basic; +import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -36,15 +40,12 @@ public class CommandTrace implements CommandExecutor { player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen"); player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer"); player.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart"); - player.sendMessage("§8/§etrace show §8<§eblock§8|§eparticle§8|§7TNT-ID§8> §8- §7Zeigt alle TNT-Positionen"); - player.sendMessage("§8/§etrace hide §8<§7TNT-ID§8> §8- §7Versteckt alle TNT-Positionen"); - player.sendMessage("§8/§etrace toggleshow §8<§7TNT-ID§8> §8- §7Zeigt/Versteckt ein TNT"); - player.sendMessage("§8/§etrace delete §8<§7TNT-ID§8> §8- §7Löscht alle TNT-Positionen"); - player.sendMessage("§8/§etrace interpolate §8[§eall§8|§eyaxis§8|§enone§8] §8- §7Interpolationsoptionen"); - player.sendMessage("§8/§etrace distance §8[§7distanz§8] §8- §7Distanzoptionen"); + player.sendMessage("§8/§etrace show §8<§enowater§8|§eadvanced§8|§eadvanced-nowater§8> §8- §7Zeigt alle TNT-Positionen"); + player.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen"); + player.sendMessage("§8/§etrace delete §8- §7Löscht alle TNT-Positionen"); // player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf"); // player.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an"); - player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); + // player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); } private boolean permissionCheck(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java index 9b4a93c..8f72dcd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java @@ -66,12 +66,7 @@ public class Record { /* The following methods should only be called by a recorder */ public void add(TNTPrimed tntPrimed) { - TNTPosition position; - if (positions.isEmpty()) { - position = new TNTPosition(tntPrimed, null, exploded); - } else { - position = new TNTPosition(tntPrimed, positions.get(positions.size() - 1), exploded); - } + TNTPosition position = new TNTPosition(tntPrimed, exploded); positions.add(position); TraceShowManager.show(position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 84dd2de..9c913e7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -44,12 +44,12 @@ public class Advanced extends Basic { public void show(TNTPosition position) { super.show(position); - if (position.getPrevious() == null) return; + if (position.getVelocity() == null) return; + Vector previousLocation = position.getLocation().clone().subtract(position.getVelocity()); - Vector vector = position.getLocation().clone().subtract(position.getPrevious().getLocation()); - Vector updatePointY = position.getPrevious().getLocation().clone().setY(position.getLocation().getY()); + Vector updatePointY = previousLocation.clone().setY(position.getLocation().getY()); Vector updatePointXZ; - if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) { + if (Math.abs(position.getVelocity().getX()) > Math.abs(position.getVelocity().getZ())) { updatePointXZ = updatePointY.clone().setX(position.getLocation().getX()); } else { updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); From dee5d9598d1d179135b57b25ace07a0a658e3f81 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 21:58:55 +0100 Subject: [PATCH 25/46] Fix Advanced Tracer --- .../src/de/steamwar/bausystem/commands/CommandTrace.java | 4 ---- .../bausystem/commands/CommandTraceTabCompleter.java | 2 +- .../de/steamwar/bausystem/tracer/show/mode/Advanced.java | 9 +++++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 7245237..a9ea8c1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -24,10 +24,6 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; -import de.steamwar.bausystem.tracer.show.mode.Advanced; -import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater; -import de.steamwar.bausystem.tracer.show.mode.Basic; -import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 486a08d..3e8279c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -49,7 +49,7 @@ public class CommandTraceTabCompleter implements TabCompleter { tabComplete.add("auto"); tabComplete.add("show"); if (args[0].equalsIgnoreCase("show") && args.length == 2) { - return manageList(new ArrayList<>(Arrays.asList("nowater", "basic", "default", "advanced", "advanced-nowater")), args, 1); + return manageList(new ArrayList<>(Arrays.asList("nowater", "basic", "advanced", "advanced-nowater")), args, 1); } tabComplete.add("hide"); tabComplete.add("delete"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 9c913e7..02ec875 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -44,15 +44,16 @@ public class Advanced extends Basic { public void show(TNTPosition position) { super.show(position); + if (position.isExploded()) return; if (position.getVelocity() == null) return; - Vector previousLocation = position.getLocation().clone().subtract(position.getVelocity()); + Vector nextLocation = position.getLocation().clone().add(position.getVelocity()); - Vector updatePointY = previousLocation.clone().setY(position.getLocation().getY()); + Vector updatePointY = position.getLocation().clone().setY(nextLocation.getY()); Vector updatePointXZ; if (Math.abs(position.getVelocity().getX()) > Math.abs(position.getVelocity().getZ())) { - updatePointXZ = updatePointY.clone().setX(position.getLocation().getX()); + updatePointXZ = updatePointY.clone().setX(nextLocation.getX()); } else { - updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); + updatePointXZ = updatePointY.clone().setZ(nextLocation.getZ()); } if (!position.getLocation().equals(updatePointY)) { From 0864b1bc920ee53755a7b70198a1f3fd85c7e45b Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 22:26:35 +0100 Subject: [PATCH 26/46] Add Experimental --- .../tracer/show/TraceShowManager.java | 8 +- .../tracer/show/mode/Experimental.java | 80 +++++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index 420125e..15c7ba9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -2,10 +2,7 @@ package de.steamwar.bausystem.tracer.show; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.tracer.TNTPosition; -import de.steamwar.bausystem.tracer.show.mode.Advanced; -import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater; -import de.steamwar.bausystem.tracer.show.mode.Basic; -import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; +import de.steamwar.bausystem.tracer.show.mode.*; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -40,6 +37,9 @@ public class TraceShowManager implements Listener { case "advancednowater": showMode = new AdvancedNoWater(player); break; + case "experimental": + showMode = new Experimental(player); + break; case "basic": case "default": default: diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java new file mode 100644 index 0000000..65ebda8 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java @@ -0,0 +1,80 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.tracer.show.mode; + +import de.steamwar.bausystem.tracer.*; +import de.steamwar.bausystem.tracer.show.ShowMode; +import de.steamwar.core.Core; +import net.minecraft.server.v1_15_R1.EntityTNTPrimed; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +public class Experimental implements ShowMode { + + private final Player player; + + private Map tntEntityMap = new HashMap<>(); + + public Experimental(Player player) { + this.player = player; + } + + @Override + public void show(TNTPosition position) { + RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); + if (tntEntityMap.containsKey(roundedTNTPosition)) { + return; + } + + switch (Core.getVersion()) { + case 12: + tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player)); + break; + default: + tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player)); + break; + } + + position = new TNTPosition(position.getLocation().clone().subtract(position.getVelocity().clone().multiply(0.98D / 20))); + + switch (Core.getVersion()) { + case 12: + tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), position, player)); + break; + default: + tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), position, player)); + break; + } + } + + @Override + public void hide() { + tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { + abstractTraceEntity.hide(player); + abstractTraceEntity.remove(); + }); + tntEntityMap.clear(); + } + +} From 2a796d710f7eda70f562a193235481be23748b4d Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 22:35:35 +0100 Subject: [PATCH 27/46] Add Recorder record first position --- .../src/de/steamwar/bausystem/tracer/record/Recorder.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java index ea0252e..25fb60a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -43,13 +43,8 @@ public class Recorder implements Listener { Recorder() { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 0, 1); record = new Record(); - - // To trace TNT initial positions with AutoTracer - if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { - run(); - } } void stopRecording() { From 8f35724d72df5205cf4e8d6a3b00fd492099c0c7 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 23:01:08 +0100 Subject: [PATCH 28/46] Simplify TNTTracer_12 and TNTTracer_15 Simplify TraceEntity_12 and TraceEntity_15 Simplify UpdateEntity_12 and UpdateEntity_15 Add TNTPosition.previousLocation Fix CommandTrace messages for argument 'auto' Remove Experimental --- .../bausystem/tracer/TNTTracer_12.java | 7 +- .../bausystem/tracer/TraceEntity_12.java | 19 ++--- .../bausystem/tracer/UpdateEntity_12.java | 13 +-- .../bausystem/tracer/TNTTracer_15.java | 7 +- .../bausystem/tracer/TraceEntity_15.java | 13 +-- .../bausystem/tracer/UpdateEntity_15.java | 9 ++- .../bausystem/tracer/TNTPosition.java | 11 ++- .../bausystem/commands/CommandTrace.java | 13 ++- .../bausystem/tracer/show/Record.java | 15 +++- .../tracer/show/TraceShowManager.java | 3 - .../bausystem/tracer/show/mode/Advanced.java | 21 +++-- .../bausystem/tracer/show/mode/Basic.java | 4 +- .../tracer/show/mode/Experimental.java | 80 ------------------- 13 files changed, 77 insertions(+), 138 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 94dc43d..1816f31 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -22,14 +22,15 @@ package de.steamwar.bausystem.tracer; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; public class TNTTracer_12 { - public static AbstractTraceEntity createTNT(World world, TNTPosition tntPosition, Player player) { - return new TraceEntity_12(world, tntPosition, player); + public static AbstractTraceEntity createTNT(World world, Vector tntPosition, Player player, boolean exploded) { + return new TraceEntity_12(world, tntPosition, player, exploded); } - public static AbstractTraceEntity createUpdatePoint(World world, TNTPosition tntPosition, Player player) { + public static AbstractTraceEntity createUpdatePoint(World world, Vector tntPosition, Player player) { return new UpdateEntity_12(world, tntPosition, player); } diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 14c2565..f3189ae 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -24,21 +24,22 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { - private TNTPosition position; - - public TraceEntity_12(World world, TNTPosition position, Player player) { - super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + private Vector position; + + public TraceEntity_12(World world, Vector position, Player player, boolean exploded) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); - if (position.isExploded()) { - this.setCustomName("Exploded"); + if (exploded) { + this.setCustomName("Bum"); } display(player); @@ -52,9 +53,9 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { @Override public AbstractTraceEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); - ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getLocation().getX()); - ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getLocation().getY()); - ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getLocation().getZ()); + ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX()); + ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY()); + ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ()); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java index 2cd3272..76ca075 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java @@ -26,13 +26,14 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; class UpdateEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { - private TNTPosition position; + private Vector position; - public UpdateEntity_12(World world, TNTPosition position, Player player) { - super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.STAINED_GLASS.getBlockData()); + public UpdateEntity_12(World world, Vector position, Player player) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.STAINED_GLASS.getBlockData()); this.position = position; this.setNoGravity(true); @@ -51,9 +52,9 @@ class UpdateEntity_12 extends EntityFallingBlock implements AbstractTraceEntity @Override public AbstractTraceEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); - ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getLocation().getX()); - ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getLocation().getY()); - ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getLocation().getZ()); + ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX()); + ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY()); + ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ()); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 823ea7a..1c541e8 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -22,14 +22,15 @@ package de.steamwar.bausystem.tracer; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; public class TNTTracer_15 { - public static AbstractTraceEntity createTNT(World world, TNTPosition tntPosition, Player player) { - return new TraceEntity_15(world, tntPosition, player); + public static AbstractTraceEntity createTNT(World world, Vector tntPosition, Player player, boolean exploded) { + return new TraceEntity_15(world, tntPosition, player, exploded); } - public static AbstractTraceEntity createUpdatePoint(World world, TNTPosition tntPosition, Player player) { + public static AbstractTraceEntity createUpdatePoint(World world, Vector tntPosition, Player player) { return new UpdateEntity_15(world, tntPosition, player); } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 738f5dd..ec58a28 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -24,22 +24,23 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private TNTPosition position; + private Vector position; - public TraceEntity_15(World world, TNTPosition position, Player player) { - super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + public TraceEntity_15(World world, Vector position, Player player, boolean exploded) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); - if (position.isExploded()) { - this.setCustomName(new ChatComponentText("Exploded")); + if (exploded) { + this.setCustomName(new ChatComponentText("Bum")); } display(player); @@ -52,7 +53,7 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { @Override public AbstractTraceEntity display(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.TNT.getBlockData()), ZERO); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.TNT.getBlockData()), ZERO); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java index 8fa1f70..7cabccd 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java @@ -26,14 +26,15 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; class UpdateEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private TNTPosition position; + private Vector position; - public UpdateEntity_15(World world, TNTPosition position, Player player) { - super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + public UpdateEntity_15(World world, Vector position, Player player) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); @@ -51,7 +52,7 @@ class UpdateEntity_15 extends EntityFallingBlock implements AbstractTraceEntity @Override public AbstractTraceEntity display(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java index 8922696..d877ae5 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java @@ -25,18 +25,17 @@ import org.bukkit.util.Vector; public class TNTPosition { private Vector location; - private Vector velocity; + private Vector previousLocation = null; private boolean exploded; - public TNTPosition(Entity entity, boolean exploded) { + public TNTPosition(Entity entity, Vector previousLocation, boolean exploded) { location = entity.getLocation().toVector(); - velocity = entity.getVelocity(); + this.previousLocation = previousLocation; this.exploded = exploded; } public TNTPosition(Vector vector) { location = vector; - this.velocity = null; this.exploded = false; } @@ -44,8 +43,8 @@ public class TNTPosition { return location; } - public Vector getVelocity() { - return velocity; + public Vector getPreviousLocation() { + return previousLocation; } public boolean isExploded() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index a9ea8c1..44a240c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.tracer.record.RecordStatus; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.world.Welt; @@ -76,7 +77,17 @@ public class CommandTrace implements CommandExecutor { case "toggleauto": case "auto": RecordStateMachine.commandAuto(); - player.sendMessage(BauSystem.PREFIX + "§eTNT-Tracer auf Auto gestellt"); + switch (RecordStateMachine.getRecordStatus()) { + case RECORD_AUTO: + player.sendMessage(BauSystem.PREFIX + "§aAuto-Tracer gestartet"); + break; + case IDLE_AUTO: + player.sendMessage(BauSystem.PREFIX + "§cAuto-Tracer gestoppt"); + break; + case RECORD: + player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer muss gestoppt werden"); + break; + } break; case "clear": case "delete": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java index 8f72dcd..8f97814 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java @@ -57,7 +57,6 @@ public class Record { public static class TNTRecord { private final List positions = new ArrayList<>(41); - private boolean exploded = false; public void showAll(ShowMode mode) { for (TNTPosition position : positions) @@ -66,14 +65,22 @@ public class Record { /* The following methods should only be called by a recorder */ public void add(TNTPrimed tntPrimed) { - TNTPosition position = new TNTPosition(tntPrimed, exploded); + add(tntPrimed, false); + } + + private void add(TNTPrimed tntPrimed, boolean exploded) { + TNTPosition position; + if (positions.isEmpty()) { + position = new TNTPosition(tntPrimed, null, exploded); + } else { + position = new TNTPosition(tntPrimed, positions.get(positions.size() - 1).getLocation(), exploded); + } positions.add(position); TraceShowManager.show(position); } public void explode(TNTPrimed tntPrimed) { - exploded = true; - add(tntPrimed); + add(tntPrimed, true); } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index 15c7ba9..0969fd9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -37,9 +37,6 @@ public class TraceShowManager implements Listener { case "advancednowater": showMode = new AdvancedNoWater(player); break; - case "experimental": - showMode = new Experimental(player); - break; case "basic": case "default": default: diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 02ec875..5a83ae6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -44,16 +44,15 @@ public class Advanced extends Basic { public void show(TNTPosition position) { super.show(position); - if (position.isExploded()) return; - if (position.getVelocity() == null) return; - Vector nextLocation = position.getLocation().clone().add(position.getVelocity()); + if (position.getPreviousLocation() == null) return; + Vector previousLocation = position.getLocation().clone().subtract(position.getPreviousLocation()); - Vector updatePointY = position.getLocation().clone().setY(nextLocation.getY()); + Vector updatePointY = previousLocation.clone().setY(position.getLocation().getY()); Vector updatePointXZ; - if (Math.abs(position.getVelocity().getX()) > Math.abs(position.getVelocity().getZ())) { - updatePointXZ = updatePointY.clone().setX(nextLocation.getX()); + if (Math.abs(position.getPreviousLocation().getX()) > Math.abs(position.getPreviousLocation().getZ())) { + updatePointXZ = updatePointY.clone().setX(position.getLocation().getX()); } else { - updatePointXZ = updatePointY.clone().setZ(nextLocation.getZ()); + updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); } if (!position.getLocation().equals(updatePointY)) { @@ -64,10 +63,10 @@ public class Advanced extends Basic { switch (Core.getVersion()) { case 12: - updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY), player)); + updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY).getLocation(), player)); break; default: - updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY), player)); + updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY).getLocation(), player)); break; } } @@ -79,10 +78,10 @@ public class Advanced extends Basic { switch (Core.getVersion()) { case 12: - updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ), player)); + updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ).getLocation(), player)); break; default: - updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ), player)); + updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ).getLocation(), player)); break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java index e72d2ab..8326b6e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -27,10 +27,10 @@ public class Basic implements ShowMode { switch (Core.getVersion()) { case 12: - tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player)); + tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded())); break; default: - tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player)); + tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded())); break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java deleted file mode 100644 index 65ebda8..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.tracer.show.mode; - -import de.steamwar.bausystem.tracer.*; -import de.steamwar.bausystem.tracer.show.ShowMode; -import de.steamwar.core.Core; -import net.minecraft.server.v1_15_R1.EntityTNTPrimed; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; - -public class Experimental implements ShowMode { - - private final Player player; - - private Map tntEntityMap = new HashMap<>(); - - public Experimental(Player player) { - this.player = player; - } - - @Override - public void show(TNTPosition position) { - RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); - if (tntEntityMap.containsKey(roundedTNTPosition)) { - return; - } - - switch (Core.getVersion()) { - case 12: - tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player)); - break; - default: - tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player)); - break; - } - - position = new TNTPosition(position.getLocation().clone().subtract(position.getVelocity().clone().multiply(0.98D / 20))); - - switch (Core.getVersion()) { - case 12: - tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), position, player)); - break; - default: - tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), position, player)); - break; - } - } - - @Override - public void hide() { - tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { - abstractTraceEntity.hide(player); - abstractTraceEntity.remove(); - }); - tntEntityMap.clear(); - } - -} From d332977a1d8457997afdf1b200c7a3fd4fbe022e Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 23:08:59 +0100 Subject: [PATCH 29/46] Fix Trace auto messages --- .../src/de/steamwar/bausystem/commands/CommandTrace.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 44a240c..336ac2c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -78,15 +78,18 @@ public class CommandTrace implements CommandExecutor { case "auto": RecordStateMachine.commandAuto(); switch (RecordStateMachine.getRecordStatus()) { - case RECORD_AUTO: - player.sendMessage(BauSystem.PREFIX + "§aAuto-Tracer gestartet"); + case IDLE: + player.sendMessage(BauSystem.PREFIX + "§cAuto-Tracer gestoppt"); break; case IDLE_AUTO: - player.sendMessage(BauSystem.PREFIX + "§cAuto-Tracer gestoppt"); + player.sendMessage(BauSystem.PREFIX + "§aAuto-Tracer gestartet"); break; case RECORD: player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer muss gestoppt werden"); break; + case RECORD_AUTO: + player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer muss aus sein"); + break; } break; case "clear": From f8d69deaa34a1d60791ef4747adc3278dcb8c090 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 23:25:09 +0100 Subject: [PATCH 30/46] Update versioned dependant code to new SpigotCore version dependant calls --- .../bausystem/tracer/show/mode/Advanced.java | 23 ++++--------------- .../bausystem/tracer/show/mode/Basic.java | 12 +++------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 5a83ae6..269fcbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -23,6 +23,7 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.*; import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -60,30 +61,16 @@ public class Advanced extends Basic { if (updateEntityMap.containsKey(updatePointPosition)) { return; } - - switch (Core.getVersion()) { - case 12: - updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY).getLocation(), player)); - break; - default: - updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY).getLocation(), player)); - break; - } + updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.createUpdatePoint(player.getWorld(), updatePointY, player), 8), + new VersionedCallable<>(() -> TNTTracer_15.createUpdatePoint(player.getWorld(), updatePointY, player), 14))); } if (!position.getLocation().equals(updatePointXZ)) { RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ); if (updateEntityMap.containsKey(updatePointPosition)) { return; } - - switch (Core.getVersion()) { - case 12: - updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ).getLocation(), player)); - break; - default: - updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ).getLocation(), player)); - break; - } + updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.createUpdatePoint(player.getWorld(), updatePointXZ, player), 8), + new VersionedCallable<>(() -> TNTTracer_15.createUpdatePoint(player.getWorld(), updatePointXZ, player), 14))); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java index 8326b6e..a9a94b2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -3,6 +3,7 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.*; import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import org.bukkit.entity.Player; import java.util.HashMap; @@ -24,15 +25,8 @@ public class Basic implements ShowMode { if (tntEntityMap.containsKey(roundedTNTPosition)) { return; } - - switch (Core.getVersion()) { - case 12: - tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded())); - break; - default: - tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded())); - break; - } + tntEntityMap.put(roundedTNTPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded()), 8), + new VersionedCallable<>(() -> TNTTracer_15.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded()), 14))); } @Override From c54980399a26c151d575fdae3f691cbcd9703106 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Dec 2020 23:11:08 +0100 Subject: [PATCH 31/46] Remove UpdateEntity_12.java Remove UpdateEntity_15.java Simplify TraceEntity_12 Simplify TraceEntity_15 --- .../bausystem/tracer/TNTTracer_12.java | 8 +- .../bausystem/tracer/TraceEntity_12.java | 4 +- .../bausystem/tracer/UpdateEntity_12.java | 85 ------------------- .../bausystem/tracer/TNTTracer_15.java | 8 +- .../bausystem/tracer/TraceEntity_15.java | 4 +- .../bausystem/tracer/UpdateEntity_15.java | 77 ----------------- .../bausystem/tracer/ReflectionUtils.java | 2 +- .../bausystem/tracer/show/mode/Advanced.java | 8 +- .../bausystem/tracer/show/mode/Basic.java | 5 +- 9 files changed, 15 insertions(+), 186 deletions(-) delete mode 100644 BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 1816f31..3dddf5f 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -26,12 +26,8 @@ import org.bukkit.util.Vector; public class TNTTracer_12 { - public static AbstractTraceEntity createTNT(World world, Vector tntPosition, Player player, boolean exploded) { - return new TraceEntity_12(world, tntPosition, player, exploded); - } - - public static AbstractTraceEntity createUpdatePoint(World world, Vector tntPosition, Player player) { - return new UpdateEntity_12(world, tntPosition, player); + public static AbstractTraceEntity create(World world, Vector tntPosition, Player player, boolean exploded, boolean tnt) { + return new TraceEntity_12(world, tntPosition, player, exploded, tnt); } public static boolean inWater(World world, TNTPosition tntPosition) { diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index f3189ae..5c0ca6a 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -30,8 +30,8 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { private Vector position; - public TraceEntity_12(World world, Vector position, Player player, boolean exploded) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); + public TraceEntity_12(World world, Vector position, Player player, boolean exploded, boolean tnt) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.STAINED_GLASS.getBlockData()); this.position = position; this.setNoGravity(true); diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java deleted file mode 100644 index 76ca075..0000000 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.tracer; - -import net.minecraft.server.v1_12_R1.*; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -class UpdateEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { - - private Vector position; - - public UpdateEntity_12(World world, Vector position, Player player) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.STAINED_GLASS.getBlockData()); - this.position = position; - - this.setNoGravity(true); - this.ticksLived = -12000; - this.dropItem = false; - this.setCustomNameVisible(true); - - display(player); - } - - @Override - public void move(EnumMoveType enummovetype, double dx, double dy, double dz) { - - } - - @Override - public AbstractTraceEntity display(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); - ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX()); - ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY()); - ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ()); - ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); - ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); - ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); - - PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); - - return this; - } - - @Override - public AbstractTraceEntity hide(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); - - return this; - } - - @Override - public void remove() { - killEntity(); - } - -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 1c541e8..2b1aa5f 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -26,12 +26,8 @@ import org.bukkit.util.Vector; public class TNTTracer_15 { - public static AbstractTraceEntity createTNT(World world, Vector tntPosition, Player player, boolean exploded) { - return new TraceEntity_15(world, tntPosition, player, exploded); - } - - public static AbstractTraceEntity createUpdatePoint(World world, Vector tntPosition, Player player) { - return new UpdateEntity_15(world, tntPosition, player); + public static AbstractTraceEntity create(World world, Vector tntPosition, Player player, boolean exploded, boolean tnt) { + return new TraceEntity_15(world, tntPosition, player, exploded, tnt); } public static boolean inWater(World world, TNTPosition tntPosition) { diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index ec58a28..d31e076 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -31,8 +31,8 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { private static final Vec3D ZERO = new Vec3D(0, 0, 0); private Vector position; - public TraceEntity_15(World world, Vector position, Player player, boolean exploded) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); + public TraceEntity_15(World world, Vector position, Player player, boolean exploded, boolean tnt) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.WHITE_STAINED_GLASS.getBlockData()); this.position = position; this.setNoGravity(true); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java deleted file mode 100644 index 7cabccd..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.tracer; - -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -class UpdateEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private Vector position; - - public UpdateEntity_15(World world, Vector position, Player player) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); - this.position = position; - - this.setNoGravity(true); - this.ticksLived = -12000; - this.dropItem = false; - this.setCustomNameVisible(true); - - display(player); - } - - @Override - public void move(EnumMoveType enummovetype, Vec3D vec3d) { - - } - - @Override - public AbstractTraceEntity display(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); - - return this; - } - - @Override - public AbstractTraceEntity hide(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); - - return this; - } - - @Override - public void remove() { - killEntity(); - } - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java index 0aac017..a891e8b 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java @@ -30,7 +30,7 @@ public class ReflectionUtils { f.setAccessible(true); f.set(object, value); } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); + throw new SecurityException(e); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 269fcbd..79948db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -61,16 +61,16 @@ public class Advanced extends Basic { if (updateEntityMap.containsKey(updatePointPosition)) { return; } - updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.createUpdatePoint(player.getWorld(), updatePointY, player), 8), - new VersionedCallable<>(() -> TNTTracer_15.createUpdatePoint(player.getWorld(), updatePointY, player), 14))); + updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointY, player, false, false), 8), + new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointY, player, false, false), 14))); } if (!position.getLocation().equals(updatePointXZ)) { RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ); if (updateEntityMap.containsKey(updatePointPosition)) { return; } - updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.createUpdatePoint(player.getWorld(), updatePointXZ, player), 8), - new VersionedCallable<>(() -> TNTTracer_15.createUpdatePoint(player.getWorld(), updatePointXZ, player), 14))); + updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointXZ, player, false, false), 8), + new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointXZ, player, false, false), 14))); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java index a9a94b2..74a43d9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -2,7 +2,6 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.*; import de.steamwar.bausystem.tracer.show.ShowMode; -import de.steamwar.core.Core; import de.steamwar.core.VersionedCallable; import org.bukkit.entity.Player; @@ -25,8 +24,8 @@ public class Basic implements ShowMode { if (tntEntityMap.containsKey(roundedTNTPosition)) { return; } - tntEntityMap.put(roundedTNTPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded()), 8), - new VersionedCallable<>(() -> TNTTracer_15.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded()), 14))); + tntEntityMap.put(roundedTNTPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 8), + new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 14))); } @Override From 83d1570efb76618b2614ece428bb748d9792ed96 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Dec 2020 23:15:02 +0100 Subject: [PATCH 32/46] Fix Update Points --- .../src/de/steamwar/bausystem/tracer/TraceEntity_15.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index d31e076..ca0422a 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -30,10 +30,12 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { private static final Vec3D ZERO = new Vec3D(0, 0, 0); private Vector position; + private boolean tnt; public TraceEntity_15(World world, Vector position, Player player, boolean exploded, boolean tnt) { super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.WHITE_STAINED_GLASS.getBlockData()); this.position = position; + this.tnt = tnt; this.setNoGravity(true); this.ticksLived = -12000; @@ -53,7 +55,7 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { @Override public AbstractTraceEntity display(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.TNT.getBlockData()), ZERO); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, tnt ? Block.getCombinedId(Blocks.TNT.getBlockData()) : Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); From 7da829eae5f062f42d9ae9cc3715c10656afdf29 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Dec 2020 23:37:10 +0100 Subject: [PATCH 33/46] Add Debug info --- .../src/de/steamwar/bausystem/tracer/TraceEntity_15.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index ca0422a..4d4a7f9 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -55,6 +55,9 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { @Override public AbstractTraceEntity display(Player player) { + if (!tnt) { + System.out.println("DISPLAY"); + } PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, tnt ? Block.getCombinedId(Blocks.TNT.getBlockData()) : Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); From e4f874a4bbbe17d2ee78147e374c100b26b7af94 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 00:13:20 +0100 Subject: [PATCH 34/46] Optimize Code Add Version Dependant Call for water check Remove TraceShowManager argument parsing Remove ReflectionUtils.java Remove BauSystem comments Move RoundedTNTPosition Move TNTPosition Fix Advanced Simplify Basic.createEntity --- .../bausystem/tracer/TNTTracer_12.java | 4 +- .../bausystem/tracer/TraceEntity_12.java | 41 +++++++++++-------- .../bausystem/tracer/TNTTracer_15.java | 4 +- .../bausystem/tracer/TraceEntity_15.java | 20 ++------- .../bausystem/tracer/AbstractTraceEntity.java | 2 +- .../bausystem/tracer/ReflectionUtils.java | 37 ----------------- .../src/de/steamwar/bausystem/BauSystem.java | 3 -- .../bausystem/commands/CommandTrace.java | 31 +++++++++++++- .../bausystem/tracer/RoundedTNTPosition.java | 0 .../bausystem/tracer/TNTPosition.java | 0 .../bausystem/tracer/record/Recorder.java | 7 +++- .../tracer/show/TraceShowManager.java | 28 +------------ .../bausystem/tracer/show/mode/Advanced.java | 23 ++++------- .../tracer/show/mode/AdvancedNoWater.java | 17 +++----- .../bausystem/tracer/show/mode/Basic.java | 13 ++++-- .../tracer/show/mode/BasicNoWater.java | 17 +++----- 16 files changed, 97 insertions(+), 150 deletions(-) delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java rename {BauSystem_API => BauSystem_Main}/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java (100%) rename {BauSystem_API => BauSystem_Main}/src/de/steamwar/bausystem/tracer/TNTPosition.java (100%) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 3dddf5f..49730dd 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -30,8 +30,8 @@ public class TNTTracer_12 { return new TraceEntity_12(world, tntPosition, player, exploded, tnt); } - public static boolean inWater(World world, TNTPosition tntPosition) { - Material material = tntPosition.getLocation().toLocation(world).getBlock().getType(); + public static boolean inWater(World world, Vector tntPosition) { + Material material = tntPosition.toLocation(world).getBlock().getType(); return material == Material.WATER || material == Material.STATIONARY_WATER; } diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 5c0ca6a..b1f76c3 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -26,6 +26,8 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import java.lang.reflect.Field; + class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { private Vector position; @@ -39,33 +41,31 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { this.dropItem = false; this.setCustomNameVisible(true); if (exploded) { - this.setCustomName("Bum"); + this.setCustomName("Bumm"); } display(player); } - @Override - public void move(EnumMoveType enummovetype, double dx, double dy, double dz) { - - } - @Override public AbstractTraceEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); - ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX()); - ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY()); - ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ()); - ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); - ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); - ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + // Todo: + // Reflection needed? + setValue("c", packetPlayOutSpawnEntity, position.getX()); + setValue("d", packetPlayOutSpawnEntity, position.getY()); + setValue("e", packetPlayOutSpawnEntity, position.getZ()); + setValue("f", packetPlayOutSpawnEntity, 0); + setValue("g", packetPlayOutSpawnEntity, 0); + setValue("h", packetPlayOutSpawnEntity, 0); + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); + playerConnection.sendPacket(packetPlayOutEntityTeleport); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); + playerConnection.sendPacket(packetPlayOutEntityMetadata); return this; } @@ -78,9 +78,14 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { return this; } - @Override - public void remove() { - killEntity(); + private static void setValue(String field, Object object, Object value) { + try { + Field f = object.getClass().getDeclaredField(field); + f.setAccessible(true); + f.set(object, value); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new SecurityException(e); + } } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 2b1aa5f..4c18ae6 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -30,8 +30,8 @@ public class TNTTracer_15 { return new TraceEntity_15(world, tntPosition, player, exploded, tnt); } - public static boolean inWater(World world, TNTPosition tntPosition) { - Material material = tntPosition.getLocation().toLocation(world).getBlock().getType(); + public static boolean inWater(World world, Vector tntPosition) { + Material material = tntPosition.toLocation(world).getBlock().getType(); return material == Material.WATER; } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 4d4a7f9..1087626 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -42,27 +42,20 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { this.dropItem = false; this.setCustomNameVisible(true); if (exploded) { - this.setCustomName(new ChatComponentText("Bum")); + this.setCustomName(new ChatComponentText("Bumm")); } display(player); } - @Override - public void move(EnumMoveType enummovetype, Vec3D vec3d) { - - } - @Override public AbstractTraceEntity display(Player player) { - if (!tnt) { - System.out.println("DISPLAY"); - } PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, tnt ? Block.getCombinedId(Blocks.TNT.getBlockData()) : Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); + playerConnection.sendPacket(packetPlayOutEntityMetadata); return this; } @@ -75,9 +68,4 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { return this; } - @Override - public void remove() { - killEntity(); - } - } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java index 1ff6886..b2825e5 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java @@ -27,6 +27,6 @@ public interface AbstractTraceEntity { AbstractTraceEntity hide(Player player); - void remove(); + void killEntity(); } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java deleted file mode 100644 index a891e8b..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import java.lang.reflect.Field; - -public class ReflectionUtils { - - @SuppressWarnings({"java:S3011"}) - static void setValue(String field, Object object, Object value) { - try { - Field f = object.getClass().getDeclaredField(field); - f.setAccessible(true); - f.set(object, value); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new SecurityException(e); - } - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 6d7dd7b..50bf488 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -121,7 +121,6 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); new AFKStopper(); - // TNTTracer.init(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); } @@ -166,8 +165,6 @@ public class BauSystem extends JavaPlugin implements Listener { Player p = e.getPlayer(); p.setOp(true); - // ShowManager.add(p); - if (Core.getVersion() == 15) Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 336ac2c..880df14 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -23,8 +23,13 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.record.RecordStatus; +import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; +import de.steamwar.bausystem.tracer.show.mode.Advanced; +import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater; +import de.steamwar.bausystem.tracer.show.mode.Basic; +import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -98,7 +103,31 @@ public class CommandTrace implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); break; case "show": - TraceShowManager.show(player, args); + ShowMode showMode; + if (args.length < 2) { + showMode = new Basic(player); + } else { + switch (args[1].toLowerCase()) { + case "nowater": + case "basic-nowater": + case "basicnowater": + showMode = new BasicNoWater(player); + break; + case "advanced": + showMode = new Advanced(player); + break; + case "advanced-nowater": + case "advancednowater": + showMode = new AdvancedNoWater(player); + break; + case "basic": + case "default": + default: + showMode = new Basic(player); + break; + } + } + TraceShowManager.show(player, showMode); player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); break; case "hide": diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java similarity index 100% rename from BauSystem_API/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTPosition.java similarity index 100% rename from BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTPosition.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java index 25fb60a..f682f6a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -43,8 +43,13 @@ public class Recorder implements Listener { Recorder() { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 0, 1); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1); record = new Record(); + + // To trace TNT initial positions with AutoTracer + if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { + run(); + } } void stopRecording() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index 0969fd9..70e8afd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -17,34 +17,8 @@ public class TraceShowManager implements Listener { private static final Map showModes = new HashMap<>(); - public static void show(Player player, String[] args) { + public static void show(Player player, ShowMode showMode) { hide(player); - - ShowMode showMode; - if (args.length < 2) { - showMode = new Basic(player); - } else { - switch (args[1].toLowerCase()) { - case "nowater": - case "basic-nowater": - case "basicnowater": - showMode = new BasicNoWater(player); - break; - case "advanced": - showMode = new Advanced(player); - break; - case "advanced-nowater": - case "advancednowater": - showMode = new AdvancedNoWater(player); - break; - case "basic": - case "default": - default: - showMode = new Basic(player); - break; - } - } - showModes.put(player, showMode); StoredRecords.showAll(showMode); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 79948db..34fa854 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -21,9 +21,9 @@ package de.steamwar.bausystem.tracer.show.mode; -import de.steamwar.bausystem.tracer.*; -import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; +import de.steamwar.bausystem.tracer.AbstractTraceEntity; +import de.steamwar.bausystem.tracer.RoundedTNTPosition; +import de.steamwar.bausystem.tracer.TNTPosition; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -32,13 +32,10 @@ import java.util.Map; public class Advanced extends Basic { - private final Player player; - private Map updateEntityMap = new HashMap<>(); public Advanced(Player player) { super(player); - this.player = player; } @Override @@ -46,11 +43,11 @@ public class Advanced extends Basic { super.show(position); if (position.getPreviousLocation() == null) return; - Vector previousLocation = position.getLocation().clone().subtract(position.getPreviousLocation()); + Vector vector = position.getLocation().clone().subtract(position.getPreviousLocation()); - Vector updatePointY = previousLocation.clone().setY(position.getLocation().getY()); + Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); Vector updatePointXZ; - if (Math.abs(position.getPreviousLocation().getX()) > Math.abs(position.getPreviousLocation().getZ())) { + if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) { updatePointXZ = updatePointY.clone().setX(position.getLocation().getX()); } else { updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); @@ -61,16 +58,14 @@ public class Advanced extends Basic { if (updateEntityMap.containsKey(updatePointPosition)) { return; } - updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointY, player, false, false), 8), - new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointY, player, false, false), 14))); + updateEntityMap.put(updatePointPosition, createEntity(updatePointY, false, false)); } if (!position.getLocation().equals(updatePointXZ)) { RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ); if (updateEntityMap.containsKey(updatePointPosition)) { return; } - updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointXZ, player, false, false), 8), - new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointXZ, player, false, false), 14))); + updateEntityMap.put(updatePointPosition, createEntity(updatePointXZ, false, false)); } } @@ -80,7 +75,7 @@ public class Advanced extends Basic { updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { abstractTraceEntity.hide(player); - abstractTraceEntity.remove(); + abstractTraceEntity.killEntity(); }); updateEntityMap.clear(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java index 9e1a932..ce45bf0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java @@ -24,7 +24,7 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.TNTPosition; import de.steamwar.bausystem.tracer.TNTTracer_12; import de.steamwar.bausystem.tracer.TNTTracer_15; -import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -39,18 +39,11 @@ public class AdvancedNoWater extends Advanced { @Override public void show(TNTPosition position) { - boolean b; - switch (Core.getVersion()) { - case 12: - b = TNTTracer_12.inWater(world, position); - break; - default: - b = TNTTracer_15.inWater(world, position); - break; - } - if (!b) { - super.show(position); + if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), + new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) { + return; } + super.show(position); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java index 74a43d9..02131db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -4,13 +4,14 @@ import de.steamwar.bausystem.tracer.*; import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.core.VersionedCallable; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import java.util.HashMap; import java.util.Map; public class Basic implements ShowMode { - private final Player player; + protected final Player player; private Map tntEntityMap = new HashMap<>(); @@ -24,15 +25,19 @@ public class Basic implements ShowMode { if (tntEntityMap.containsKey(roundedTNTPosition)) { return; } - tntEntityMap.put(roundedTNTPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 8), - new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 14))); + tntEntityMap.put(roundedTNTPosition, createEntity(position.getLocation(), position.isExploded(), true)); + } + + protected AbstractTraceEntity createEntity(Vector position, boolean exploded, boolean tnt) { + return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, player, exploded, tnt), 8), + new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, player, exploded, tnt), 14)); } @Override public void hide() { tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { abstractTraceEntity.hide(player); - abstractTraceEntity.remove(); + abstractTraceEntity.killEntity(); }); tntEntityMap.clear(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java index 8f9e2f7..0eb94ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java @@ -24,7 +24,7 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.TNTPosition; import de.steamwar.bausystem.tracer.TNTTracer_12; import de.steamwar.bausystem.tracer.TNTTracer_15; -import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -39,18 +39,11 @@ public class BasicNoWater extends Basic { @Override public void show(TNTPosition position) { - boolean b; - switch (Core.getVersion()) { - case 12: - b = TNTTracer_12.inWater(world, position); - break; - default: - b = TNTTracer_15.inWater(world, position); - break; - } - if (!b) { - super.show(position); + if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), + new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) { + return; } + super.show(position); } } From bd06e710f7d5b0b0364cfea8f08f4ca17a50d330 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 13:40:02 +0100 Subject: [PATCH 35/46] Add waterlogged check --- .../de/steamwar/bausystem/tracer/TNTTracer_15.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 4c18ae6..b6f0419 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -21,6 +21,9 @@ package de.steamwar.bausystem.tracer; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Waterlogged; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -31,8 +34,15 @@ public class TNTTracer_15 { } public static boolean inWater(World world, Vector tntPosition) { - Material material = tntPosition.toLocation(world).getBlock().getType(); - return material == Material.WATER; + Block block = tntPosition.toLocation(world).getBlock(); + if(block.getType() == Material.WATER) + return true; + + BlockData data = block.getBlockData(); + if(!(data instanceof Waterlogged)) + return false; + + return ((Waterlogged) data).isWaterlogged(); } } From 6b23f88ea0424ab7f246ee2ff9b975b644b7450b Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 13:47:43 +0100 Subject: [PATCH 36/46] Optimize Packets in TraceEntity_12 and TraceEntity_15 Simplify messages in CommandTrace --- .../bausystem/tracer/TraceEntity_12.java | 8 +++-- .../bausystem/tracer/TraceEntity_15.java | 6 ++-- .../bausystem/commands/CommandTrace.java | 33 +++++-------------- .../bausystem/tracer/record/RecordStatus.java | 22 ++++++++++--- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index b1f76c3..18f3981 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -31,10 +31,12 @@ import java.lang.reflect.Field; class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { private Vector position; + private boolean tnt; public TraceEntity_12(World world, Vector position, Player player, boolean exploded, boolean tnt) { super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.STAINED_GLASS.getBlockData()); this.position = position; + this.tnt = tnt; this.setNoGravity(true); this.ticksLived = -12000; @@ -64,8 +66,10 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); playerConnection.sendPacket(packetPlayOutEntityTeleport); - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - playerConnection.sendPacket(packetPlayOutEntityMetadata); + if (tnt) { + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + playerConnection.sendPacket(packetPlayOutEntityMetadata); + } return this; } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 1087626..0c69184 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -54,8 +54,10 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; playerConnection.sendPacket(packetPlayOutSpawnEntity); - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - playerConnection.sendPacket(packetPlayOutEntityMetadata); + if (tnt) { + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + playerConnection.sendPacket(packetPlayOutEntityMetadata); + } return this; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 880df14..cc59977 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -22,8 +22,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; -import de.steamwar.bausystem.tracer.record.RecordStatus; -import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.tracer.show.mode.Advanced; @@ -73,29 +71,16 @@ public class CommandTrace implements CommandExecutor { switch (args[0].toLowerCase()) { case "start": RecordStateMachine.commandStart(); - player.sendMessage(BauSystem.PREFIX + "§aTNT-Tracer gestartet"); + player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getMessage()); break; case "stop": RecordStateMachine.commandStop(); - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); + player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getMessage()); break; case "toggleauto": case "auto": RecordStateMachine.commandAuto(); - switch (RecordStateMachine.getRecordStatus()) { - case IDLE: - player.sendMessage(BauSystem.PREFIX + "§cAuto-Tracer gestoppt"); - break; - case IDLE_AUTO: - player.sendMessage(BauSystem.PREFIX + "§aAuto-Tracer gestartet"); - break; - case RECORD: - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer muss gestoppt werden"); - break; - case RECORD_AUTO: - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer muss aus sein"); - break; - } + player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getAutoMessage()); break; case "clear": case "delete": @@ -103,31 +88,29 @@ public class CommandTrace implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); break; case "show": - ShowMode showMode; if (args.length < 2) { - showMode = new Basic(player); + TraceShowManager.show(player, new Basic(player)); } else { switch (args[1].toLowerCase()) { case "nowater": case "basic-nowater": case "basicnowater": - showMode = new BasicNoWater(player); + TraceShowManager.show(player, new BasicNoWater(player)); break; case "advanced": - showMode = new Advanced(player); + TraceShowManager.show(player, new Advanced(player)); break; case "advanced-nowater": case "advancednowater": - showMode = new AdvancedNoWater(player); + TraceShowManager.show(player, new AdvancedNoWater(player)); break; case "basic": case "default": default: - showMode = new Basic(player); + TraceShowManager.show(player, new Basic(player)); break; } } - TraceShowManager.show(player, showMode); player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); break; case "hide": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java index 45cbec3..4e21971 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java @@ -21,17 +21,21 @@ package de.steamwar.bausystem.tracer.record; public enum RecordStatus { - RECORD("§aan", true), - RECORD_AUTO("§aan", true), - IDLE("§caus", false), - IDLE_AUTO("§eauto", false); + RECORD("§aan", true, "§aTNT-Tracer gestartet", "§cTNT-Tracer muss gestoppt werden"), + RECORD_AUTO("§aan", true, "§cAuto-Tracer muss aus sein", "§cTNT-Tracer muss aus sein"), + IDLE("§caus", false, "§cTNT-Tracer gestoppt", "§cAuto-Tracer gestoppt"), + IDLE_AUTO("§eauto", false, "§cTNT-Tracer muss gestoppt werden", "§aAuto-Tracer gestartet"); String name; boolean tracing; + String message; + String autoMessage; - RecordStatus(String value, boolean tracing) { + RecordStatus(String value, boolean tracing, String message, String autoMessage) { this.name = value; this.tracing = tracing; + this.message = message; + this.autoMessage = autoMessage; } public String getName() { @@ -42,4 +46,12 @@ public enum RecordStatus { return tracing; } + public String getMessage() { + return message; + } + + public String getAutoMessage() { + return autoMessage; + } + } From df00896c93348b30cbcb1f905e431886649a6871 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 14:19:58 +0100 Subject: [PATCH 37/46] Optimize TraceEntity_12 Optimize TraceEntity_15 Optimize CommandTraceTabCompleter Optimize Recorder --- .../bausystem/tracer/TraceEntity_12.java | 3 +- .../bausystem/tracer/TraceEntity_15.java | 3 +- .../commands/CommandTraceTabCompleter.java | 59 +++++++++++-------- .../bausystem/tracer/record/Recorder.java | 4 +- .../tracer/show/mode/AdvancedNoWater.java | 1 + .../tracer/show/mode/BasicNoWater.java | 1 + 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 18f3981..292d514 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -40,9 +40,8 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { this.setNoGravity(true); this.ticksLived = -12000; - this.dropItem = false; - this.setCustomNameVisible(true); if (exploded) { + this.setCustomNameVisible(true); this.setCustomName("Bumm"); } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 0c69184..e0aab38 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -39,9 +39,8 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { this.setNoGravity(true); this.ticksLived = -12000; - this.dropItem = false; - this.setCustomNameVisible(true); if (exploded) { + this.setCustomNameVisible(true); this.setCustomName(new ChatComponentText("Bumm")); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 3e8279c..16d2970 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -29,9 +29,19 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.function.BiPredicate; public class CommandTraceTabCompleter implements TabCompleter { + private static List tabCompletes = new ArrayList<>(); + + static { + tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO), "start")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() != RecordStatus.IDLE && RecordStateMachine.getRecordStatus() != RecordStatus.IDLE_AUTO), "stop")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 1, "toggleauto", "auto", "show", "hide", "delete", "clear")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "nowater", "basic", "advanced", "advanced-nowater")); + } + @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); @@ -40,36 +50,37 @@ public class CommandTraceTabCompleter implements TabCompleter { private List tracerTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); - if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { - tabComplete.add("start"); - } else { - tabComplete.add("stop"); + for (TabComplete tab : tabCompletes) { + if (tab.test(player, args)) tabComplete.addAll(Arrays.asList(tab.getTabCompletes())); } - tabComplete.add("toggleauto"); - tabComplete.add("auto"); - tabComplete.add("show"); - if (args[0].equalsIgnoreCase("show") && args.length == 2) { - return manageList(new ArrayList<>(Arrays.asList("nowater", "basic", "advanced", "advanced-nowater")), args, 1); - } - tabComplete.add("hide"); - tabComplete.add("delete"); - tabComplete.add("clear"); - //tabComplete.add("gui"); - //tabComplete.add("list"); - - if (args.length >= 2) { - return new ArrayList<>(); - } - return manageList(tabComplete, args, 0); + return manageList(tabComplete, args); } - private List manageList(List strings, String[] args, int index) { + private List manageList(List strings, String[] args) { for (int i = strings.size() - 1; i >= 0; i--) { - if (!strings.get(i).startsWith(args[index])) { - strings.remove(i); - } + if (!strings.get(i).startsWith(args[args.length - 1])) strings.remove(i); } return strings; } + private static class TabComplete { + + private BiPredicate function; + private String[] tabCompletes; + + private TabComplete(BiPredicate function, String... tabCompletes) { + this.function = function; + this.tabCompletes = tabCompletes; + } + + public boolean test(Player player, String[] args) { + return function.test(player, args); + } + + public String[] getTabCompletes() { + return tabCompletes; + } + + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java index f682f6a..f330d81 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -47,9 +47,7 @@ public class Recorder implements Listener { record = new Record(); // To trace TNT initial positions with AutoTracer - if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { - run(); - } + run(); } void stopRecording() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java index ce45bf0..afbde3f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java @@ -37,6 +37,7 @@ public class AdvancedNoWater extends Advanced { super(player); } + @SuppressWarnings({"java:S5411"}) @Override public void show(TNTPosition position) { if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java index 0eb94ce..fc19b8a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java @@ -37,6 +37,7 @@ public class BasicNoWater extends Basic { super(player); } + @SuppressWarnings({"java:S5411"}) @Override public void show(TNTPosition position) { if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), From 6c89fec5a122deb1ef891b0e76d838b9ddd25073 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 15:10:26 +0100 Subject: [PATCH 38/46] Simplify TraceEntity_12 --- .../bausystem/tracer/TraceEntity_12.java | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 292d514..cbf48d4 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -50,21 +50,10 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { @Override public AbstractTraceEntity display(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); - // Todo: - // Reflection needed? - setValue("c", packetPlayOutSpawnEntity, position.getX()); - setValue("d", packetPlayOutSpawnEntity, position.getY()); - setValue("e", packetPlayOutSpawnEntity, position.getZ()); - setValue("f", packetPlayOutSpawnEntity, 0); - setValue("g", packetPlayOutSpawnEntity, 0); - setValue("h", packetPlayOutSpawnEntity, 0); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0, 0); PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; playerConnection.sendPacket(packetPlayOutSpawnEntity); - PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); - playerConnection.sendPacket(packetPlayOutEntityTeleport); - if (tnt) { PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); playerConnection.sendPacket(packetPlayOutEntityMetadata); @@ -81,14 +70,4 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { return this; } - private static void setValue(String field, Object object, Object value) { - try { - Field f = object.getClass().getDeclaredField(field); - f.setAccessible(true); - f.set(object, value); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new SecurityException(e); - } - } - } From 2e097b9b213d36f3c93c12397bd1811ff7b16f75 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 15:11:05 +0100 Subject: [PATCH 39/46] Optimize Imports --- .../src/de/steamwar/bausystem/tracer/TraceEntity_12.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index cbf48d4..2e46bee 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -26,8 +26,6 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.lang.reflect.Field; - class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { private Vector position; From 8e012cb9ca94862a2c57e6d1cf132f40a8ba7e6a Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 15:11:24 +0100 Subject: [PATCH 40/46] Simplify TraceEntity_12 --- .../src/de/steamwar/bausystem/tracer/TraceEntity_12.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 2e46bee..331bac5 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -28,12 +28,10 @@ import org.bukkit.util.Vector; class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { - private Vector position; private boolean tnt; public TraceEntity_12(World world, Vector position, Player player, boolean exploded, boolean tnt) { super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.STAINED_GLASS.getBlockData()); - this.position = position; this.tnt = tnt; this.setNoGravity(true); From a19e0436fb55679e36072a30b93105762eb84587 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 15:34:00 +0100 Subject: [PATCH 41/46] Add ShowMode arguments with ShowModeParameter --- .../bausystem/commands/CommandTrace.java | 19 ++-- .../commands/CommandTraceTabCompleter.java | 4 +- .../bausystem/tracer/show/ShowMode.java | 19 ++++ .../tracer/show/ShowModeParameter.java | 89 +++++++++++++++++++ .../bausystem/tracer/show/mode/Advanced.java | 19 ++-- .../tracer/show/mode/AdvancedNoWater.java | 50 ----------- .../bausystem/tracer/show/mode/Basic.java | 13 ++- .../tracer/show/mode/BasicNoWater.java | 50 ----------- 8 files changed, 137 insertions(+), 126 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index cc59977..f4730f8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -22,12 +22,11 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.tracer.show.ShowModeParameter; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.tracer.show.mode.Advanced; -import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater; import de.steamwar.bausystem.tracer.show.mode.Basic; -import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -89,25 +88,17 @@ public class CommandTrace implements CommandExecutor { break; case "show": if (args.length < 2) { - TraceShowManager.show(player, new Basic(player)); + TraceShowManager.show(player, new Basic(player, new ShowModeParameter())); } else { + ShowModeParameter showModeParameter = ShowModeParameter.parseArguments(args, 2); switch (args[1].toLowerCase()) { - case "nowater": - case "basic-nowater": - case "basicnowater": - TraceShowManager.show(player, new BasicNoWater(player)); - break; case "advanced": - TraceShowManager.show(player, new Advanced(player)); - break; - case "advanced-nowater": - case "advancednowater": - TraceShowManager.show(player, new AdvancedNoWater(player)); + TraceShowManager.show(player, new Advanced(player, showModeParameter)); break; case "basic": case "default": default: - TraceShowManager.show(player, new Basic(player)); + TraceShowManager.show(player, new Basic(player, showModeParameter)); break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 16d2970..5efe116 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -39,7 +39,9 @@ public class CommandTraceTabCompleter implements TabCompleter { tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO), "start")); tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() != RecordStatus.IDLE && RecordStateMachine.getRecordStatus() != RecordStatus.IDLE_AUTO), "stop")); tabCompletes.add(new TabComplete((player, args) -> args.length == 1, "toggleauto", "auto", "show", "hide", "delete", "clear")); - tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "nowater", "basic", "advanced", "advanced-nowater")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "basic", "advanced")); + tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && (args[1].equalsIgnoreCase("basic") || args[1].equalsIgnoreCase("advanced")), "-water")); + tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && args[1].equalsIgnoreCase("advanced"), "-interpolate-xz", "-interpolate-y")); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java index c3ad9da..5a96232 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.tracer.show; import de.steamwar.bausystem.tracer.TNTPosition; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java new file mode 100644 index 0000000..e3ee044 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java @@ -0,0 +1,89 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.tracer.show; + +public class ShowModeParameter { + + private boolean water = false; + private boolean interpolate_SET = false; + private boolean interpolate_Y = true; + private boolean interpolate_XZ = true; + + public ShowModeParameter() { + + } + + public boolean isWater() { + return water; + } + + public boolean isInterpolate_Y() { + return interpolate_Y; + } + + public boolean isInterpolate_XZ() { + return interpolate_XZ; + } + + public static ShowModeParameter parseArguments(String[] args, int index) { + ShowModeParameter showModeParameter = new ShowModeParameter(); + for (int i = index; i < args.length; i++) { + switch (args[i].toLowerCase()) { + case "-water": + showModeParameter.water = true; + break; + case "-interpolatey": + case "-interpolate-y": + case "-interpolate_y": + case "-y": + if (showModeParameter.interpolate_SET) { + showModeParameter.interpolate_Y = true; + } else { + showModeParameter.interpolate_XZ = false; + showModeParameter.interpolate_SET = true; + } + break; + case "-interpolatex": + case "-interpolate-x": + case "-interpolate_x": + case "-x": + case "-interpolatez": + case "-interpolate-z": + case "-interpolate_z": + case "-z": + case "-interpolatexz": + case "-interpolate-xz": + case "-interpolate_xz": + case "-xz": + if (showModeParameter.interpolate_SET) { + showModeParameter.interpolate_XZ = true; + } else { + showModeParameter.interpolate_Y = false; + showModeParameter.interpolate_SET = true; + } + break; + } + } + return showModeParameter; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 34fa854..c9bf35a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -24,6 +24,7 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.AbstractTraceEntity; import de.steamwar.bausystem.tracer.RoundedTNTPosition; import de.steamwar.bausystem.tracer.TNTPosition; +import de.steamwar.bausystem.tracer.show.ShowModeParameter; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -34,8 +35,8 @@ public class Advanced extends Basic { private Map updateEntityMap = new HashMap<>(); - public Advanced(Player player) { - super(player); + public Advanced(Player player, ShowModeParameter showModeParameter) { + super(player, showModeParameter); } @Override @@ -53,19 +54,17 @@ public class Advanced extends Basic { updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); } - if (!position.getLocation().equals(updatePointY)) { + if (showModeParameter.isInterpolate_Y() && !position.getLocation().equals(updatePointY)) { RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointY); - if (updateEntityMap.containsKey(updatePointPosition)) { - return; + if (!updateEntityMap.containsKey(updatePointPosition)) { + updateEntityMap.put(updatePointPosition, createEntity(updatePointY, false, false)); } - updateEntityMap.put(updatePointPosition, createEntity(updatePointY, false, false)); } - if (!position.getLocation().equals(updatePointXZ)) { + if (showModeParameter.isInterpolate_XZ() && !position.getLocation().equals(updatePointXZ)) { RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ); - if (updateEntityMap.containsKey(updatePointPosition)) { - return; + if (!updateEntityMap.containsKey(updatePointPosition)) { + updateEntityMap.put(updatePointPosition, createEntity(updatePointXZ, false, false)); } - updateEntityMap.put(updatePointPosition, createEntity(updatePointXZ, false, false)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java deleted file mode 100644 index afbde3f..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.tracer.show.mode; - -import de.steamwar.bausystem.tracer.TNTPosition; -import de.steamwar.bausystem.tracer.TNTTracer_12; -import de.steamwar.bausystem.tracer.TNTTracer_15; -import de.steamwar.core.VersionedCallable; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; - -public class AdvancedNoWater extends Advanced { - - private static final World world = Bukkit.getWorlds().get(0); - - public AdvancedNoWater(Player player) { - super(player); - } - - @SuppressWarnings({"java:S5411"}) - @Override - public void show(TNTPosition position) { - if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), - new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) { - return; - } - super.show(position); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java index 02131db..6ff527f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.*; import de.steamwar.bausystem.tracer.show.ShowMode; +import de.steamwar.bausystem.tracer.show.ShowModeParameter; import de.steamwar.core.VersionedCallable; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -12,15 +13,20 @@ import java.util.Map; public class Basic implements ShowMode { protected final Player player; + protected final ShowModeParameter showModeParameter; private Map tntEntityMap = new HashMap<>(); - public Basic(Player player) { + public Basic(Player player, ShowModeParameter showModeParameter) { this.player = player; + this.showModeParameter = showModeParameter; } @Override public void show(TNTPosition position) { + if (showModeParameter.isWater() && checkWater(position.getLocation())) { + return; + } RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); if (tntEntityMap.containsKey(roundedTNTPosition)) { return; @@ -28,6 +34,11 @@ public class Basic implements ShowMode { tntEntityMap.put(roundedTNTPosition, createEntity(position.getLocation(), position.isExploded(), true)); } + protected boolean checkWater(Vector position) { + return (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(player.getWorld(), position), 8), + new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 14))); + } + protected AbstractTraceEntity createEntity(Vector position, boolean exploded, boolean tnt) { return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, player, exploded, tnt), 8), new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, player, exploded, tnt), 14)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java deleted file mode 100644 index fc19b8a..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.tracer.show.mode; - -import de.steamwar.bausystem.tracer.TNTPosition; -import de.steamwar.bausystem.tracer.TNTTracer_12; -import de.steamwar.bausystem.tracer.TNTTracer_15; -import de.steamwar.core.VersionedCallable; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; - -public class BasicNoWater extends Basic { - - private static final World world = Bukkit.getWorlds().get(0); - - public BasicNoWater(Player player) { - super(player); - } - - @SuppressWarnings({"java:S5411"}) - @Override - public void show(TNTPosition position) { - if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), - new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) { - return; - } - super.show(position); - } - -} From c3f9a6182613b59304940b3803f650ad4f789c0f Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 21:56:09 +0100 Subject: [PATCH 42/46] Simplify TNTTracer_12 Simplify TNTTracer_15 --- .../src/de/steamwar/bausystem/tracer/TNTTracer_12.java | 3 ++- .../src/de/steamwar/bausystem/tracer/TNTTracer_15.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 49730dd..89b8080 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.tracer; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -31,7 +32,7 @@ public class TNTTracer_12 { } public static boolean inWater(World world, Vector tntPosition) { - Material material = tntPosition.toLocation(world).getBlock().getType(); + Material material = world.getBlockAt(tntPosition.getBlockX(), tntPosition.getBlockY(), tntPosition.getBlockZ()).getType(); return material == Material.WATER || material == Material.STATIONARY_WATER; } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index b6f0419..bd0b25e 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -34,7 +34,7 @@ public class TNTTracer_15 { } public static boolean inWater(World world, Vector tntPosition) { - Block block = tntPosition.toLocation(world).getBlock(); + Block block = world.getBlockAt(tntPosition.getBlockX(), tntPosition.getBlockY(), tntPosition.getBlockZ()); if(block.getType() == Material.WATER) return true; From 30a0cea0f47b03d182fbb5b770f719314bb7c253 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 22:01:31 +0100 Subject: [PATCH 43/46] Use RecordStatus only in '/trace auto' only --- .../bausystem/commands/CommandTrace.java | 4 ++-- .../bausystem/tracer/record/RecordStatus.java | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index f4730f8..638b76a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -70,11 +70,11 @@ public class CommandTrace implements CommandExecutor { switch (args[0].toLowerCase()) { case "start": RecordStateMachine.commandStart(); - player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getMessage()); + player.sendMessage(BauSystem.PREFIX + "§aTNT-Tracer gestartet"); break; case "stop": RecordStateMachine.commandStop(); - player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getMessage()); + player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); break; case "toggleauto": case "auto": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java index 4e21971..49bab4d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java @@ -21,20 +21,18 @@ package de.steamwar.bausystem.tracer.record; public enum RecordStatus { - RECORD("§aan", true, "§aTNT-Tracer gestartet", "§cTNT-Tracer muss gestoppt werden"), - RECORD_AUTO("§aan", true, "§cAuto-Tracer muss aus sein", "§cTNT-Tracer muss aus sein"), - IDLE("§caus", false, "§cTNT-Tracer gestoppt", "§cAuto-Tracer gestoppt"), - IDLE_AUTO("§eauto", false, "§cTNT-Tracer muss gestoppt werden", "§aAuto-Tracer gestartet"); + RECORD("§aan", true,"§cTNT-Tracer muss gestoppt werden"), + RECORD_AUTO("§aan", true, "§cTNT-Tracer muss aus sein"), + IDLE("§caus", false, "§cAuto-Tracer gestoppt"), + IDLE_AUTO("§eauto", false, "§aAuto-Tracer gestartet"); String name; boolean tracing; - String message; String autoMessage; - RecordStatus(String value, boolean tracing, String message, String autoMessage) { + RecordStatus(String value, boolean tracing, String autoMessage) { this.name = value; this.tracing = tracing; - this.message = message; this.autoMessage = autoMessage; } @@ -46,10 +44,6 @@ public enum RecordStatus { return tracing; } - public String getMessage() { - return message; - } - public String getAutoMessage() { return autoMessage; } From b8672a9134a473ee140aace84d9094b62e827629 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 22:02:18 +0100 Subject: [PATCH 44/46] Use RecordStatus only in '/trace auto' only --- .../src/de/steamwar/bausystem/tracer/record/RecordStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java index 49bab4d..e9f69e7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.tracer.record; public enum RecordStatus { RECORD("§aan", true,"§cTNT-Tracer muss gestoppt werden"), - RECORD_AUTO("§aan", true, "§cTNT-Tracer muss aus sein"), + RECORD_AUTO("§aan", true, "§cTNT-Tracer darf nicht aufnehmen"), IDLE("§caus", false, "§cAuto-Tracer gestoppt"), IDLE_AUTO("§eauto", false, "§aAuto-Tracer gestartet"); From c32702fce9d9298d2306038508dabefbbe0fe859 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 22:08:10 +0100 Subject: [PATCH 45/46] Add '/trace show' options to help --- .../src/de/steamwar/bausystem/commands/CommandTrace.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 638b76a..7a034e9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -39,7 +39,7 @@ public class CommandTrace implements CommandExecutor { player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen"); player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer"); player.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart"); - player.sendMessage("§8/§etrace show §8<§enowater§8|§eadvanced§8|§eadvanced-nowater§8> §8- §7Zeigt alle TNT-Positionen"); + player.sendMessage("§8/§etrace show §8<§edefault§8|§eadvanced§8> §8<§ewater§8|§einterpolate-xz§8|§einterpolate-y§8> §8- §7Zeigt alle TNT-Positionen"); player.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen"); player.sendMessage("§8/§etrace delete §8- §7Löscht alle TNT-Positionen"); // player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf"); From 8d8d9bc1fb6948a233a743d59af07819e2847ed3 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 22:08:34 +0100 Subject: [PATCH 46/46] Fix CommandTrace --- .../src/de/steamwar/bausystem/commands/CommandTrace.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 7a034e9..a4594cd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -39,7 +39,7 @@ public class CommandTrace implements CommandExecutor { player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen"); player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer"); player.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart"); - player.sendMessage("§8/§etrace show §8<§edefault§8|§eadvanced§8> §8<§ewater§8|§einterpolate-xz§8|§einterpolate-y§8> §8- §7Zeigt alle TNT-Positionen"); + player.sendMessage("§8/§etrace show §8<§edefault§8|§eadvanced§8> §8<§e-water§8|§e-interpolate-xz§8|§e-interpolate-y§8> §8- §7Zeigt alle TNT-Positionen"); player.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen"); player.sendMessage("§8/§etrace delete §8- §7Löscht alle TNT-Positionen"); // player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf");