124 lines
10 KiB
Diff
124 lines
10 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cryptite <cryptite@gmail.com>
|
|
Date: Wed, 10 May 2023 08:58:29 -0500
|
|
Subject: [PATCH] Add PlayerPreSendChunkPacketEvent
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java
|
|
index f90f27d9d9a4043198c33d65efa7068b76b58818..b8181bc872034dcab9272d5890f565800cfdb8f8 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java
|
|
@@ -53,10 +53,10 @@ public final class ChunkPacketBlockControllerAntiXray extends ChunkPacketBlockCo
|
|
private final LevelChunkSection[] emptyNearbyChunkSections = {EMPTY_SECTION, EMPTY_SECTION, EMPTY_SECTION, EMPTY_SECTION};
|
|
private final int maxBlockHeightUpdatePosition;
|
|
|
|
- public ChunkPacketBlockControllerAntiXray(Level level, Executor executor) {
|
|
+ public ChunkPacketBlockControllerAntiXray(Level level, Executor executor, EngineMode providedMode) { // Slice
|
|
this.executor = executor;
|
|
WorldConfiguration.Anticheat.AntiXray paperWorldConfig = level.paperConfig().anticheat.antiXray;
|
|
- engineMode = paperWorldConfig.engineMode;
|
|
+ engineMode = providedMode != null ? providedMode : paperWorldConfig.engineMode; // Slice
|
|
maxBlockHeight = paperWorldConfig.maxBlockHeight >> 4 << 4;
|
|
updateRadius = paperWorldConfig.updateRadius;
|
|
usePermission = paperWorldConfig.usePermission;
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
|
|
index 000853110c7a89f2d0403a7a2737025a5ac28240..919493a3d23ccd9eb1894f8510f96b1ad2aae2ff 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
|
|
@@ -27,17 +27,21 @@ public class ClientboundLevelChunkWithLightPacket implements Packet<ClientGamePa
|
|
// Paper end
|
|
|
|
// Paper start - Anti-Xray - Add chunk packet info
|
|
- @Deprecated @io.papermc.paper.annotation.DoNotUse public ClientboundLevelChunkWithLightPacket(LevelChunk chunk, LevelLightEngine lightProvider, @Nullable BitSet skyBits, @Nullable BitSet blockBits, boolean nonEdge) { this(chunk, lightProvider, skyBits, blockBits, nonEdge, true); }
|
|
- public ClientboundLevelChunkWithLightPacket(LevelChunk chunk, LevelLightEngine lightProvider, @Nullable BitSet skyBits, @Nullable BitSet blockBits, boolean nonEdge, boolean modifyBlocks) {
|
|
+ // Slice start
|
|
+ @Deprecated @io.papermc.paper.annotation.DoNotUse public ClientboundLevelChunkWithLightPacket(LevelChunk chunk, LevelLightEngine lightProvider, @Nullable BitSet skyBits, @Nullable BitSet blockBits, boolean nonEdge) { this(chunk, lightProvider, skyBits, blockBits, nonEdge, true, false); }
|
|
+ public ClientboundLevelChunkWithLightPacket(LevelChunk chunk, LevelLightEngine lightProvider, @Nullable BitSet skyBits, @Nullable BitSet blockBits, boolean nonEdge, boolean modifyBlocks, boolean mode2) {
|
|
ChunkPos chunkPos = chunk.getPos();
|
|
this.x = chunkPos.x;
|
|
this.z = chunkPos.z;
|
|
- com.destroystokyo.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo = modifyBlocks ? chunk.getLevel().chunkPacketBlockController.getChunkPacketInfo(this, chunk) : null;
|
|
+
|
|
+ com.destroystokyo.paper.antixray.ChunkPacketBlockController chunkPacketBlockController = mode2 ? chunk.getLevel().chunkPacketBlockControllerMode2 : chunk.getLevel().chunkPacketBlockController;
|
|
+ com.destroystokyo.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo = modifyBlocks ? chunkPacketBlockController.getChunkPacketInfo(this, chunk) : null;
|
|
this.chunkData = new ClientboundLevelChunkPacketData(chunk, chunkPacketInfo);
|
|
// Paper end
|
|
this.lightData = new ClientboundLightUpdatePacketData(chunkPos, lightProvider, skyBits, blockBits, nonEdge);
|
|
- chunk.getLevel().chunkPacketBlockController.modifyBlocks(this, chunkPacketInfo); // Paper - Anti-Xray - Modify blocks
|
|
+ chunkPacketBlockController.modifyBlocks(this, chunkPacketInfo); // Paper - Anti-Xray - Modify blocks
|
|
}
|
|
+ // Slice end
|
|
|
|
public ClientboundLevelChunkWithLightPacket(FriendlyByteBuf buf) {
|
|
this.x = buf.readInt();
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
index 67a8b0145e4ed096b4fc520202098b9b1d259bd6..ae3d1baa28ab591501b270fa57d7c00886109aee 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
@@ -1463,7 +1463,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
}
|
|
}
|
|
// Paper end - Fix MC-162253
|
|
- return new ClientboundLevelChunkWithLightPacket(chunk, this.lightEngine, (BitSet) null, (BitSet) null, true, (Boolean) s);
|
|
+ // Slice start
|
|
+ io.papermc.paper.event.player.PlayerPreSendChunkPacketEvent event = new io.papermc.paper.event.player.PlayerPreSendChunkPacketEvent(player.getBukkitEntity().getPlayer(), new org.bukkit.craftbukkit.CraftChunk(chunk));
|
|
+ event.callEvent();
|
|
+ return new ClientboundLevelChunkWithLightPacket(chunk, this.lightEngine, (BitSet) null, (BitSet) null, true, (Boolean) s, event.isUseMode2());
|
|
+ // Slice end
|
|
}));
|
|
// Paper end
|
|
DebugPackets.sendPoiPacketsForChunk(this.level, chunk.getPos());
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index e0bd18ac70a93d41762fb23e7442d06355384d59..30978f9a40cd4744e99f4c596cd9bfa9531d7eda 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -399,7 +399,7 @@ public abstract class PlayerList {
|
|
.getHolderOrThrow(net.minecraft.world.level.biome.Biomes.PLAINS);
|
|
player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket(
|
|
new net.minecraft.world.level.chunk.EmptyLevelChunk(worldserver1, player.chunkPosition(), plains),
|
|
- worldserver1.getLightEngine(), null, null, true, false)
|
|
+ worldserver1.getLightEngine(), null, null, true, false, false) // Slice
|
|
);
|
|
}
|
|
// Paper end
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index 23630e4ab396158d8f3f77bf9aa05f66c6b27a9d..d301de59501ddfbf6f5da66191a871089242250c 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -177,6 +177,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
// Paper end
|
|
|
|
public final com.destroystokyo.paper.antixray.ChunkPacketBlockController chunkPacketBlockController; // Paper - Anti-Xray
|
|
+ public final com.destroystokyo.paper.antixray.ChunkPacketBlockController chunkPacketBlockControllerMode2; // Paper - Anti-Xray
|
|
public final co.aikar.timings.WorldTimingsHandler timings; // Paper
|
|
public static BlockPos lastPhysicsProblem; // Spigot
|
|
private org.spigotmc.TickLimiter entityLimiter;
|
|
@@ -381,7 +382,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
this.keepSpawnInMemory = this.paperConfig().spawn.keepSpawnLoaded; // Paper
|
|
this.entityLimiter = new org.spigotmc.TickLimiter(spigotConfig.entityMaxTickTime);
|
|
this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime);
|
|
- this.chunkPacketBlockController = this.paperConfig().anticheat.antiXray.enabled ? new com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray(this, executor) : com.destroystokyo.paper.antixray.ChunkPacketBlockController.NO_OPERATION_INSTANCE; // Paper - Anti-Xray
|
|
+ this.chunkPacketBlockController = this.paperConfig().anticheat.antiXray.enabled ? new com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray(this, executor, null) : com.destroystokyo.paper.antixray.ChunkPacketBlockController.NO_OPERATION_INSTANCE; // Paper - Anti-Xray
|
|
+ this.chunkPacketBlockControllerMode2 = this.paperConfig().anticheat.antiXray.enabled ? new com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray(this, executor, io.papermc.paper.configuration.type.EngineMode.OBFUSCATE) : com.destroystokyo.paper.antixray.ChunkPacketBlockController.NO_OPERATION_INSTANCE; // Paper - Anti-Xray // Slice
|
|
}
|
|
|
|
// Paper start
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index 3e45551d8d677ccfb362e3039d7dee10018206d6..b13a55624365a72d323292259c1974dba0b4a76c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -524,8 +524,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
if (player.connection == null) continue;
|
|
|
|
Boolean shouldModify = chunk.getLevel().chunkPacketBlockController.shouldModify(player, chunk);
|
|
+ // Slice start
|
|
+ io.papermc.paper.event.player.PlayerPreSendChunkPacketEvent event = new io.papermc.paper.event.player.PlayerPreSendChunkPacketEvent(player.getBukkitEntity().getPlayer(), new CraftChunk(chunk));
|
|
+ event.callEvent();
|
|
+ // Slice end
|
|
player.connection.send(refreshPackets.computeIfAbsent(shouldModify, s -> { // Use connection to prevent creating firing event
|
|
- return new ClientboundLevelChunkWithLightPacket(chunk, this.world.getLightEngine(), null, null, true, (Boolean) s);
|
|
+ return new ClientboundLevelChunkWithLightPacket(chunk, this.world.getLightEngine(), null, null, true, (Boolean) s, event.isUseMode2()); // Slice
|
|
}));
|
|
// Paper end
|
|
}
|