Tracer-entity #147
@ -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 +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}*/
|
||||
}
|
||||
|
@ -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<String> tracerTabComplete(Player player, String[] args) {
|
||||
List<String> 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");
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
package de.steamwar.bausystem.tracer.record;
|
||||
|
||||
public enum RecordStatus {
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<TNTPosition> 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 +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
86
BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java
Normale Datei
86
BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<TNTPrimed, Record.TNTRecord> 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;
|
||||
}
|
||||
}
|
@ -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<TNTPrimed, RecordTrace> 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);
|
||||
}
|
||||
private void run(){
|
||||
lastExplosion++;
|
||||
|
||||
static void add(TNTPrimed tntPrimed) {
|
||||
get(tntPrimed).add(tntPrimed);
|
||||
if (lastExplosion > 80) {
|
||||
RecordStateMachine.autoIdle();
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
return recordTraceMap.get(tntPrimed);
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return recordTraceMap.size();
|
||||
}
|
||||
|
||||
}
|
79
BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java
Normale Datei
79
BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<TNTRecord> 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<TNTPosition> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package de.steamwar.bausystem.tracer.show;
|
||||
|
||||
import de.steamwar.bausystem.tracer.record.RecordTrace;
|
||||
|
||||
public class ShowTrace {
|
||||
|
||||
public ShowTrace(RecordTrace recordTrace) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -17,13 +17,24 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.record;
|
||||
package de.steamwar.bausystem.tracer.show;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DataHolder {
|
||||
|
||||
public static List<RecordTrace> finished = new ArrayList<>();
|
||||
public class StoredRecords {
|
||||
private static final List<Record> records = 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();
|
||||
}
|
||||
}
|
@ -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<Player, ShowMode> 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());
|
||||
}
|
||||
}
|
@ -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() {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren