From 3bd54fcdbdd4d9f7815746380b305103065a0d53 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 13 Mar 2024 13:08:17 +0100 Subject: [PATCH] Bugfixes, Block precise performance improvement Signed-off-by: Lixfel --- .../steamwar/fightsystem/utils/HullHiderWrapper18.java | 3 +++ .../src/de/steamwar/fightsystem/utils/Hull.java | 7 +++++++ .../src/de/steamwar/fightsystem/utils/HullHider.java | 10 ++++++++++ .../steamwar/fightsystem/utils/TechHiderWrapper.java | 9 ++++++--- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index 45db342..6087aab 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -48,6 +48,9 @@ public class HullHiderWrapper18 implements HullHiderWrapper { return unchanged; }); + if(changes.isEmpty()) + return null; + return generateBlockChangePacket(changes, blockdata.toArray()); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 6111388..3b96281 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -94,6 +94,10 @@ public class Hull { } } + public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) { + return players.contains(player) && !region.chunkSectionOutside(chunkX, chunkY, chunkZ); + } + public boolean isBlockHidden(Player player, int x, int y, int z) { return region.inRegion(x, y, z) && players.contains(player) && !visibility.get(((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX())); } @@ -234,6 +238,9 @@ public class Hull { for (Map.Entry> entry : sectionWise.entrySet()) { Object packet = HullHiderWrapper.impl.generateBlockChangePacket(entry.getValue()); + if(packet == null) + continue; + players.forEach(player -> TinyProtocol.instance.sendPacket(player, packet)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 259433f..286490c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -155,6 +155,16 @@ public class HullHider implements Listener { return false; } + public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) { + if(!ENABLED) + return false; + + for (Hull hull : hulls) + if(hull.blockPrecise(player, chunkX, chunkY, chunkZ)) + return true; + + return false; + } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSpawn(EntitySpawnEvent e) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java index 6168706..9e97afa 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -31,13 +31,11 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.techhider.TechHider; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.Collections; import java.util.concurrent.ConcurrentHashMap; public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator, Listener { @@ -49,7 +47,7 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati public TechHiderWrapper() { super(ENABLED, FightState.Schem); - techHider = new TechHider(this, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks, Config.HiddenBlockEntities); + techHider = new TechHider(this, Config.ObfuscateWith, Config.HiddenBlocks, Config.HiddenBlockEntities); new StateDependentListener(ENABLED, FightState.Schem, this); register(); @@ -123,6 +121,11 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati } } + @Override + public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) { + return FightSystem.getHullHider().blockPrecise(player, chunkX, chunkY, chunkZ); + } + private Region getHiddenRegion(Player player) { if(Config.isReferee(player)) return Region.EMPTY;