Port anti x-ray patch

This commit is contained in:
Nassim Jahnke 2021-06-15 15:20:52 +02:00
parent aa6c0aa554
commit 3cf01f9fca
10 changed files with 1528 additions and 63 deletions

View File

@ -52,8 +52,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- private final LevelChunkSection[] sections;
+ private LevelChunkSection[] sections; // Paper - remove final
private Set<BlockPos> tiles;
private World world; // Paper - Anti-Xray - Add world
public CraftChunkData(World world) {
@@ -0,0 +0,0 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData {
return this.sections;
}

File diff suppressed because it is too large Load Diff

View File

@ -8,18 +8,18 @@ diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/m
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -0,0 +0,0 @@ import java.util.EnumMap;
import java.util.HashMap;
@@ -0,0 +0,0 @@ package com.destroystokyo.paper;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-
+import java.util.stream.Collectors;
+import net.minecraft.world.Difficulty;
+import net.minecraft.world.entity.monster.Vindicator;
+import net.minecraft.world.entity.monster.Zombie;
import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray.EngineMode;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -0,0 +0,0 @@ public class PaperWorldConfig {
disableMobSpawnerSpawnEggTransformation = getBoolean("game-mechanics.disable-mob-spawner-spawn-egg-transformation", disableMobSpawnerSpawnEggTransformation);
}

View File

@ -34,7 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
public boolean altItemDespawnRateEnabled;
public Map<Material, Integer> altItemDespawnRateMap;
public java.util.Map<org.bukkit.Material, Integer> altItemDespawnRateMap;
private void altItemDespawnRate() {
diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644

View File

@ -301,8 +301,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
return this.typeKey;
}
public final Map<Explosion.CacheKey, Float> explosionDensityCache = new HashMap<>(); // Paper - Optimize explosions
public java.util.ArrayDeque<net.minecraft.world.level.block.RedstoneTorchBlock.Toggle> redstoneUpdateInfos; // Paper - Move from Map in BlockRedstoneTorch to here
+ // Paper start - fix and optimise world upgrading
+ // copied from below
@ -312,9 +312,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ });
+ }
+ // Paper end - fix and optimise world upgrading
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, final DimensionType dimensionmanager, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, org.bukkit.generator.ChunkGenerator gen, org.bukkit.World.Environment env) {
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
this.paperConfig = new com.destroystokyo.paper.PaperWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName(), this.spigotConfig); // Paper
+
public CraftWorld getWorld() {
return this.world;
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java

View File

@ -8,41 +8,26 @@ diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/m
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -0,0 +0,0 @@
package com.destroystokyo.paper;
+import java.util.EnumMap;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.spigotmc.SpigotWorldConfig;
@@ -0,0 +0,0 @@ public class PaperWorldConfig {
private void viewDistance() {
this.noTickViewDistance = this.getInt("viewdistances.no-tick-view-distance", -1);
}
+
+ public boolean altItemDespawnRateEnabled;
+ public Map<Material, Integer> altItemDespawnRateMap;
+ public java.util.Map<org.bukkit.Material, Integer> altItemDespawnRateMap;
+ private void altItemDespawnRate() {
+ String path = "alt-item-despawn-rate";
+
+ altItemDespawnRateEnabled = getBoolean(path + ".enabled", false);
+
+ Map<Material, Integer> altItemDespawnRateMapDefault = new EnumMap<>(Material.class);
+ altItemDespawnRateMapDefault.put(Material.COBBLESTONE, 300);
+ for (Material key : altItemDespawnRateMapDefault.keySet()) {
+ java.util.Map<org.bukkit.Material, Integer> altItemDespawnRateMapDefault = new java.util.EnumMap<>(org.bukkit.Material.class);
+ altItemDespawnRateMapDefault.put(org.bukkit.Material.COBBLESTONE, 300);
+ for (org.bukkit.Material key : altItemDespawnRateMapDefault.keySet()) {
+ config.addDefault("world-settings.default." + path + ".items." + key, altItemDespawnRateMapDefault.get(key));
+ }
+
+ Map<String, Integer> rawMap = new HashMap<>();
+ java.util.Map<String, Integer> rawMap = new java.util.HashMap<>();
+ try {
+ ConfigurationSection mapSection = config.getConfigurationSection("world-settings." + worldName + "." + path + ".items");
+ org.bukkit.configuration.ConfigurationSection mapSection = config.getConfigurationSection("world-settings." + worldName + "." + path + ".items");
+ if (mapSection == null) {
+ mapSection = config.getConfigurationSection("world-settings.default." + path + ".items");
+ }
@ -56,26 +41,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ altItemDespawnRateEnabled = false;
+ }
+
+ altItemDespawnRateMap = new EnumMap<>(Material.class);
+ altItemDespawnRateMap = new java.util.EnumMap<>(org.bukkit.Material.class);
+ if (!altItemDespawnRateEnabled) {
+ return;
+ }
+
+ for(String key : rawMap.keySet()) {
+ try {
+ altItemDespawnRateMap.put(Material.valueOf(key), rawMap.get(key));
+ altItemDespawnRateMap.put(org.bukkit.Material.valueOf(key), rawMap.get(key));
+ } catch (Exception e) {
+ logError("Could not add item " + key + " to altItemDespawnRateMap: " + e.getMessage());
+ }
+ }
+ if(altItemDespawnRateEnabled) {
+ for(Material key : altItemDespawnRateMap.keySet()) {
+ for(org.bukkit.Material key : altItemDespawnRateMap.keySet()) {
+ log("Alternative item despawn rate of " + key + ": " + altItemDespawnRateMap.get(key));
+ }
+ }
+ }
}
+
public boolean antiXray;
public EngineMode engineMode;
public int maxChunkSectionIndex;
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java

View File

@ -27,16 +27,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -0,0 +0,0 @@ public class PaperWorldConfig {
private void lightQueueSize() {
lightQueueSize = getInt("light-queue-size", lightQueueSize);
}
+
+ public int noTickViewDistance;
+ private void viewDistance() {
+ this.noTickViewDistance = this.getInt("viewdistances.no-tick-view-distance", -1);
+ }
}
+
public boolean antiXray;
public EngineMode engineMode;
public int maxChunkSectionIndex;
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java
@ -486,7 +487,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ public void playerLoadedChunk(ServerPlayer player, Packet<?>[] packets, LevelChunk chunk) { // Paper - private -> public
if (packets[0] == null) {
packets[0] = new ClientboundLevelChunkPacket(chunk);
packets[0] = new ClientboundLevelChunkPacket(chunk, chunk.level.chunkPacketBlockController.shouldModify(player, chunk)); // Paper - Ani-Xray - Bypass
packets[1] = new ClientboundLightUpdatePacket(chunk.getPos(), this.lightEngine, (BitSet) null, (BitSet) null, true);
diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644

View File

@ -318,8 +318,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
final PalettedContainer<BlockState> states; // Paper - package-private
+ public final com.destroystokyo.paper.util.maplist.IBlockDataList tickingList = new com.destroystokyo.paper.util.maplist.IBlockDataList(); // Paper
public LevelChunkSection(int yOffset) {
this(yOffset, (short)0, (short)0, (short)0);
// Paper start - Anti-Xray - Add parameters
@Deprecated public LevelChunkSection(int yOffset) { this(yOffset, null, null, true); } // Notice for updates: Please make sure this constructor isn't used anywhere
@@ -0,0 +0,0 @@ public class LevelChunkSection {
--this.nonEmptyBlockCount;
if (blockState.isRandomlyTicking()) {

View File

@ -35,7 +35,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ //this.lock.release(); // Paper - disable this
}
public PalettedContainer(Palette<T> fallbackPalette, IdMapper<T> idList, Function<CompoundTag, T> elementDeserializer, Function<T, CompoundTag> elementSerializer, T defaultElement) {
// Paper start - Anti-Xray - Add predefined objects
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T> {
return this.palette.idFor(objectAdded);
}
@ -64,14 +64,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.acquire();
int i = buf.readByte();
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T> {
@Deprecated public void write(FriendlyByteBuf buf) {
write(buf, null, 0);
}
public void writeDataPaletteBlock(FriendlyByteBuf packetDataSerializer) { this.write(packetDataSerializer); } // Paper - OBFHELPER
- public void write(FriendlyByteBuf buf) {
+ public synchronized void write(FriendlyByteBuf buf) { // Paper - synchronize
- public void write(FriendlyByteBuf buf, com.destroystokyo.paper.antixray.ChunkPacketInfo<T> chunkPacketInfo, int chunkSectionIndex) {
+ public synchronized void write(FriendlyByteBuf buf, com.destroystokyo.paper.antixray.ChunkPacketInfo<T> chunkPacketInfo, int chunkSectionIndex) { // Paper - synchronize
// Paper end
try {
this.acquire();
buf.writeByte(this.bits);
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T> {
}
@ -80,7 +80,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public synchronized void read(ListTag paletteNbt, long[] data) { // Paper - synchronize
try {
this.acquire();
int i = Math.max(4, Mth.ceillog2(paletteNbt.size()));
// Paper - Anti-Xray - TODO: Should this.predefinedObjects.length just be added here (faster) or should the contents be compared to calculate the size (less RAM)?
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T> {
}

View File

@ -29,7 +29,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -0,0 +0,0 @@ public class PaperWorldConfig {
}
Bukkit.getLogger().warning("You have enabled permission-based Anti-Xray checking - depending on your permission plugin, this may cause performance issues");
}
}
+
@ -548,14 +548,6 @@ diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/j
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -0,0 +0,0 @@ import net.minecraft.util.thread.ProcessorMailbox;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
+import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.ai.village.poi.PoiManager;
import net.minecraft.world.entity.boss.EnderDragonPart;
import net.minecraft.world.level.ChunkPos;
@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
private final Long2ByteMap chunkTypeCache;
private final Queue<Runnable> unloadQueue;
@ -590,7 +582,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ }
+
+ public int getMobCountNear(ServerPlayer entityPlayer, MobCategory enumCreatureType) {
+ public int getMobCountNear(ServerPlayer entityPlayer, net.minecraft.world.entity.MobCategory enumCreatureType) {
+ return entityPlayer.mobCounts[enumCreatureType.ordinal()];
+ }
+ // Paper end