diff --git a/build.gradle.kts b/build.gradle.kts index 1e9c65e..caa783c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.moulberry.axiom" -version = "1.5.1" +version = "1.5.2" description = "Serverside component for Axiom on Paper" java { diff --git a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java index db92663..5a891e9 100644 --- a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java @@ -93,39 +93,43 @@ public class RequestChunkDataPacketListener implements PluginMessageListener { int playerSectionZ = player.getBlockZ() >> 4; Long2ObjectMap> sections = new Long2ObjectOpenHashMap<>(); - count = friendlyByteBuf.readVarInt(); - for (int i = 0; i < count; i++) { - long pos = friendlyByteBuf.readLong(); - int sx = BlockPos.getX(pos); - int sy = BlockPos.getY(pos); - int sz = BlockPos.getZ(pos); + int maxChunkLoadDistance = this.plugin.configuration.getInt("max-chunk-load-distance"); + if (maxChunkLoadDistance > 0) { + count = friendlyByteBuf.readVarInt(); + for (int i = 0; i < count; i++) { + long pos = friendlyByteBuf.readLong(); - int distance = Math.abs(playerSectionX - sx) + Math.abs(playerSectionZ - sz); - if (distance > 128) continue; + int sx = BlockPos.getX(pos); + int sy = BlockPos.getY(pos); + int sz = BlockPos.getZ(pos); - LevelChunk chunk = level.getChunk(sx, sz); - int sectionIndex = chunk.getSectionIndexFromSectionY(sy); - if (sectionIndex < 0 || sectionIndex >= chunk.getSectionsCount()) continue; - LevelChunkSection section = chunk.getSection(sectionIndex); + int distance = Math.abs(playerSectionX - sx) + Math.abs(playerSectionZ - sz); + if (distance > maxChunkLoadDistance) continue; - if (section.hasOnlyAir()) { - sections.put(pos, null); - } else { - PalettedContainer container = section.getStates(); - sections.put(pos, container); + LevelChunk chunk = level.getChunk(sx, sz); + int sectionIndex = chunk.getSectionIndexFromSectionY(sy); + if (sectionIndex < 0 || sectionIndex >= chunk.getSectionsCount()) continue; + LevelChunkSection section = chunk.getSection(sectionIndex); - if (sendBlockEntitiesInChunks && section.maybeHas(BlockState::hasBlockEntity)) { - for (int x = 0; x < 16; x++) { - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - BlockState blockState = container.get(x, y, z); - if (blockState.hasBlockEntity()) { - mutableBlockPos.set(sx*16 + x, sy*16 + y, sz*16 + z); - BlockEntity blockEntity = chunk.getBlockEntity(mutableBlockPos, LevelChunk.EntityCreationType.CHECK); - if (blockEntity != null) { - CompoundTag tag = blockEntity.saveWithoutMetadata(); - blockEntityMap.put(mutableBlockPos.asLong(), CompressedBlockEntity.compress(tag, baos)); + if (section.hasOnlyAir()) { + sections.put(pos, null); + } else { + PalettedContainer container = section.getStates(); + sections.put(pos, container); + + if (sendBlockEntitiesInChunks && section.maybeHas(BlockState::hasBlockEntity)) { + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + BlockState blockState = container.get(x, y, z); + if (blockState.hasBlockEntity()) { + mutableBlockPos.set(sx*16 + x, sy*16 + y, sz*16 + z); + BlockEntity blockEntity = chunk.getBlockEntity(mutableBlockPos, LevelChunk.EntityCreationType.CHECK); + if (blockEntity != null) { + CompoundTag tag = blockEntity.saveWithoutMetadata(); + blockEntityMap.put(mutableBlockPos.asLong(), CompressedBlockEntity.compress(tag, baos)); + } } } } @@ -135,7 +139,6 @@ public class RequestChunkDataPacketListener implements PluginMessageListener { } } - // Send response packet boolean firstPart = true; diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java index 247af05..41b28a9 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java @@ -38,7 +38,6 @@ import java.lang.reflect.Method; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.logging.Level; public class SetBlockPacketListener implements PluginMessageListener { diff --git a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java b/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java index 7fff066..b8b6ec7 100644 --- a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java @@ -38,6 +38,12 @@ public class TeleportPacketListener implements PluginMessageListener { World world = Bukkit.getWorld(namespacedKey); if (world == null) return; + // Prevent teleport based on config value + boolean allowTeleportBetweenWorlds = this.plugin.configuration.getBoolean("allow-teleport-between-worlds"); + if (!allowTeleportBetweenWorlds && world != player.getWorld()) { + return; + } + // Call event AxiomTeleportEvent teleportEvent = new AxiomTeleportEvent(player, new Location(world, x, y, z, yRot, xRot)); Bukkit.getPluginManager().callEvent(teleportEvent);