SteamWar/BauSystem2.0
Archiviert
12
0

Update tracer
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2024-04-09 14:59:19 +02:00
Ursprung af19931946
Commit 1aa63255e7
6 geänderte Dateien mit 235 neuen und 203 gelöschten Zeilen

Datei anzeigen

@ -482,36 +482,30 @@ TRACE_HAS_TRACES=§ehas Traces
TRACE_IDLE_SINGLE=§esingle TRACE_IDLE_SINGLE=§esingle
TRACE_IDLE_AUTO_IGNITE=§eauto TRACE_IDLE_AUTO_IGNITE=§eauto
TRACE_MESSAGE_AUTO_IDLE_IGNITE = §aAuto-Tracer ignite started TRACE_MESSAGE_AUTO_IDLE_IGNITE = §aAuto-Tracer ignite started
TRACE_MESSAGE_AUTO_DELETE_INVALID = §cAuto delete cannot be used currently
TRACE_MESSAGE_AUTO_DELETE_ALWAYS = §7Last Shot will §ealways §7be deleted
TRACE_MESSAGE_AUTO_DELETE_NEVER = §7Last Shot will §enever §7be deleted
TRACE_MESSAGE_AUTO_DELETE_NO_BUILD_DESTROY = §7Last Shot will be deleted if §eno build §7block was destroyed
TRACE_MESSAGE_AUTO_DELETE_BUILD_DESTROY = §7Last Shot will be deleted if §ea build §7block was destroyed
TRACE_MESSAGE_AUTO_DELETE_NO_TESTBLOCK_DESTROY = §7Last Shot will be deleted if §eno testblock §7block was destroyed
TRACE_MESSAGE_AUTO_DELETE_TESTBLOCK_DESTROY = §7Last Shot will be deleted if §ea testlblock §7block was destroyed
TRACE_MESSAGE_START = §aTNT-Tracer started TRACE_MESSAGE_START = §aTNT-Tracer started
TRACE_MESSAGE_SINGLE = §aSingle-Tracer started
TRACE_MESSAGE_STOP = §cTNT-Tracer stopped TRACE_MESSAGE_STOP = §cTNT-Tracer stopped
TRACE_MESSAGE_DELETE = §cAll TNT-positions deleted TRACE_MESSAGE_DELETE = §cAll TNT-positions deleted
TRACE_MESSAGE_DELETE_SPECIFIC=§cTrace TNT-positions deleted
TRACE_MESSAGE_SHOW = §aAll TNT-positions shown TRACE_MESSAGE_SHOW = §aAll TNT-positions shown
TRACE_MESSAGE_HIDE = §cAll TNT-positions hidden TRACE_MESSAGE_HIDE = §cAll TNT-positions hidden
TRACE_MESSAGE_DISALLOWED = §cYou are not allowed to use the TNT-Tracer here TRACE_MESSAGE_SHOW_AT=§aTNT-positions shown at {1}
TRACE_MESSAGE_SHOW_AT = §aTNT-positions shown with {0} at {1} TRACE_MESSAGE_SHOW_FROM=§aAll TNT-positions shown from {1}
TRACE_MESSAGE_SHOW_FROM = §aAll TNT-positions shown with {0} from {1} TRACE_MESSAGE_SHOW_FROM_TO=§aAll TNT-positions shown from {1} to {2}
TRACE_MESSAGE_SHOW_FROM_TO = §aAll TNT-positions shown with {0} from {1} to {2}
TRACE_MESSAGE_SHOW_TO_SMALLER = §cTo must be bigger then from TRACE_MESSAGE_SHOW_TO_SMALLER = §cTo must be bigger then from
TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Starts recording of all TNT-positions TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Starts recording of all TNT-positions
TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Starts a single recording of all TNT-positions
TRACE_COMMAND_HELP_STOP = §8/§etrace stop §8- §7Stops the TNT-Tracer TRACE_COMMAND_HELP_STOP = §8/§etrace stop §8- §7Stops the TNT-Tracer
TRACE_COMMAND_HELP_AUTO = §8/§etrace toggleauto §8- §7Automatic start of recording TRACE_COMMAND_HELP_AUTO = §8/§etrace toggleauto §8- §7Automatic start of recording
TRACE_COMMAND_HELP_AUTO_REMOVE = §8/§etrace autoremove §8<§eParameter§8> §8- §7Remove last Trace Record automatically
TRACE_COMMAND_HELP_SHOW = §8/§etrace show §8<§eParameter§8> - §7Shows all TNT-positions TRACE_COMMAND_HELP_SHOW = §8/§etrace show §8<§eParameter§8> - §7Shows all TNT-positions
TRACE_COMMAND_HELP_SHOW_AT = §8/§etrace show §8(§etime§8|§7fuse§8) §7at §8<§eTIME§8> - §7Shows all Trace Positions at §8<§eTIME§8> TRACE_COMMAND_HELP_SHOW_AT=§8/§etrace show §7at §8<§eTIME§8> - §7Shows all Trace Positions at §8<§eTIME§8>
TRACE_COMMAND_HELP_SHOW_FROM = §8/§etrace show §8(§etime§8|§7fuse§8) §7from §8<§eFROM§8> - §7Shows all Trace Positions from §8<§eFROM§8> TRACE_COMMAND_HELP_SHOW_AT_WITH=§8/§etrace show §7at §8<§eTIME§8> §7with §8<§eParameter§8> - §7Shows all Trace Positions at §8<§eTIME§8>
TRACE_COMMAND_HELP_SHOW_FROM_TO = §8/§etrace show §8(§etime§8|§7fuse§8) §7from §8<§eFROM§8> §7to §8<§eTO§8> - §7Shows all Trace Positions from §8<§eFROM§8> to §8<§eTO§8> TRACE_COMMAND_HELP_SHOW_FROM=§8/§etrace show §7from §8<§eFROM§8> - §7Shows all Trace Positions from §8<§eFROM§8>
TRACE_COMMAND_HELP_SHOW_FROM_WITH=§8/§etrace show §7from §8<§eFROM§8> §7with §8<§eParameter§8> - §7Shows all Trace Positions from §8<§eFROM§8>
TRACE_COMMAND_HELP_SHOW_FROM_TO=§8/§etrace show §7from §8<§eFROM§8> §7to §8<§eTO§8> - §7Shows all Trace Positions from §8<§eFROM§8> to §8<§eTO§8>
TRACE_COMMAND_HELP_SHOW_FROM_TO_WITH=§8/§etrace show §7from §8<§eFROM§8> §7to §8<§eTO§8> §7with §8<§eParameter§8> - §7Shows all Trace Positions from §8<§eFROM§8> to §8<§eTO§8>
TRACE_COMMAND_HELP_HIDE = §8/§etrace hide §8- §7Hides all TNT-positions TRACE_COMMAND_HELP_HIDE = §8/§etrace hide §8- §7Hides all TNT-positions
TRACE_COMMAND_HELP_DELETE = §8/§etrace delete §8- §7Deletes all TNT-positions TRACE_COMMAND_HELP_DELETE=§8/§etrace delete §8[§eTrace§8] §8- §7Deletes all TNT-positions or a Trace
TRACE_COMMAND_HELP_ISOLATE=§8/§etrace isolate §8[§eTrace§8] §8[§eTNT§8] §8- §7Isolates specific TNTs from the Trace
TRACE_GUI_ITEM_NAME = §eTracer TRACE_GUI_ITEM_NAME = §eTracer
TRACE_GUI_ITEM_LORE = §7Status§8: {0} TRACE_GUI_ITEM_LORE = §7Status§8: {0}

