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
4 geänderte Dateien mit 58 neuen und 59 gelöschten Zeilen
Nur Änderungen aus Commit c0dcb99f7b werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -160,7 +160,7 @@ public class Trace {
* @param flags Flags modefieing the rendering * @param flags Flags modefieing the rendering
* @param bundleFilter Filter to determin bundeling of records * @param bundleFilter Filter to determin bundeling of records
*/ */
private void render (REntityServer server, List<TNTRecord> records, ViewFlag[] flags, BundleFilter bundleFilter){ private void render(REntityServer server, List<TNTRecord> records, ViewFlag[] flags, BundleFilter bundleFilter){
if(records.size() == 0) return; if(records.size() == 0) return;
List<TNTRecord> workingRecords = records; List<TNTRecord> workingRecords = records;
@ -181,8 +181,9 @@ public class Trace {
}); });
//Apply filters //Apply filters
for(ViewFlag flag : flagList) for(ViewFlag flag : flagList) {
workingRecords = flag.filter(workingRecords); workingRecords = flag.filter(workingRecords);
}
//Bundle records at unique positions //Bundle records at unique positions
List<List<TNTRecord>> bundles = bundleRecords(workingRecords, bundleFilter); List<List<TNTRecord>> bundles = bundleRecords(workingRecords, bundleFilter);
@ -190,12 +191,14 @@ public class Trace {
//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(server, bundle.get(0).getLocation(), bundle.get(0).isExplosion(), bundle));
}
//Apply modifiers //Apply modifiers
for(ViewFlag flag : flags) for(ViewFlag flag : flags) {
flag.modify(server, entities); flag.modify(server, entities);
}
} }
/** 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

Datei anzeigen

@ -37,6 +37,7 @@ import org.bukkit.entity.Player;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
@Linked @Linked
public class TraceCommand extends SWCommand { public class TraceCommand extends SWCommand {
@ -119,7 +120,7 @@ public class TraceCommand extends SWCommand {
@ClassMapper(value = Trace.class, local = true) @ClassMapper(value = Trace.class, local = true)
public TypeMapper<Trace> traceClassMapper(){ public TypeMapper<Trace> traceClassMapper(){
return new TypeMapper<Trace>() { return new TypeMapper<Trace>() {
@Override @Override
public Trace map(CommandSender commandSender, String[] previousArguments, String s) { public Trace map(CommandSender commandSender, String[] previousArguments, String s) {
int id = Integer.parseInt(s); int id = Integer.parseInt(s);
@ -199,7 +200,7 @@ public class TraceCommand extends SWCommand {
return flag; return flag;
for(String alias: flag.aliases) for(String alias: flag.aliases)
if (s.equals("--" + alias)) if (s.equals("-" + alias))
return flag; return flag;
} }
return null; return null;
@ -207,8 +208,8 @@ public class TraceCommand extends SWCommand {
@Override @Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
return ViewFlag.flags.stream() return ViewFlag.flags.stream()
.map(flag -> flag.name) .flatMap(viewFlag -> Stream.concat(Stream.of("--" + viewFlag.name),
.map(name -> "--" + name) Arrays.stream(viewFlag.aliases).map(name -> "-" + name)))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
}; };

Datei anzeigen

@ -20,17 +20,16 @@
package de.steamwar.bausystem.features.tracer.rendering; package de.steamwar.bausystem.features.tracer.rendering;
import de.steamwar.bausystem.features.tracer.TNTRecord; import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer; import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.entity.RFallingBlockEntity;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.*; import java.util.ArrayList;
import java.util.function.BiConsumer; import java.util.HashSet;
import java.util.function.UnaryOperator; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public abstract class ViewFlag { public abstract class ViewFlag {
@ -44,7 +43,7 @@ public abstract class ViewFlag {
*/ */
public static final List<ViewFlag> inverseFlags = new ArrayList<>(); public static final List<ViewFlag> inverseFlags = new ArrayList<>();
public static ViewFlag EXPLOSION = new ViewFlag(true, false,"explosion") { public static ViewFlag EXPLOSION = new ViewFlag(true, false,"explosion", "e") {
@Override @Override
public List<TNTRecord> filter(List<TNTRecord> records) { public List<TNTRecord> filter(List<TNTRecord> records) {
return records.stream() return records.stream()
@ -56,7 +55,7 @@ public abstract class ViewFlag {
public void modify(REntityServer server, List<TraceEntity> entities) {} public void modify(REntityServer server, List<TraceEntity> entities) {}
}; };
public static ViewFlag IGNITE = new ViewFlag(true, true, "ignite") { public static ViewFlag IGNITE = new ViewFlag(true, true, "ignite", "i") {
@Override @Override
public List<TNTRecord> filter(List<TNTRecord> records) { public List<TNTRecord> filter(List<TNTRecord> records) {
return records.stream() return records.stream()
@ -68,7 +67,7 @@ public abstract class ViewFlag {
public void modify(REntityServer server, List<TraceEntity> entities) {} public void modify(REntityServer server, List<TraceEntity> entities) {}
}; };
public static ViewFlag SOURCE = new ViewFlag(true, false, IGNITE, "source") { public static ViewFlag SOURCE = new ViewFlag(true, false, IGNITE, "source", "s") {
@Override @Override
public List<TNTRecord> filter(List<TNTRecord> records) { public List<TNTRecord> filter(List<TNTRecord> records) {
return records.stream() return records.stream()
@ -148,32 +147,33 @@ public abstract class ViewFlag {
@Override @Override
public void modify(REntityServer server, List<TraceEntity> entities) { public void modify(REntityServer server, List<TraceEntity> entities) {
for(TraceEntity entity: entities) { for(TraceEntity entity: entities) {
TNTRecord representaitv = entity.getRecords().get(0); TNTRecord current = entity.getRecords().get(0);
if(current.isExplosion()) continue;
TNTRecord next = current.getNext().orElse(null);
if (next == null) continue;
if(representaitv.isExplosion()) continue; Location pos = current.getLocation().clone();
pos.setY(next.getLocation().getY());
Location pos = representaitv.getLocation(); if (pos.distanceSquared(current.getLocation()) >= 1.0 / 256.0) {
RFallingBlockEntity y = new RFallingBlockEntity(server, pos, Material.WHITE_STAINED_GLASS);
y.setNoGravity(true);
}
double xVelocity = representaitv.getVelocity().getX(); if (current.getVelocity().getX() >= current.getVelocity().getZ()) {
double yVelocity = representaitv.getVelocity().getY(); pos.setX(next.getLocation().getX());
double zVelocity = representaitv.getVelocity().getZ(); } else {
pos.setZ(next.getLocation().getZ());
pos = pos.add(0,yVelocity,0); }
RFallingBlockEntity y = new RFallingBlockEntity(server, pos, Material.WHITE_STAINED_GLASS); if (pos.distanceSquared(next.getLocation()) >= 1.0 / 256.0) {
y.setNoGravity(true); RFallingBlockEntity second = new RFallingBlockEntity(server, pos, Material.WHITE_STAINED_GLASS);
second.setNoGravity(true);
if(xVelocity >= zVelocity) }
pos.add(xVelocity, 0, 0);
else
pos.add(0,0,zVelocity);
RFallingBlockEntity secound = new RFallingBlockEntity(server, pos, Material.WHITE_STAINED_GLASS);
secound.setNoGravity(true);
} }
} }
}; };
public static ViewFlag COUNT = new ViewFlag(true, false, "count") { public static ViewFlag COUNT = new ViewFlag(true, false, "count", "c") {
@Override @Override
public List<TNTRecord> filter(List<TNTRecord> records) { return records; } public List<TNTRecord> filter(List<TNTRecord> records) { return records; }
@ -185,7 +185,7 @@ public abstract class ViewFlag {
} }
}; };
public static ViewFlag FUSE = new ViewFlag(true, false, "fuse") { public static ViewFlag FUSE = new ViewFlag(true, false, "fuse", "f") {
@Override @Override
public List<TNTRecord> filter(List<TNTRecord> records) { return records; } public List<TNTRecord> filter(List<TNTRecord> records) { return records; }
@ -197,7 +197,7 @@ public abstract class ViewFlag {
} }
}; };
public static ViewFlag TIME = new ViewFlag(true, false, "time") { public static ViewFlag TIME = new ViewFlag(true, false, "time", "t") {
@Override @Override
public List<TNTRecord> filter(List<TNTRecord> records) { return records; } public List<TNTRecord> filter(List<TNTRecord> records) { return records; }
@ -222,27 +222,23 @@ public abstract class ViewFlag {
/** /**
* A flag that is used whenever this flag is used * A flag that is used whenever this flag is used
*/ */
public final ViewFlag required; public final ViewFlag[] required;
public ViewFlag(boolean isStatic, boolean isInverse, String name, String... aliases) { public 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);
}
public ViewFlag(boolean isStatic, boolean isInverse, ViewFlag[] required, String name, String... aliases){
this.name = name; this.name = name;
this.aliases = aliases; this.aliases = aliases;
if(isStatic) if(isStatic) flags.add(this);
flags.add(this); if(isInverse) inverseFlags.add(this);
if(isInverse) this.required = required;
inverseFlags.add(this); }
required = null;
}
public 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);
this.required = required;
}
/** Filters the given records for a given condition /** Filters the given records for a given condition
* *

Datei anzeigen

@ -35,7 +35,7 @@ public class IsolateFlag extends ViewFlag {
private final Set<Integer> tntToIsolate = new HashSet<>(); private final Set<Integer> tntToIsolate = new HashSet<>();
public IsolateFlag(){ public IsolateFlag(){
super(false, false, ViewFlag.IGNITE, "isolate"); super(false, false, ViewFlag.IGNITE, null);
} }
/** /**
@ -43,10 +43,9 @@ public class IsolateFlag extends ViewFlag {
* @param id * @param id
*/ */
public void toggleId(int id){ public void toggleId(int id){
if(tntToIsolate.contains(id)) if (!tntToIsolate.remove(id)) {
tntToIsolate.remove(id);
else
tntToIsolate.add(id); tntToIsolate.add(id);
}
} }
@Override @Override