forked from SteamWar/SteamWar
Add handling for container
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util.function.ToDoubleFunction;
|
|||||||
import java.util.function.ToIntFunction;
|
import java.util.function.ToIntFunction;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
|
import net.minecraft.server.packs.repository.Pack;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@@ -377,11 +378,11 @@ public abstract class TechHider {
|
|||||||
|
|
||||||
// --- Container packets ---
|
// --- Container packets ---
|
||||||
// 7.1.19 Set Container Content
|
// 7.1.19 Set Container Content
|
||||||
processors.put(ClientboundContainerSetContentPacket.class, tossPacket);
|
processors.put(ClientboundContainerSetContentPacket.class, buildContainerPacketProcessor(ClientboundContainerSetContentPacket::containerId));
|
||||||
// 7.1.20 Set Container Property
|
// 7.1.20 Set Container Property
|
||||||
processors.put(ClientboundContainerSetDataPacket.class, tossPacket);
|
processors.put(ClientboundContainerSetDataPacket.class, buildContainerPacketProcessor(ClientboundContainerSetDataPacket::getContainerId));
|
||||||
// 7.1.21 Set Container Slot
|
// 7.1.21 Set Container Slot
|
||||||
processors.put(ClientboundContainerSetSlotPacket.class, tossPacket);
|
processors.put(ClientboundContainerSetSlotPacket.class, buildContainerPacketProcessor(ClientboundContainerSetSlotPacket::getContainerId));
|
||||||
|
|
||||||
// --- Others ---
|
// --- Others ---
|
||||||
// 7.1.37 Explosion: position, affected blocks, and knockback can reveal
|
// 7.1.37 Explosion: position, affected blocks, and knockback can reveal
|
||||||
@@ -618,11 +619,25 @@ public abstract class TechHider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final ChunkHider chunkHider = new ChunkHider();
|
private final ChunkHider chunkHider = new ChunkHider();
|
||||||
|
|
||||||
private ClientboundLevelChunkWithLightPacket processChunkWithLight(Player p, ClientboundLevelChunkWithLightPacket packet) {
|
private ClientboundLevelChunkWithLightPacket processChunkWithLight(Player p, ClientboundLevelChunkWithLightPacket packet) {
|
||||||
return chunkHider.processLevelChunkWithLightPacket(p, blockEntitiesToHide, this::isPlayerPrivilegedToAccessBlockPos, blockToObfuscateTo, blockIdsToObfuscate, packet);
|
return chunkHider.processLevelChunkWithLightPacket(p, blockEntitiesToHide, this::isPlayerPrivilegedToAccessBlockPos, blockToObfuscateTo, blockIdsToObfuscate, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Packet<? extends PacketListener> processContainerPacket(Player player, int containerId, Packet<? extends PacketListener> packet) {
|
||||||
|
if(isPlayerPrivilegedToAccessContainer(player, containerId)) {
|
||||||
|
return packet;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private <TTargetPacket extends Packet<?>> BiFunction<Player, Packet<?>, Packet<?>> buildContainerPacketProcessor(ToIntFunction<TTargetPacket> containerIdExtractor) {
|
||||||
|
return (p, rawPacket) -> {
|
||||||
|
TTargetPacket packet = (TTargetPacket) rawPacket;
|
||||||
|
|
||||||
|
return processContainerPacket(p, containerIdExtractor.applyAsInt(packet), packet);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public abstract boolean isPlayerPrivilegedToAccessPosition(Player p, int blockX, int blockY, int blockZ);
|
public abstract boolean isPlayerPrivilegedToAccessPosition(Player p, int blockX, int blockY, int blockZ);
|
||||||
public abstract boolean isPlayerPrivilegedToAccessBlock(Player p, int blockX, int blockY, int blockZ, Block block);
|
public abstract boolean isPlayerPrivilegedToAccessBlock(Player p, int blockX, int blockY, int blockZ, Block block);
|
||||||
public abstract boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId);
|
public abstract boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId);
|
||||||
|
|||||||
Reference in New Issue
Block a user