SteamWar/BauSystem2.0
Archiviert
12
0

Added proper info print to chat
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Refactored Isolate
Dieser Commit ist enthalten in:
D4rkr34lm 2024-03-26 22:11:08 +01:00
Ursprung c0dcb99f7b
Commit 987a00ae51
5 geänderte Dateien mit 74 neuen und 48 gelöschten Zeilen

Datei anzeigen

@ -136,4 +136,15 @@ public class TNTRecord {
", velocity=" + velocity + ", velocity=" + velocity +
'}'; '}';
} }
@Override
public boolean equals(Object obj) {
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;
return true;
}
} }

Datei anzeigen

@ -23,12 +23,14 @@ import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter; import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity; import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag; 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.bausystem.region.Region;
import de.steamwar.entity.REntityServer; import de.steamwar.entity.REntityServer;
import lombok.Getter; import lombok.Getter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*; import java.util.*;
import java.util.stream.Stream;
public class Trace { public class Trace {
/** /**
@ -199,6 +201,15 @@ public class Trace {
for(ViewFlag flag : flags) { for(ViewFlag flag : flags) {
flag.modify(server, entities); flag.modify(server, entities);
} }
server.setCallback(((player, rEntity, entityAction) -> {
for(TraceEntity entity: entities){
if(((TraceEntity) rEntity).equals(entity)){
entity.printIntoChat(player);
return;
}
}
}));
} }
/** 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
@ -236,6 +247,37 @@ public class Trace {
return bundles; return bundles;
} }
/** 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){
IsolateFlag isolationFlag = null;
ViewFlag[] viewFlags = viewFlagMap.get(player);
if(viewFlags != null) {
isolationFlag = Stream.of(viewFlags)
.filter(IsolateFlag.class::isInstance)
.map(IsolateFlag.class::cast)
.findFirst()
.orElse(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());
render(player, viewFlags, BundleFilter.STRICT);
}
/** Hides this trail for the given player /** Hides this trail for the given player
* *
* @param player * @param player
@ -249,13 +291,6 @@ public class Trace {
server.close(); server.close();
} }
/** Returns the flags used by the given player to render the trace or null if not present
*
* @param player
* @return
*/
protected ViewFlag[] getViewFlags(Player player){return viewFlagMap.get(player);}
@Override @Override
public String toString() { public String toString() {
return "Trace{" + return "Trace{" +

Datei anzeigen

@ -92,29 +92,7 @@ public class TraceCommand extends SWCommand {
@Register(value = "isolate", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "isolate", description = "TRACE_COMMAND_HELP_SHOW")
public void isolate(Player player, Trace trace, @ErrorMessage("test") TNTRecord... records){ public void isolate(Player player, Trace trace, @ErrorMessage("test") TNTRecord... records){
IsolateFlag isolationFlag = null; trace.isolate(player, records);
ViewFlag[] viewFlags = trace.getViewFlags(player);
if(viewFlags != null) {
isolationFlag = Stream.of(viewFlags)
.filter(IsolateFlag.class::isInstance)
.map(IsolateFlag.class::cast)
.findFirst()
.orElse(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());
trace.render(player, viewFlags, BundleFilter.STRICT);
} }
//TODO warning if nothing is shown //TODO warning if nothing is shown

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.entity.RFallingBlockEntity;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityInteractEvent;
@ -44,23 +45,26 @@ public class TraceEntity extends RFallingBlockEntity {
super(server, location, isExplosion ? Material.RED_STAINED_GLASS : Material.TNT); super(server, location, isExplosion ? Material.RED_STAINED_GLASS : Material.TNT);
setNoGravity(true); setNoGravity(true);
this.records = records; this.records = records;
server.setCallback(((player, rEntity, entityAction) -> {
if (entityAction != REntityServer.EntityAction.INTERACT) return;
TNTRecord representative = records.get(0);
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player);
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, representative.getFuse());
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", player, representative.getLocation().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", player, representative.getLocation().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", player, representative.getLocation().getZ() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", player, representative.getVelocity().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", player, representative.getVelocity().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, representative.getVelocity().getZ() + "");
}));
} }
public void printIntoChat(Player player){
TNTRecord representative = records.get(0);
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player);
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, representative.getFuse());
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", player, representative.getLocation().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", player, representative.getLocation().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", player, representative.getLocation().getZ() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", player, representative.getVelocity().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", player, representative.getVelocity().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, representative.getVelocity().getZ() + "");
}
@Override
public boolean equals(Object object) {
if(!(object instanceof TraceEntity)) return false;
TraceEntity entity = (TraceEntity) object;
return records.get(0).equals(entity.getRecords().get(0));
}
} }

Datei anzeigen

@ -103,7 +103,6 @@ public abstract class ViewFlag {
public void modify(REntityServer server, List<TraceEntity> entities) {} public void modify(REntityServer server, List<TraceEntity> entities) {}
}; };
//TODO fix?
public static ViewFlag MICROMOTION = new ViewFlag(true, false, "micromotion", "m") { public static ViewFlag MICROMOTION = new ViewFlag(true, false, "micromotion", "m") {
@Override @Override
public List<TNTRecord> filter(List<TNTRecord> records) { public List<TNTRecord> filter(List<TNTRecord> records) {
@ -139,7 +138,6 @@ public abstract class ViewFlag {
public void modify(REntityServer server, List<TraceEntity> entities) {} public void modify(REntityServer server, List<TraceEntity> entities) {}
}; };
//TODO fix?
public static ViewFlag ADVANCED = new ViewFlag(true, false, "advanced", "a") { public static ViewFlag ADVANCED = new ViewFlag(true, false, "advanced", "a") {
@Override @Override
public List<TNTRecord> filter(List<TNTRecord> records) {return records;} public List<TNTRecord> filter(List<TNTRecord> records) {return records;}