forked from SteamWar/SteamWar
Do not hide entities with the BauSystem hullhider
HullHider gets a hideEntities parameter: the fight still hides entities inside hidden hulls, /hullhider only hides blocks. As the TechHider also dropped spawn packets at hidden positions, ForPlayer#canAccessEntitySpawn decides about them now, which the BauTechHider always allows.
This commit is contained in:
+2
-5
@@ -36,7 +36,6 @@ import de.steamwar.techhider.ObfuscationConfig;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -61,7 +60,8 @@ public class HullHiderCommand extends SWCommand implements Listener {
|
||||
}
|
||||
|
||||
@Linked
|
||||
private final HullHider<Region> hullHider = new HullHider<>();
|
||||
// Only blocks are hidden, entities stay visible
|
||||
private final HullHider<Region> hullHider = new HullHider<>(false);
|
||||
// Read on netty threads by the BauTechHider
|
||||
private final Map<Region, HiddenHull> hulls = new ConcurrentHashMap<>();
|
||||
private final Map<Region, Set<Player>> hidden = new ConcurrentHashMap<>();
|
||||
@@ -143,9 +143,6 @@ public class HullHiderCommand extends SWCommand implements Listener {
|
||||
private void onTick() {
|
||||
if (hidden.isEmpty()) return;
|
||||
|
||||
for (Entity entity : world().getEntities()) {
|
||||
hullHider.checkEntity(entity);
|
||||
}
|
||||
hullHider.sendUncoveredBlocks();
|
||||
}
|
||||
|
||||
|
||||
+7
-4
@@ -30,7 +30,6 @@ import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -38,6 +37,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* The single TechHider of the server. It combines the hiding rules of the spectator techhider, /techhider and /xray and the hulls of /hullhider per player.
|
||||
* Entities are never hidden.
|
||||
*/
|
||||
@Linked
|
||||
public class BauTechHider implements AccessPrivilegeProvider {
|
||||
@@ -128,10 +128,13 @@ public class BauTechHider implements AccessPrivilegeProvider {
|
||||
|
||||
@Override
|
||||
public boolean canAccessEntity(int entityId) {
|
||||
if (hulls.length == 0) return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
net.minecraft.world.entity.Entity nmsEntity = ((CraftWorld) player.getWorld()).getHandle().moonrise$getEntityLookup().get(entityId);
|
||||
return nmsEntity == null || canAccessPosition(nmsEntity.getBlockX(), nmsEntity.getBlockY(), nmsEntity.getBlockZ());
|
||||
// Entities are not hidden, even if they spawn inside a hidden hull
|
||||
@Override
|
||||
public boolean canAccessEntitySpawn(int entityId, int blockX, int blockY, int blockZ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,7 +50,7 @@ import java.util.function.BiConsumer;
|
||||
*/
|
||||
public class FightHullHider {
|
||||
|
||||
private final HullHider<FightTeam> hullHider = new HullHider<>();
|
||||
private final HullHider<FightTeam> hullHider = new HullHider<>(true);
|
||||
|
||||
public FightHullHider() {
|
||||
if (!TechHiderWrapper.ENABLED) return;
|
||||
|
||||
@@ -42,10 +42,18 @@ import java.util.function.BiConsumer;
|
||||
*/
|
||||
public class HullHider<K> implements Listener {
|
||||
|
||||
private final boolean hideEntities;
|
||||
private final Map<K, Hull> hullMap = new LinkedHashMap<>();
|
||||
// Read on netty threads, replaced on every change
|
||||
private volatile Hull[] hulls = new Hull[0];
|
||||
|
||||
/**
|
||||
* @param hideEntities whether entities and REntities inside the hidden part of a hull are hidden from non-viewers as well
|
||||
*/
|
||||
public HullHider(boolean hideEntities) {
|
||||
this.hideEntities = hideEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hull hides everything from non-viewers until it is initialised.
|
||||
*/
|
||||
@@ -157,6 +165,8 @@ public class HullHider<K> implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDeath(EntityDeathEvent e) {
|
||||
if (!hideEntities) return;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
hull.removeEntity(e.getEntity());
|
||||
}
|
||||
@@ -166,6 +176,8 @@ public class HullHider<K> implements Listener {
|
||||
* Has to be called every tick for every entity, as entities can move into or out of the hidden part of a hull.
|
||||
*/
|
||||
public void checkEntity(Entity entity) {
|
||||
if (!hideEntities) return;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
hull.checkEntity(entity);
|
||||
}
|
||||
@@ -181,12 +193,16 @@ public class HullHider<K> implements Listener {
|
||||
}
|
||||
|
||||
public void updateREntity(REntity e) {
|
||||
if (!hideEntities) return;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
hull.checkREntity(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void despawnREntity(REntity e) {
|
||||
if (!hideEntities) return;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
hull.removeREntity(e);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,13 @@ public interface AccessPrivilegeProvider {
|
||||
|
||||
boolean canAccessEntity(int entityId);
|
||||
|
||||
/**
|
||||
* @return whether the player may see the entity spawning at this position
|
||||
*/
|
||||
default boolean canAccessEntitySpawn(int entityId, int blockX, int blockY, int blockZ) {
|
||||
return canAccessEntity(entityId) && canAccessPosition(blockX, blockY, blockZ);
|
||||
}
|
||||
|
||||
boolean canAccessBlockEntity(int blockX, int blockY, int blockZ, BlockEntityType<?> type);
|
||||
|
||||
/**
|
||||
|
||||
@@ -372,7 +372,7 @@ public class TechHider {
|
||||
}
|
||||
|
||||
private Packet<? extends PacketListener> processAddEntityPacket(ForPlayer access, ClientboundAddEntityPacket packet) {
|
||||
if (access.canAccessEntity(packet.getId()) && access.canAccessPosition(Mth.floor(packet.getX()), Mth.floor(packet.getY()), Mth.floor(packet.getZ()))) {
|
||||
if (access.canAccessEntitySpawn(packet.getId(), Mth.floor(packet.getX()), Mth.floor(packet.getY()), Mth.floor(packet.getZ()))) {
|
||||
return packet;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user