3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-08 17:40:04 +01:00

Add option to allow large payload for all packets

Dieser Commit ist enthalten in:
Moulberry 2024-09-21 14:15:36 +08:00
Ursprung 7c7f300a8f
Commit de534a2f05
28 geänderte Dateien mit 294 neuen und 363 gelöschten Zeilen

Datei anzeigen

@ -8,7 +8,7 @@ plugins {
}
group = "com.moulberry.axiom"
version = "4.0.1"
version = "4.0.2"
description = "Serverside component for Axiom on Paper"
java {

Datei anzeigen

@ -7,12 +7,12 @@ paper = "1.20.1-R0.1-SNAPSHOT"
plotsquared = "7.3.9-20240513.192211-13"
reflection-remapper = "0.1.2-20240315.033304-2"
viaversion-api = "5.0.1"
worldguard-bukkit = "7.1.0-20240503.180049-12"
worldguard-bukkit = "7.0.9-SNAPSHOT"
zstd-jni = "1.5.5-4"
# Plugins
paperweight-userdev = "1.5.11"
run-paper = "2.2.2"
paperweight-userdev = "1.7.2"
run-paper = "2.3.0"
shadow = "8.1.1"
[libraries]

Datei anzeigen

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Datei anzeigen

@ -9,6 +9,25 @@ import com.moulberry.axiom.event.AxiomModifyWorldEvent;
import com.moulberry.axiom.integration.coreprotect.CoreProtectIntegration;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.packet.*;
import com.moulberry.axiom.packet.impl.BlueprintRequestPacketListener;
import com.moulberry.axiom.packet.impl.DeleteEntityPacketListener;
import com.moulberry.axiom.packet.impl.HelloPacketListener;
import com.moulberry.axiom.packet.impl.ManipulateEntityPacketListener;
import com.moulberry.axiom.packet.impl.MarkerNbtRequestPacketListener;
import com.moulberry.axiom.packet.impl.RequestChunkDataPacketListener;
import com.moulberry.axiom.packet.impl.SetBlockBufferPacketListener;
import com.moulberry.axiom.packet.impl.SetBlockPacketListener;
import com.moulberry.axiom.packet.impl.SetEditorViewsPacketListener;
import com.moulberry.axiom.packet.impl.SetFlySpeedPacketListener;
import com.moulberry.axiom.packet.impl.SetGamemodePacketListener;
import com.moulberry.axiom.packet.impl.SetHotbarSlotPacketListener;
import com.moulberry.axiom.packet.impl.SetTimePacketListener;
import com.moulberry.axiom.packet.impl.SetWorldPropertyListener;
import com.moulberry.axiom.packet.impl.SpawnEntityPacketListener;
import com.moulberry.axiom.packet.impl.SwitchActiveHotbarPacketListener;
import com.moulberry.axiom.packet.impl.TeleportPacketListener;
import com.moulberry.axiom.packet.impl.UpdateAnnotationPacketListener;
import com.moulberry.axiom.packet.impl.UploadBlueprintPacketListener;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
@ -111,64 +130,31 @@ public class AxiomPaper extends JavaPlugin implements Listener {
msg.registerOutgoingPluginChannel(this, "axiom:marker_nbt_response");
msg.registerOutgoingPluginChannel(this, "axiom:annotation_update");
if (configuration.getBoolean("packet-handlers.hello")) {
msg.registerIncomingPluginChannel(this, "axiom:hello", new HelloPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.set-gamemode")) {
msg.registerIncomingPluginChannel(this, "axiom:set_gamemode", new SetGamemodePacketListener(this));
}
if (configuration.getBoolean("packet-handlers.set-fly-speed")) {
msg.registerIncomingPluginChannel(this, "axiom:set_fly_speed", new SetFlySpeedPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.set-world-time")) {
msg.registerIncomingPluginChannel(this, "axiom:set_world_time", new SetTimePacketListener(this));
}
if (configuration.getBoolean("packet-handlers.set-world-property")) {
msg.registerIncomingPluginChannel(this, "axiom:set_world_property", new SetWorldPropertyListener(this));
}
if (configuration.getBoolean("packet-handlers.set-single-block")) {
msg.registerIncomingPluginChannel(this, "axiom:set_block", new SetBlockPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.set-hotbar-slot")) {
msg.registerIncomingPluginChannel(this, "axiom:set_hotbar_slot", new SetHotbarSlotPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.switch-active-hotbar")) {
msg.registerIncomingPluginChannel(this, "axiom:switch_active_hotbar", new SwitchActiveHotbarPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.teleport")) {
msg.registerIncomingPluginChannel(this, "axiom:teleport", new TeleportPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.set-editor-views")) {
msg.registerIncomingPluginChannel(this, "axiom:set_editor_views", new SetEditorViewsPacketListener(this));
}
if (!allowLargeChunkDataRequest) {
if (configuration.getBoolean("packet-handlers.request-chunk-data")) {
msg.registerIncomingPluginChannel(this, "axiom:request_chunk_data", new RequestChunkDataPacketListener(this));
}
}
if (configuration.getBoolean("packet-handlers.spawn-entity")) {
msg.registerIncomingPluginChannel(this, "axiom:spawn_entity", new SpawnEntityPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.manipulate-entity")) {
msg.registerIncomingPluginChannel(this, "axiom:manipulate_entity", new ManipulateEntityPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.delete-entity")) {
msg.registerIncomingPluginChannel(this, "axiom:delete_entity", new DeleteEntityPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.marker-nbt-request")) {
msg.registerIncomingPluginChannel(this, "axiom:marker_nbt_request", new MarkerNbtRequestPacketListener(this));
}
if (configuration.getBoolean("packet-handlers.blueprint-request")) {
msg.registerIncomingPluginChannel(this, "axiom:request_blueprint", new BlueprintRequestPacketListener(this));
}
Map<String, PacketHandler> largePayloadHandlers = new HashMap<>();
if (configuration.getBoolean("packet-handlers.set-buffer")) {
SetBlockBufferPacketListener setBlockBufferPacketListener = new SetBlockBufferPacketListener(this);
UploadBlueprintPacketListener uploadBlueprintPacketListener = new UploadBlueprintPacketListener(this);
UpdateAnnotationPacketListener updateAnnotationPacketListener = new UpdateAnnotationPacketListener(this);
RequestChunkDataPacketListener requestChunkDataPacketListener = allowLargeChunkDataRequest ?
new RequestChunkDataPacketListener(this) : null;
registerPacketHandler("hello", new HelloPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("set_gamemode", new SetGamemodePacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("set_fly_speed", new SetFlySpeedPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("set_world_time", new SetTimePacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("set_world_property", new SetWorldPropertyListener(this), msg, largePayloadHandlers);
registerPacketHandler("set_block", new SetBlockPacketListener(this), msg, largePayloadHandlers); // set-single-block
registerPacketHandler("set_hotbar_slot", new SetHotbarSlotPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("switch_active_hotbar", new SwitchActiveHotbarPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("teleport", new TeleportPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("set_editor_views", new SetEditorViewsPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("request_chunk_data", new RequestChunkDataPacketListener(this,
!configuration.getBoolean("packet-handlers.request-chunk-data")), msg, largePayloadHandlers);
registerPacketHandler("spawn_entity", new SpawnEntityPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("manipulate_entity", new ManipulateEntityPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("delete_entity", new DeleteEntityPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("marker_nbt_request", new MarkerNbtRequestPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("request_blueprint", new BlueprintRequestPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("set_buffer", new SetBlockBufferPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("upload_blueprint", new UploadBlueprintPacketListener(this), msg, largePayloadHandlers);
registerPacketHandler("annotation_update", new UpdateAnnotationPacketListener(this), msg, largePayloadHandlers);
if (!largePayloadHandlers.isEmpty()) {
ChannelInitializeListenerHolder.addListener(Key.key("axiom:handle_big_payload"), new ChannelInitializeListener() {
@Override
public void afterInitChannel(@NonNull Channel channel) {
@ -186,8 +172,7 @@ public class AxiomPaper extends JavaPlugin implements Listener {
Connection connection = (Connection) channel.pipeline().get("packet_handler");
channel.pipeline().addBefore("decoder", "axiom-big-payload-handler",
new AxiomBigPayloadHandler(payloadId, connection, setBlockBufferPacketListener,
uploadBlueprintPacketListener, updateAnnotationPacketListener, requestChunkDataPacketListener));
new AxiomBigPayloadHandler(payloadId, connection, largePayloadHandlers));
}
});
}
@ -317,6 +302,35 @@ public class AxiomPaper extends JavaPlugin implements Listener {
}
}
private void registerPacketHandler(String name, PacketHandler handler, Messenger messenger, Map<String, PacketHandler> largePayloadHandlers) {
String configEntry = "packet-handlers." + name.replace("_", "-");
if (name.equals("set_block")) {
configEntry = "packet-handlers.set-single-block";
} else if (name.equals("request_blueprint")) {
configEntry = "packet-handlers.blueprint-request";
}
if (name.equals("request-chunk-data") || this.configuration.getBoolean(configEntry, true)) {
boolean isLargePayload = false;
if (name.equals("hello")) { // Hello must use normal system, as non-Axiom players can't send large payloads
isLargePayload = false;
} else if (this.configuration.getBoolean("allow-large-payload-for-all-packets")) {
isLargePayload = true;
} else if (name.equals("set_buffer") || name.equals("upload_blueprint") || name.equals("annotation_update")) {
isLargePayload = true;
} else if (name.equals("request_chunk_data") && this.configuration.getBoolean("allow-large-chunk-data-request")) {
isLargePayload = true;
}
if (isLargePayload) {
largePayloadHandlers.put("axiom:"+name, handler);
messenger.registerIncomingPluginChannel(this, "axiom:"+name, new DummyPacketListener());
} else {
messenger.registerIncomingPluginChannel(this, "axiom:"+name, new WrapperPacketListener(handler));
}
}
}
private int calculateAllowedCapabilities() {
Set<String> allowed = new HashSet<>(this.configuration.getStringList("allow-capabilities"));
if (allowed.contains("all")) {

Datei anzeigen

@ -2,42 +2,36 @@ package com.moulberry.axiom.packet;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.VersionHelper;
import com.moulberry.axiom.packet.impl.RequestChunkDataPacketListener;
import com.moulberry.axiom.packet.impl.SetBlockBufferPacketListener;
import com.moulberry.axiom.packet.impl.UpdateAnnotationPacketListener;
import com.moulberry.axiom.packet.impl.UploadBlueprintPacketListener;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.papermc.paper.network.ConnectionEvent;
import net.kyori.adventure.text.Component;
import net.minecraft.network.Connection;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class AxiomBigPayloadHandler extends MessageToMessageDecoder<ByteBuf> {
private static final ResourceLocation SET_BUFFER = VersionHelper.createResourceLocation("axiom", "set_buffer");
private static final ResourceLocation UPLOAD_BLUEPRINT = VersionHelper.createResourceLocation("axiom", "upload_blueprint");
private static final ResourceLocation UPDATE_ANNOTATIONS = VersionHelper.createResourceLocation("axiom", "annotation_update");
private static final ResourceLocation REQUEST_CHUNK_DATA = VersionHelper.createResourceLocation("axiom", "request_chunk_data");
private final int payloadId;
private final Connection connection;
private final SetBlockBufferPacketListener setBlockBuffer;
private final UploadBlueprintPacketListener uploadBlueprint;
private final UpdateAnnotationPacketListener updateAnnotation;
private final RequestChunkDataPacketListener requestChunkDataPacketListener;
private final Map<String, PacketHandler> packetHandlers;
public AxiomBigPayloadHandler(int payloadId, Connection connection, SetBlockBufferPacketListener setBlockBuffer,
UploadBlueprintPacketListener uploadBlueprint, UpdateAnnotationPacketListener updateAnnotation,
RequestChunkDataPacketListener requestChunkDataPacketListener) {
public AxiomBigPayloadHandler(int payloadId, Connection connection, Map<String, PacketHandler> packetHandlers) {
this.payloadId = payloadId;
this.connection = connection;
this.setBlockBuffer = setBlockBuffer;
this.uploadBlueprint = uploadBlueprint;
this.updateAnnotation = updateAnnotation;
this.requestChunkDataPacketListener = requestChunkDataPacketListener;
this.packetHandlers = packetHandlers;
}
@Override
@ -67,47 +61,29 @@ public class AxiomBigPayloadHandler extends MessageToMessageDecoder<ByteBuf> {
int packetId = buf.readVarInt();
if (packetId == payloadId) {
ResourceLocation identifier = buf.readResourceLocation();
if (identifier.equals(SET_BUFFER)) {
setBlockBuffer.onReceive(player, buf);
success = true;
if (in.readableBytes() > 0) {
throw new IOException("Axiom packet " + identifier + " was larger than I expected, found " + in.readableBytes() +
" bytes extra whilst reading packet");
}
return;
} else if (identifier.equals(UPLOAD_BLUEPRINT)) {
uploadBlueprint.onReceive(player, buf);
success = true;
if (in.readableBytes() > 0) {
throw new IOException("Axiom packet " + identifier + " was larger than I expected, found " + in.readableBytes() +
" bytes extra whilst reading packet");
}
return;
} else if (identifier.equals(UPDATE_ANNOTATIONS)) {
updateAnnotation.onReceive(player, buf);
success = true;
if (in.readableBytes() > 0) {
throw new IOException("Axiom packet " + identifier + " was larger than I expected, found " + in.readableBytes() +
" bytes extra whilst reading packet");
}
return;
} else if (requestChunkDataPacketListener != null && identifier.equals(REQUEST_CHUNK_DATA)) {
byte[] bytes = new byte[buf.writerIndex() - buf.readerIndex()];
buf.getBytes(buf.readerIndex(), bytes);
String identifier = buf.readUtf(32767);
PacketHandler handler = this.packetHandlers.get(identifier);
if (handler != null) {
if (handler.handleAsync()) {
handler.onReceive(player.getBukkitEntity(), buf);
success = true;
} else {
byte[] bytes = new byte[buf.writerIndex() - buf.readerIndex()];
buf.getBytes(buf.readerIndex(), bytes);
Player bukkitPlayer = player.getBukkitEntity();
player.getServer().execute(() -> {
try {
requestChunkDataPacketListener.onPluginMessageReceived(
identifier.toString(), player.getBukkitEntity(), bytes);
} catch (Throwable t) {
player.getBukkitEntity().kick(net.kyori.adventure.text.Component.text(
"An error occured while requesting chunk data: " + t.getMessage()));
}
});
player.getServer().execute(() -> {
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes));
try {
handler.onReceive(bukkitPlayer, friendlyByteBuf);
} catch (Throwable t) {
bukkitPlayer.kick(Component.text("Error while processing packet " + identifier + ": " + t.getMessage()));
}
});
success = true;
in.skipBytes(in.readableBytes());
success = true;
in.readerIndex(in.writerIndex());
}
return;
}
}
@ -134,7 +110,7 @@ public class AxiomBigPayloadHandler extends MessageToMessageDecoder<ByteBuf> {
if (evt == ConnectionEvent.COMPRESSION_THRESHOLD_SET || evt == ConnectionEvent.COMPRESSION_DISABLED) {
ctx.channel().pipeline().remove("axiom-big-payload-handler");
ctx.channel().pipeline().addBefore("decoder", "axiom-big-payload-handler",
new AxiomBigPayloadHandler(payloadId, connection, setBlockBuffer, uploadBlueprint, updateAnnotation, requestChunkDataPacketListener));
new AxiomBigPayloadHandler(payloadId, connection, packetHandlers));
}
super.userEventTriggered(ctx, evt);
}

Datei anzeigen

@ -0,0 +1,18 @@
package com.moulberry.axiom.packet;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class DummyPacketListener implements PluginMessageListener {
public DummyPacketListener() {
}
@Override
public void onPluginMessageReceived(@NotNull String s, @NotNull Player player, @NotNull byte[] bytes) {
}
}

Datei anzeigen

@ -0,0 +1,15 @@
package com.moulberry.axiom.packet;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.entity.Player;
public interface PacketHandler {
default boolean handleAsync() {
return false;
}
void onReceive(Player player, FriendlyByteBuf friendlyByteBuf);
}

Datei anzeigen

@ -0,0 +1,27 @@
package com.moulberry.axiom.packet;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class WrapperPacketListener implements PluginMessageListener {
private final PacketHandler packetHandler;
public WrapperPacketListener(PacketHandler packetHandler) {
this.packetHandler = packetHandler;
}
@Override
public void onPluginMessageReceived(@NotNull String s, @NotNull Player player, @NotNull byte[] bytes) {
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes));
try {
this.packetHandler.onReceive(player, friendlyByteBuf);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + s + ": " + t.getMessage()));
}
}
}

Datei anzeigen

@ -1,10 +1,11 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.VersionHelper;
import com.moulberry.axiom.blueprint.RawBlueprint;
import com.moulberry.axiom.blueprint.ServerBlueprintManager;
import com.moulberry.axiom.blueprint.ServerBlueprintRegistry;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.SharedConstants;
@ -15,9 +16,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class BlueprintRequestPacketListener implements PluginMessageListener {
public class BlueprintRequestPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public BlueprintRequestPacketListener(AxiomPaper plugin) {
@ -27,15 +26,7 @@ public class BlueprintRequestPacketListener implements PluginMessageListener {
private static final ResourceLocation RESPONSE_PACKET_IDENTIFIER = VersionHelper.createResourceLocation("axiom:response_blueprint");
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.blueprint.request")) {
return;
}
@ -45,7 +36,6 @@ public class BlueprintRequestPacketListener implements PluginMessageListener {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
String path = friendlyByteBuf.readUtf();
ServerBlueprintRegistry registry = ServerBlueprintManager.getRegistry();

Datei anzeigen

@ -1,8 +1,8 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.integration.Integration;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
@ -18,7 +18,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class DeleteEntityPacketListener implements PluginMessageListener {
public class DeleteEntityPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public DeleteEntityPacketListener(AxiomPaper plugin) {
@ -26,15 +26,7 @@ public class DeleteEntityPacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.entity.delete", true)) {
return;
}
@ -43,7 +35,6 @@ public class DeleteEntityPacketListener implements PluginMessageListener {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
List<UUID> delete = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000),
FriendlyByteBuf::readUUID);

Datei anzeigen

@ -1,15 +1,14 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.google.common.util.concurrent.RateLimiter;
import com.moulberry.axiom.*;
import com.moulberry.axiom.annotations.ServerAnnotations;
import com.moulberry.axiom.blueprint.ServerBlueprintManager;
import com.moulberry.axiom.event.AxiomHandshakeEvent;
import com.moulberry.axiom.packet.PacketHandler;
import com.moulberry.axiom.persistence.ItemStackDataType;
import com.moulberry.axiom.persistence.UUIDDataType;
import com.moulberry.axiom.viaversion.ViaVersionHelper;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
@ -21,20 +20,17 @@ import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.UUID;
public class HelloPacketListener implements PluginMessageListener {
public class HelloPacketListener implements PacketHandler {
private final AxiomPaper plugin;
@ -43,20 +39,11 @@ public class HelloPacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.hasAxiomPermission(player)) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
int apiVersion = friendlyByteBuf.readVarInt();
if (apiVersion != AxiomConstants.API_VERSION) {

Datei anzeigen

@ -1,12 +1,11 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.NbtSanitization;
import com.moulberry.axiom.event.AxiomManipulateEntityEvent;
import com.moulberry.axiom.integration.Integration;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.packet.PacketHandler;
import com.moulberry.axiom.viaversion.UnknownVersionHelper;
import com.moulberry.axiom.viaversion.ViaVersionHelper;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.core.BlockPos;
@ -34,7 +33,7 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
public class ManipulateEntityPacketListener implements PluginMessageListener {
public class ManipulateEntityPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public ManipulateEntityPacketListener(AxiomPaper plugin) {
@ -82,15 +81,7 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
private static final Rotation[] ROTATION_VALUES = Rotation.values();
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.entity.manipulate", true)) {
return;
}
@ -99,7 +90,6 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
List<ManipulateEntry> entries = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000),
buf -> ManipulateEntry.read(buf, player));

Datei anzeigen

@ -1,7 +1,8 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.marker.MarkerData;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.nbt.CompoundTag;
@ -16,7 +17,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class MarkerNbtRequestPacketListener implements PluginMessageListener {
public class MarkerNbtRequestPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public MarkerNbtRequestPacketListener(AxiomPaper plugin) {
@ -24,15 +25,7 @@ public class MarkerNbtRequestPacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.entity.manipulate", true)) {
return;
}
@ -41,7 +34,6 @@ public class MarkerNbtRequestPacketListener implements PluginMessageListener {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
UUID uuid = friendlyByteBuf.readUUID();
ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle();

Datei anzeigen

@ -1,10 +1,11 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomConstants;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.VersionHelper;
import com.moulberry.axiom.buffer.CompressedBlockEntity;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.longs.*;
import net.kyori.adventure.text.Component;
@ -32,30 +33,23 @@ import org.jetbrains.annotations.NotNull;
import java.io.ByteArrayOutputStream;
public class RequestChunkDataPacketListener implements PluginMessageListener {
public class RequestChunkDataPacketListener implements PacketHandler {
private static final ResourceLocation RESPONSE_ID = VersionHelper.createResourceLocation("axiom:response_chunk_data");
private final AxiomPaper plugin;
public RequestChunkDataPacketListener(AxiomPaper plugin) {
private final boolean forceFail;
public RequestChunkDataPacketListener(AxiomPaper plugin, boolean forceFail) {
this.plugin = plugin;
this.forceFail = forceFail;
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player bukkitPlayer, byte[] message) {
public void onReceive(Player bukkitPlayer, FriendlyByteBuf friendlyByteBuf) {
ServerPlayer player = ((CraftPlayer)bukkitPlayer).getHandle();
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
long id = friendlyByteBuf.readLong();
if (!this.plugin.canUseAxiom(bukkitPlayer, "axiom.chunk.request") || this.plugin.isMismatchedDataVersion(bukkitPlayer.getUniqueId())) {
if (this.forceFail || !this.plugin.canUseAxiom(bukkitPlayer, "axiom.chunk.request") || this.plugin.isMismatchedDataVersion(bukkitPlayer.getUniqueId())) {
// We always send an 'empty' response in order to make the client happy
sendEmptyResponse(player, id);
return;

Datei anzeigen

@ -1,4 +1,4 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.google.common.util.concurrent.RateLimiter;
import com.moulberry.axiom.AxiomPaper;
@ -9,6 +9,7 @@ import com.moulberry.axiom.buffer.CompressedBlockEntity;
import com.moulberry.axiom.integration.Integration;
import com.moulberry.axiom.integration.SectionPermissionChecker;
import com.moulberry.axiom.integration.coreprotect.CoreProtectIntegration;
import com.moulberry.axiom.packet.PacketHandler;
import com.moulberry.axiom.viaversion.UnknownVersionHelper;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
@ -41,6 +42,8 @@ import net.minecraft.world.level.chunk.PalettedContainer;
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.entity.Player;
import xyz.jpenilla.reflectionremapper.ReflectionRemapper;
import java.lang.reflect.InvocationTargetException;
@ -48,11 +51,10 @@ import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class SetBlockBufferPacketListener {
public class SetBlockBufferPacketListener implements PacketHandler {
private final AxiomPaper plugin;
private final Method updateBlockEntityTicker;
private final WeakHashMap<ServerPlayer, RateLimiter> packetRateLimiter = new WeakHashMap<>();
public SetBlockBufferPacketListener(AxiomPaper plugin) {
this.plugin = plugin;
@ -69,8 +71,14 @@ public class SetBlockBufferPacketListener {
}
}
public void onReceive(ServerPlayer player, FriendlyByteBuf friendlyByteBuf) {
MinecraftServer server = player.getServer();
@Override
public boolean handleAsync() {
return true;
}
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle();
MinecraftServer server = serverPlayer.getServer();
if (server == null) return;
ResourceKey<Level> worldKey = friendlyByteBuf.readResourceKey(Registries.DIMENSION);
@ -78,42 +86,42 @@ public class SetBlockBufferPacketListener {
boolean continuation = friendlyByteBuf.readBoolean();
if (!continuation) {
UnknownVersionHelper.skipTagUnknown(friendlyByteBuf, player.getBukkitEntity());
UnknownVersionHelper.skipTagUnknown(friendlyByteBuf, serverPlayer.getBukkitEntity());
}
RateLimiter rateLimiter = this.plugin.getBlockBufferRateLimiter(player.getUUID());
RateLimiter rateLimiter = this.plugin.getBlockBufferRateLimiter(serverPlayer.getUUID());
byte type = friendlyByteBuf.readByte();
if (type == 0) {
AtomicBoolean reachedRateLimit = new AtomicBoolean(false);
BlockBuffer buffer = BlockBuffer.load(friendlyByteBuf, rateLimiter, reachedRateLimit, this.plugin.getBlockRegistry(player.getUUID()));
BlockBuffer buffer = BlockBuffer.load(friendlyByteBuf, rateLimiter, reachedRateLimit, this.plugin.getBlockRegistry(serverPlayer.getUUID()));
if (reachedRateLimit.get()) {
player.sendSystemMessage(Component.literal("[Axiom] Exceeded server rate-limit of " + (int)rateLimiter.getRate() + " sections per second")
serverPlayer.sendSystemMessage(Component.literal("[Axiom] Exceeded server rate-limit of " + (int)rateLimiter.getRate() + " sections per second")
.withStyle(ChatFormatting.RED));
}
if (this.plugin.logLargeBlockBufferChanges()) {
this.plugin.getLogger().info("Player " + player.getUUID() + " modified " + buffer.entrySet().size() + " chunk sections (blocks)");
this.plugin.getLogger().info("Player " + serverPlayer.getUUID() + " modified " + buffer.entrySet().size() + " chunk sections (blocks)");
if (buffer.getTotalBlockEntities() > 0) {
this.plugin.getLogger().info("Player " + player.getUUID() + " modified " + buffer.getTotalBlockEntities() + " block entities, compressed bytes = " +
this.plugin.getLogger().info("Player " + serverPlayer.getUUID() + " modified " + buffer.getTotalBlockEntities() + " block entities, compressed bytes = " +
buffer.getTotalBlockEntityBytes());
}
}
applyBlockBuffer(player, server, buffer, worldKey);
applyBlockBuffer(serverPlayer, server, buffer, worldKey);
} else if (type == 1) {
AtomicBoolean reachedRateLimit = new AtomicBoolean(false);
BiomeBuffer buffer = BiomeBuffer.load(friendlyByteBuf, rateLimiter, reachedRateLimit);
if (reachedRateLimit.get()) {
player.sendSystemMessage(Component.literal("[Axiom] Exceeded server rate-limit of " + (int)rateLimiter.getRate() + " sections per second")
serverPlayer.sendSystemMessage(Component.literal("[Axiom] Exceeded server rate-limit of " + (int)rateLimiter.getRate() + " sections per second")
.withStyle(ChatFormatting.RED));
}
if (this.plugin.logLargeBlockBufferChanges()) {
this.plugin.getLogger().info("Player " + player.getUUID() + " modified " + buffer.size() + " chunk sections (biomes)");
this.plugin.getLogger().info("Player " + serverPlayer.getUUID() + " modified " + buffer.size() + " chunk sections (biomes)");
}
applyBiomeBuffer(player, server, buffer, worldKey);
applyBiomeBuffer(serverPlayer, server, buffer, worldKey);
} else {
throw new RuntimeException("Unknown buffer type: " + type);
}

Datei anzeigen

@ -1,9 +1,10 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.google.common.collect.Maps;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.integration.Integration;
import com.moulberry.axiom.integration.coreprotect.CoreProtectIntegration;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.core.BlockPos;
@ -54,7 +55,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.function.IntFunction;
public class SetBlockPacketListener implements PluginMessageListener {
public class SetBlockPacketListener implements PacketHandler {
private final AxiomPaper plugin;
private final Method updateBlockEntityTicker;
@ -74,22 +75,14 @@ public class SetBlockPacketListener implements PluginMessageListener {
}
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
public static class AxiomPlacingCraftBlockState extends CraftBlockState {
public AxiomPlacingCraftBlockState(@Nullable World world, BlockPos blockPosition, BlockState blockData) {
super(world, blockPosition, blockData);
}
}
private void process(Player bukkitPlayer, byte[] message) {
@Override
public void onReceive(Player bukkitPlayer, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(bukkitPlayer, "axiom.build.place")) {
return;
}
@ -99,7 +92,6 @@ public class SetBlockPacketListener implements PluginMessageListener {
}
// Read packet
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
IntFunction<Map<BlockPos, BlockState>> mapFunction = FriendlyByteBuf.limitValue(Maps::newLinkedHashMapWithExpectedSize, 512);
IdMapper<BlockState> registry = this.plugin.getBlockRegistry(bukkitPlayer.getUniqueId());
Map<BlockPos, BlockState> blocks = friendlyByteBuf.readMap(mapFunction,

Datei anzeigen

@ -1,9 +1,10 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.google.common.collect.Lists;
import com.moulberry.axiom.AxiomConstants;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.View;
import com.moulberry.axiom.packet.PacketHandler;
import com.moulberry.axiom.persistence.UUIDDataType;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
@ -18,7 +19,7 @@ import java.util.List;
import java.util.UUID;
import java.util.function.IntFunction;
public class SetEditorViewsPacketListener implements PluginMessageListener {
public class SetEditorViewsPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public SetEditorViewsPacketListener(AxiomPaper plugin) {
@ -26,20 +27,11 @@ public class SetEditorViewsPacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.editor.views")) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
UUID uuid = friendlyByteBuf.readUUID();
IntFunction<List<View>> listFunction = FriendlyByteBuf.limitValue(Lists::newArrayListWithCapacity, 64);
List<View> views = friendlyByteBuf.readCollection(listFunction, View::read);

Datei anzeigen

@ -1,7 +1,8 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.event.AxiomFlySpeedChangeEvent;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
@ -11,7 +12,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class SetFlySpeedPacketListener implements PluginMessageListener {
public class SetFlySpeedPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public SetFlySpeedPacketListener(AxiomPaper plugin) {
@ -19,20 +20,11 @@ public class SetFlySpeedPacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.player.speed")) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
float flySpeed = friendlyByteBuf.readFloat();
// Call event

Datei anzeigen

@ -1,7 +1,8 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.event.AxiomGameModeChangeEvent;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
@ -13,7 +14,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class SetGamemodePacketListener implements PluginMessageListener {
public class SetGamemodePacketListener implements PacketHandler {
private final AxiomPaper plugin;
public SetGamemodePacketListener(AxiomPaper plugin) {
@ -21,20 +22,11 @@ public class SetGamemodePacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.player.gamemode")) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
GameType gameType = GameType.byId(friendlyByteBuf.readByte());
// Call event

Datei anzeigen

@ -1,9 +1,9 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomConstants;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.packet.PacketHandler;
import com.moulberry.axiom.persistence.ItemStackDataType;
import com.viaversion.viaversion.api.Via;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
@ -15,7 +15,7 @@ import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class SetHotbarSlotPacketListener implements PluginMessageListener {
public class SetHotbarSlotPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public SetHotbarSlotPacketListener(AxiomPaper plugin) {
@ -23,20 +23,11 @@ public class SetHotbarSlotPacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.player.hotbar") || this.plugin.isMismatchedDataVersion(player.getUniqueId())) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
int index = friendlyByteBuf.readByte();
if (index < 0 || index >= 9*9) return;
net.minecraft.world.item.ItemStack nmsStack = friendlyByteBuf.readItem();

Datei anzeigen

@ -1,8 +1,9 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.event.AxiomTimeChangeEvent;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.core.registries.Registries;
@ -17,7 +18,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class SetTimePacketListener implements PluginMessageListener {
public class SetTimePacketListener implements PacketHandler {
private final AxiomPaper plugin;
public SetTimePacketListener(AxiomPaper plugin) {
@ -25,20 +26,11 @@ public class SetTimePacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.world.time")) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
ResourceKey<Level> key = friendlyByteBuf.readResourceKey(Registries.DIMENSION);
Integer time = friendlyByteBuf.readNullable(FriendlyByteBuf::readInt);
Boolean freezeTime = friendlyByteBuf.readNullable(FriendlyByteBuf::readBoolean);

Datei anzeigen

@ -1,7 +1,8 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.packet.PacketHandler;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertyHolder;
import io.netty.buffer.Unpooled;
@ -12,7 +13,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class SetWorldPropertyListener implements PluginMessageListener {
public class SetWorldPropertyListener implements PacketHandler {
private final AxiomPaper plugin;
public SetWorldPropertyListener(AxiomPaper plugin) {
@ -20,20 +21,11 @@ public class SetWorldPropertyListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.world.property")) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
ResourceLocation id = friendlyByteBuf.readResourceLocation();
int type = friendlyByteBuf.readVarInt();
byte[] data = friendlyByteBuf.readByteArray();

Datei anzeigen

@ -1,11 +1,10 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.NbtSanitization;
import com.moulberry.axiom.integration.Integration;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.packet.PacketHandler;
import com.moulberry.axiom.viaversion.UnknownVersionHelper;
import com.moulberry.axiom.viaversion.ViaVersionHelper;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.core.BlockPos;
@ -32,7 +31,7 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
public class SpawnEntityPacketListener implements PluginMessageListener {
public class SpawnEntityPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public SpawnEntityPacketListener(AxiomPaper plugin) {
@ -46,15 +45,7 @@ public class SpawnEntityPacketListener implements PluginMessageListener {
private static final Rotation[] ROTATION_VALUES = Rotation.values();
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.entity.spawn", true)) {
return;
}
@ -63,7 +54,6 @@ public class SpawnEntityPacketListener implements PluginMessageListener {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
List<SpawnEntry> entries = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000),
buf -> new SpawnEntry(buf.readUUID(), buf.readDouble(), buf.readDouble(),
buf.readDouble(), buf.readFloat(), buf.readFloat(),

Datei anzeigen

@ -1,7 +1,8 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomConstants;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.packet.PacketHandler;
import com.moulberry.axiom.persistence.ItemStackDataType;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
@ -17,7 +18,7 @@ import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class SwitchActiveHotbarPacketListener implements PluginMessageListener {
public class SwitchActiveHotbarPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public SwitchActiveHotbarPacketListener(AxiomPaper plugin) {
@ -25,20 +26,11 @@ public class SwitchActiveHotbarPacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.player.hotbar") || this.plugin.isMismatchedDataVersion(player.getUniqueId())) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
int oldHotbarIndex = friendlyByteBuf.readByte();
int activeHotbarIndex = friendlyByteBuf.readByte();

Datei anzeigen

@ -1,8 +1,9 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.event.AxiomUnknownTeleportEvent;
import com.moulberry.axiom.event.AxiomTeleportEvent;
import com.moulberry.axiom.packet.PacketHandler;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.core.registries.Registries;
@ -16,7 +17,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
public class TeleportPacketListener implements PluginMessageListener {
public class TeleportPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public TeleportPacketListener(AxiomPaper plugin) {
@ -24,20 +25,11 @@ public class TeleportPacketListener implements PluginMessageListener {
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
try {
this.process(player, message);
} catch (Throwable t) {
player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage()));
}
}
private void process(Player player, byte[] message) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.world.teleport")) {
return;
}
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
ResourceKey<Level> resourceKey = friendlyByteBuf.readResourceKey(Registries.DIMENSION);
double x = friendlyByteBuf.readDouble();
double y = friendlyByteBuf.readDouble();

Datei anzeigen

@ -1,38 +1,36 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.annotations.AnnotationUpdateAction;
import com.moulberry.axiom.annotations.ServerAnnotations;
import com.moulberry.axiom.blueprint.BlueprintIo;
import com.moulberry.axiom.blueprint.RawBlueprint;
import com.moulberry.axiom.blueprint.ServerBlueprintManager;
import com.moulberry.axiom.blueprint.ServerBlueprintRegistry;
import net.minecraft.SharedConstants;
import com.moulberry.axiom.packet.PacketHandler;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public class UpdateAnnotationPacketListener {
public class UpdateAnnotationPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public UpdateAnnotationPacketListener(AxiomPaper plugin) {
this.plugin = plugin;
}
public void onReceive(ServerPlayer serverPlayer, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.allowAnnotations || !this.plugin.canUseAxiom(serverPlayer.getBukkitEntity(), "axiom.annotation.create")) {
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.allowAnnotations || !this.plugin.canUseAxiom(player, "axiom.annotation.create")) {
friendlyByteBuf.writerIndex(friendlyByteBuf.readerIndex());
return;
}
if (!this.plugin.canModifyWorld(player, player.getWorld())) {
return;
}
ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle();
// Read actions
int length = friendlyByteBuf.readVarInt();
List<AnnotationUpdateAction> actions = new ArrayList<>(Math.min(256, length));

Datei anzeigen

@ -1,14 +1,17 @@
package com.moulberry.axiom.packet;
package com.moulberry.axiom.packet.impl;
import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.blueprint.BlueprintIo;
import com.moulberry.axiom.blueprint.RawBlueprint;
import com.moulberry.axiom.blueprint.ServerBlueprintManager;
import com.moulberry.axiom.blueprint.ServerBlueprintRegistry;
import com.moulberry.axiom.packet.PacketHandler;
import net.minecraft.SharedConstants;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.BufferedOutputStream;
import java.io.IOException;
@ -16,19 +19,26 @@ import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
public class UploadBlueprintPacketListener {
public class UploadBlueprintPacketListener implements PacketHandler {
private final AxiomPaper plugin;
public UploadBlueprintPacketListener(AxiomPaper plugin) {
this.plugin = plugin;
}
public void onReceive(ServerPlayer serverPlayer, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(serverPlayer.getBukkitEntity(), "axiom.blueprint.upload")) {
@Override
public boolean handleAsync() {
return true;
}
public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) {
if (!this.plugin.canUseAxiom(player, "axiom.blueprint.upload")) {
friendlyByteBuf.writerIndex(friendlyByteBuf.readerIndex());
return;
}
ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle();
if (this.plugin.isMismatchedDataVersion(serverPlayer.getUUID())) {
serverPlayer.sendSystemMessage(Component.literal("Axiom+ViaVersion: This feature isn't supported. Switch your client version to " + SharedConstants.VERSION_STRING + " to use this"));
return;

Datei anzeigen

@ -17,6 +17,9 @@ blueprint-sharing: false
# Allow large chunk data requests, not recommended for public servers
allow-large-chunk-data-request: false
# Raise the size limit for *all* packets to 2mb instead of 32kb. NOT RECOMMENDED FOR PUBLIC SERVERS
allow-large-payload-for-all-packets: false
# Action to take when a user with an incompatible Minecraft version or Axiom version joins
# Valid actions are 'kick' and 'warn'
# 'warn' will give the player a warning and disable Axiom
@ -97,4 +100,5 @@ packet-handlers:
manipulate-entity: true
delete-entity: true
marker-nbt-request: true
blueprint-request: true
upload-blueprint: true
annotation-update: true