From 27a542590c6141a0479a2d2f343eefb154d40aa7 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Mon, 6 Nov 2023 00:11:03 +0100 Subject: [PATCH] Started Trace Refactoring Laid out basic class structure --- .../src/de/steamwar/bausystem/BauSystem.java | 6 ++ .../bausystem/features/tracer2/Recorder.java | 84 +++++++++++++++++++ .../bausystem/features/tracer2/TNTRecord.java | 23 +++++ .../bausystem/features/tracer2/Trace.java | 35 ++++++++ .../features/tracer2/TraceCommand.java | 23 +++++ .../features/tracer2/TraceManager.java | 56 +++++++++++++ 6 files changed, 227 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TNTRecord.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 88a46ddc..5bf3fb98 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils; +import de.steamwar.bausystem.features.tracer2.TraceManager; import de.steamwar.bausystem.features.world.RamUsage; import de.steamwar.bausystem.linkage.LinkageUtils; import de.steamwar.bausystem.region.loader.PrototypeLoader; @@ -50,6 +51,11 @@ public class BauSystem extends JavaPlugin implements Listener { // This should be treated as final! public static Message MESSAGE; + /* + * Plugin wide availeble data + */ + public static final TraceManager TRACES = new TraceManager(); + @Getter private static BauSystem instance; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java new file mode 100644 index 00000000..fa00cab0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java @@ -0,0 +1,84 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer2; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.TNTPrimeEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntitySpawnEvent; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Linked +public class Recorder { + private final Map activeTraces = new HashMap<>(); + private final Map> trackedTNT = new HashMap<>(); + + /** Starts a recording at the given region + * + * @param region region to be recorded + */ + public void startRecording(Region region){ + Trace trace = new Trace(region); + activeTraces.put(region, trace); + BauSystem.TRACES.add(trace); + } + + /** Stops the recording at the given region + * + * @param region region to stop recording + */ + public void stopRecording(Region region){ + activeTraces.remove(region); + } + + /** Internal methode to record all tracked TNT Entities + * + */ + private void record(){ + + } + + /** Eventhandler for TNTs beeing spawn. + * Registers newly spawn to be traced if reqired + * @param event + */ + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onTNTPrimed(EntitySpawnEvent event){ + + } + + /** Event for TNTs exploding + * Unregisters TNTs from beeing traced on explode + * @param event + */ + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onTNTExplode(EntityExplodeEvent event){ + + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TNTRecord.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TNTRecord.java new file mode 100644 index 00000000..01b8642a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TNTRecord.java @@ -0,0 +1,23 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer2; + +public class TNTRecord { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java new file mode 100644 index 00000000..fc32864c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java @@ -0,0 +1,35 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer2; + +import de.steamwar.bausystem.region.Region; + +import java.util.HashSet; +import java.util.Set; + +public class Trace { + private final Region region; + private final Set records = new HashSet<>(); + + public Trace (Region region){ + this.region = region; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceCommand.java new file mode 100644 index 00000000..1fdfaf2f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceCommand.java @@ -0,0 +1,23 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer2; + +public class TraceCommand { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java new file mode 100644 index 00000000..bcce47be --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java @@ -0,0 +1,56 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer2; + +import java.util.HashMap; +import java.util.Map; + +public class TraceManager { + private final Map traces = new HashMap<>(); + private int currOpenId = 0; + + /** Adds a new trace to the global record + * + * @param trace Trace to be added + * @return id of the newly added trace + */ + public int add(Trace trace){ + int id = currOpenId; + traces.put(id, trace); + currOpenId++; + return id; + } + + /** Removes the trace with the given id + * + * @param id Id of the trace to be removed + */ + public void remove(int id){ + traces.remove(id); + } + + /** Clears all traces + * + */ + public void clear(){ + traces.clear(); + currOpenId = 1; + } +}