From 599c6049be2a4c515a06e220661fc6d358b5f654 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 16 Dec 2020 16:27:08 +0100 Subject: [PATCH] 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;