Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.PAPER_ANTI_XRAY
//FAWE end
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ public BaseBlock getFullBlock(final Location location) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.PAPER_ANTI_XRAY
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ public void run(Object value) {
return;
}
for (IntPair chunk : toSend) {
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
PaperweightPlatformAdapter.sendChunk(
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
);
}
}
};
Expand All @@ -268,7 +271,10 @@ public void run(Object value) {
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
));
for (IntPair chunk : cachedChunksToSend) {
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
PaperweightPlatformAdapter.sendChunk(
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ protected <T extends Future<T>> T internalCall(
if (!set
.getSideEffectSet()
.shouldApply(SideEffect.LIGHTING) || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING || finalMask == 0 && biomes != null) {
this.send();
this.send(set.getSideEffectSet().shouldApply(SideEffect.PAPER_ANTI_XRAY));
}
if (finalizer != null) {
finalizer.run();
Expand Down Expand Up @@ -788,9 +788,9 @@ private void updateGet(
}

@Override
public void send() {
public void send(boolean obfuscateAntiXRay) {
synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ);
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ, obfuscateAntiXRay);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2;

import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray;
import com.destroystokyo.paper.antixray.ChunkPacketInfoAntiXray;
import com.destroystokyo.paper.util.maplist.EntityList;
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
import com.fastasyncworldedit.bukkit.adapter.DelegateSemaphore;
Expand All @@ -25,6 +27,7 @@
import net.minecraft.core.Holder;
import net.minecraft.core.IdMap;
import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder;
Expand Down Expand Up @@ -106,6 +109,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {

private static final Field fieldRemove;

private static final Field fieldChunkData;

private static final Logger LOGGER = LogManagerCompat.getLogger();

static final boolean POST_CHUNK_REWRITE;
Expand Down Expand Up @@ -211,6 +216,16 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
);
palettedContaienrGet.setAccessible(true);
PALETTED_CONTAINER_GET = lookup.unreflect(palettedContaienrGet);

if (PaperLib.isPaper()) {
fieldChunkData = ClientboundLevelChunkWithLightPacket.class.getDeclaredField(Refraction.pickName(
"chunkData",
"d"
));
fieldChunkData.setAccessible(true);
} else {
fieldChunkData = null; // not needed on Spigot as we don't touch Anti-X-Ray there
}
} catch (RuntimeException | Error e) {
throw e;
} catch (Exception e) {
Expand Down Expand Up @@ -343,7 +358,7 @@ public static ChunkHolder getPlayerChunk(ServerLevel nmsWorld, final int chunkX,
}

@SuppressWarnings("deprecation")
public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int chunkZ) {
public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int chunkZ, boolean obfuscateAntiXRay) {
ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (chunkHolder == null) {
return;
Expand Down Expand Up @@ -378,8 +393,19 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
nmsWorld.getChunkSource().getLightEngine(),
null,
null,
false // last false is to not bother with x-ray
false // false so we can handle anti-X-Ray ourselves
);
if (obfuscateAntiXRay && nmsWorld.chunkPacketBlockController instanceof ChunkPacketBlockControllerAntiXray antiXray) {
ChunkPacketInfoAntiXray info = antiXray.getChunkPacketInfo(packet, levelChunk);
info.setNearbyChunks(
nmsWorld.getChunkIfLoaded(chunkX - 1, chunkZ),
nmsWorld.getChunkIfLoaded(chunkX + 1, chunkZ),
nmsWorld.getChunkIfLoaded(chunkX, chunkZ - 1),
nmsWorld.getChunkIfLoaded(chunkX, chunkZ + 1)
);
fieldChunkData.set(packet, new ClientboundLevelChunkPacketData(levelChunk, info));
antiXray.obfuscate(info);
}
} else {
// deprecated on paper - deprecation suppressed
packet = new ClientboundLevelChunkWithLightPacket(
Expand All @@ -390,6 +416,8 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
);
}
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
} catch (IllegalAccessException e) {
LOGGER.error("Failed to reflectively apply anti x-ray data", e);
} finally {
NMSAdapter.endChunkPacketSend(nmsWorld.getWorld().getName(), pair, lockHolder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void postProcessChunks(Set<ChunkPos> coords) {
int x = pos.x;
int z = pos.z;
if (delay) { // we still need to send the block changes of that chunk
PaperweightPlatformAdapter.sendChunk(new IntPair(x, z), serverLevel, x, z);
PaperweightPlatformAdapter.sendChunk(new IntPair(x, z), serverLevel, x, z, this.obfuscateAntiXRay);
}
serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.PAPER_ANTI_XRAY
//FAWE end
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ public BaseBlock getFullBlock(final Location location) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.PAPER_ANTI_XRAY
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ public void run(Object value) {
return;
}
for (IntPair chunk : toSend) {
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
PaperweightPlatformAdapter.sendChunk(
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
);
}
}
};
Expand All @@ -268,7 +271,10 @@ public void run(Object value) {
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
));
for (IntPair chunk : cachedChunksToSend) {
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
PaperweightPlatformAdapter.sendChunk(
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ protected <T extends Future<T>> T internalCall(
if (!set
.getSideEffectSet()
.shouldApply(SideEffect.LIGHTING) || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING || finalMask == 0 && biomes != null) {
this.send();
this.send(set.getSideEffectSet().shouldApply(SideEffect.PAPER_ANTI_XRAY));
}
if (finalizer != null) {
finalizer.run();
Expand Down Expand Up @@ -789,9 +789,9 @@ private void updateGet(
}

@Override
public void send() {
public void send(boolean obfuscateAntiXRay) {
synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ);
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ, obfuscateAntiXRay);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3;

import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray;
import com.destroystokyo.paper.antixray.ChunkPacketInfoAntiXray;
import com.destroystokyo.paper.util.maplist.EntityList;
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
import com.fastasyncworldedit.bukkit.adapter.DelegateSemaphore;
Expand All @@ -25,6 +27,7 @@
import net.minecraft.core.Holder;
import net.minecraft.core.IdMap;
import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder;
Expand Down Expand Up @@ -106,6 +109,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {

private static final Field fieldRemove;

private static final Field fieldChunkData;

private static final Logger LOGGER = LogManagerCompat.getLogger();

static final boolean POST_CHUNK_REWRITE;
Expand Down Expand Up @@ -211,6 +216,16 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
);
palettedContaienrGet.setAccessible(true);
PALETTED_CONTAINER_GET = lookup.unreflect(palettedContaienrGet);

if (PaperLib.isPaper()) {
fieldChunkData = ClientboundLevelChunkWithLightPacket.class.getDeclaredField(Refraction.pickName(
"chunkData",
"d"
));
fieldChunkData.setAccessible(true);
} else {
fieldChunkData = null; // not needed on Spigot as we don't touch Anti-X-Ray there
}
} catch (RuntimeException | Error e) {
throw e;
} catch (Exception e) {
Expand Down Expand Up @@ -343,7 +358,7 @@ public static ChunkHolder getPlayerChunk(ServerLevel nmsWorld, final int chunkX,
}

@SuppressWarnings("deprecation")
public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int chunkZ) {
public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int chunkZ, boolean obfuscateAntiXRay) {
ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (chunkHolder == null) {
return;
Expand Down Expand Up @@ -378,8 +393,19 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
nmsWorld.getChunkSource().getLightEngine(),
null,
null,
false // last false is to not bother with x-ray
false // false so we can handle anti-X-Ray ourselves
);
if (obfuscateAntiXRay && nmsWorld.chunkPacketBlockController instanceof ChunkPacketBlockControllerAntiXray antiXray) {
ChunkPacketInfoAntiXray info = antiXray.getChunkPacketInfo(packet, levelChunk);
info.setNearbyChunks(
nmsWorld.getChunkIfLoaded(chunkX - 1, chunkZ),
nmsWorld.getChunkIfLoaded(chunkX + 1, chunkZ),
nmsWorld.getChunkIfLoaded(chunkX, chunkZ - 1),
nmsWorld.getChunkIfLoaded(chunkX, chunkZ + 1)
);
fieldChunkData.set(packet, new ClientboundLevelChunkPacketData(levelChunk, info));
antiXray.obfuscate(info);
}
} else {
// deprecated on paper - deprecation suppressed
packet = new ClientboundLevelChunkWithLightPacket(
Expand All @@ -390,6 +416,8 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
);
}
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
} catch (IllegalAccessException e) {
LOGGER.error("Failed to reflectively apply anti x-ray data", e);
} finally {
NMSAdapter.endChunkPacketSend(nmsWorld.getWorld().getName(), pair, lockHolder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void postProcessChunks(Set<ChunkPos> coords) {
int x = pos.x;
int z = pos.z;
if (delay) { // we still need to send the block changes of that chunk
PaperweightPlatformAdapter.sendChunk(new IntPair(x, z), serverLevel, x, z);
PaperweightPlatformAdapter.sendChunk(new IntPair(x, z), serverLevel, x, z, this.obfuscateAntiXRay);
}
serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,8 @@ private ResourceKey<LevelStem> getWorldDimKey(Environment env) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.PAPER_ANTI_XRAY
//FAWE end
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ public BaseBlock getFullBlock(final Location location) {
SideEffect.HISTORY,
SideEffect.HEIGHTMAPS,
SideEffect.LIGHTING,
SideEffect.NEIGHBORS
SideEffect.NEIGHBORS,
SideEffect.PAPER_ANTI_XRAY
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ public void run(Object value) {
return;
}
for (IntPair chunk : toSend) {
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
PaperweightPlatformAdapter.sendChunk(
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
);
}
}
};
Expand All @@ -269,7 +272,10 @@ public void run(Object value) {
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
));
for (IntPair chunk : cachedChunksToSend) {
PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
PaperweightPlatformAdapter.sendChunk(
chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z(),
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.PAPER_ANTI_XRAY)
);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ protected <T extends Future<T>> T internalCall(
if (!set
.getSideEffectSet()
.shouldApply(SideEffect.LIGHTING) || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING || finalMask == 0 && biomes != null) {
this.send();
this.send(set.getSideEffectSet().shouldApply(SideEffect.PAPER_ANTI_XRAY));
}
if (finalizer != null) {
finalizer.run();
Expand Down Expand Up @@ -790,9 +790,9 @@ private void updateGet(
}

@Override
public void send() {
public void send(boolean obfuscateAntiXRay) {
synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ);
PaperweightPlatformAdapter.sendChunk(new IntPair(chunkX, chunkZ), serverLevel, chunkX, chunkZ, obfuscateAntiXRay);
}
}

Expand Down
Loading
Loading