Migrate BauSystem to the new TechHider and remove the legacy TechHider

The new TechHider registers a permanent global filter, so BauSystem now uses
a single BauTechHider that combines the hiding rules of the spectator
techhider, /techhider and /xray per player. To support the different
obfuscation blocks of these rules, ForPlayer now provides the obfuscation
block per position.

The ChunkHider now also checks single valued chunk sections, which were sent
unfiltered before, and recalculates their block count if they change.
Unhandled packet types are logged once; statistics, debug samples and ping
responses are passed through.

The legacy TechHider and its access widener entries are removed.
This commit is contained in:
2026-10-31 15:00:37 +01:00
parent 7d4252325a
commit ce2a23f4b8
16 changed files with 295 additions and 644 deletions
@@ -36,6 +36,7 @@ dependencies {
annotationProcessor(libs.classindex)
compileOnly(project(":SpigotCore", "default"))
compileOnly(project(":KotlinCore", "default"))
implementation(project(":HiderCore"))
compileOnly(libs.axiom)
compileOnly(libs.authlib)
@@ -0,0 +1,137 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.techhider;
import de.steamwar.bausystem.features.world.SpectatorListener;
import de.steamwar.bausystem.features.xray.XrayCommand;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import de.steamwar.techhider.AccessPrivilegeProvider;
import de.steamwar.techhider.TechHider;
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.entity.Player;
import java.util.ArrayList;
import java.util.List;
/**
* The single TechHider of the server. It combines the hiding rules of the spectator techhider, /techhider and /xray per player.
*/
@Linked
public class BauTechHider implements AccessPrivilegeProvider {
private static final HidingRule[] NO_RULES = new HidingRule[0];
// Injected after construction, until then nothing is hidden
@LinkedInstance
public XrayCommand xrayCommand;
@LinkedInstance
public TechHiderCommand techHiderCommand;
@LinkedInstance
public SpectatorListener spectatorListener;
public BauTechHider() {
new TechHider(this);
}
@Override
public ForPlayer forPlayer(Player p) {
if (xrayCommand == null || techHiderCommand == null || spectatorListener == null) {
return new BauPlayerAccess(p, NO_RULES);
}
// Region rules first: where rules overlap, the first one decides the obfuscation block
List<HidingRule> rules = new ArrayList<>();
xrayCommand.addHidingRules(p, rules);
techHiderCommand.addHidingRules(p, rules);
spectatorListener.addHidingRules(p, rules);
return new BauPlayerAccess(p, rules.toArray(NO_RULES));
}
@Override
public boolean isPlayerPrivilegedToPerformAction(Player p) {
return true;
}
/**
* Snapshot of the hiding rules of one player, taken once per outgoing packet on the netty thread.
*/
private record BauPlayerAccess(Player player, HidingRule[] rules) implements ForPlayer {
@Override
public Player getPlayer() {
return player;
}
@Override
public boolean canAccessAllDataWithinChunk(int chunkX, int chunkZ) {
for (HidingRule rule : rules) {
if (rule.coversChunk(chunkX, chunkZ)) return false;
}
return true;
}
@Override
public boolean canAccessPosition(int blockX, int blockY, int blockZ) {
return true;
}
@Override
public boolean canAccessBlock(int blockX, int blockY, int blockZ, Block block) {
for (HidingRule rule : rules) {
if (rule.covers(blockX, blockY, blockZ) && rule.obfuscation().hidesBlock(block)) return false;
}
return true;
}
@Override
public boolean canAccessBlockState(int blockX, int blockY, int blockZ, BlockState blockState) {
for (HidingRule rule : rules) {
if (rule.covers(blockX, blockY, blockZ) && rule.obfuscation().hidesBlockState(blockState)) return false;
}
return true;
}
@Override
public boolean canAccessEntity(int entityId) {
return true;
}
@Override
public boolean canAccessBlockEntity(int blockX, int blockY, int blockZ, BlockEntityType<?> type) {
for (HidingRule rule : rules) {
if (rule.covers(blockX, blockY, blockZ) && rule.obfuscation().hidesBlockEntity(type)) return false;
}
return true;
}
@Override
public BlockState getObfuscation(int blockX, int blockY, int blockZ) {
for (HidingRule rule : rules) {
if (rule.covers(blockX, blockY, blockZ)) return rule.obfuscation().getObfuscationState();
}
// Only asked for positions a rule hides
return Blocks.END_STONE.defaultBlockState();
}
}
}
@@ -0,0 +1,52 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.techhider;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region;
import de.steamwar.hullhider.HullRegion;
import de.steamwar.techhider.ObfuscationConfig;
/**
* Hides the blocks of an obfuscation config within an area, or everywhere if the area is null.
*/
public record HidingRule(HullRegion area, ObfuscationConfig obfuscation) {
public static HidingRule everywhere(ObfuscationConfig obfuscation) {
return new HidingRule(null, obfuscation);
}
/**
* Covers the area including its extension.
*/
public static HidingRule of(Region.Area area, ObfuscationConfig obfuscation) {
Point min = area.getMinPoint(true);
Point max = area.getMaxPoint(true);
return new HidingRule(HullRegion.fromInclusive(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ()), obfuscation);
}
public boolean covers(int x, int y, int z) {
return area == null || area.contains(x, y, z);
}
public boolean coversChunk(int chunkX, int chunkZ) {
return area == null || !area.chunkOutside(chunkX, chunkZ);
}
}
@@ -31,7 +31,7 @@ import de.steamwar.command.TypeMapper;
import de.steamwar.core.CraftbukkitWrapper;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import de.steamwar.techhider.legacy.TechHider;
import de.steamwar.techhider.ObfuscationConfig;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@@ -41,6 +41,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Linked
@@ -50,8 +51,9 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
super("techhider", "hider", "obfuscate", "hide", "hide-tech");
}
private Map<Region, Optional<TechHider>> techHiders = new HashMap<>();
private Map<Region, Set<Player>> hidden = new HashMap<>();
// Read on netty threads by the BauTechHider
private Map<Region, Optional<HidingRule>> hidingRules = new ConcurrentHashMap<>();
private Map<Region, Set<Player>> hidden = new ConcurrentHashMap<>();
@LinkedInstance
public XrayCommand xrayCommand;
@@ -64,22 +66,15 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
return;
}
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
Optional<HidingRule> hidingRule = hidingRules.computeIfAbsent(region, rg -> {
if (!region.getGameModeConfig().Techhider.Active) {
return Optional.empty();
}
hidden.put(rg, new HashSet<>());
TechHider current = new TechHider((p, cX, cY) -> {
if (rg.getBuildArea().isChunkOutside(cX, cY)) return true;
return !hidden.get(rg).contains(p);
}, region.getGameModeConfig().Techhider.ObfuscateWith, region.getGameModeConfig().Techhider.HiddenBlocks, region.getGameModeConfig().Techhider.HiddenBlockEntities);
current.enable();
return Optional.of(current);
hidden.put(rg, ConcurrentHashMap.newKeySet());
return Optional.of(HidingRule.of(rg.getBuildArea(), ObfuscationConfig.of(rg.getGameModeConfig().Techhider)));
});
if (!techHider.isPresent()) {
if (!hidingRule.isPresent()) {
return;
}
@@ -128,6 +123,14 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
hidden.values().forEach(set -> set.remove(event.getPlayer()));
}
public void addHidingRules(Player player, List<HidingRule> rules) {
hidden.forEach((region, players) -> {
if (players.contains(player)) {
hidingRules.getOrDefault(region, Optional.empty()).ifPresent(rules::add);
}
});
}
public void disable(Region region, Player player) {
hidden.computeIfPresent(region, (rg, set) -> {
set.remove(player);
@@ -22,10 +22,11 @@ package de.steamwar.bausystem.features.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.config.BauServer;
import de.steamwar.bausystem.features.techhider.HidingRule;
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
import de.steamwar.linkage.Linked;
import de.steamwar.sql.BauweltMember;
import de.steamwar.techhider.legacy.TechHider;
import de.steamwar.techhider.ObfuscationConfig;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -41,14 +42,18 @@ import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.*;
import org.bukkit.util.Vector;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@Linked
public class SpectatorListener implements Listener {
private static final TechHider techHider;
private static final Set<Player> NO_TECHHIDER = new HashSet<>();
private static final HidingRule SPECTATOR_RULE;
// Read on netty threads by the BauTechHider
private static final Set<Player> NO_TECHHIDER = ConcurrentHashMap.newKeySet();
static {
Set<Material> materials = new HashSet<>();
@@ -99,19 +104,12 @@ public class SpectatorListener implements Listener {
materials.add(Material.WATER);
materials.remove(Material.BARRIER);
materials.remove(Material.STONE);
techHider = new TechHider((TechHider.LocationEvaluator) (player, i, i1) -> {
return Permission.BUILD.hasPermission(player) || NO_TECHHIDER.contains(player);
}, Material.END_STONE, materials, new HashSet<>());
SPECTATOR_RULE = HidingRule.everywhere(new ObfuscationConfig(Material.END_STONE, materials, Collections.emptySet()));
}
private static void enableOrDisableTechhider() {
boolean enable = Bukkit.getOnlinePlayers()
.stream()
.anyMatch(player -> !(Permission.BUILD.hasPermission(player) || NO_TECHHIDER.contains(player)));
if (enable) {
techHider.enable();
} else {
techHider.disable();
public void addHidingRules(Player player, List<HidingRule> rules) {
if (!(Permission.BUILD.hasPermission(player) || NO_TECHHIDER.contains(player))) {
rules.add(SPECTATOR_RULE);
}
}
@@ -122,7 +120,6 @@ public class SpectatorListener implements Listener {
NO_TECHHIDER.add(player);
}
resendChunks(player);
enableOrDisableTechhider();
}
private static void resendChunks(Player player) {
@@ -141,7 +138,6 @@ public class SpectatorListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
enableOrDisableTechhider();
if (BauSystem.DEV_SERVER) return;
if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) {
return;
@@ -163,7 +159,6 @@ public class SpectatorListener implements Listener {
@EventHandler
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
enableOrDisableTechhider();
if (!anySupervisorOnline(null) && !BauSystem.DEV_SERVER) {
Bukkit.getOnlinePlayers().forEach(player -> {
player.kickPlayer("");
@@ -180,7 +175,6 @@ public class SpectatorListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
NO_TECHHIDER.remove(event.getPlayer());
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), SpectatorListener::enableOrDisableTechhider, 1);
if (BauSystem.DEV_SERVER) return;
if (!anySupervisorOnline(event.getPlayer())) {
Bukkit.getOnlinePlayers().forEach(player -> {
@@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.xray;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.techhider.HidingRule;
import de.steamwar.bausystem.features.techhider.TechHiderCommand;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.utils.ScoreboardElement;
@@ -28,7 +29,7 @@ import de.steamwar.command.SWCommand;
import de.steamwar.core.CraftbukkitWrapper;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import de.steamwar.techhider.legacy.TechHider;
import de.steamwar.techhider.ObfuscationConfig;
import net.md_5.bungee.api.ChatMessageType;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.server.level.ServerPlayer;
@@ -43,6 +44,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
@Linked
@@ -52,9 +54,10 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
super("xray");
}
private Map<Region, Optional<TechHider>> techHiders = new HashMap<>();
// Read on netty threads by the BauTechHider and the movement filter
private Map<Region, Optional<HidingRule>> hidingRules = new ConcurrentHashMap<>();
private Map<Region, Set<Material>> xrayedBlocks = new HashMap<>();
private Map<Region, Set<Player>> hidden = new HashMap<>();
private Map<Region, Set<Player>> hidden = new ConcurrentHashMap<>();
@LinkedInstance
public TechHiderCommand techHiderCommand;
@@ -67,19 +70,19 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
return;
}
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
Optional<HidingRule> hidingRule = hidingRules.computeIfAbsent(region, rg -> {
if (!region.getGameModeConfig().Techhider.Active) {
return Optional.empty();
}
hidden.put(rg, new HashSet<>());
hidden.put(rg, ConcurrentHashMap.newKeySet());
Set<Material> blocks = new HashSet<>(Arrays.asList(region.getGameModeConfig().Techhider.ObfuscateWith));
if (blocks.contains(Material.END_STONE)) blocks.add(Material.END_STONE_BRICKS);
xrayedBlocks.put(region, blocks);
return Optional.of(createXray(rg, blocks));
return Optional.of(HidingRule.of(rg.getBuildArea(), new ObfuscationConfig(Material.STRUCTURE_VOID, blocks, Collections.emptySet())));
});
if (!techHider.isPresent()) {
if (!hidingRule.isPresent()) {
return;
}
@@ -139,13 +142,12 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
}
}
private TechHider createXray(Region rg, Set<Material> obfuscate) {
TechHider current = new TechHider((TechHider.LocationEvaluator) (p, cX, cY) -> {
if (rg.getBuildArea().isChunkOutside(cX, cY)) return true;
return !hidden.get(rg).contains(p);
}, Material.STRUCTURE_VOID, obfuscate, new HashSet<>());
current.enable();
return current;
public void addHidingRules(Player player, List<HidingRule> rules) {
hidden.forEach((region, players) -> {
if (players.contains(player)) {
hidingRules.getOrDefault(region, Optional.empty()).ifPresent(rules::add);
}
});
}
@EventHandler