Commits vergleichen
7 Commits
5de070c90e
...
f94aeeda01
Autor | SHA1 | Datum | |
---|---|---|---|
|
f94aeeda01 | ||
b58e418ea4 | |||
|
979428d493 | ||
|
84150aadd2 | ||
|
32fb859764 | ||
|
b886745113 | ||
|
27a542590c |
@ -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;
|
||||
|
||||
|
141
BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java
Normale Datei
141
BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java
Normale Datei
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
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.Listener;
|
||||
import org.bukkit.event.block.TNTPrimeEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Linked
|
||||
public class Recorder implements Listener {
|
||||
/**
|
||||
* Map for all traces beeing activly recorded
|
||||
*/
|
||||
private final Map<Region, Trace> activeTraces = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Map for all tnts being traced, by region
|
||||
*/
|
||||
private final Map<Region, List<TNTPrimed>> trackedTNT = new HashMap<>();
|
||||
|
||||
/** Map from TNT to Region the TNT spawned in
|
||||
*
|
||||
*/
|
||||
private final Map<TNTPrimed, Region> tntSpawnRegion = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Maps a tracked tnt entity to the last record taken of it
|
||||
*/
|
||||
private final Map<TNTPrimed, TNTRecord> lastRecordMap = new HashMap<>();
|
||||
|
||||
public Recorder(){
|
||||
BauSystem.runTaskTimer(BauSystem.getInstance(), () ->{
|
||||
record();
|
||||
}, 0, 1);
|
||||
}
|
||||
|
||||
/** 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);
|
||||
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) lastRecordMap.remove(tnt);
|
||||
trackedTNT.put(region, new ArrayList<>());
|
||||
}
|
||||
|
||||
/** Internal methode to record all tracked TNT Entities
|
||||
*
|
||||
*/
|
||||
private void record(){
|
||||
for(Region region : activeTraces.keySet()){
|
||||
Trace trace = activeTraces.get(region);
|
||||
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
|
||||
record(tnt, trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Internal methode to record exploded tnt
|
||||
*
|
||||
* @param tntPrimed tnt exploding
|
||||
* @param trace trace to record the tnt for
|
||||
*/
|
||||
private void record(TNTPrimed tntPrimed, Trace trace){
|
||||
TNTRecord lastRecord = lastRecordMap.getOrDefault(tntPrimed, null);
|
||||
|
||||
TNTRecord record = new TNTRecord(tntPrimed, tntPrimed.getFuseTicks() == 0, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecord);
|
||||
if(lastRecord != null) lastRecord.setNext(record);
|
||||
lastRecordMap.put(tntPrimed, record);
|
||||
trace.add(record);
|
||||
}
|
||||
|
||||
/** Event for TNTs beeing spawn.
|
||||
* Registers newly spawned TNT to be traced if reqired
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onTNTSpawn(EntitySpawnEvent event){
|
||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
Region region = Region.getRegion(event.getLocation());
|
||||
if(activeTraces.containsKey(region)){
|
||||
//Check whether set for tracking already exists. Creating it if necessary
|
||||
if(!trackedTNT.containsKey(region)) trackedTNT.put(region, new ArrayList<>());
|
||||
|
||||
trackedTNT.get(region).add((TNTPrimed) event.getEntity());
|
||||
tntSpawnRegion.put((TNTPrimed) event.getEntity(), region);
|
||||
}
|
||||
}
|
||||
|
||||
/** Event for TNTs exploding
|
||||
* Unregisters TNTs from beeing traced on explode
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onTNTExplode(EntityExplodeEvent event){
|
||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
Region region = tntSpawnRegion.getOrDefault((TNTPrimed) event.getEntity(), null);
|
||||
if(region == null) return;
|
||||
trackedTNT.get(region).remove((TNTPrimed) event.getEntity());
|
||||
tntSpawnRegion.remove((TNTPrimed) event.getEntity());
|
||||
|
||||
record((TNTPrimed) event.getEntity(), activeTraces.get(region));
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@Getter
|
||||
public class TNTRecord {
|
||||
/**
|
||||
* Whether this is a record of a tnt explosion or an entity
|
||||
*/
|
||||
private final boolean explosion;
|
||||
|
||||
/**
|
||||
* Tick offset, from this record being taken to the start of the trace
|
||||
*/
|
||||
private final long ticksSinceStart;
|
||||
|
||||
/**
|
||||
* Fuse ticks of the recorded tnt (0 if this is an explosion)
|
||||
*/
|
||||
private final int fuse;
|
||||
|
||||
/**
|
||||
* Location of the recorded tnt
|
||||
*/
|
||||
private final Location location;
|
||||
|
||||
/**
|
||||
* Velocity of the recorded tnt
|
||||
*/
|
||||
private final Vector velocity;
|
||||
|
||||
/**
|
||||
* Reference to the last record having been taken of the tnt represented by this record
|
||||
*/
|
||||
private final TNTRecord previous;
|
||||
|
||||
/**
|
||||
* Reference to the next record of the tnt represented by this record
|
||||
*/
|
||||
private TNTRecord next;
|
||||
|
||||
public TNTRecord(TNTPrimed tnt, boolean explosion, long ticksSinceStart, TNTRecord previous){
|
||||
this.explosion = explosion;
|
||||
this.ticksSinceStart = ticksSinceStart;
|
||||
fuse = tnt.getFuseTicks();
|
||||
location = tnt.getLocation();
|
||||
velocity = tnt.getVelocity();
|
||||
this.previous = previous;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* One call only function to set next
|
||||
* @param next
|
||||
*/
|
||||
protected void setNext(TNTRecord next){
|
||||
if(this.next == null) this.next = next;
|
||||
}
|
||||
}
|
60
BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java
Normale Datei
60
BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java
Normale Datei
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Trace {
|
||||
/**
|
||||
* Region this trace has been recorded in
|
||||
*/
|
||||
@Getter
|
||||
private final Region region;
|
||||
|
||||
/**
|
||||
* Tick the recording started at
|
||||
*/
|
||||
@Getter
|
||||
private final long startTime = TPSUtils.currentTick.get();
|
||||
|
||||
/**
|
||||
* Records of TNTs, making up the trace
|
||||
*/
|
||||
private final List<TNTRecord> records = new ArrayList<>();
|
||||
|
||||
public Trace (Region region){
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
/** Methode to add a record to the trace
|
||||
*
|
||||
* @param record record to add
|
||||
*/
|
||||
protected void add (TNTRecord record){
|
||||
records.add(record);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class TraceCommand extends SWCommand {
|
||||
|
||||
@LinkedInstance
|
||||
public Recorder recorder;
|
||||
public TraceCommand(){super("tracetest");}
|
||||
|
||||
@Register
|
||||
public void test(@Validator Player player){
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
public class TraceManager implements Listener {
|
||||
/**
|
||||
* Map of all current traces
|
||||
*/
|
||||
private final Map<Integer, Trace> traces = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Utility variable to keep track of the next open trace id
|
||||
*/
|
||||
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
|
||||
*/
|
||||
protected 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;
|
||||
}
|
||||
|
||||
/** Methode to get all traces in a certain region
|
||||
*
|
||||
* @param region Region to look for traces in
|
||||
* @return All traces recorded in the given Region
|
||||
*/
|
||||
public Set<Trace> get(Region region){
|
||||
return traces.values()
|
||||
.stream()
|
||||
.filter((Trace trace) -> trace.getRegion() == region)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/** Methode to get the trace with specific id
|
||||
*
|
||||
* @param id id of the trace
|
||||
* @return the trace with given id or null if no trace with id is found
|
||||
*/
|
||||
public Trace get(int id){
|
||||
return traces.getOrDefault(id, null);
|
||||
}
|
||||
|
||||
/** Methode to get all traces
|
||||
*
|
||||
* @return fresh set of all current traces
|
||||
*/
|
||||
public Set<Trace> getAll(){
|
||||
return new HashSet<>(traces.values());
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren