From 6766862a006981b21608930d45362ba20f739e29 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Wed, 13 May 2026 22:48:44 +0200 Subject: [PATCH] Refactored over all functionality --- .../features/techhider/TechHiderCommand.java | 1 - .../features/world/SpectatorListener.java | 1 - .../bausystem/features/xray/XrayCommand.java | 1 - .../steamwar/fightsystem/utils/HullHider.java | 2 - .../fightsystem/utils/TechHiderWrapper.java | 1 - .../de/steamwar/techhider/ChunkHider18.java | 4 +- .../de/steamwar/techhider/ChunkHider21.java | 4 +- .../de/steamwar/techhider/ChunkHider9.java | 2 +- .../de/steamwar/core/events/AntiNocom.java | 1 - .../src/de/steamwar/techhider/ChunkHider.java | 94 ++++--------- .../de/steamwar/techhider/QuadFunction.java | 24 ++++ .../src/de/steamwar/techhider/TechHider.java | 128 ------------------ .../steamwar/techhider/TechHiderUpdated.java | 62 +++++---- 13 files changed, 91 insertions(+), 234 deletions(-) create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/QuadFunction.java delete mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java index 74888bec..ba727fba 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -31,7 +31,6 @@ import de.steamwar.command.TypeMapper; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; -import de.steamwar.techhider.TechHider; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index cfdc6fe3..28a77b54 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -27,7 +27,6 @@ import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; import de.steamwar.sql.BauweltMember; -import de.steamwar.techhider.TechHider; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index b128e27a..2a5a09f0 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -30,7 +30,6 @@ import de.steamwar.command.SWCommand; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; -import de.steamwar.techhider.TechHider; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 074a9e4d..c2af05ee 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -32,7 +32,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; -import de.steamwar.techhider.TechHider; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -49,7 +48,6 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.BiFunction; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java index d72e6949..c581525c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -31,7 +31,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.sql.SteamwarUser; -import de.steamwar.techhider.TechHider; import lombok.Getter; import org.bukkit.GameMode; import org.bukkit.entity.Player; diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java index 3033feac..76ab1ad8 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java @@ -102,7 +102,7 @@ public class ChunkHider18 implements ChunkHider { boolean singletonPalette = section.getBitsPerBlock() == 0; if(singletonPalette) { int value = ProtocolUtils.readVarInt(section.getIn()); - ProtocolUtils.writeVarInt(section.getOut(), !section.isSkipSection() && section.getObfuscate().contains(value) ? section.getTarget() : value); + ProtocolUtils.writeVarInt(section.getOut(), !section.isSkipSection() && section.getBlockIdsToObfuscate().contains(value) ? section.getTarget() : value); }else if(section.getBitsPerBlock() < 15) { section.processPalette(); } @@ -123,7 +123,7 @@ public class ChunkHider18 implements ChunkHider { case SKIP: break; case CHECK: - if(!section.getObfuscate().contains(values.a(pos))) + if(!section.getBlockIdsToObfuscate().contains(values.a(pos))) break; case HIDE: values.b(pos, section.getTarget()); diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/techhider/ChunkHider21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/techhider/ChunkHider21.java index 1cc6c29c..b26a4ceb 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/techhider/ChunkHider21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/techhider/ChunkHider21.java @@ -105,7 +105,7 @@ public class ChunkHider21 implements ChunkHider { boolean singleValued = section.getBitsPerBlock() == 0; if (singleValued) { int value = ProtocolUtils.readVarInt(section.getIn()); - ProtocolUtils.writeVarInt(section.getOut(), !section.isSkipSection() && section.getObfuscate().contains(value) ? section.getTarget() : value); + ProtocolUtils.writeVarInt(section.getOut(), !section.isSkipSection() && section.getBlockIdsToObfuscate().contains(value) ? section.getTarget() : value); return; } else if (section.getBitsPerBlock() < 9) { // Indirect (paletted) storage – only present when bitsPerBlock < 9 in 1.21+ @@ -130,7 +130,7 @@ public class ChunkHider21 implements ChunkHider { case SKIP: break; case CHECK: - if (!section.getObfuscate().contains(values.get(pos))) + if (!section.getBlockIdsToObfuscate().contains(values.get(pos))) break; case HIDE: values.set(pos, section.getTarget()); diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java index 71b47743..edea577b 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java @@ -100,7 +100,7 @@ public class ChunkHider9 extends ChunkHider8 { case SKIP: break; case CHECK: - if(!section.getObfuscate().contains(values.get(pos))) + if(!section.getBlockIdsToObfuscate().contains(values.get(pos))) break; case HIDE: values.set(pos, section.getTarget()); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index 40cdb955..5ed98eac 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -25,7 +25,6 @@ import de.steamwar.core.Core; import de.steamwar.linkage.Linked; import de.steamwar.sql.SWException; import de.steamwar.techhider.ProtocolUtils; -import de.steamwar.techhider.TechHider; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java index 69f0123a..79559b56 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java @@ -19,15 +19,13 @@ package de.steamwar.techhider; -import de.steamwar.core.Core; -import de.steamwar.core.VersionDependent; import io.netty.buffer.ByteBuf; import lombok.Getter; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.entity.Player; import java.util.Collections; import java.util.Set; -import java.util.function.BiFunction; /* * This file is a part of the SteamWar software. @@ -51,17 +49,13 @@ import java.util.function.BiFunction; package de.steamwar.techhider; import de.steamwar.Reflection; -import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.util.SimpleBitStorage; import net.minecraft.world.level.block.entity.BlockEntityType; -import org.bukkit.entity.Player; import java.util.List; -import java.util.Set; -import java.util.function.BiFunction; import java.util.function.UnaryOperator; import java.util.stream.Collectors; @@ -69,33 +63,27 @@ public class ChunkHider { private static final UnaryOperator chunkPacketCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkWithLightPacket.class); private static final UnaryOperator chunkDataCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkPacketData.class); - private static final Reflection.Field chunkXField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 0); - private static final Reflection.Field chunkZField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 1); private static final Reflection.Field chunkData = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, ClientboundLevelChunkPacketData.class, 0); private static final Reflection.Field dataField = Reflection.getField(ClientboundLevelChunkPacketData.class, byte[].class, 0); private static final Reflection.Field tileEntities = Reflection.getField(ClientboundLevelChunkPacketData.class, List.class, 0); - public BiFunction processLevelChunkWithLightPacket(TechHider techHider) { - return (p, packet) -> { - int chunkX = chunkXField.get(packet); - int chunkZ = chunkZField.get(packet); - if (techHider.getLocationEvaluator().skipChunk(p, chunkX, chunkZ)) - return packet; + public ClientboundLevelChunkWithLightPacket processLevelChunkWithLightPacket(Player recivingPlayer, Set hiddenBlockEntities , QuadFunction isPlayerPrivilegedToAccessBlockPos, BlockState blockToObfuscateTo, Set blockIdsToObfuscate, ClientboundLevelChunkWithLightPacket packet) { + int chunkX = packet.getX(); + int chunkZ = packet.getZ(); - packet = chunkPacketCloner.apply(packet); - Object dataWrapper = chunkDataCloner.apply(chunkData.get(packet)); + Object clonedPacket = chunkPacketCloner.apply(packet); + Object dataWrapper = chunkDataCloner.apply(chunkData.get(clonedPacket)); - Set hiddenBlockEntities = techHider.getHiddenBlockEntities(); tileEntities.set(dataWrapper, ((List)tileEntities.get(dataWrapper)).stream().filter(te -> tileEntityVisible(hiddenBlockEntities, te)).collect(Collectors.toList())); ByteBuf in = Unpooled.wrappedBuffer(dataField.get(dataWrapper)); ByteBuf out = Unpooled.buffer(in.readableBytes() + 64); - for(int yOffset = p.getWorld().getMinHeight(); yOffset < p.getWorld().getMaxHeight(); yOffset += 16) { - SectionHider section = new SectionHider(p, techHider, in, out, chunkX, yOffset/16, chunkZ); + for(int yOffset = recivingPlayer.getWorld().getMinHeight(); yOffset < recivingPlayer.getWorld().getMaxHeight(); yOffset += 16) { + SectionHider section = new SectionHider(recivingPlayer, blockToObfuscateTo, blockIdsToObfuscate, in, out, chunkX, yOffset/16, chunkZ); section.copyBlockCount(); - blocks(section); + blocks(section, isPlayerPrivilegedToAccessBlockPos); biomes(section); } @@ -109,7 +97,6 @@ public class ChunkHider { chunkData.set(packet, dataWrapper); return packet; - }; } public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo"); @@ -124,45 +111,29 @@ public class ChunkHider { return !hiddenBlockEntities.contains(getName.invoke(getKey.invoke(nameField.get(null), entityType.get(tile)))); } - private void blocks(SectionHider section) { + private void blocks(SectionHider section, QuadFunction isPlayerPrivilegedToAccessBlockPos) { section.copyBitsPerBlock(); boolean singleValued = section.getBitsPerBlock() == 0; if (singleValued) { int value = ProtocolUtils.readVarInt(section.getIn()); - ProtocolUtils.writeVarInt(section.getOut(), !section.isSkipSection() && section.getObfuscate().contains(value) ? section.getTarget() : value); + ProtocolUtils.writeVarInt(section.getOut(), section.getBlockIdsToObfuscate().contains(value) ? section.getTarget() : value); return; } else if (section.getBitsPerBlock() < 9) { // Indirect (paletted) storage – only present when bitsPerBlock < 9 in 1.21+ section.processPalette(); } - if (section.isSkipSection() || (!section.blockPrecise() && section.isPaletted())) { - section.skipNewDataArray(4096); - return; - } - SimpleBitStorage values = new SimpleBitStorage(section.getBitsPerBlock(), 4096, section.readNewDataArray(4096)); for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { int pos = (((y * 16) + z) * 16) + x; + int blockId = values.get(pos); - TechHider.State test = section.test(x, y, z); - - switch (test) { - case SKIP: - break; - case CHECK: - if (!section.getObfuscate().contains(values.get(pos))) - break; - case HIDE: - values.set(pos, section.getTarget()); - break; - case HIDE_AIR: - default: - values.set(pos, section.getAir()); + if(!isPlayerPrivilegedToAccessBlockPos.apply(section.player, section.getOffsetX() * x, section.getOffsetY() * y, section.getOffsetZ() * z) && !section.getBlockIdsToObfuscate().contains(blockId)) { + values.set(pos, section.getTarget()); } } } @@ -187,7 +158,6 @@ public class ChunkHider { @Getter class SectionHider { private final Player player; - private final TechHider techHider; private final ByteBuf in; private final ByteBuf out; @@ -198,18 +168,17 @@ public class ChunkHider { private final int offsetY; private final int offsetZ; - private final boolean skipSection; private boolean paletted; private int bitsPerBlock; private int blockCount; private int air; private int target; - private Set obfuscate; + private Set blockIdsToObfuscate; + private final int blockIdToObfuscateTo; - public SectionHider(Player player, TechHider techHider, ByteBuf in, ByteBuf out, int chunkX, int chunkY, int chunkZ) { + public SectionHider(Player player, BlockState blockToObfuscateTo, Set blockIdsToObfuscate, ByteBuf in, ByteBuf out, int chunkX, int chunkY, int chunkZ) { this.player = player; - this.techHider = techHider; this.in = in; this.out = out; this.chunkX = chunkX; @@ -218,21 +187,13 @@ public class ChunkHider { this.offsetX = 16*chunkX; this.offsetY = 16*chunkY; this.offsetZ = 16*chunkZ; - this.skipSection = techHider.getLocationEvaluator().skipChunkSection(player, chunkX, chunkY, chunkZ); + + this.blockIdsToObfuscate = blockIdsToObfuscate; + this.blockIdToObfuscateTo = BlockIds.impl.getCombinedId(blockToObfuscateTo); + this.paletted = false; this.bitsPerBlock = 0; - this.air = TechHider.AIR_ID; - this.target = techHider.getObfuscationTargetId(); - this.obfuscate = techHider.getObfuscateIds(); - } - - public boolean blockPrecise() { - return techHider.getLocationEvaluator().blockPrecise(player, chunkX, chunkY, chunkZ); - } - - public TechHider.State test(int x, int y, int z) { - return techHider.getLocationEvaluator().check(player, offsetX+x, offsetY+y, offsetZ+z); } public void copyBlockCount() { @@ -258,11 +219,6 @@ public class ChunkHider { } public void processPalette() { - if(skipSection) { - skipPalette(); - return; - } - int paletteLength = copyVarInt(); if(paletteLength == 0) return; @@ -273,17 +229,17 @@ public class ChunkHider { for(int i = 0; i < paletteLength; i++) { int entry = ProtocolUtils.readVarInt(in); - if(obfuscate.contains(entry)) - entry = techHider.getObfuscationTargetId(); + if(blockIdsToObfuscate.contains(entry)) + entry = blockIdToObfuscateTo; if(entry == TechHider.AIR_ID) air = i; - else if(entry == techHider.getObfuscationTargetId()) + else if(entry == blockIdToObfuscateTo) target = i; ProtocolUtils.writeVarInt(out, entry); } - obfuscate = Collections.emptySet(); + blockIdsToObfuscate = Collections.emptySet(); } public void skipDataArray() { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/QuadFunction.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/QuadFunction.java new file mode 100644 index 00000000..43df8d3b --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/QuadFunction.java @@ -0,0 +1,24 @@ +/* + * 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 . + */ + +package de.steamwar.techhider; + +public interface QuadFunction { + Return apply(A a, B b, C c, D d); +} \ No newline at end of file diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java deleted file mode 100644 index bd8e41d8..00000000 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 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 . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.Reflection; -import de.steamwar.core.Core; -import lombok.Getter; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; - -public class TechHider { - - public static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); - private static final Class baseBlockPosition = Reflection.getClass("net.minecraft.core.Vec3i"); - public static final Reflection.Field blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); - public static final Reflection.Field blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); - public static final Reflection.Field blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - - public static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); - public static final Class block = Reflection.getClass("net.minecraft.world.level.block.Block"); - private static final Reflection.Method getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); - - public static final Class craftMagicNumbers = Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); - private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); - - public boolean iBlockDataHidden(Object iBlockData) { - return obfuscateIds.contains(BlockIds.impl.getCombinedId(iBlockData)); - } - - public static final Object AIR = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.AIR)); - public static final int AIR_ID = BlockIds.impl.materialToId(Material.AIR); - - private final Map, BiFunction> techhiders = new HashMap<>(); - @Getter - private final LocationEvaluator locationEvaluator; - @Getter - private final Object obfuscationTarget; - @Getter - private final int obfuscationTargetId; - @Getter - private final Set obfuscateIds; - @Getter - private final Set hiddenBlockEntities; - - public TechHider(LocationEvaluator locationEvaluator, Material obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { - this.locationEvaluator = locationEvaluator; - this.obfuscateIds = obfuscate.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); - this.hiddenBlockEntities = hiddenBlockEntities; - this.obfuscationTarget = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, obfuscationTarget)); - this.obfuscationTargetId = BlockIds.impl.materialToId(obfuscationTarget); - - techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(this)); - - if(Core.getVersion() > 12 && Core.getVersion() < 19) { - Class blockBreakClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket"); - techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass, this)); - } - - if(Core.getVersion() > 8){ - techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"), (p, packet) -> locationEvaluator.suppressInteractions(p) ? null : packet); - } - techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"), (p, packet) -> locationEvaluator.suppressInteractions(p) ? null : packet); - - } - - public void enable() { - techhiders.forEach(TinyProtocol.instance::addFilter); - } - - public void disable() { - techhiders.forEach(TinyProtocol.instance::removeFilter); - } - - public enum State { - SKIP, - CHECK, - HIDE, - HIDE_AIR - } - - public interface LocationEvaluator { - default boolean suppressInteractions(Player player) { - return false; - } - - boolean skipChunk(Player player, int x, int z); - default boolean skipChunkSection(Player player, int x, int y, int z) { - return skipChunk(player, x, z); - } - default State check(Player player, int x, int y, int z) { - return skipChunkSection(player, ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(y), ProtocolUtils.posToChunk(z)) ? State.SKIP : State.CHECK; - } - - default State checkBlockPos(Player player, Object pos) { - return check(player, blockPositionX.get(pos), blockPositionY.get(pos), blockPositionZ.get(pos)); - } - - default boolean blockPrecise(Player player, int x, int y, int z) { - return false; - } - } -} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHiderUpdated.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHiderUpdated.java index 26138c02..7ad1f958 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHiderUpdated.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHiderUpdated.java @@ -67,11 +67,13 @@ public class TechHiderUpdated { private final Map>, BiFunction, Packet>> packetProcessors; private final TinyProtocol interceptor; private final Set blockIdsToObfuscate; + private final Set blockEntitiesToHide; private final BlockState blockToObfuscateTo; - public TechHiderUpdated(Plugin plugin, Set blockIdsToObfuscate, BlockState blockToObfuscateTo) { + public TechHiderUpdated(Plugin plugin, Set blockIdsToObfuscate, BlockState blockToObfuscateTo, Set blockEntitiesToHide) { this.blockIdsToObfuscate = blockIdsToObfuscate; this.blockToObfuscateTo = blockToObfuscateTo; + this.blockEntitiesToHide = blockEntitiesToHide; this.bypassingPackets = Set.of( // --- Handshake & Login Protocol --- // These must be whitelisted to allow the player to actually reach the 'Play' @@ -112,8 +114,7 @@ public class TechHiderUpdated { ClientboundCommandsPacket.class // Command tree for tab-complete ); - BiFunction, Packet> tossPacket = (p, - packet) -> null; + BiFunction, Packet> tossPacket = (p, packet) -> null; this.packetProcessors = Map.of( ClientboundBlockEventPacket.class, @@ -122,8 +123,11 @@ public class TechHiderUpdated { (p, packet) -> processBlockUpdatePacket(p, (ClientboundBlockUpdatePacket) packet), ClientboundBlockEntityDataPacket.class, (p, packet) -> processBlockEntityDataPacket(p, (ClientboundBlockEntityDataPacket) packet), - ClientboundSectionBlocksUpdatePacket.class, tossPacket, - ClientboundLevelChunkWithLightPacket.class, tossPacket); + ClientboundSectionBlocksUpdatePacket.class, + (p, packet) -> processSectionUpdate(p, (ClientboundSectionBlocksUpdatePacket) packet), + ClientboundLevelChunkWithLightPacket.class, + (p, packet) -> processChunkWithLight(p, (ClientboundLevelChunkWithLightPacket) packet) + ); this.interceptor = new TinyProtocol(plugin) { @Override @@ -131,8 +135,7 @@ public class TechHiderUpdated { if (bypassingPackets.stream().anyMatch(clazz -> clazz.isInstance(packet))) { return packet; } else if (packetProcessors.containsKey(packet.getClass())) { - return packetProcessors.get(packet.getClass()).apply(receiver, - (Packet) packet); + return packetProcessors.get(packet.getClass()).apply(receiver, (Packet) packet); } else { return null; } @@ -144,29 +147,32 @@ public class TechHiderUpdated { private ClientboundBlockEventPacket processBlockEventPacket(Player player, ClientboundBlockEventPacket packet) { BlockPos blockPos = packet.getPos(); - if (isPlayerPrivilegedToAccessBlockPos(player, blockPos)) { + if (isPlayerPrivilegedToAccessBlockPos(player, blockPos.getX(), blockPos.getY(), blockPos.getZ())) { return packet; } else { return null; } } - private ClientboundBlockUpdatePacket processBlockUpdatePacket(Player p, ClientboundBlockUpdatePacket packet) { + private ClientboundBlockUpdatePacket processBlockUpdatePacket(Player player, ClientboundBlockUpdatePacket packet) { + BlockPos blockPos = packet.getPos(); int id = BlockIds.impl.getCombinedId(packet.getBlockState()); - if (blockIdsToObfuscate.contains(id)) { - // Return a modified copy of the packet with the obfuscated block state - ClientboundBlockUpdatePacket modifiedPacket = new ClientboundBlockUpdatePacket(packet.getPos(), - blockToObfuscateTo); + if(isPlayerPrivilegedToAccessBlockPos(player, blockPos.getX(), blockPos.getY(), blockPos.getZ())) { + return packet; + } + else if (blockIdsToObfuscate.contains(id)) { + ClientboundBlockUpdatePacket modifiedPacket = new ClientboundBlockUpdatePacket(packet.getPos(), blockToObfuscateTo); return modifiedPacket; } else { return packet; } } - private ClientboundBlockEntityDataPacket processBlockEntityDataPacket(Player p, - ClientboundBlockEntityDataPacket packet) { - if (isPlayerPrivilegedToAccessBlockPos(p, packet.getPos())) { + private ClientboundBlockEntityDataPacket processBlockEntityDataPacket(Player p, ClientboundBlockEntityDataPacket packet) { + BlockPos blockPos = packet.getPos(); + + if (isPlayerPrivilegedToAccessBlockPos(p, blockPos.getX(), blockPos.getY(), blockPos.getZ())) { return packet; } else if (ProtocolWrapper.impl.unfilteredTileEntityDataAction(packet)) { return packet; @@ -175,8 +181,7 @@ public class TechHiderUpdated { } } - private ClientboundSectionBlocksUpdatePacket processSectionUpdate(Player p, - ClientboundSectionBlocksUpdatePacket packet) { + private ClientboundSectionBlocksUpdatePacket processSectionUpdate(Player p, ClientboundSectionBlocksUpdatePacket packet) { SectionPos sectionPos = packet.sectionPos; short[] oldPos = packet.positions; BlockState[] oldStates = packet.states; @@ -195,7 +200,7 @@ public class TechHiderUpdated { BlockPos pos = new BlockPos(worldX, worldY, worldZ); - if (isPlayerPrivilegedToAccessBlockPos(p, pos)) { + if (isPlayerPrivilegedToAccessBlockPos(p, pos.getX(), pos.getY(), pos.getZ())) { filteredPos.add(posShort); filteredStates.add(state); } else { @@ -211,14 +216,19 @@ public class TechHiderUpdated { } } - if (filteredStates.isEmpty()) + if (filteredStates.isEmpty()) { return null; - if (!modified) + } + if (!modified) { return packet; + } + short[] newPos = new short[filteredPos.size()]; - for (int i = 0; i < newPos.length; i++) + for (int i = 0; i < newPos.length; i++) { newPos[i] = filteredPos.get(i); + } + BlockState[] newStates = filteredStates.toArray(new BlockState[0]); return new ClientboundSectionBlocksUpdatePacket( @@ -228,10 +238,12 @@ public class TechHiderUpdated { newStates); } - private ClientboundLevelChunkWithLightPacket processChunkWithLight(Player p, ClientboundLevelChunkWithLightPacket packet) { - } + private final ChunkHider chunkHider = new ChunkHider(); + private ClientboundLevelChunkWithLightPacket processChunkWithLight(Player p, ClientboundLevelChunkWithLightPacket packet) { + return chunkHider.processLevelChunkWithLightPacket(p, blockEntitiesToHide, this::isPlayerPrivilegedToAccessBlockPos,blockToObfuscateTo, blockIdsToObfuscate, packet); + } - private boolean isPlayerPrivilegedToAccessBlockPos(Player p, BlockPos pos) { + private boolean isPlayerPrivilegedToAccessBlockPos(Player p, int blockX, int blockY, int blockZ) { return false; }