SteamWar/BauSystem2.0
Archiviert
12
0

Reformat many things
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
yoyosource 2024-04-07 13:38:36 +02:00
Ursprung 207826ae8a
Commit e64c50b566
9 geänderte Dateien mit 287 neuen und 288 gelöschten Zeilen

Datei anzeigen

@ -53,8 +53,8 @@ public class Recorder implements Listener {
*/
private final Map<Region, List<TNTPrimed>> trackedTNT = new HashMap<>();
/** Map from TNT to Region the TNT spawned in
*
/**
* Map from TNT to Region the TNT spawned in
*/
private final Map<TNTPrimed, Region> tntSpawnRegion = new HashMap<>();
@ -78,41 +78,44 @@ public class Recorder implements Listener {
*/
private final Set<Region> autoTraceRegions = new HashSet<>();
public Recorder(){
public Recorder() {
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
record();
checkForAutoTraceFinish();
}, 0, 1);
}
/** Toggles auto trace for the given region
/**
* Toggles auto trace for the given region
*
* @param region
*/
public void toggleAutoTrace(Region region) {
if (autoTraceRegions.contains(region))
if (autoTraceRegions.contains(region)) {
autoTraceRegions.remove(region);
else
} else {
autoTraceRegions.add(region);
}
}
/** Makes checks for whether auto traces finished
*
/**
* Makes checks for whether auto traces finished
*/
public void checkForAutoTraceFinish(){
for(Region region: autoTraceRegions) {
public void checkForAutoTraceFinish() {
for (Region region : autoTraceRegions) {
if (autoTraceRegions.contains(region) && trackedTNT.getOrDefault(region, Collections.emptyList()).size() == 0) {
stopRecording(region);
}
}
}
/** Starts a recording at the given region
/**
* Starts a recording at the given region
*
* @param region region to be recorded
*/
public int startRecording(Region region){
if(activeTraces.containsKey(region)) return -1;
public int startRecording(Region region) {
if (activeTraces.containsKey(region)) return -1;
Trace trace = new Trace(region);
noExplosionRecorded.add(trace);
activeTraces.put(region, trace);
@ -120,32 +123,34 @@ public class Recorder implements Listener {
return manager.add(trace);
}
/** Stops the recording at the given region
/**
* Stops the recording at the given region
*
* @param region region to stop recording
*/
public void stopRecording(Region region){
public void stopRecording(Region region) {
Trace trace = activeTraces.getOrDefault(region, null);
if (trace == null) return;
trace.setRecords(Collections.unmodifiableList(trace.getRecords()));
noExplosionRecorded.remove(trace);
activeTraces.remove(region);
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList()))
for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) {
historyMap.remove(tnt);
}
recordsToAddMap.remove(trace);
trackedTNT.put(region, new ArrayList<>());
}
/** Internal methode to record all tracked TNT Entities
*
/**
* Internal methode to record all tracked TNT Entities
*/
private void record(){
for(Region region : activeTraces.keySet()){
private void record() {
for (Region region : activeTraces.keySet()) {
Trace trace = activeTraces.get(region);
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) {
record(tnt, trace, Collections.emptyList());
}
trace.addAll(recordsToAddMap.get(trace));
@ -153,25 +158,27 @@ public class Recorder implements Listener {
}
}
/** Internal methode to record exploded tnt
/**
* Internal methode to record exploded tnt
*
* @param tntPrimed tnt exploding
* @param trace trace to record the tnt for
*/
private void record(TNTPrimed tntPrimed, Trace trace, List<Block> destroyedBlocks){
private void record(TNTPrimed tntPrimed, Trace trace, List<Block> destroyedBlocks) {
List<TNTRecord> history = historyMap.getOrDefault(tntPrimed, new ArrayList<>());
int tntID;
if(history.size() == 0){
if (history.size() == 0) {
historyMap.put(tntPrimed, history);
tntID = trace.getAndIncrementNextOpenRecordId();
}
else
} else {
tntID = history.get(0).getTntId();
}
boolean isExplosion = tntPrimed.getFuseTicks() == 0;
if(isExplosion)
if (isExplosion) {
noExplosionRecorded.remove(trace);
}
boolean afterFirstExplosion = noExplosionRecorded.contains(trace);
TNTRecord record = new TNTRecord(tntID, tntPrimed, isExplosion, afterFirstExplosion, TPSUtils.currentTick.get() - trace.getStartTime(), history, destroyedBlocks);
@ -180,23 +187,27 @@ public class Recorder implements Listener {
recordsToAddMap.get(trace).add(record);
}
/** Event for TNTs beeing spawn.
/**
* Event for TNTs beeing spawn.
* Registers newly spawned TNT to be traced if reqired
*
* @param event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTNTSpawn(EntitySpawnEvent event){
if(!(event.getEntity() instanceof TNTPrimed)) return;
public void onTNTSpawn(EntitySpawnEvent event) {
if (!(event.getEntity() instanceof TNTPrimed)) return;
Region region = Region.getRegion(event.getLocation());
if(autoTraceRegions.contains(region) && !activeTraces.containsKey(region))
if (autoTraceRegions.contains(region) && !activeTraces.containsKey(region)) {
startRecording(region);
}
if(activeTraces.containsKey(region)){
//Check whether set for tracking already exists. Creating it if necessary
if(!trackedTNT.containsKey(region))
if (activeTraces.containsKey(region)) {
// Check whether set for tracking already exists. Creating it if necessary
if (!trackedTNT.containsKey(region)) {
trackedTNT.put(region, new ArrayList<>());
}
trackedTNT.get(region).add((TNTPrimed) event.getEntity());
tntSpawnRegion.put((TNTPrimed) event.getEntity(), region);
@ -204,16 +215,18 @@ public class Recorder implements Listener {
}
}
/** Event for TNTs exploding
/**
* Event for TNTs exploding
* Unregisters TNTs from beeing traced on explode
*
* @param event
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTNTExplode(EntityExplodeEvent event){
if(!(event.getEntity() instanceof TNTPrimed)) return;
public void onTNTExplode(EntityExplodeEvent event) {
if (!(event.getEntity() instanceof TNTPrimed)) return;
Region region = tntSpawnRegion.getOrDefault((TNTPrimed) event.getEntity(), null);
if(region == null) return;
if (region == null) return;
trackedTNT.get(region).remove((TNTPrimed) event.getEntity());
tntSpawnRegion.remove((TNTPrimed) event.getEntity());

Datei anzeigen

@ -30,7 +30,6 @@ import org.bukkit.util.Vector;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Getter
public class TNTRecord {
@ -90,7 +89,7 @@ public class TNTRecord {
*/
private final List<TNTRecord> history;
public TNTRecord(int tntId, TNTPrimed tnt, boolean explosion, boolean afterFirstExplosion, long ticksSinceStart, List<TNTRecord> history, List<Block> destroyedBlocks){
public TNTRecord(int tntId, TNTPrimed tnt, boolean explosion, boolean afterFirstExplosion, long ticksSinceStart, List<TNTRecord> history, List<Block> destroyedBlocks) {
this.tntId = tntId;
this.explosion = explosion;
this.inWater = tnt.isInWater();
@ -103,26 +102,26 @@ public class TNTRecord {
boolean buildDestroy = false;
boolean testblockDestroy = false;
for(Block destroyedBlock: destroyedBlocks){
if (Region.getRegion(destroyedBlock.getLocation()).inRegion(destroyedBlock.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION))
for (Block destroyedBlock : destroyedBlocks) {
if (Region.getRegion(destroyedBlock.getLocation()).inRegion(destroyedBlock.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)) {
buildDestroy = true;
if (Region.getRegion(destroyedBlock.getLocation()).inRegion(destroyedBlock.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION))
}
if (Region.getRegion(destroyedBlock.getLocation()).inRegion(destroyedBlock.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) {
testblockDestroy = true;
}
}
destroyedBuildArea = buildDestroy;
destroyedTestBlock = testblockDestroy;
}
public Optional<TNTRecord> getNext(){
public Optional<TNTRecord> getNext() {
int index = history.indexOf(this);
return index == history.size() - 1 ? Optional.empty() : Optional.of(history.get(index + 1));
}
public Optional<TNTRecord> getPrevious(){
public Optional<TNTRecord> getPrevious() {
int index = history.indexOf(this);
return index == 0 ? Optional.empty() : Optional.of(history.get(index - 1));
}
@ -139,12 +138,11 @@ public class TNTRecord {
@Override
public boolean equals(Object obj) {
if(!(obj instanceof TNTRecord)) return false;
if (!(obj instanceof TNTRecord)) return false;
TNTRecord record = (TNTRecord) obj;
if(record.isExplosion() != explosion) return false;
if(!record.getLocation().equals(location)) return false;
if(!record.getVelocity().equals(velocity)) return false;
if (record.isExplosion() != explosion) return false;
if (!record.getLocation().equals(location)) return false;
if (!record.getVelocity().equals(velocity)) return false;
return true;
}
}

Datei anzeigen

@ -23,8 +23,8 @@ import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import de.steamwar.bausystem.features.tracer.rendering.dynamicFlags.AtFlag;
import de.steamwar.bausystem.features.tracer.rendering.dynamicFlags.IsolateFlag;
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.entity.REntityServer;
import lombok.Getter;
@ -79,15 +79,16 @@ public class Trace {
*/
private final Map<Player, ViewFlag[]> viewFlagMap = new HashMap<>();
public Trace (Region region){
public Trace(Region region) {
this.region = region;
}
/**
* Gets and increments the next open record id
*
* @return next open record id
*/
protected int getAndIncrementNextOpenRecordId(){
protected int getAndIncrementNextOpenRecordId() {
nextOpenRecordId++;
usedIds.add(Integer.toString(nextOpenRecordId));
return nextOpenRecordId;
@ -96,10 +97,10 @@ public class Trace {
/**
* Adds the given records and updates potential trace renderings
*/
protected void addAll(List<TNTRecord> records){
protected void addAll(List<TNTRecord> records) {
this.records.addAll(records);
for(Player player: serverMap.keySet()){
for (Player player : serverMap.keySet()) {
REntityServer server = serverMap.get(player);
BundleFilter bundleFilter = bundleFilterMap.get(player);
ViewFlag[] viewFlags = viewFlagMap.get(player);
@ -108,36 +109,39 @@ public class Trace {
}
}
/** Internal methode to make records immutable after recording is finished
/**
* Internal methode to make records immutable after recording is finished
*
* @param records immutable records list
*/
protected void setRecords(List<TNTRecord> records){
protected void setRecords(List<TNTRecord> records) {
this.records = records;
}
/** Gets the historys of all tnts in this trace
/**
* Gets the historys of all tnts in this trace
*
* @return the historys of this trace
*/
public Set<List<TNTRecord>> getHistories() {
Set<List<TNTRecord>> histories = new HashSet<>();
for(TNTRecord record: records) {
for (TNTRecord record : records) {
histories.add(record.getHistory());
}
return histories;
}
/** Renders this traces
/**
* Renders this traces
*
* @param player The player the trace is rendered to
* @param flags Flags modefieing the rendering
* @param bundleFilter Filter to determin bundeling of records
*/
public void render(Player player, ViewFlag[] flags, BundleFilter bundleFilter){
if(serverMap.containsKey(player)){
public void render(Player player, ViewFlag[] flags, BundleFilter bundleFilter) {
if (serverMap.containsKey(player)) {
REntityServer server = serverMap.get(player);
server.close();
@ -156,15 +160,16 @@ public class Trace {
render(server, records, flags, 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 flags Flags modefieing the rendering
* @param bundleFilter Filter to determin bundeling of records
*/
private void render(REntityServer server, List<TNTRecord> records, ViewFlag[] flags, BundleFilter bundleFilter){
if(records.size() == 0) return;
private void render(REntityServer server, List<TNTRecord> records, ViewFlag[] flags, BundleFilter bundleFilter) {
if (records.isEmpty()) return;
List<TNTRecord> workingRecords = records;
@ -184,7 +189,7 @@ public class Trace {
});
//Apply filters
for(ViewFlag flag : flagList) {
for (ViewFlag flag : flagList) {
workingRecords = flag.filter(workingRecords);
}
@ -194,18 +199,18 @@ public class Trace {
//Render bundled records
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));
}
//Apply modifiers
for(ViewFlag flag : flags) {
for (ViewFlag flag : flags) {
flag.modify(server, entities);
}
server.setCallback(((player, rEntity, entityAction) -> {
for(TraceEntity entity: entities){
if(((TraceEntity) rEntity).equals(entity)){
for (TraceEntity entity : entities) {
if (rEntity.equals(entity)) {
entity.printIntoChat(player);
return;
}
@ -213,23 +218,24 @@ public class Trace {
}));
}
/** Bundles the passed TNTRecords based on whether they are at the same location
/**
* Bundles the passed TNTRecords based on whether they are at the same location
*
* @param records The TNTRecords that are supposed to be bundled
* @return A list of bundles
*/
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter){
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter) {
List<List<TNTRecord>> bundles = new ArrayList<>();
recordsLoop:
for (TNTRecord record : records) {
if(bundles.isEmpty()){
if (bundles.isEmpty()) {
List<TNTRecord> firstBundle = new ArrayList<>();
firstBundle.add(record);
bundles.add(firstBundle);
}
for(int i = bundles.size() - 1; i >= 0; i--){
for (int i = bundles.size() - 1; i >= 0; i--) {
List<TNTRecord> bundle = bundles.get(i);
Boolean filterResult = filter.function.apply(record, bundle.get(0));
@ -248,15 +254,16 @@ public class Trace {
}
/** Modifies the render for the given player, to only show tnts at the given time interval
/**
* 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){
public void renderAt(Player player, int from, int to) {
ViewFlag[] viewFlags = viewFlagMap.get(player);
if(viewFlags == null) return;
if (viewFlags == null) return;
AtFlag atFlag = null;
atFlag = Stream.of(viewFlags)
@ -265,10 +272,9 @@ public class Trace {
.findFirst()
.orElse(null);
if(atFlag != null){
if (atFlag != null) {
atFlag.update(from, to);
}
else {
} else {
atFlag = new AtFlag(from, to);
viewFlags = Arrays.copyOf(viewFlags, viewFlags.length + 1);
viewFlags[viewFlags.length - 1] = atFlag;
@ -277,16 +283,17 @@ public class Trace {
render(player, viewFlags, BundleFilter.STRICT);
}
/** Toggles the isolated render for the given records and player
/**
* 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){
public void isolate(Player player, TNTRecord... records) {
IsolateFlag isolationFlag = null;
ViewFlag[] viewFlags = viewFlagMap.get(player);
if(viewFlags != null) {
if (viewFlags != null) {
isolationFlag = Stream.of(viewFlags)
.filter(IsolateFlag.class::isInstance)
.map(IsolateFlag.class::cast)
@ -302,46 +309,50 @@ public class Trace {
}
viewFlags[0] = isolationFlag;
for(TNTRecord record: records)
for (TNTRecord record : records) {
isolationFlag.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
*
* @param player
* @param toFollow
*/
public void follow(Player player, Player toFollow){
for(REntityServer server :serverMap.values()){
public void follow(Player player, Player toFollow) {
for (REntityServer server : serverMap.values()) {
server.removePlayer(player);
}
serverMap.get(toFollow).addPlayer(player);
}
/** Makes the passed player stop following any other players trace render
/**
* Makes the passed player stop following any other players trace render
*
* @param player
*/
public void unfollow(Player player){
for(REntityServer server :serverMap.values()){
public void unfollow(Player player) {
for (REntityServer server : serverMap.values()) {
server.removePlayer(player);
}
if(serverMap.get(player) != null){
if (serverMap.get(player) != null) {
serverMap.get(player).addPlayer(player);
}
}
/** Hides this trail for the given player
/**
* Hides this trail for the given player
*
* @param player
*/
public void hide(Player player){
public void hide(Player player) {
REntityServer server = serverMap.get(player);
if(server == null) return;
if (server == null) return;
bundleFilterMap.remove(player);
viewFlagMap.remove(player);

Datei anzeigen

@ -21,21 +21,19 @@ package de.steamwar.bausystem.features.tracer;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import de.steamwar.bausystem.features.tracer.rendering.dynamicFlags.IsolateFlag;
import de.steamwar.bausystem.region.Region;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.entity.REntityServer;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -46,96 +44,96 @@ public class TraceCommand extends SWCommand {
public Recorder recorder;
@LinkedInstance
public TraceManager manager;
public TraceCommand(){super("trace", "trail");}
public TraceCommand() {
super("trace", "trail");
}
@Register(value = "start", description = "TRACE_COMMAND_HELP_START")
public void start(Player player){
public void start(@Validator Player player) {
Region region = Region.getRegion(player.getLocation());
recorder.startRecording(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_START", player);
}
@Register(value = "stop", description = "TRACE_COMMAND_HELP_STOP")
public void stop(Player player){
public void stop(@Validator Player player) {
Region region = Region.getRegion(player.getLocation());
recorder.stopRecording(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player);
}
@Register(value = "auto", description = "TRACE_COMMAND_HELP_SHOW")
public void auto (Player player) {
public void auto(@Validator Player player) {
Region region = Region.getRegion(player.getLocation());
recorder.toggleAutoTrace(region);
}
@Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW")
public void show(Player player, @OptionalValue("STRICT") BundleFilter filter, ViewFlag... flags){
public void show(@Validator Player player, @OptionalValue("STRICT") BundleFilter filter, ViewFlag... flags) {
manager.show(player, flags, filter);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", player);
}
@Register(value = "hide", description = "TRACE_COMMAND_HELP_SHOW")
public void hide(Player player){
public void hide(@Validator Player player) {
manager.hide(player);
BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", player);
}
@Register(value = "delete", description = "TRACE_COMMAND_HELP_SHOW")
public void delete(Player player){
public void delete(@Validator Player player) {
manager.clear();
}
@Register(value = "delete", description = "TRACE_COMMAND_HELP_SHOW")
public void delete(Player player, int id){
public void delete(@Validator Player player, int id) {
manager.remove(id);
}
@Register(value = "isolate", description = "TRACE_COMMAND_HELP_SHOW")
public void isolate(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);
}
@Register(value="at", description = "TRACE_COMMAND_HELP_SHOW")
public void at(Player player, int start, int end){
for(Trace trace: manager.getAll()){
@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")
public void share(Player player){
@Register(value = "share", description = "TRACE_COMMAND_HELP_SHOW")
public void share(@Validator Player player) {
//TODO Rücksprache
}
@Register(value="follow", description = "TRACE_COMMAND_HELP_SHOW")
public void follow(Player player, Player toFollow){
for(Trace trace: manager.getAll()){
@Register(value = "follow", description = "TRACE_COMMAND_HELP_SHOW")
public void follow(@Validator Player player, Player toFollow) {
for (Trace trace : manager.getAll()) {
trace.follow(player, toFollow);
}
}
@Register(value="unfollow", description = "TRACE_COMMAND_HELP_SHOW")
public void unfollow(Player player){
for(Trace trace: manager.getAll()){
@Register(value = "unfollow", description = "TRACE_COMMAND_HELP_SHOW")
public void unfollow(@Validator Player player) {
for (Trace trace : manager.getAll()) {
trace.unfollow(player);
}
}
@ClassMapper(value = Trace.class, local = true)
public TypeMapper<Trace> traceClassMapper(){
return new TypeMapper<Trace>() {
public TypeMapper<Trace> traceClassMapper() {
return new TypeMapper<>() {
@Override
public Trace map(CommandSender commandSender, String[] previousArguments, String s) {
int id = Integer.parseInt(s);
Optional<Trace> trace = manager.get(id);
return trace.orElse(null);
return manager.get(Integer.parseInt(s)).orElse(null);
}
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
return manager.getAllIds().stream()
.map(id -> id.toString())
.map(Object::toString)
.collect(Collectors.toList());
}
};
@ -143,14 +141,13 @@ public class TraceCommand extends SWCommand {
@ClassMapper(value = TNTRecord.class, local = true)
public TypeMapper<TNTRecord> recordMapper() {
return new TypeMapper<TNTRecord>() {
return new TypeMapper<>() {
@Override
public TNTRecord map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
Trace trace = previousArguments.getFirst(Trace.class).orElse(null);
if(trace == null) return null;
if (trace == null) return null;
int id = Integer.parseInt(s);
return trace.getRecords().stream()
.filter(record -> record.getTntId() == id)
.findFirst()
@ -161,8 +158,7 @@ public class TraceCommand extends SWCommand {
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
Trace trace = previousArguments.getFirst(Trace.class).orElse(null);
if(trace == null) return null;
if (trace == null) return null;
return trace.getUsedIds();
}
};
@ -170,20 +166,22 @@ public class TraceCommand extends SWCommand {
@ClassMapper(value = BundleFilter.class, local = true)
public TypeMapper<BundleFilter> bundleFilterClassMapper() {
return new TypeMapper<BundleFilter>() {
return new TypeMapper<>() {
@Override
public BundleFilter map(CommandSender commandSender, String[] previousArguments, String s) {
for(BundleFilter filter: BundleFilter.values()) {
if (s.equals(filter.toString()))
for (BundleFilter filter : BundleFilter.values()) {
if (s.equals(filter.toString())) {
return filter;
}
}
return null;
}
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
if(s.length() == 0)
if (s.length() == 0) {
return new ArrayList<>();
}
return Arrays.stream(BundleFilter.values())
.map(Enum::toString)
@ -193,20 +191,24 @@ public class TraceCommand extends SWCommand {
}
@ClassMapper(value = ViewFlag.class, local = true)
public TypeMapper<ViewFlag> viewFlagClassMapper () {
public TypeMapper<ViewFlag> viewFlagClassMapper() {
return new TypeMapper<ViewFlag>() {
@Override
public ViewFlag map(CommandSender commandSender, String[] previousArguments, String s) {
for(ViewFlag flag: ViewFlag.flags) {
if (s.equals("--" + flag.name))
for (ViewFlag flag : ViewFlag.flags) {
if (s.equals("--" + flag.name)) {
return flag;
}
for(String alias: flag.aliases)
if (s.equals("-" + alias))
for (String alias : flag.aliases) {
if (s.equals("-" + alias)) {
return flag;
}
}
}
return null;
}
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
return ViewFlag.flags.stream()

Datei anzeigen

@ -24,9 +24,7 @@ import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import de.steamwar.bausystem.region.Region;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.*;
import java.util.stream.Collectors;
@ -53,79 +51,92 @@ public class TraceManager implements Listener {
*/
private int nextOpenId = 0;
/** Adds a new trace to the global record
/**
* Adds a new trace to the global record
*
* @param trace Trace to be added
* @return id of the created trace
*/
protected int add(Trace trace){
for(Player player: viewFlagMap.keySet())
protected int add(Trace trace) {
for (Player player : viewFlagMap.keySet()) {
trace.render(player, viewFlagMap.get(player), bundleFilterMap.get(player));
}
traces.put(nextOpenId, trace);
nextOpenId++;
return nextOpenId;
}
/** Removes the trace with the given id
/**
* Removes the trace with the given id
*
* @param id id of the trace to be removed
*/
public boolean remove(int id){
if(id >= nextOpenId) return false;
if(traces.get(id) == null) return false;
for(Player player: viewFlagMap.keySet())
public boolean remove(int id) {
if (id >= nextOpenId) return false;
if (traces.get(id) == null) return false;
for (Player player : viewFlagMap.keySet()) {
traces.get(id).hide(player);
}
traces.remove(id);
return true;
}
/** Clears all traces
*
/**
* Clears all traces
*/
public void clear(){
for (Player player: viewFlagMap.keySet())
for(Trace trace: traces.values())
public void clear() {
for (Player player : viewFlagMap.keySet()) {
for (Trace trace : traces.values()) {
trace.hide(player);
}
}
traces.clear();
nextOpenId = 0;
}
/** Methode to get all traces in a certain region
/**
* Methode to get all traces in a certain region
*
* @param region Region to look for traces in
* @return All traces recorded in the given Region
*/
public Set<Trace> get(Region region){
public Set<Trace> get(Region region) {
return traces.values().stream()
.filter((Trace trace) -> trace.getRegion() == region)
.collect(Collectors.toSet());
}
/** Methode to get the trace with specific id
/**
* Methode to get the trace with specific id
*
* @param index index of the trace
* @return the trace with given id or null if no trace with id is found
*/
public Optional<Trace> get(int index){
if(index < traces.size())
public Optional<Trace> get(int index) {
if (index < traces.size()) {
return Optional.of(traces.get(index));
}
return Optional.empty();
}
/** Methode to get all traces
/**
* Methode to get all traces
*
* @return fresh list of all current traces
*/
public List<Trace> getAll(){
public List<Trace> getAll() {
return new ArrayList<>(traces.values());
}
/**
* @return all ids of active traces
*/
public Set<Integer> getAllIds(){return traces.keySet();}
public Set<Integer> getAllIds() {
return traces.keySet();
}
/** Toggles trace show on for player
/**
* Toggles trace show on for player
*
* @param player
* @param viewFlags
@ -135,17 +146,20 @@ public class TraceManager implements Listener {
viewFlagMap.put(player, viewFlags);
bundleFilterMap.put(player, bundleFilter);
for(Trace trace: traces.values())
for (Trace trace : traces.values()) {
trace.render(player, viewFlags, bundleFilter);
}
}
/** Toggles trace show of for player
/**
* Toggles trace show of for player
*
* @param player
*/
public void hide(Player player){
for(Trace trace: traces.values())
public void hide(Player player) {
for (Trace trace : traces.values()) {
trace.hide(player);
}
viewFlagMap.remove(player);
bundleFilterMap.remove(player);

Datei anzeigen

@ -27,9 +27,6 @@ import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityInteractEvent;
import java.util.List;
@ -47,7 +44,7 @@ public class TraceEntity extends RFallingBlockEntity {
this.records = records;
}
public void printIntoChat(Player player){
public void printIntoChat(Player player) {
TNTRecord representative = records.get(0);
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player);
@ -62,9 +59,8 @@ public class TraceEntity extends RFallingBlockEntity {
@Override
public boolean equals(Object object) {
if(!(object instanceof TraceEntity)) return false;
if (!(object instanceof TraceEntity)) return false;
TraceEntity entity = (TraceEntity) object;
return records.get(0).equals(entity.getRecords().get(0));
}
}

Datei anzeigen

@ -43,16 +43,13 @@ public abstract class ViewFlag {
*/
public static final List<ViewFlag> inverseFlags = new ArrayList<>();
public static ViewFlag EXPLOSION = new ViewFlag(true, false,"explosion", "e") {
public static ViewFlag EXPLOSION = new ViewFlag(true, false, "explosion", "e") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
return records.stream()
.filter(TNTRecord::isExplosion)
.collect(Collectors.toList());
}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {}
};
public static ViewFlag IGNITE = new ViewFlag(true, true, "ignite", "i") {
@ -62,9 +59,6 @@ public abstract class ViewFlag {
.filter(record -> !record.isAfterFirstExplosion())
.collect(Collectors.toList());
}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {}
};
public static ViewFlag SOURCE = new ViewFlag(true, false, IGNITE, "source", "s") {
@ -74,9 +68,6 @@ public abstract class ViewFlag {
.filter(record -> record.getFuse() == 80)
.collect(Collectors.toList());
}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {}
};
public static ViewFlag BUILD_DESTROY_ONLY = new ViewFlag(true, false, "build-destroy-only") {
@ -86,9 +77,6 @@ public abstract class ViewFlag {
.filter(record -> record.getHistory().get(record.getHistory().size() - 1).isDestroyedBuildArea())
.collect(Collectors.toList());
}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {}
};
public static ViewFlag TESTBLOCK_DESTROY_ONLY = new ViewFlag(true, false, "testblock-destroy-only") {
@ -98,9 +86,6 @@ public abstract class ViewFlag {
.filter(record -> record.getHistory().get(record.getHistory().size() - 1).isDestroyedTestBlock())
.collect(Collectors.toList());
}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {}
};
public static ViewFlag MICROMOTION = new ViewFlag(true, false, "micromotion", "m") {
@ -109,44 +94,38 @@ public abstract class ViewFlag {
Set<Integer> seen = new HashSet<>();
Set<TNTRecord> toRemove = new HashSet<>();
for(TNTRecord uniqueRecord: records){
if(seen.contains(uniqueRecord.getTntId())) continue;
for (TNTRecord uniqueRecord : records) {
if (seen.contains(uniqueRecord.getTntId())) continue;
boolean hasMicromotion = false;
for(TNTRecord record: uniqueRecord.getHistory()){
for (TNTRecord record : uniqueRecord.getHistory()) {
Vector velocity = record.getVelocity();
if(velocity.getY() == 0 && (Math.abs(velocity.getX()) < 0.001 || Math.abs(velocity.getZ()) < 0.001)){
if (velocity.getY() == 0 && (Math.abs(velocity.getX()) < 0.001 || Math.abs(velocity.getZ()) < 0.001)) {
hasMicromotion = true;
break;
}
}
if(!hasMicromotion)
if (!hasMicromotion)
toRemove.add(uniqueRecord);
seen.add(uniqueRecord.getTntId());
}
for(TNTRecord record: toRemove){
for (TNTRecord record : toRemove) {
records.removeAll(record.getHistory());
}
return records;
}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {}
};
public static ViewFlag ADVANCED = new ViewFlag(true, false, "advanced", "a") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {return records;}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {
for(TraceEntity entity: entities) {
for (TraceEntity entity : entities) {
TNTRecord current = entity.getRecords().get(0);
if(current.isExplosion()) continue;
if (current.isExplosion()) continue;
TNTRecord next = current.getNext().orElse(null);
if (next == null) continue;
@ -172,36 +151,27 @@ public abstract class ViewFlag {
};
public static ViewFlag COUNT = new ViewFlag(true, false, "count", "c") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) { return records; }
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {
for(TraceEntity entity: entities){
for (TraceEntity entity : entities) {
entity.setDisplayName(String.valueOf(entity.getRecords().size()));
}
}
};
public static ViewFlag FUSE = new ViewFlag(true, false, "fuse", "f") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) { return records; }
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {
for(TraceEntity entity: entities){
for (TraceEntity entity : entities) {
entity.setDisplayName(String.valueOf(entity.getRecords().get(0).getFuse()));
}
}
};
public static ViewFlag TIME = new ViewFlag(true, false, "time", "t") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) { return records; }
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {
for(TraceEntity entity: entities){
for (TraceEntity entity : entities) {
entity.setDisplayName(String.valueOf(entity.getRecords().get(0).getTicksSinceStart()));
}
}
@ -222,33 +192,38 @@ public abstract class ViewFlag {
*/
public final ViewFlag[] required;
public ViewFlag(boolean isStatic, boolean isInverse, String name, String... aliases) {
protected ViewFlag(boolean isStatic, boolean isInverse, String name, String... aliases) {
this(isStatic, isInverse, new ViewFlag[0], name, aliases);
}
public ViewFlag(boolean isStatic, boolean isInverse, ViewFlag required, String name, String... aliases) {
this(isStatic, isInverse, new ViewFlag[] { required }, name, aliases);
protected ViewFlag(boolean isStatic, boolean isInverse, ViewFlag required, String name, String... aliases) {
this(isStatic, isInverse, new ViewFlag[]{required}, name, aliases);
}
public ViewFlag(boolean isStatic, boolean isInverse, ViewFlag[] required, String name, String... aliases){
protected ViewFlag(boolean isStatic, boolean isInverse, ViewFlag[] required, String name, String... aliases) {
this.name = name;
this.aliases = aliases;
if(isStatic) flags.add(this);
if(isInverse) inverseFlags.add(this);
if (isStatic) flags.add(this);
if (isInverse) inverseFlags.add(this);
this.required = required;
}
/** Filters the given records for a given condition
/**
* Filters the given records for a given condition
*
* @param records Records to be filtered
* @return Filtered records
*/
public abstract List<TNTRecord> filter (List<TNTRecord> records);
public List<TNTRecord> filter(List<TNTRecord> records) {
return records;
}
/** Modifies the trace rendering
/**
* Modifies the trace rendering
*
* @param server the server the trace is rendered on
* @param entities the entities representing tnts
*/
public abstract void modify (REntityServer server, List<TraceEntity> entities);
public void modify(REntityServer server, List<TraceEntity> entities) {
}
}

Datei anzeigen

@ -17,12 +17,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.tracer.rendering.dynamicFlags;
package de.steamwar.bausystem.features.tracer.rendering.dynamicflags;
import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import de.steamwar.entity.REntityServer;
import java.util.List;
import java.util.stream.Collectors;
@ -31,19 +29,19 @@ public class AtFlag extends ViewFlag {
private int start;
private int end;
public AtFlag(int start, int end){
public AtFlag(int start, int end) {
super(false, false, ViewFlag.IGNITE, null);
this.start = start;
this.end = end;
}
/** Update this flag to represent another time interval
/**
* Update this flag to represent another time interval
*
* @param start new interval start
* @param end new interval end
*/
public void update(int start, int end){
public void update(int start, int end) {
this.start = start;
this.end = end;
}
@ -54,7 +52,4 @@ public class AtFlag extends ViewFlag {
.filter(record -> record.getTicksSinceStart() <= start && record.getTicksSinceStart() >= end)
.collect(Collectors.toList());
}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {}
}

Datei anzeigen

@ -17,14 +17,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.tracer.rendering.dynamicFlags;
package de.steamwar.bausystem.features.tracer.rendering.dynamicflags;
import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import de.steamwar.entity.REntityServer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -37,15 +34,16 @@ public class IsolateFlag extends ViewFlag {
*/
private final Set<Integer> tntToIsolate = new HashSet<>();
public IsolateFlag(){
public IsolateFlag() {
super(false, false, ViewFlag.IGNITE, null);
}
/**
* Toggles the given id to be or not to be rendered
*
* @param id
*/
public void toggleId(int id){
public void toggleId(int id) {
if (!tntToIsolate.remove(id)) {
tntToIsolate.add(id);
}
@ -57,7 +55,4 @@ public class IsolateFlag extends ViewFlag {
.filter(record -> tntToIsolate.contains(record.getTntId()))
.collect(Collectors.toList());
}
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {}
}