SteamWar/BauSystem
Archiviert
13
0

Tracer-entity #147

Manuell gemergt
YoyoNow hat 47 Commits von Tracer-entity nach master 2020-12-27 22:16:04 +01:00 zusammengeführt
16 geänderte Dateien mit 384 neuen und 390 gelöschten Zeilen
Nur Änderungen aus Commit ba7888eb56 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -6,26 +6,19 @@ import org.bukkit.util.Vector;
public class TNTPosition { public class TNTPosition {
private Vector location; private Vector location;
private Vector vector;
public TNTPosition(Entity entity) { public TNTPosition(Entity entity) {
location = entity.getLocation().toVector(); location = entity.getLocation().toVector();
vector = entity.getVelocity();
} }
public Vector getLocation() { public Vector getLocation() {
return location; return location;
} }
public Vector getVector() {
return vector;
}
@Override @Override
public String toString() { public String toString() {
return "Position{" + return "Position{" +
"location=" + location + "location=" + location +
", vector=" + vector +
'}'; '}';
} }

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.bausystem; package de.steamwar.bausystem;
import de.steamwar.bausystem.commands.*; import de.steamwar.bausystem.commands.*;
import de.steamwar.bausystem.tracer.record.ExplodeListener;
import de.steamwar.bausystem.world.*; import de.steamwar.bausystem.world.*;
import de.steamwar.core.CommandRemover; import de.steamwar.core.CommandRemover;
import de.steamwar.core.Core; 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 RegionListener(), this);
Bukkit.getPluginManager().registerEvents(new ScriptListener(), this); Bukkit.getPluginManager().registerEvents(new ScriptListener(), this);
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), 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); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
new AFKStopper(); new AFKStopper();
// TNTTracer.init(); // TNTTracer.init();

Datei anzeigen

@ -21,7 +21,8 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; 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 de.steamwar.bausystem.world.Welt;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -67,185 +68,34 @@ public class CommandTrace implements CommandExecutor {
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "start": case "start":
RecordManager.commandStart(); RecordStateMachine.commandStart();
break; break;
case "stop": case "stop":
RecordManager.commandStop(); RecordStateMachine.commandStop();
break; break;
case "toggleauto": case "toggleauto":
case "auto": case "auto":
RecordManager.commandAuto(); RecordStateMachine.commandAuto();
break;
case "clear":
case "delete":
StoredRecords.clear();
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
break; break;
case "show": case "show":
Veraltet
Review

Idee: Zugehörige Message als Parameter eines RecordStatus. Dann musst du hier nicht switch-casen.

Idee: Zugehörige Message als Parameter eines RecordStatus. Dann musst du hier nicht switch-casen.
// TraceManager.commandShow(player);
break; break;
case "hide": case "hide":
// TraceManager.commandHide(player);
break; break;
case "toggleshow": case "toggleshow":
case "interpolate": case "interpolate":
case "distance": case "distance":
/*if (tracer(player, args)) {
help(player);
}*/
break; break;
case "list": case "list":
case "gui": case "gui":
// player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau");
break;
case "delete":
if (delete(player, args)) {
help(player);
}
break; break;
default: default:
help(player); help(player);
} }
return false; 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;
}*/
} }

Datei anzeigen

@ -19,8 +19,8 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.tracer.record.RecordManager; import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.tracer.RecordStatus; import de.steamwar.bausystem.tracer.record.RecordStatus;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
@ -40,7 +40,7 @@ public class CommandTraceTabCompleter implements TabCompleter {
private List<String> tracerTabComplete(Player player, String[] args) { private List<String> tracerTabComplete(Player player, String[] args) {
List<String> tabComplete = new ArrayList<>(); 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"); tabComplete.add("start");
} else { } else {
tabComplete.add("stop"); tabComplete.add("stop");

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. 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 { public enum RecordStatus {

Datei anzeigen

@ -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 +
'}';
}
}

Datei anzeigen

@ -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(){
Veraltet
Review

Würde ich unabhängig vom derzeitgen RecordStatus machen. Wenn du einen Recorder erzeugst, möchtest du ja aufnehmen.

Würde ich unabhängig vom derzeitgen RecordStatus machen. Wenn du einen Recorder erzeugst, möchtest du ja aufnehmen.
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;
}
}

Datei anzeigen

@ -19,50 +19,52 @@
package de.steamwar.bausystem.tracer.record; package de.steamwar.bausystem.tracer.record;
import de.steamwar.bausystem.BauSystem;
import org.bukkit.Bukkit;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.scheduler.BukkitTask;
import java.util.HashMap; public class TraceAutoHandler implements Listener {
import java.util.Map; /* 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 @EventHandler
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
if (!(event.getEntity() instanceof TNTPrimed)) return; if (!(event.getEntity() instanceof TNTPrimed))
TNTPrimed tntPrimed = (TNTPrimed) event.getEntity();
RecordManager.tntExplode();
if (!RecordManager.getRecordStatus().isTracing()) {
return; 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) { if (lastExplosion > 80) {
get(tntPrimed).add(tntPrimed); 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();
}
} }

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -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();
}

Datei anzeigen

@ -1,11 +0,0 @@
package de.steamwar.bausystem.tracer.show;
import de.steamwar.bausystem.tracer.record.RecordTrace;
public class ShowTrace {
public ShowTrace(RecordTrace recordTrace) {
}
}

Datei anzeigen

@ -17,13 +17,24 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. 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.ArrayList;
import java.util.List; import java.util.List;
public class DataHolder { public class StoredRecords {
private static final List<Record> records = new ArrayList<>();
public static List<RecordTrace> 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();
}
} }

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -22,8 +22,7 @@ package de.steamwar.bausystem.world;
import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandFreeze;
import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTNT;
import de.steamwar.bausystem.commands.CommandTPSLimiter; import de.steamwar.bausystem.commands.CommandTPSLimiter;
import de.steamwar.bausystem.tracer.record.ExplodeListener; import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.tracer.record.RecordManager;
import de.steamwar.core.TPSWatcher; import de.steamwar.core.TPSWatcher;
import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback; import de.steamwar.scoreboard.ScoreboardCallback;
@ -33,7 +32,10 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import java.text.SimpleDateFormat; 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 { public class BauScoreboard implements Listener {
@ -61,14 +63,13 @@ public class BauScoreboard implements Listener {
strings.add("§2"); strings.add("§2");
strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"));
strings.add("§eFreeze§8: " + (CommandFreeze.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")); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));
if (RecordManager.getRecordStatus().isTracing()) { if (RecordStateMachine.getRecordStatus().isTracing()) {
strings.add("§3"); 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("§eTicks§8: §7" + traceTicks());
strings.add("§eAnzahl TNT§8: §7" + ExplodeListener.size()); strings.add("§eAnzahl TNT§8: §7" + RecordStateMachine.size());
} }
strings.add("§4"); strings.add("§4");
@ -82,7 +83,7 @@ public class BauScoreboard implements Listener {
} }
private long traceTicks() { private long traceTicks() {
return (System.currentTimeMillis() - RecordManager.getStartTime()) / 50; return (System.currentTimeMillis() - RecordStateMachine.getStartTime()) / 50;
} }
private String tpsColor() { private String tpsColor() {