Add chunk skipping optimisation

This commit is contained in:
D4rkr34lm
2026-05-21 20:20:18 +02:00
parent 108aa2af9a
commit bede8caa82
2 changed files with 17 additions and 1 deletions
@@ -22,6 +22,7 @@ package de.steamwar.fightsystem.utils;
import de.steamwar.Reflection; import de.steamwar.Reflection;
import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.core.CraftbukkitWrapper;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.events.BoardingEvent; import de.steamwar.fightsystem.events.BoardingEvent;
import de.steamwar.fightsystem.events.TeamLeaveEvent; import de.steamwar.fightsystem.events.TeamLeaveEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent; import de.steamwar.fightsystem.events.TeamSpawnEvent;
@@ -107,6 +108,11 @@ public class TechHiderWrapper extends StateDependent implements Listener {
Region hiddenRegion = getHiddenRegion(p); Region hiddenRegion = getHiddenRegion(p);
return !hiddenRegion.inRegion(blockX, blockY, blockZ) || !blockEntityTypeToObfuscate.contains(type); return !hiddenRegion.inRegion(blockX, blockY, blockZ) || !blockEntityTypeToObfuscate.contains(type);
} }
@Override
public boolean isEveryonePrivilegedToAccessAllDataWithinChunk(int chunkX, int chunkZ) {
return getHiddenRegions().stream().allMatch(region -> region.chunkOutside(chunkX, chunkZ));
}
}; };
new StateDependentListener(ENABLED, FightState.Schem, this); new StateDependentListener(ENABLED, FightState.Schem, this);
@@ -158,6 +164,10 @@ public class TechHiderWrapper extends StateDependent implements Listener {
}); });
} }
private Set<Region> getHiddenRegions() {
return Fight.teams().stream().map(FightTeam::getExtendRegion).collect(Collectors.toSet());
}
private Region getHiddenRegion(Player player) { private Region getHiddenRegion(Player player) {
if (Config.isReferee(player)) return Region.EMPTY; if (Config.isReferee(player)) return Region.EMPTY;
@@ -536,8 +536,13 @@ public abstract class TechHider {
} }
private ClientboundLevelChunkWithLightPacket processChunkWithLight(Player p, ClientboundLevelChunkWithLightPacket packet) { private ClientboundLevelChunkWithLightPacket processChunkWithLight(Player p, ClientboundLevelChunkWithLightPacket packet) {
if(isEveryonePrivilegedToAccessAllDataWithinChunk(packet.getX(), packet.getZ())) {
return packet;
}
else {
return chunkHider.processLevelChunkWithLightPacket(p, packet); return chunkHider.processLevelChunkWithLightPacket(p, packet);
} }
}
private Packet<? extends PacketListener> proccessPositionBasedPacket(Player player, int blockX, int blockY, int blockZ, Packet<? extends PacketListener> packet) { private Packet<? extends PacketListener> proccessPositionBasedPacket(Player player, int blockX, int blockY, int blockZ, Packet<? extends PacketListener> packet) {
if(isPlayerPrivilegedToAccessPosition(player, blockX, blockY, blockZ)) { if(isPlayerPrivilegedToAccessPosition(player, blockX, blockY, blockZ)) {
@@ -562,4 +567,5 @@ public abstract class TechHider {
public abstract boolean isPlayerPrivilegedToAccessBlock(Player p, int blockX, int blockY, int blockZ, Block block); public abstract boolean isPlayerPrivilegedToAccessBlock(Player p, int blockX, int blockY, int blockZ, Block block);
public abstract boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId); public abstract boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId);
public abstract boolean isPlayerPrivilegedToAccessBlocEntity(Player p, int blockX, int blockY, int blockZ, BlockEntityType<?> type); public abstract boolean isPlayerPrivilegedToAccessBlocEntity(Player p, int blockX, int blockY, int blockZ, BlockEntityType<?> type);
public abstract boolean isEveryonePrivilegedToAccessAllDataWithinChunk(int chunkX, int chunkZ);
} }