Datei anzeigen

@ -17,15 +17,25 @@
* 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.features.tracer.rendering; package de.steamwar.bausystem.features.tracer;
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import lombok.Getter;
import lombok.Setter;
import java.util.*; import java.util.*;
public class ViewFlagHolder { public class PlayerTraceShowData {
@Getter
@Setter
private BundleFilter bundleFilter;
private Map<Class<? extends ViewFlag>, ViewFlag> viewFlags = new HashMap<>(); private Map<Class<? extends ViewFlag>, ViewFlag> viewFlags = new HashMap<>();
public ViewFlagHolder(ViewFlag... viewFlags) { public PlayerTraceShowData(BundleFilter bundleFilter, ViewFlag... viewFlags) {
this.bundleFilter = bundleFilter;
for (ViewFlag viewFlag : viewFlags) { for (ViewFlag viewFlag : viewFlags) {
this.viewFlags.put(viewFlag.getClass(), viewFlag); this.viewFlags.put(viewFlag.getClass(), viewFlag);
} }
@ -51,10 +61,18 @@ public class ViewFlagHolder {
return flagList; return flagList;
} }
public boolean hasNoViewFlags() {
return viewFlags.isEmpty();
}
public boolean hasViewFlag(Class<? extends ViewFlag> clazz) { public boolean hasViewFlag(Class<? extends ViewFlag> clazz) {
return viewFlags.containsKey(clazz); return viewFlags.containsKey(clazz);
} }
public boolean hasViewFlagOnly(Class<? extends ViewFlag> clazz) {
return viewFlags.containsKey(clazz) && viewFlags.size() == 1;
}
public <T extends ViewFlag> T getViewFlag(Class<T> clazz) { public <T extends ViewFlag> T getViewFlag(Class<T> clazz) {
return (T) viewFlags.get(clazz); return (T) viewFlags.get(clazz);
} }

Datei anzeigen

@ -23,15 +23,14 @@ import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter; import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity; import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag; import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlagHolder;
import de.steamwar.bausystem.features.tracer.rendering.dynamicflags.AtFlag;
import de.steamwar.bausystem.features.tracer.rendering.dynamicflags.IsolateFlag;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer; import de.steamwar.entity.REntityServer;
import lombok.Getter; import lombok.Getter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Trace { // TODO: Add UUID for file saving and so on! public class Trace { // TODO: Add UUID for file saving and so on!
@ -54,11 +53,13 @@ public class Trace { // TODO: Add UUID for file saving and so on!
private List<TNTRecord> records = new ArrayList<>(); private List<TNTRecord> records = new ArrayList<>();
/** /**
* ID that should be asigned to the next record of a unique tnt * ID that should be assigned to the next record of a unique tnt
*/ */
@Getter @Getter
private int nextOpenRecordId = -1; private int nextOpenRecordId = -1;
private final Map<Player, REntityServer> entityServerMap = new HashMap<>();
/** /**
* List of all used ids * List of all used ids
*/ */
@ -70,21 +71,6 @@ public class Trace { // TODO: Add UUID for file saving and so on!
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* A map of players -> REntityServers for rendering traces to a player
*/
private final Map<Player, REntityServer> serverMap = new HashMap<>();
/**
* A map saving the bundle filters for rendered traces, for life rendering
*/
private final Map<Player, BundleFilter> bundleFilterMap = new HashMap<>();
/**
* A map saving the view flags for rendered traces, for life rendering
*/
private final Map<Player, ViewFlagHolder> viewFlagMap = new HashMap<>();
public Trace(Region region) { public Trace(Region region) {
this.region = region; this.region = region;
} }
@ -101,15 +87,17 @@ public class Trace { // TODO: Add UUID for file saving and so on!
/** /**
* Adds the given records and updates potential trace renderings * Adds the given records and updates potential trace renderings
*/ */
protected void addAll(List<TNTRecord> records) { protected void addAll(List<TNTRecord> records, Function<Player, PlayerTraceShowData> getter) {
this.records.addAll(records); this.records.addAll(records);
Iterator<Player> keySetIterator = entityServerMap.keySet().iterator();
for (Player player : serverMap.keySet()) { while (keySetIterator.hasNext()) {
REntityServer server = serverMap.get(player); Player player = keySetIterator.next();
BundleFilter bundleFilter = bundleFilterMap.getOrDefault(player, BundleFilter.DEFAULT); PlayerTraceShowData playerTraceShowData = getter.apply(player);
ViewFlagHolder viewFlagHolder = viewFlagMap.computeIfAbsent(player, ignored -> new ViewFlagHolder()); if (playerTraceShowData == null) {
keySetIterator.remove();
render(server, records, viewFlagHolder, bundleFilter); continue;
}
render(getRecords(), entityServerMap.get(player), playerTraceShowData);
} }
} }
@ -130,7 +118,7 @@ public class Trace { // TODO: Add UUID for file saving and so on!
public Set<List<TNTRecord>> getHistories() { public Set<List<TNTRecord>> getHistories() {
Set<List<TNTRecord>> histories = new HashSet<>(); Set<List<TNTRecord>> histories = new HashSet<>();
for (TNTRecord record : records) { for (TNTRecord record : getRecords()) {
histories.add(record.getHistory()); histories.add(record.getHistory());
} }
@ -141,42 +129,30 @@ public class Trace { // TODO: Add UUID for file saving and so on!
* Renders this traces * Renders this traces
* *
* @param player The player the trace is rendered to * @param player The player the trace is rendered to
* @param viewFlagHolder Flags modefieing the rendering * @param playerTraceShowData The showData for modifying the rendering
* @param bundleFilter Filter to determin bundeling of records
*/ */
public void render(Player player, ViewFlagHolder viewFlagHolder, BundleFilter bundleFilter) { public void render(Player player, PlayerTraceShowData playerTraceShowData) {
if (serverMap.containsKey(player)) { REntityServer entityServer = entityServerMap.get(player);
REntityServer server = serverMap.get(player); if (entityServer != null) {
server.close(); entityServer.getEntities().forEach(REntity::die);
} else {
serverMap.remove(player); entityServer = new REntityServer();
viewFlagMap.remove(player); entityServerMap.put(player, entityServer);
bundleFilterMap.remove(player);
} }
render(getRecords(), entityServer, playerTraceShowData);
viewFlagMap.put(player, viewFlagHolder);
bundleFilterMap.put(player, bundleFilter);
REntityServer server = new REntityServer();
server.addPlayer(player);
serverMap.put(player, server);
render(server, records, viewFlagHolder, bundleFilter);
} }
/** /**
* Internal methode to render records to a REntityServer * Internal methode to render records to a REntityServer
* *
* @param server Server to render to
* @param records Records to render * @param records Records to render
* @param viewFlagHolder Flags modefieing the rendering * @param playerTraceShowData The showData for modifying the rendering
* @param bundleFilter Filter to determin bundeling of records
*/ */
private void render(REntityServer server, List<TNTRecord> records, ViewFlagHolder viewFlagHolder, BundleFilter bundleFilter) { private void render(List<TNTRecord> records, REntityServer entityServer, PlayerTraceShowData playerTraceShowData) {
if (records.isEmpty()) return; if (records.isEmpty()) return;
List<TNTRecord> workingRecords = records; List<TNTRecord> workingRecords = records;
Set<ViewFlag> flagList = viewFlagHolder.getEffectiveViewFlags(); Set<ViewFlag> flagList = playerTraceShowData.getEffectiveViewFlags();
//Apply filters //Apply filters
for (ViewFlag flag : flagList) { for (ViewFlag flag : flagList) {
@ -184,28 +160,27 @@ public class Trace { // TODO: Add UUID for file saving and so on!
} }
//Bundle records at unique positions //Bundle records at unique positions
List<List<TNTRecord>> bundles = bundleRecords(workingRecords, bundleFilter); List<List<TNTRecord>> bundles = bundleRecords(workingRecords, playerTraceShowData.getBundleFilter());
//Render bundled records //Render bundled records
List<TraceEntity> entities = new LinkedList<>(); List<TraceEntity> entities = new LinkedList<>();
for (List<TNTRecord> bundle : bundles) { for (List<TNTRecord> bundle : bundles) {
entities.add(new TraceEntity(server, bundle.get(0).getLocation(), bundle.get(0).isExplosion(), bundle)); entities.add(new TraceEntity(entityServer, bundle.get(0).getLocation(), bundle.get(0).isExplosion(), bundle));
} }
//Apply modifiers //Apply modifiers
for (ViewFlag flag : flagList) { for (ViewFlag flag : flagList) {
flag.modify(server, entities); flag.modify(entityServer, entities);
} }
entityServer.setCallback((player, rEntity, entityAction) -> {
server.setCallback(((player, rEntity, entityAction) -> {
for (TraceEntity entity : entities) { for (TraceEntity entity : entities) {
if (rEntity.equals(entity)) { if (rEntity.equals(entity)) {
entity.printIntoChat(player); entity.printIntoChat(player);
return; return;
} }
} }
})); });
} }
/** /**
@ -243,48 +218,6 @@ public class Trace { // TODO: Add UUID for file saving and so on!
return bundles; return bundles;
} }
/**
* Modifies the render for the given player, to only show tnts at the given time interval
*
* @param player
* @param from start of time interval
* @param to end of time interval
*/
public void renderAt(Player player, int from, int to) {
ViewFlagHolder viewFlags = viewFlagMap.computeIfAbsent(player, p -> new ViewFlagHolder());
if (viewFlags.hasViewFlag(AtFlag.class)) {
viewFlags.getViewFlag(AtFlag.class).update(from, to);
} else {
viewFlags.addViewFlag(new AtFlag(from, to));
}
render(player, viewFlags, BundleFilter.STRICT);
}
/**
* Toggles the isolated render for the given records and player
*
* @param player the player the trace is shown to
* @param records the record for which isolation is toggled
*/
public void isolate(Player player, TNTRecord... records) {
IsolateFlag isolateFlag;
ViewFlagHolder viewFlags = viewFlagMap.get(player);
if (viewFlags != null && viewFlags.hasViewFlag(IsolateFlag.class)) {
isolateFlag = viewFlags.getViewFlag(IsolateFlag.class);
} else {
viewFlags = new ViewFlagHolder();
isolateFlag = new IsolateFlag();
viewFlags.addViewFlag(isolateFlag);
}
for (TNTRecord record : records) {
isolateFlag.toggleId(record.getTntId());
}
render(player, viewFlags, BundleFilter.STRICT);
}
/** /**
* Makes the first passed player follow the trace render of the second passed player * Makes the first passed player follow the trace render of the second passed player
* *
@ -292,11 +225,7 @@ public class Trace { // TODO: Add UUID for file saving and so on!
* @param toFollow * @param toFollow
*/ */
public void follow(Player player, Player toFollow) { public void follow(Player player, Player toFollow) {
for (REntityServer server : serverMap.values()) { throw new UnsupportedOperationException();
server.removePlayer(player);
}
serverMap.get(toFollow).addPlayer(player);
} }
/** /**
@ -305,13 +234,7 @@ public class Trace { // TODO: Add UUID for file saving and so on!
* @param player * @param player
*/ */
public void unfollow(Player player) { public void unfollow(Player player) {
for (REntityServer server : serverMap.values()) { throw new UnsupportedOperationException();
server.removePlayer(player);
}
if (serverMap.get(player) != null) {
serverMap.get(player).addPlayer(player);
}
} }
/** /**
@ -320,12 +243,8 @@ public class Trace { // TODO: Add UUID for file saving and so on!
* @param player * @param player
*/ */
public void hide(Player player) { public void hide(Player player) {
REntityServer server = serverMap.get(player); REntityServer entityServer = entityServerMap.remove(player);
if (server == null) return; if (entityServer != null) entityServer.close();
bundleFilterMap.remove(player);
viewFlagMap.remove(player);
server.close();
} }
@Override @Override

Datei anzeigen

@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.tracer;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter; import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag; import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlagHolder; import de.steamwar.bausystem.features.tracer.rendering.dynamicflags.AtFlag;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.command.PreviousArguments; import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
@ -43,6 +43,7 @@ public class TraceCommand extends SWCommand {
@LinkedInstance @LinkedInstance
public TraceRecorder traceRecorder; public TraceRecorder traceRecorder;
@LinkedInstance @LinkedInstance
public TraceManager manager; public TraceManager manager;
@ -64,44 +65,87 @@ public class TraceCommand extends SWCommand {
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player); BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player);
} }
@Register(value = "auto", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "auto", description = "TRACE_COMMAND_HELP_AUTO")
public void auto(@Validator Player player) { public void auto(@Validator Player player) {
Region region = Region.getRegion(player.getLocation()); Region region = Region.getRegion(player.getLocation());
traceRecorder.toggleAutoTrace(region); traceRecorder.toggleAutoTrace(region);
// TODO: Add Auto toggle Message!
} }
@Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW")
public void show(@Validator Player player, @OptionalValue("STRICT") BundleFilter filter, ViewFlag... flags) { public void show(@Validator Player player, @OptionalValue("STRICT") BundleFilter bundleFilter, ViewFlag... flags) {
manager.show(player, new ViewFlagHolder(flags), filter); showInternal(player, 0, Integer.MAX_VALUE, bundleFilter, flags);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", player); BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", player);
} }
@Register(value = "hide", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = {"show", "at"}, description = "TRACE_COMMAND_HELP_SHOW_AT_WITH")
public void showAt(@Validator Player player, @Min(intValue = 0) int time, @StaticValue("with") String with, @OptionalValue("STRICT") BundleFilter bundleFilter, @ArrayLength(min = 1) ViewFlag... flags) {
showInternal(player, time, time, bundleFilter, flags);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_AT", player, time);
}
@Register(value = {"show", "from"}, description = "TRACE_COMMAND_HELP_SHOW_FROM_WITH")
public void showFromTo(@Validator Player player, @Min(intValue = 0) int from, @StaticValue("with") String with, @OptionalValue("STRICT") BundleFilter bundleFilter, @ArrayLength(min = 1) ViewFlag... flags) {
showInternal(player, from, Integer.MAX_VALUE, bundleFilter, flags);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_FROM", player, from);
}
@Register(value = {"show", "from"}, description = "TRACE_COMMAND_HELP_SHOW_FROM_TO_WITH")
public void showFromTo(@Validator Player player, @Min(intValue = 0) int from, @StaticValue("to") String toString, int to, @StaticValue("with") String with, @OptionalValue("STRICT") BundleFilter bundleFilter, @ArrayLength(min = 1) ViewFlag... flags) {
if (to < from) {
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_TO_SMALLER", player);
return;
}
showInternal(player, from, to, bundleFilter, flags);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_FROM_TO", player, from, to);
}
private void showInternal(Player player, int from, int to, BundleFilter bundleFilter, ViewFlag... flags) {
PlayerTraceShowData playerTraceShowData = new PlayerTraceShowData(bundleFilter, flags);
playerTraceShowData.addViewFlag(new AtFlag(from, to));
manager.show(player, playerTraceShowData);
}
@Register(value = {"show", "at"}, description = "TRACE_COMMAND_HELP_SHOW_AT")
public void showAt(@Validator Player player, @Min(intValue = 0) int time) {
manager.renderAt(player, time, time);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_AT", player, time);
}
@Register(value = {"show", "from"}, description = "TRACE_COMMAND_HELP_SHOW_FROM")
public void showFrom(@Validator Player player, @Min(intValue = 0) int from) {
manager.renderAt(player, from, Integer.MAX_VALUE);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_FROM", player, from);
}
@Register(value = {"show", "from"}, description = "TRACE_COMMAND_HELP_SHOW_FROM_TO")
public void showFromTo(@Validator Player player, @Min(intValue = 0) int from, @StaticValue("to") String toString, int to) {
manager.renderAt(player, from, to);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_FROM_TO", player, from, to);
}
@Register(value = "hide", description = "TRACE_COMMAND_HELP_HIDE")
public void hide(@Validator Player player) { public void hide(@Validator Player player) {
manager.hide(player); manager.hide(player);
BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", player); BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", player);
} }
@Register(value = "delete", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "delete", description = "TRACE_COMMAND_HELP_DELETE")
public void delete(@Validator Player player) { public void delete(@Validator Player player) {
manager.clear(); manager.clear();
BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", player);
} }
@Register(value = "delete", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "delete")
public void delete(@Validator Player player, int id) { public void delete(@Validator Player player, Trace trace) {
manager.remove(id); // TODO: Reimplement manager.remove(trace);
BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE_SPECIFIC", player);
} }
@Register(value = "isolate", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "isolate", description = "TRACE_COMMAND_HELP_ISOLATE")
public void isolate(@Validator Player player, Trace trace, @ErrorMessage("TRACE_RECORD_ID_INVALID") TNTRecord... records) { public void isolate(@Validator Player player, Trace trace, @ErrorMessage("TRACE_RECORD_ID_INVALID") TNTRecord... records) {
trace.isolate(player, records); manager.isolate(player, records);
} // TODO: Add Message!
@Register(value = "at", description = "TRACE_COMMAND_HELP_SHOW")
public void at(@Validator Player player, int start, int end) {
for (Trace trace : manager.getAll()) {
trace.renderAt(player, start, end);
}
} }
@Register(value = "share", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "share", description = "TRACE_COMMAND_HELP_SHOW")
@ -111,6 +155,7 @@ public class TraceCommand extends SWCommand {
@Register(value = "follow", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "follow", description = "TRACE_COMMAND_HELP_SHOW")
public void follow(@Validator Player player, Player toFollow) { public void follow(@Validator Player player, Player toFollow) {
// TODO: Implement
for (Trace trace : manager.getAll()) { for (Trace trace : manager.getAll()) {
trace.follow(player, toFollow); trace.follow(player, toFollow);
} }
@ -118,6 +163,7 @@ public class TraceCommand extends SWCommand {
@Register(value = "unfollow", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "unfollow", description = "TRACE_COMMAND_HELP_SHOW")
public void unfollow(@Validator Player player) { public void unfollow(@Validator Player player) {
// TODO: Implement
for (Trace trace : manager.getAll()) { for (Trace trace : manager.getAll()) {
trace.unfollow(player); trace.unfollow(player);
} }

Datei anzeigen

@ -20,7 +20,8 @@
package de.steamwar.bausystem.features.tracer; package de.steamwar.bausystem.features.tracer;
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter; import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlagHolder; import de.steamwar.bausystem.features.tracer.rendering.dynamicflags.AtFlag;
import de.steamwar.bausystem.features.tracer.rendering.dynamicflags.IsolateFlag;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -37,15 +38,7 @@ public class TraceManager implements Listener {
private final Map<Region, Map<Integer, Trace>> tracesByRegion = new HashMap<>(); private final Map<Region, Map<Integer, Trace>> tracesByRegion = new HashMap<>();
/** private final Map<Region, Map<Player, PlayerTraceShowData>> showDataPerRegionPerPlayer = new HashMap<>();
* A map saving the view flags used by Players
*/
private final Map<Player, ViewFlagHolder> viewFlagMap = new HashMap<>();
/**
* A map saving the bundle filter used by Players
*/
private final Map<Player, BundleFilter> bundleFilterMap = new HashMap<>();
/** /**
* Utility variable to keep track of the next open trace id; * Utility variable to keep track of the next open trace id;
@ -59,15 +52,21 @@ public class TraceManager implements Listener {
* @return id of the created trace * @return id of the created trace
*/ */
protected int add(Trace trace) { protected int add(Trace trace) {
for (Player player : viewFlagMap.keySet()) { showDataPerRegionPerPlayer.getOrDefault(trace.getRegion(), Collections.emptyMap()).forEach((player, playerTraceShowData) -> {
trace.render(player, viewFlagMap.get(player), bundleFilterMap.get(player)); trace.render(player, playerTraceShowData);
} });
traces.put(nextOpenId, trace); traces.put(nextOpenId, trace);
tracesByRegion.computeIfAbsent(trace.getRegion(), region -> new HashMap<>()).put(nextOpenId, trace); tracesByRegion.computeIfAbsent(trace.getRegion(), region -> new HashMap<>()).put(nextOpenId, trace);
nextOpenId++; nextOpenId++;
return nextOpenId; return nextOpenId;
} }
protected void addAll(Trace trace, List<TNTRecord> tntRecords) {
trace.addAll(tntRecords, player -> {
return showDataPerRegionPerPlayer.getOrDefault(trace.getRegion(), Collections.emptyMap()).get(player);
});
}
/** /**
* Removes the trace with the given id * Removes the trace with the given id
* *
@ -76,13 +75,11 @@ public class TraceManager implements Listener {
public boolean remove(int id) { public boolean remove(int id) {
if (id >= nextOpenId) return false; if (id >= nextOpenId) return false;
if (traces.get(id) == null) return false; if (traces.get(id) == null) return false;
for (Player player : viewFlagMap.keySet()) {
traces.get(id).hide(player);
}
Trace trace = traces.remove(id); Trace trace = traces.remove(id);
if (trace != null) { showDataPerRegionPerPlayer.get(trace.getRegion()).forEach((player, playerTraceShowData) -> {
trace.hide(player);
});
tracesByRegion.get(trace.getRegion()).remove(id); tracesByRegion.get(trace.getRegion()).remove(id);
}
return true; return true;
} }
@ -90,11 +87,15 @@ public class TraceManager implements Listener {
* Clears all traces * Clears all traces
*/ */
public void clear() { public void clear() {
for (Player player : viewFlagMap.keySet()) { showDataPerRegionPerPlayer.values()
for (Trace trace : traces.values()) { .stream()
.flatMap(map -> map.entrySet().stream())
.map(Map.Entry::getKey)
.forEach(player -> {
traces.values().forEach(trace -> {
trace.hide(player); trace.hide(player);
} });
} });
traces.clear(); traces.clear();
tracesByRegion.clear(); tracesByRegion.clear();
nextOpenId = 0; nextOpenId = 0;
@ -117,10 +118,7 @@ public class TraceManager implements Listener {
* @return the trace with given id or null if no trace with id is found * @return the trace with given id or null if no trace with id is found
*/ */
public Optional<Trace> get(int index) { public Optional<Trace> get(int index) {
if (index < traces.size()) { return Optional.ofNullable(traces.get(index));
return Optional.of(traces.get(index));
}
return Optional.empty();
} }
/** /**
@ -140,32 +138,87 @@ public class TraceManager implements Listener {
} }
/** /**
* Toggles trace show on for player * Shows traces for the player of the current Region
* *
* @param player * @param player
* @param viewFlagHolder * @param playerTraceShowData
* @param bundleFilter
*/ */
public void show(Player player, ViewFlagHolder viewFlagHolder, BundleFilter bundleFilter) { public void show(Player player, PlayerTraceShowData playerTraceShowData) {
viewFlagMap.put(player, viewFlagHolder); Region region = Region.getRegion(player.getLocation());
bundleFilterMap.put(player, bundleFilter); showDataPerRegionPerPlayer.computeIfAbsent(region, ignored -> new HashMap<>()).put(player, playerTraceShowData);
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
for (Trace trace : traces.values()) { trace.render(player, playerTraceShowData);
trace.render(player, viewFlagHolder, bundleFilter); });
}
} }
/** /**
* Toggles trace show of for player * Hides traces for the player of the current Region
* *
* @param player * @param player
*/ */
public void hide(Player player) { public void hide(Player player) {
for (Trace trace : traces.values()) { Region region = Region.getRegion(player.getLocation());
PlayerTraceShowData previous = showDataPerRegionPerPlayer.getOrDefault(region, Collections.emptyMap()).remove(player);
if (previous == null) return;
tracesByRegion.getOrDefault(player, Collections.emptyMap()).forEach((integer, trace) -> {
trace.hide(player); trace.hide(player);
});
} }
viewFlagMap.remove(player); /**
bundleFilterMap.remove(player); * Modifies the render for the given player, to only show tnts at the given time interval
*
* @param player
* @param from start of time interval
* @param to end of time interval
*/
public void renderAt(Player player, int from, int to) {
Region region = Region.getRegion(player.getLocation());
PlayerTraceShowData playerTraceShowData = showDataPerRegionPerPlayer.computeIfAbsent(region, ignored -> new HashMap<>()).computeIfAbsent(player, ignored -> new PlayerTraceShowData(BundleFilter.STRICT));
AtFlag atFlag = playerTraceShowData.getViewFlag(AtFlag.class);
if (atFlag == null) {
atFlag = new AtFlag(from, to);
playerTraceShowData.addViewFlag(atFlag);
} else {
atFlag.update(from, to);
}
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
trace.render(player, playerTraceShowData);
});
}
/**
* Toggles the isolated render for the given records and player
*
* @param player the player the trace is shown to
* @param records the record for which isolation is toggled
*/
public void isolate(Player player, TNTRecord... records) {
Region region = Region.getRegion(player.getLocation());
PlayerTraceShowData playerTraceShowData = showDataPerRegionPerPlayer.computeIfAbsent(region, ignored -> new HashMap<>()).computeIfAbsent(player, ignored -> new PlayerTraceShowData(BundleFilter.STRICT));
IsolateFlag isolateFlag;
if (playerTraceShowData.hasViewFlagOnly(IsolateFlag.class)) {
isolateFlag = playerTraceShowData.getViewFlag(IsolateFlag.class);
} else if (playerTraceShowData.hasNoViewFlags()) {
isolateFlag = new IsolateFlag();
playerTraceShowData.addViewFlag(isolateFlag);
} else {
playerTraceShowData = new PlayerTraceShowData(BundleFilter.STRICT);
isolateFlag = new IsolateFlag();
playerTraceShowData.addViewFlag(isolateFlag);
showDataPerRegionPerPlayer.get(region).put(player, playerTraceShowData);
}
for (TNTRecord record : records) {
isolateFlag.toggleId(record.getTntId());
}
PlayerTraceShowData finalPlayerTraceShowData = playerTraceShowData;
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
trace.render(player, finalPlayerTraceShowData);
});
} }
} }

Datei anzeigen

@ -159,8 +159,10 @@ public class TraceRecorder implements Listener {
for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) { for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) {
record(tnt, trace, Collections.emptyList()); record(tnt, trace, Collections.emptyList());
} }
trace.addAll(recordsToAddMap.get(trace));
recordsToAddMap.get(trace).clear(); List<TNTRecord> tntRecords = recordsToAddMap.get(trace);
manager.addAll(trace, tntRecords);
tntRecords.clear();
} }
} }