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 net.md_5.bungee.api.ChatMessageType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
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;
|
||||||
@@ -61,7 +60,8 @@ public class HullHiderCommand extends SWCommand implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Linked
|
@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
|
// Read on netty threads by the BauTechHider
|
||||||
private final Map<Region, HiddenHull> hulls = new ConcurrentHashMap<>();
|
private final Map<Region, HiddenHull> hulls = new ConcurrentHashMap<>();
|
||||||
private final Map<Region, Set<Player>> hidden = 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() {
|
private void onTick() {
|
||||||
if (hidden.isEmpty()) return;
|
if (hidden.isEmpty()) return;
|
||||||
|
|
||||||
for (Entity entity : world().getEntities()) {
|
|
||||||
hullHider.checkEntity(entity);
|
|
||||||
}
|
|
||||||
hullHider.sendUncoveredBlocks();
|
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.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
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.
|
* 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
|
@Linked
|
||||||
public class BauTechHider implements AccessPrivilegeProvider {
|
public class BauTechHider implements AccessPrivilegeProvider {
|
||||||
@@ -128,10 +128,13 @@ public class BauTechHider implements AccessPrivilegeProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAccessEntity(int entityId) {
|
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);
|
// Entities are not hidden, even if they spawn inside a hidden hull
|
||||||
return nmsEntity == null || canAccessPosition(nmsEntity.getBlockX(), nmsEntity.getBlockY(), nmsEntity.getBlockZ());
|
@Override
|
||||||
|
public boolean canAccessEntitySpawn(int entityId, int blockX, int blockY, int blockZ) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ import java.util.function.BiConsumer;
|
|||||||
*/
|
*/
|
||||||
public class FightHullHider {
|
public class FightHullHider {
|
||||||
|
|
||||||
private final HullHider<FightTeam> hullHider = new HullHider<>();
|
private final HullHider<FightTeam> hullHider = new HullHider<>(true);
|
||||||
|
|
||||||
public FightHullHider() {
|
public FightHullHider() {
|
||||||
if (!TechHiderWrapper.ENABLED) return;
|
if (!TechHiderWrapper.ENABLED) return;
|
||||||
|
|||||||
@@ -42,10 +42,18 @@ import java.util.function.BiConsumer;
|
|||||||
*/
|
*/
|
||||||
public class HullHider<K> implements Listener {
|
public class HullHider<K> implements Listener {
|
||||||
|
|
||||||
|
private final boolean hideEntities;
|
||||||
private final Map<K, Hull> hullMap = new LinkedHashMap<>();
|
private final Map<K, Hull> hullMap = new LinkedHashMap<>();
|
||||||
// Read on netty threads, replaced on every change
|
// Read on netty threads, replaced on every change
|
||||||
private volatile Hull[] hulls = new Hull[0];
|
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.
|
* 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)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onDeath(EntityDeathEvent e) {
|
public void onDeath(EntityDeathEvent e) {
|
||||||
|
if (!hideEntities) return;
|
||||||
|
|
||||||
for (Hull hull : hulls) {
|
for (Hull hull : hulls) {
|
||||||
hull.removeEntity(e.getEntity());
|
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.
|
* 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) {
|
public void checkEntity(Entity entity) {
|
||||||
|
if (!hideEntities) return;
|
||||||
|
|
||||||
for (Hull hull : hulls) {
|
for (Hull hull : hulls) {
|
||||||
hull.checkEntity(entity);
|
hull.checkEntity(entity);
|
||||||
}
|
}
|
||||||
@@ -181,12 +193,16 @@ public class HullHider<K> implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateREntity(REntity e) {
|
public void updateREntity(REntity e) {
|
||||||
|
if (!hideEntities) return;
|
||||||
|
|
||||||
for (Hull hull : hulls) {
|
for (Hull hull : hulls) {
|
||||||
hull.checkREntity(e);
|
hull.checkREntity(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void despawnREntity(REntity e) {
|
public void despawnREntity(REntity e) {
|
||||||
|
if (!hideEntities) return;
|
||||||
|
|
||||||
for (Hull hull : hulls) {
|
for (Hull hull : hulls) {
|
||||||
hull.removeREntity(e);
|
hull.removeREntity(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ public interface AccessPrivilegeProvider {
|
|||||||
|
|
||||||
boolean canAccessEntity(int entityId);
|
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);
|
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) {
|
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;
|
return packet;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user