Trace Refactor #233
@ -55,6 +55,12 @@ public class Trace {
|
||||
@Getter
|
||||
private int nextOpenRecordId = -1;
|
||||
|
||||
/**
|
||||
* List of all used ids
|
||||
*/
|
||||
@Getter
|
||||
private final List<String> usedIds = new ArrayList();
|
||||
|
||||
/**
|
||||
* A map of players -> REntityServers for rendering traces to a player
|
||||
*/
|
||||
@ -80,6 +86,7 @@ public class Trace {
|
||||
*/
|
||||
protected int getAndIncrementNextOpenRecordId(){
|
||||
nextOpenRecordId++;
|
||||
usedIds.add(Integer.toString(nextOpenRecordId));
|
||||
return nextOpenRecordId;
|
||||
}
|
||||
|
||||
@ -158,21 +165,20 @@ public class Trace {
|
||||
|
||||
List<TNTRecord> workingRecords = records;
|
||||
|
||||
List<ViewFlag> flagList = new ArrayList<>();
|
||||
|
||||
//Manage required flags
|
||||
for(ViewFlag flag: flags)
|
||||
if(flag.required != null)
|
||||
flagList.add(flag.required);
|
||||
//Manage flags and required flags
|
||||
Set<ViewFlag> flagList = new HashSet<>(Arrays.asList(flags));
|
||||
for (ViewFlag flag : flags) {
|
||||
if (flag.required != null) {
|
||||
flagList.addAll(Arrays.asList(flag.required));
|
||||
}
|
||||
}
|
||||
|
||||
//Manage inverse flags
|
||||
flagList.addAll(ViewFlag.inverseFlags);
|
||||
for(ViewFlag flag: flags){
|
||||
if(flagList.contains(flag))
|
||||
flagList.remove(flag);
|
||||
else
|
||||
flagList.add(flag);
|
||||
}
|
||||
ViewFlag.inverseFlags.forEach(viewFlag -> {
|
||||
if (!flagList.remove(viewFlag)) {
|
||||
flagList.add(viewFlag);
|
||||
}
|
||||
});
|
||||
|
||||
//Apply filters
|
||||
for(ViewFlag flag : flagList)
|
||||
|
@ -94,22 +94,28 @@ public class TraceCommand extends SWCommand {
|
||||
IsolateFlag isolationFlag = null;
|
||||
|
||||
ViewFlag[] viewFlags = trace.getViewFlags(player);
|
||||
if(viewFlags != null)
|
||||
for(ViewFlag flag: viewFlags)
|
||||
if(flag.name.equals("isolate"))
|
||||
isolationFlag = (IsolateFlag) flag;
|
||||
if(viewFlags != null) {
|
||||
isolationFlag = Stream.of(viewFlags)
|
||||
.filter(IsolateFlag.class::isInstance)
|
||||
.map(IsolateFlag.class::cast)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
if(isolationFlag == null)
|
||||
if (viewFlags == null || isolationFlag == null) {
|
||||
viewFlags = new ViewFlag[1];
|
||||
}
|
||||
if (isolationFlag == null) {
|
||||
isolationFlag = new IsolateFlag();
|
||||
}
|
||||
viewFlags[0] = isolationFlag;
|
||||
|
||||
for(TNTRecord record: records)
|
||||
isolationFlag.toggleId(record.getTntId());
|
||||
|
||||
ViewFlag[] flags = new ViewFlag [1];
|
||||
flags[0] = isolationFlag;
|
||||
|
||||
trace.render(player, viewFlags, BundleFilter.STRICT);
|
||||
}
|
||||
//TODO warning if nothing is shown
|
||||
|
||||
@ClassMapper(value = Trace.class, local = true)
|
||||
public TypeMapper<Trace> traceClassMapper(){
|
||||
@ -147,6 +153,15 @@ public class TraceCommand extends SWCommand {
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
//TODO change when new command framework update
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
Trace trace = previousArguments.getFirst(Trace.class).orElse(null);
|
||||
if(trace == null) return null;
|
||||
|
||||
return trace.getUsedIds();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,8 @@ public abstract class ViewFlag {
|
||||
public void modify(REntityServer server, List<TraceEntity> entities) {}
|
||||
};
|
||||
|
||||
public static ViewFlag MICROMOTION = new ViewFlag(true, false, "micromotion") {
|
||||
//TODO fix?
|
||||
public static ViewFlag MICROMOTION = new ViewFlag(true, false, "micromotion", "m") {
|
||||
@Override
|
||||
public List<TNTRecord> filter(List<TNTRecord> records) {
|
||||
Set<Integer> seen = new HashSet<>();
|
||||
@ -139,7 +140,8 @@ public abstract class ViewFlag {
|
||||
public void modify(REntityServer server, List<TraceEntity> entities) {}
|
||||
};
|
||||
|
||||
public static ViewFlag ADVANCED = new ViewFlag(true, false, "advanced") {
|
||||
//TODO fix?
|
||||
public static ViewFlag ADVANCED = new ViewFlag(true, false, "advanced", "a") {
|
||||
@Override
|
||||
public List<TNTRecord> filter(List<TNTRecord> records) {return records;}
|
||||
|
||||
|
@ -25,12 +25,14 @@ 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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IsolateFlag extends ViewFlag {
|
||||
|
||||
private final List<Integer> tntToIsolate = new ArrayList<>();
|
||||
private final Set<Integer> tntToIsolate = new HashSet<>();
|
||||
|
||||
public IsolateFlag(){
|
||||
super(false, false, ViewFlag.IGNITE, "isolate");
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren