Skip to content

Commit

Permalink
Fixed creation of islands not working due to anti-xray (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jan 5, 2022
1 parent bc5cc2c commit 9584020
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 32 deletions.
Expand Up @@ -155,6 +155,8 @@ private void loadWorld(String worldName, Difficulty difficulty, World.Environmen
world.setDifficulty(difficulty);
islandWorlds.put(environment, world);

plugin.getNMSWorld().removeAntiXray(world);

if (Bukkit.getPluginManager().isPluginEnabled("Multiverse-Core")) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mv import " + worldName + " normal -g " + plugin.getName());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mv modify set generator " + plugin.getName() + " " + worldName);
Expand Down
Expand Up @@ -61,4 +61,6 @@ public interface NMSWorld {

int getMinHeight(World world);

void removeAntiXray(World world);

}
Expand Up @@ -294,4 +294,9 @@ public int getMinHeight(World world) {
return 0;
}

@Override
public void removeAntiXray(World world) {

}

}
Expand Up @@ -16,6 +16,7 @@
import com.bgsoftware.superiorskyblock.world.blocks.BlockData;
import com.bgsoftware.superiorskyblock.world.blocks.ICachedBlock;
import com.bgsoftware.superiorskyblock.utils.logic.BlocksLogic;
import com.destroystokyo.paper.antixray.ChunkPacketBlockController;
import net.minecraft.server.v1_15_R1.BiomeBase;
import net.minecraft.server.v1_15_R1.BiomeStorage;
import net.minecraft.server.v1_15_R1.Block;
Expand All @@ -40,13 +41,13 @@
import net.minecraft.server.v1_15_R1.TileEntity;
import net.minecraft.server.v1_15_R1.TileEntityMobSpawner;
import net.minecraft.server.v1_15_R1.TileEntitySign;
import net.minecraft.server.v1_15_R1.World;
import net.minecraft.server.v1_15_R1.WorldBorder;
import net.minecraft.server.v1_15_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.data.Waterlogged;
Expand All @@ -71,6 +72,8 @@ public final class NMSWorldImpl implements NMSWorld {
private static final ReflectField<BiomeBase[]> BIOME_BASE_ARRAY = new ReflectField<>(BiomeStorage.class, BiomeBase[].class, "f", "g");
private static final ReflectField<BiomeStorage> BIOME_STORAGE = new ReflectField<>(
"org.bukkit.craftbukkit.VERSION.generator.CustomChunkGenerator$CustomBiomeGrid", BiomeStorage.class, "biome");
private static final ReflectField<Object> CHUNK_PACKET_BLOCK_CONTROLLER = new ReflectField<>(World.class,
Object.class, "chunkPacketBlockController").removeFinal();

@Override
public Key getBlockKey(ChunkSnapshot chunkSnapshot, int x, int y, int z) {
Expand Down Expand Up @@ -114,7 +117,7 @@ public void setWorldBorder(SuperiorPlayer superiorPlayer, Island island) {
boolean disabled = !superiorPlayer.hasWorldBorderEnabled();

Player player = superiorPlayer.asPlayer();
World world = superiorPlayer.getWorld();
org.bukkit.World world = superiorPlayer.getWorld();

if (world == null || player == null)
return;
Expand Down Expand Up @@ -331,8 +334,15 @@ public void playPlaceSound(Location location) {
}

@Override
public int getMinHeight(World world) {
public int getMinHeight(org.bukkit.World world) {
return 0;
}

@Override
public void removeAntiXray(org.bukkit.World bukkitWorld) {
World world = ((CraftWorld) bukkitWorld).getHandle();
if (CHUNK_PACKET_BLOCK_CONTROLLER.isValid())
CHUNK_PACKET_BLOCK_CONTROLLER.set(world, ChunkPacketBlockController.NO_OPERATION_INSTANCE);
}

}
Expand Up @@ -14,9 +14,10 @@
import com.bgsoftware.superiorskyblock.tag.StringTag;
import com.bgsoftware.superiorskyblock.tag.Tag;
import com.bgsoftware.superiorskyblock.utils.StringUtils;
import com.bgsoftware.superiorskyblock.utils.logic.BlocksLogic;
import com.bgsoftware.superiorskyblock.world.blocks.BlockData;
import com.bgsoftware.superiorskyblock.world.blocks.ICachedBlock;
import com.bgsoftware.superiorskyblock.utils.logic.BlocksLogic;
import com.destroystokyo.paper.antixray.ChunkPacketBlockController;
import net.minecraft.server.v1_16_R3.BiomeBase;
import net.minecraft.server.v1_16_R3.BiomeStorage;
import net.minecraft.server.v1_16_R3.Block;
Expand All @@ -43,13 +44,13 @@
import net.minecraft.server.v1_16_R3.TileEntity;
import net.minecraft.server.v1_16_R3.TileEntityMobSpawner;
import net.minecraft.server.v1_16_R3.TileEntitySign;
import net.minecraft.server.v1_16_R3.World;
import net.minecraft.server.v1_16_R3.WorldBorder;
import net.minecraft.server.v1_16_R3.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.data.Waterlogged;
Expand Down Expand Up @@ -77,12 +78,11 @@ public final class NMSWorldImpl implements NMSWorld {
BiomeStorage.class, Registry.class, "registry", "g");
private static final ReflectField<BiomeStorage> BIOME_STORAGE = new ReflectField<>(
"org.bukkit.craftbukkit.VERSION.generator.CustomChunkGenerator$CustomBiomeGrid", BiomeStorage.class, "biome");
private static final ReflectMethod<Object> LINES_SIGN_CHANGE_EVENT = new ReflectMethod<>(
SignChangeEvent.class, "lines");
private static final ReflectMethod<Float> SOUND_VOLUME = new ReflectMethod<>(
SoundEffectType.class, "a");
private static final ReflectMethod<Float> SOUND_PITCH = new ReflectMethod<>(
SoundEffectType.class, "b");
private static final ReflectMethod<Object> LINES_SIGN_CHANGE_EVENT = new ReflectMethod<>(SignChangeEvent.class, "lines");
private static final ReflectMethod<Float> SOUND_VOLUME = new ReflectMethod<>(SoundEffectType.class, "a");
private static final ReflectMethod<Float> SOUND_PITCH = new ReflectMethod<>(SoundEffectType.class, "b");
private static final ReflectField<Object> CHUNK_PACKET_BLOCK_CONTROLLER = new ReflectField<>(World.class,
Object.class, "chunkPacketBlockController").removeFinal();

@Override
public Key getBlockKey(ChunkSnapshot chunkSnapshot, int x, int y, int z) {
Expand Down Expand Up @@ -126,7 +126,7 @@ public void setWorldBorder(SuperiorPlayer superiorPlayer, Island island) {
boolean disabled = !superiorPlayer.hasWorldBorderEnabled();

Player player = superiorPlayer.asPlayer();
World world = superiorPlayer.getWorld();
org.bukkit.World world = superiorPlayer.getWorld();

if (world == null || player == null)
return;
Expand Down Expand Up @@ -352,12 +352,19 @@ public void playPlaceSound(Location location) {
}

@Override
public int getMinHeight(World world) {
public int getMinHeight(org.bukkit.World world) {
try {
return world.getMinHeight();
} catch (Throwable error) {
return 0;
}
}

@Override
public void removeAntiXray(org.bukkit.World bukkitWorld) {
World world = ((CraftWorld) bukkitWorld).getHandle();
if (CHUNK_PACKET_BLOCK_CONTROLLER.isValid())
CHUNK_PACKET_BLOCK_CONTROLLER.set(world, ChunkPacketBlockController.NO_OPERATION_INSTANCE);
}

}
Expand Up @@ -17,6 +17,7 @@
import com.bgsoftware.superiorskyblock.world.blocks.BlockData;
import com.bgsoftware.superiorskyblock.world.blocks.ICachedBlock;
import com.bgsoftware.superiorskyblock.utils.logic.BlocksLogic;
import com.destroystokyo.paper.antixray.ChunkPacketBlockController;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.IRegistry;
import net.minecraft.nbt.NBTTagCompound;
Expand All @@ -27,6 +28,7 @@
import net.minecraft.sounds.SoundCategory;
import net.minecraft.tags.TagsBlock;
import net.minecraft.world.level.EnumSkyBlock;
import net.minecraft.world.level.World;
import net.minecraft.world.level.biome.BiomeBase;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BlockStepAbstract;
Expand All @@ -48,7 +50,6 @@
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.data.Waterlogged;
Expand All @@ -74,8 +75,9 @@ public final class NMSWorldImpl implements NMSWorld {
BiomeStorage.class, BiomeBase[].class, "f");
private static final ReflectField<BiomeStorage> BIOME_STORAGE = new ReflectField<>(
"org.bukkit.craftbukkit.VERSION.generator.CustomChunkGenerator$CustomBiomeGrid", BiomeStorage.class, "biome");
private static final ReflectMethod<Object> LINES_SIGN_CHANGE_EVENT = new ReflectMethod<>(
SignChangeEvent.class, "lines");
private static final ReflectMethod<Object> LINES_SIGN_CHANGE_EVENT = new ReflectMethod<>(SignChangeEvent.class, "lines");
private static final ReflectField<Object> CHUNK_PACKET_BLOCK_CONTROLLER = new ReflectField<>(World.class,
Object.class, "chunkPacketBlockController").removeFinal();

@Override
public Key getBlockKey(ChunkSnapshot chunkSnapshot, int x, int y, int z) {
Expand Down Expand Up @@ -119,7 +121,7 @@ public void setWorldBorder(SuperiorPlayer superiorPlayer, Island island) {
boolean disabled = !superiorPlayer.hasWorldBorderEnabled();

Player player = superiorPlayer.asPlayer();
World world = superiorPlayer.getWorld();
org.bukkit.World world = superiorPlayer.getWorld();

if (world == null || player == null)
return;
Expand Down Expand Up @@ -339,8 +341,15 @@ public void playPlaceSound(Location location) {
}

@Override
public int getMinHeight(World world) {
public int getMinHeight(org.bukkit.World world) {
return world.getMinHeight();
}

@Override
public void removeAntiXray(org.bukkit.World bukkitWorld) {
World world = ((CraftWorld) bukkitWorld).getHandle();
if (CHUNK_PACKET_BLOCK_CONTROLLER.isValid())
CHUNK_PACKET_BLOCK_CONTROLLER.set(world, ChunkPacketBlockController.NO_OPERATION_INSTANCE);
}

}
Expand Up @@ -30,11 +30,13 @@
import com.bgsoftware.superiorskyblock.utils.StringUtils;
import com.bgsoftware.superiorskyblock.utils.logic.BlocksLogic;
import com.bgsoftware.superiorskyblock.world.blocks.ICachedBlock;
import com.destroystokyo.paper.antixray.ChunkPacketBlockController;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.ClientboundInitializeBorderPacket;
import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
import net.minecraft.sounds.SoundCategory;
import net.minecraft.world.level.EnumSkyBlock;
import net.minecraft.world.level.World;
import net.minecraft.world.level.biome.BiomeBase;
import net.minecraft.world.level.block.BlockStepAbstract;
import net.minecraft.world.level.block.entity.TileEntitySign;
Expand All @@ -50,7 +52,6 @@
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.data.Waterlogged;
Expand All @@ -73,8 +74,9 @@ public final class NMSWorldImpl implements NMSWorld {

private static final ReflectField<IChunkAccess> CHUNK_ACCESS = new ReflectField<>(
"org.bukkit.craftbukkit.VERSION.generator.CustomChunkGenerator$CustomBiomeGrid", IChunkAccess.class, "biome");
private static final ReflectMethod<Object> LINES_SIGN_CHANGE_EVENT = new ReflectMethod<>(
SignChangeEvent.class, "lines");
private static final ReflectMethod<Object> LINES_SIGN_CHANGE_EVENT = new ReflectMethod<>(SignChangeEvent.class, "lines");
private static final ReflectField<Object> CHUNK_PACKET_BLOCK_CONTROLLER = new ReflectField<>(World.class,
Object.class, "chunkPacketBlockController").removeFinal();

@Override
public Key getBlockKey(ChunkSnapshot chunkSnapshot, int x, int y, int z) {
Expand All @@ -95,7 +97,7 @@ public Key getBlockKey(ChunkSnapshot chunkSnapshot, int x, int y, int z) {
@Override
public int getSpawnerDelay(CreatureSpawner creatureSpawner) {
Location location = creatureSpawner.getLocation();
World world = location.getWorld();
org.bukkit.World world = location.getWorld();

if (world == null)
return 0;
Expand All @@ -109,7 +111,7 @@ public int getSpawnerDelay(CreatureSpawner creatureSpawner) {
@Override
public void setSpawnerDelay(CreatureSpawner creatureSpawner, int spawnDelay) {
Location location = creatureSpawner.getLocation();
World world = location.getWorld();
org.bukkit.World world = location.getWorld();

if (world == null)
return;
Expand All @@ -130,7 +132,7 @@ public void setWorldBorder(SuperiorPlayer superiorPlayer, Island island) {
boolean disabled = !superiorPlayer.hasWorldBorderEnabled();

Player player = superiorPlayer.asPlayer();
World world = superiorPlayer.getWorld();
org.bukkit.World world = superiorPlayer.getWorld();

if (world == null || player == null)
return;
Expand Down Expand Up @@ -205,7 +207,7 @@ public void setBlocks(org.bukkit.Chunk bukkitChunk,

@Override
public void setBlock(Location location, Material material, byte data) {
World bukkitWorld = location.getWorld();
org.bukkit.World bukkitWorld = location.getWorld();

if (bukkitWorld == null)
return;
Expand All @@ -227,7 +229,7 @@ public ICachedBlock cacheBlock(org.bukkit.block.Block block) {

@Override
public CompoundTag readBlockStates(Location location) {
World bukkitWorld = location.getWorld();
org.bukkit.World bukkitWorld = location.getWorld();

if (bukkitWorld == null)
return null;
Expand Down Expand Up @@ -264,7 +266,7 @@ public CompoundTag readBlockStates(Location location) {

@Override
public byte[] getLightLevels(Location location) {
World bukkitWorld = location.getWorld();
org.bukkit.World bukkitWorld = location.getWorld();

if (bukkitWorld == null)
return new byte[0];
Expand All @@ -282,7 +284,7 @@ public byte[] getLightLevels(Location location) {

@Override
public CompoundTag readTileEntity(Location location) {
World bukkitWorld = location.getWorld();
org.bukkit.World bukkitWorld = location.getWorld();

if (bukkitWorld == null)
return null;
Expand Down Expand Up @@ -329,7 +331,7 @@ public int getDefaultAmount(org.bukkit.block.Block block) {

@Override
public void placeSign(Island island, Location location) {
World bukkitWorld = location.getWorld();
org.bukkit.World bukkitWorld = location.getWorld();

if (bukkitWorld == null)
return;
Expand Down Expand Up @@ -366,7 +368,7 @@ public void setSignLines(SignChangeEvent signChangeEvent, String[] lines) {

@Override
public void playGeneratorSound(Location location) {
World bukkitWorld = location.getWorld();
org.bukkit.World bukkitWorld = location.getWorld();

if (bukkitWorld == null)
return;
Expand All @@ -385,7 +387,7 @@ public void playBreakAnimation(org.bukkit.block.Block block) {

@Override
public void playPlaceSound(Location location) {
World bukkitWorld = location.getWorld();
org.bukkit.World bukkitWorld = location.getWorld();

if (bukkitWorld == null)
return;
Expand All @@ -399,8 +401,15 @@ public void playPlaceSound(Location location) {
}

@Override
public int getMinHeight(World world) {
public int getMinHeight(org.bukkit.World world) {
return world.getMinHeight();
}

@Override
public void removeAntiXray(org.bukkit.World bukkitWorld) {
World world = ((CraftWorld) bukkitWorld).getHandle();
if (CHUNK_PACKET_BLOCK_CONTROLLER.isValid())
CHUNK_PACKET_BLOCK_CONTROLLER.set(world, ChunkPacketBlockController.NO_OPERATION_INSTANCE);
}

}
Expand Up @@ -297,4 +297,9 @@ public int getMinHeight(World world) {
return 0;
}

@Override
public void removeAntiXray(World bukkitWorld) {

}

}

0 comments on commit 9584020

Please sign in to comment.