Skip to content

Commit

Permalink
Port changes to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulberry committed Oct 11, 2024
1 parent 6959cf2 commit cdcece8
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ static SectionPermissionChecker checkSection(Player player, World world, int sec
BlockVector3 minPoint = region.getMinimumPoint();
BlockVector3 maxPoint = region.getMaximumPoint();

int minPlotX = Math.max(minPoint.x(), minX);
int minPlotY = Math.max(minPoint.y(), minY);
int minPlotZ = Math.max(minPoint.z(), minZ);
int maxPlotX = Math.min(maxPoint.x(), maxX);
int maxPlotY = Math.min(maxPoint.y(), maxY);
int maxPlotZ = Math.min(maxPoint.z(), maxZ);
int minPlotX = Math.max(minPoint.getBlockX(), minX);
int minPlotY = Math.max(minPoint.getBlockY(), minY);
int minPlotZ = Math.max(minPoint.getBlockZ(), minZ);
int maxPlotX = Math.min(maxPoint.getBlockX(), maxX);
int maxPlotY = Math.min(maxPoint.getBlockY(), maxY);
int maxPlotZ = Math.min(maxPoint.getBlockZ(), maxZ);

if (minPlotX > maxPlotX) continue;
if (minPlotY > maxPlotY) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ static SectionPermissionChecker checkSection(Player player, World world, int cx,
BlockVector3 regionMin = region.getMinimumPoint();
BlockVector3 regionMax = region.getMaximumPoint();

int regionMinX = Math.max(regionMin.x(), cx*16) - minX;
int regionMinY = Math.max(regionMin.y(), cy*16) - minY;
int regionMinZ = Math.max(regionMin.z(), cz*16) - minZ;
int regionMaxX = Math.min(regionMax.x(), cx*16+15) - minX;
int regionMaxY = Math.min(regionMax.y(), cy*16+15) - minY;
int regionMaxZ = Math.min(regionMax.z(), cz*16+15) - minZ;
int regionMinX = Math.max(regionMin.getBlockX(), cx*16) - minX;
int regionMinY = Math.max(regionMin.getBlockY(), cy*16) - minY;
int regionMinZ = Math.max(regionMin.getBlockZ(), cz*16) - minZ;
int regionMaxX = Math.min(regionMax.getBlockX(), cx*16+15) - minX;
int regionMaxY = Math.min(regionMax.getBlockY(), cy*16+15) - minY;
int regionMaxZ = Math.min(regionMax.getBlockZ(), cz*16+15) - minZ;

Box box = new Box(regionMinX, regionMinY, regionMinZ, regionMaxX, regionMaxY, regionMaxZ);
if (value == StateFlag.State.DENY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.kyori.adventure.text.Component;
import net.minecraft.network.Connection;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -65,15 +66,15 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
PacketHandler handler = this.packetHandlers.get(identifier);
if (handler != null) {
if (handler.handleAsync()) {
handler.onReceive(player.getBukkitEntity(), buf);
handler.onReceive(player.getBukkitEntity(), new RegistryFriendlyByteBuf(buf, player.registryAccess()));
success = true;
} else {
byte[] bytes = new byte[buf.writerIndex() - buf.readerIndex()];
buf.getBytes(buf.readerIndex(), bytes);
Player bukkitPlayer = player.getBukkitEntity();

player.getServer().execute(() -> {
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes));
RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(bytes), player.registryAccess());
try {
handler.onReceive(bukkitPlayer, friendlyByteBuf);
} catch (Throwable t) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/moulberry/axiom/packet/PacketHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moulberry.axiom.packet;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.entity.Player;

Expand All @@ -10,6 +11,6 @@ default boolean handleAsync() {
return false;
}

void onReceive(Player player, FriendlyByteBuf friendlyByteBuf);
void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,7 +19,7 @@ public WrapperPacketListener(PacketHandler packetHandler) {

@Override
public void onPluginMessageReceived(@NotNull String s, @NotNull Player player, @NotNull byte[] bytes) {
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes));
RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(bytes), ((CraftPlayer)player).getHandle().registryAccess());
try {
this.packetHandler.onReceive(player, friendlyByteBuf);
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.kyori.adventure.text.Component;
import net.minecraft.SharedConstants;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
Expand All @@ -26,7 +27,7 @@ public BlueprintRequestPacketListener(AxiomPaper plugin) {
private static final ResourceLocation RESPONSE_PACKET_IDENTIFIER = VersionHelper.createResourceLocation("axiom:response_blueprint");

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.blueprint.request")) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand All @@ -26,7 +27,7 @@ public DeleteEntityPacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.entity.delete", true)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public HelloPacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.hasAxiomPermission(player)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand Down Expand Up @@ -80,7 +81,7 @@ public static ManipulateEntry read(FriendlyByteBuf friendlyByteBuf, Player playe
private static final Rotation[] ROTATION_VALUES = Rotation.values();

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.entity.manipulate", true)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.kyori.adventure.text.Component;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Marker;
Expand All @@ -25,7 +26,7 @@ public MarkerNbtRequestPacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.entity.manipulate", true)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -45,7 +46,7 @@ public RequestChunkDataPacketListener(AxiomPaper plugin, boolean forceFail) {
}

@Override
public void onReceive(Player bukkitPlayer, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player bukkitPlayer, RegistryFriendlyByteBuf friendlyByteBuf) {
ServerPlayer player = ((CraftPlayer)bukkitPlayer).getHandle();
long id = friendlyByteBuf.readLong();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import io.netty.buffer.Unpooled;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.entity.CraftPlayer;

import java.util.*;

Expand All @@ -30,7 +30,7 @@ public RequestEntityDataPacketListener(AxiomPaper plugin, boolean forceFail) {
}

@Override
public void onReceive(org.bukkit.entity.Player bukkitPlayer, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(org.bukkit.entity.Player bukkitPlayer, RegistryFriendlyByteBuf friendlyByteBuf) {
ServerPlayer player = ((CraftPlayer)bukkitPlayer).getHandle();
long id = friendlyByteBuf.readLong();

Expand Down Expand Up @@ -102,7 +102,9 @@ private static void sendResponse(ServerPlayer player, long id, boolean finished,
friendlyByteBuf.writeBoolean(finished);
friendlyByteBuf.writeMap(map, (buf, uuid) -> buf.writeUUID(uuid), (buf, nbt) -> buf.writeNbt(nbt));

player.connection.send(new ClientboundCustomPayloadPacket(RESPONSE_ID, friendlyByteBuf));
byte[] bytes = new byte[friendlyByteBuf.writerIndex()];
friendlyByteBuf.getBytes(0, bytes);
VersionHelper.sendCustomPayload(player, RESPONSE_ID, bytes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundChunksBiomesPacket;
import net.minecraft.resources.ResourceKey;
Expand All @@ -42,7 +43,7 @@
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.lighting.LightEngine;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import xyz.jpenilla.reflectionremapper.ReflectionRemapper;

Expand Down Expand Up @@ -76,7 +77,7 @@ public boolean handleAsync() {
return true;
}

public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle();
MinecraftServer server = serverPlayer.getServer();
if (server == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.core.IdMapper;
import net.minecraft.core.SectionPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -82,7 +83,7 @@ public AxiomPlacingCraftBlockState(@Nullable World world, BlockPos blockPosition
}

@Override
public void onReceive(Player bukkitPlayer, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player bukkitPlayer, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(bukkitPlayer, "axiom.build.place")) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
Expand All @@ -27,7 +28,7 @@ public SetEditorViewsPacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.editor.views")) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
Expand All @@ -20,7 +21,7 @@ public SetFlySpeedPacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.player.speed")) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.world.level.GameType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
Expand All @@ -22,7 +23,7 @@ public SetGamemodePacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.player.gamemode")) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SetHotbarSlotPacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.player.hotbar") || this.plugin.isMismatchedDataVersion(player.getUniqueId())) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.kyori.adventure.text.Component;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.GameRules;
Expand All @@ -26,7 +27,7 @@ public SetTimePacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.world.time")) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
Expand All @@ -21,7 +22,7 @@ public SetWorldPropertyListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.world.property")) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand Down Expand Up @@ -45,7 +46,7 @@ private record SpawnEntry(UUID newUuid, double x, double y, double z, float yaw,
private static final Rotation[] ROTATION_VALUES = Rotation.values();

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.entity.spawn", true)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public SwitchActiveHotbarPacketListener(AxiomPaper plugin) {
}

@Override
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
public void onReceive(Player player, RegistryFriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.player.hotbar") || this.plugin.isMismatchedDataVersion(player.getUniqueId())) {
return;
}
Expand Down
Loading

0 comments on commit cdcece8

Please sign in to comment.