Trace Refactor #233
@ -30,7 +30,6 @@ import de.steamwar.entity.REntityServer;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -222,7 +221,8 @@ public class Trace {
|
||||
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter){
|
||||
List<List<TNTRecord>> bundles = new ArrayList<>();
|
||||
|
||||
recordsLoop : for(TNTRecord record : records) {
|
||||
recordsLoop:
|
||||
for (TNTRecord record : records) {
|
||||
if(bundles.isEmpty()){
|
||||
List<TNTRecord> firstBundle = new ArrayList<>();
|
||||
firstBundle.add(record);
|
||||
@ -232,17 +232,15 @@ public class Trace {
|
||||
for(int i = bundles.size() - 1; i >= 0; i--){
|
||||
List<TNTRecord> bundle = bundles.get(i);
|
||||
|
||||
Optional<Boolean> filterResult = filter.apply.apply(record, bundle.get(0));
|
||||
|
||||
if(filterResult.isPresent() && filterResult.get())
|
||||
bundle.add(record);
|
||||
else{
|
||||
Boolean filterResult = filter.function.apply(record, bundle.get(0));
|
||||
if (filterResult == null || !filterResult) {
|
||||
ArrayList<TNTRecord> newBundle = new ArrayList<>();
|
||||
newBundle.add(record);
|
||||
bundles.add(newBundle);
|
||||
continue recordsLoop;
|
||||
} else {
|
||||
bundle.add(record);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,45 +20,47 @@
|
||||
package de.steamwar.bausystem.features.tracer.rendering;
|
||||
|
||||
import de.steamwar.bausystem.features.tracer.TNTRecord;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum BundleFilter {
|
||||
|
||||
//TODO chagne optional to true flase null
|
||||
LOOSE((TNTRecord a, TNTRecord b) -> {
|
||||
if(a.isExplosion() != b.isExplosion()) return Optional.of(false);
|
||||
if(a.getLocation().distance(b.getLocation()) <= BundleFilter.pixelSize) return Optional.of(false);
|
||||
if(a.getVelocity().distance(b.getVelocity()) <= BundleFilter.pixelSize) return Optional.of(false);
|
||||
return Optional.of(true);
|
||||
if (a.isExplosion() != b.isExplosion()) return false;
|
||||
if (a.getLocation().distanceSquared(b.getLocation()) <= BundleFilter.pixelSizeSquared) return false;
|
||||
if (a.getVelocity().distanceSquared(b.getVelocity()) <= BundleFilter.pixelSizeSquared) return false;
|
||||
return true;
|
||||
}),
|
||||
|
||||
DEFAULT((TNTRecord a, TNTRecord b) -> {
|
||||
if(a.isExplosion() != b.isExplosion()) return Optional.of(false);
|
||||
if(a.getTicksSinceStart() != b.getTicksSinceStart()) return Optional.empty();
|
||||
if(a.getLocation().distance(b.getLocation()) <= BundleFilter.pixelSize) return Optional.of(false);
|
||||
if(a.getVelocity().distance(b.getVelocity()) <= BundleFilter.pixelSize) return Optional.of(false);
|
||||
return Optional.of(true);
|
||||
if (a.isExplosion() != b.isExplosion()) return false;
|
||||
if (a.getTicksSinceStart() != b.getTicksSinceStart()) return null;
|
||||
if (a.getLocation().distanceSquared(b.getLocation()) <= BundleFilter.pixelSizeSquared) return false;
|
||||
if (a.getVelocity().distanceSquared(b.getVelocity()) <= BundleFilter.pixelSizeSquared) return false;
|
||||
return true;
|
||||
}),
|
||||
|
||||
STRICT((TNTRecord a, TNTRecord b) -> {
|
||||
if(a.isExplosion() != b.isExplosion()) return Optional.of(false);
|
||||
if(!a.getLocation().equals(b.getLocation())) return Optional.of(false);
|
||||
if(!a.getVelocity().equals(b.getVelocity())) return Optional.of(false);
|
||||
if(a.getTicksSinceStart() != b.getTicksSinceStart()) return Optional.empty();
|
||||
return Optional.of(true);
|
||||
if (a.isExplosion() != b.isExplosion()) return false;
|
||||
if (!a.getLocation().equals(b.getLocation())) return false;
|
||||
if (!a.getVelocity().equals(b.getVelocity())) return false;
|
||||
if (a.getTicksSinceStart() != b.getTicksSinceStart()) return null;
|
||||
return true;
|
||||
}),
|
||||
|
||||
NONE((TNTRecord a, TNTRecord b) -> {
|
||||
return Optional.empty();
|
||||
return null;
|
||||
});
|
||||
|
||||
public BiFunction<TNTRecord, TNTRecord, Optional<Boolean>> apply;
|
||||
/**
|
||||
* {@code null}: Bundling can be stopped from this point forward
|
||||
* {@code false}: No bundling allowed
|
||||
* {@code true}: Bundling should be applied
|
||||
*/
|
||||
public final BiFunction<TNTRecord, TNTRecord, Boolean> function;
|
||||
|
||||
private static final double pixelSize = 0.0625;
|
||||
|
||||
BundleFilter(BiFunction<TNTRecord, TNTRecord, Optional<Boolean>> apply){
|
||||
this.apply = apply;
|
||||
}
|
||||
private static final double pixelSizeSquared = pixelSize * pixelSize;
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren