SteamWar/BauSystem2.0
Archiviert
12
0

Trace Refactor #233

Zusammengeführt
YoyoNow hat 121 Commits von TracerGUI nach master 2024-04-21 16:03:26 +02:00 zusammengeführt
2 geänderte Dateien mit 28 neuen und 15 gelöschten Zeilen
Nur Änderungen aus Commit c03fbb65e6 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -101,18 +101,22 @@ public class TraceCommand extends SWCommand {
return new TypeMapper<ViewFlag>() { return new TypeMapper<ViewFlag>() {
@Override @Override
public ViewFlag map(CommandSender commandSender, String[] previousArguments, String s) { public ViewFlag map(CommandSender commandSender, String[] previousArguments, String s) {
for(ViewFlag filter: ViewFlag.values()) { for(ViewFlag flag: ViewFlag.flags) {
if (s.equals("--" + filter.toString().toLowerCase())) if (s.equals("--" + flag.name))
return filter; return flag;
for(String alias: flag.aliases)
if (s.equals("--" + alias))
return flag;
} }
return null; return null;
} }
@Override @Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
return Arrays.stream(ViewFlag.values()) return ViewFlag.flags.stream()
.map(Enum::toString) .map(viewFlag -> viewFlag.name)
.map(string -> "--" + string.toLowerCase()) .map(name -> "--" + name)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
}; };

Datei anzeigen

@ -28,14 +28,7 @@ import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
public enum ViewFlag { public abstract class ViewFlag {
EXPLOSION((List<TNTRecord> records) ->{
List<TNTRecord> ret = new ArrayList<>();
for(TNTRecord record : records)
if(record.isExplosion())
ret.add(record);
return ret;
}, (REntityServer server , List<TraceEntity> entities) -> {});
/** /**
* The filtering part of the flag * The filtering part of the flag
@ -47,8 +40,24 @@ public enum ViewFlag {
*/ */
public final BiConsumer<REntityServer, List<TraceEntity>> modify; public final BiConsumer<REntityServer, List<TraceEntity>> modify;
ViewFlag(UnaryOperator<List<TNTRecord>> filter, BiConsumer<REntityServer,List<TraceEntity>> modify) { /**
* Name of the flag
*/
public final String name;
/**
* Aliases of the flag
*/
public final String[] aliases;
public static final List<ViewFlag> flags = new ArrayList<>();
public ViewFlag(UnaryOperator<List<TNTRecord>> filter, BiConsumer<REntityServer,List<TraceEntity>> modify, boolean isStatic, String name, String... aliases) {
this.filter = filter; this.filter = filter;
this.modify = modify; this.modify = modify;
this.name = name;
this.aliases = aliases;
if(isStatic)
flags.add(this);
} }
} }