Skip to content

Commit a13b763

Browse files
committed
feat: start work on paper anti-x-ray support
1 parent 0a754a3 commit a13b763

File tree

49 files changed

+342
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+342
-78
lines changed

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_20_R2/PaperweightAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
863863
SideEffect.HISTORY,
864864
SideEffect.HEIGHTMAPS,
865865
SideEffect.LIGHTING,
866-
SideEffect.NEIGHBORS
866+
SideEffect.NEIGHBORS,
867+
SideEffect.PAPER_ANTI_XRAY
867868
//FAWE end
868869
);
869870

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ public BaseBlock getFullBlock(final Location location) {
309309
SideEffect.HISTORY,
310310
SideEffect.HEIGHTMAPS,
311311
SideEffect.LIGHTING,
312-
SideEffect.NEIGHBORS
312+
SideEffect.NEIGHBORS,
313+
SideEffect.PAPER_ANTI_XRAY
313314
);
314315

315316
@Override

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweWorldNativeAccess.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ public void run(Object value) {
252252
return;
253253
}
254254
for (IntPair chunk : toSend) {
255-
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
255+
PaperweightPlatformAdapter.sendChunk(
256+
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
257+
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
258+
);
256259
}
257260
}
258261
};
@@ -268,7 +271,10 @@ public void run(Object value) {
268271
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
269272
));
270273
for (IntPair chunk : cachedChunksToSend) {
271-
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
274+
PaperweightPlatformAdapter.sendChunk(
275+
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
276+
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
277+
);
272278
}
273279
}
274280
};

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ protected <T extends Future<T>> T internalCall(
747747
if (!set
748748
.getSideEffectSet()
749749
.shouldApply(SideEffect.LIGHTING) || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING || finalMask == 0 && biomes != null) {
750-
this.send();
750+
this.send(set.getSideEffectSet().shouldApply(SideEffect.PAPER_ANTI_XRAY));
751751
}
752752
if (finalizer != null) {
753753
finalizer.run();
@@ -788,9 +788,9 @@ private void updateGet(
788788
}
789789

790790
@Override
791-
public void send() {
791+
public void send(boolean obfuscateAntiXRay) {
792792
synchronized (sendLock) {
793-
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ);
793+
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ, obfuscateAntiXRay);
794794
}
795795
}
796796

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlatformAdapter.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2;
22

3+
import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray;
4+
import com.destroystokyo.paper.antixray.ChunkPacketInfoAntiXray;
35
import com.destroystokyo.paper.util.maplist.EntityList;
46
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
57
import com.fastasyncworldedit.bukkit.adapter.DelegateSemaphore;
@@ -25,6 +27,7 @@
2527
import net.minecraft.core.Holder;
2628
import net.minecraft.core.IdMap;
2729
import net.minecraft.core.Registry;
30+
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
2831
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
2932
import net.minecraft.server.MinecraftServer;
3033
import net.minecraft.server.level.ChunkHolder;
@@ -106,6 +109,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
106109

107110
private static final Field fieldRemove;
108111

112+
private static final Field fieldChunkData;
113+
109114
private static final Logger LOGGER = LogManagerCompat.getLogger();
110115

111116
static final boolean POST_CHUNK_REWRITE;
@@ -211,6 +216,16 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
211216
);
212217
palettedContaienrGet.setAccessible(true);
213218
PALETTED_CONTAINER_GET = lookup.unreflect(palettedContaienrGet);
219+
220+
if (PaperLib.isPaper()) {
221+
fieldChunkData = ClientboundLevelChunkWithLightPacket.class.getDeclaredField(Refraction.pickName(
222+
"chunkData",
223+
"d"
224+
));
225+
fieldChunkData.setAccessible(true);
226+
} else {
227+
fieldChunkData = null; // not needed on Spigot as we don't touch Anti-X-Ray there
228+
}
214229
} catch (RuntimeException | Error e) {
215230
throw e;
216231
} catch (Exception e) {
@@ -343,7 +358,7 @@ public static ChunkHolder getPlayerChunk(ServerLevel nmsWorld, final int chunkX,
343358
}
344359

345360
@SuppressWarnings("deprecation")
346-
public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int chunkZ) {
361+
public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int chunkZ, boolean obfuscateAntiXRay) {
347362
ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ);
348363
if (chunkHolder == null) {
349364
return;
@@ -378,8 +393,19 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
378393
nmsWorld.getChunkSource().getLightEngine(),
379394
null,
380395
null,
381-
false // last false is to not bother with x-ray
396+
false // false so we can handle anti-X-Ray ourselves
382397
);
398+
if (obfuscateAntiXRay && nmsWorld.chunkPacketBlockController instanceof ChunkPacketBlockControllerAntiXray antiXray) {
399+
ChunkPacketInfoAntiXray info = antiXray.getChunkPacketInfo(packet, levelChunk);
400+
info.setNearbyChunks(
401+
nmsWorld.getChunkIfLoaded(chunkX - 1, chunkZ),
402+
nmsWorld.getChunkIfLoaded(chunkX + 1, chunkZ),
403+
nmsWorld.getChunkIfLoaded(chunkX, chunkZ - 1),
404+
nmsWorld.getChunkIfLoaded(chunkX, chunkZ + 1)
405+
);
406+
fieldChunkData.set(packet, new ClientboundLevelChunkPacketData(levelChunk, info));
407+
antiXray.obfuscate(info);
408+
}
383409
} else {
384410
// deprecated on paper - deprecation suppressed
385411
packet = new ClientboundLevelChunkWithLightPacket(
@@ -390,6 +416,8 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
390416
);
391417
}
392418
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
419+
} catch (IllegalAccessException e) {
420+
LOGGER.error("Failed to reflectively apply anti x-ray data", e);
393421
} finally {
394422
NMSAdapter.endChunkPacketSend(nmsWorld.getWorld().getName(), pair, lockHolder);
395423
}

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightStarlightRelighter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void postProcessChunks(Set<ChunkPos> coords) {
6868
int x = pos.x;
6969
int z = pos.z;
7070
if (delay) { // we still need to send the block changes of that chunk
71-
PaperweightPlatformAdapter.sendChunk(new IntPair(x, z), serverLevel, x, z);
71+
PaperweightPlatformAdapter.sendChunk(new IntPair(x, z), serverLevel, x, z, this.obfuscateAntiXRay);
7272
}
7373
serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE);
7474
}

worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext.fawe/v1_20_R3/PaperweightAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
862862
SideEffect.HISTORY,
863863
SideEffect.HEIGHTMAPS,
864864
SideEffect.LIGHTING,
865-
SideEffect.NEIGHBORS
865+
SideEffect.NEIGHBORS,
866+
SideEffect.PAPER_ANTI_XRAY
866867
//FAWE end
867868
);
868869

worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ public BaseBlock getFullBlock(final Location location) {
308308
SideEffect.HISTORY,
309309
SideEffect.HEIGHTMAPS,
310310
SideEffect.LIGHTING,
311-
SideEffect.NEIGHBORS
311+
SideEffect.NEIGHBORS,
312+
SideEffect.PAPER_ANTI_XRAY
312313
);
313314

314315
@Override

worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweWorldNativeAccess.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ public void run(Object value) {
252252
return;
253253
}
254254
for (IntPair chunk : toSend) {
255-
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
255+
PaperweightPlatformAdapter.sendChunk(
256+
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
257+
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
258+
);
256259
}
257260
}
258261
};
@@ -268,7 +271,10 @@ public void run(Object value) {
268271
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
269272
));
270273
for (IntPair chunk : cachedChunksToSend) {
271-
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
274+
PaperweightPlatformAdapter.sendChunk(
275+
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
276+
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
277+
);
272278
}
273279
}
274280
};

worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightGetBlocks.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ protected <T extends Future<T>> T internalCall(
748748
if (!set
749749
.getSideEffectSet()
750750
.shouldApply(SideEffect.LIGHTING) || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING || finalMask == 0 && biomes != null) {
751-
this.send();
751+
this.send(set.getSideEffectSet().shouldApply(SideEffect.PAPER_ANTI_XRAY));
752752
}
753753
if (finalizer != null) {
754754
finalizer.run();
@@ -789,9 +789,9 @@ private void updateGet(
789789
}
790790

791791
@Override
792-
public void send() {
792+
public void send(boolean obfuscateAntiXRay) {
793793
synchronized (sendLock) {
794-
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ);
794+
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ, obfuscateAntiXRay);
795795
}
796796
}
797797

0 commit comments

Comments
 (0)