From 90634a6680a4a6616598662e0c24696415fbf34b Mon Sep 17 00:00:00 2001 From: Moulberry Date: Sat, 4 May 2024 22:10:26 +0800 Subject: [PATCH] Add try-catch to all bukkit plugin message handlers to kick player --- .../axiom/packet/BlueprintRequestPacketListener.java | 8 ++++++++ .../axiom/packet/DeleteEntityPacketListener.java | 9 +++++++++ .../moulberry/axiom/packet/HelloPacketListener.java | 8 ++++++++ .../axiom/packet/ManipulateEntityPacketListener.java | 9 +++++++++ .../axiom/packet/MarkerNbtRequestPacketListener.java | 9 +++++++++ .../axiom/packet/RequestChunkDataPacketListener.java | 11 ++++++++++- .../axiom/packet/SetBlockPacketListener.java | 11 ++++++++++- .../axiom/packet/SetEditorViewsPacketListener.java | 9 +++++++++ .../axiom/packet/SetFlySpeedPacketListener.java | 9 +++++++++ .../axiom/packet/SetGamemodePacketListener.java | 9 +++++++++ .../axiom/packet/SetHotbarSlotPacketListener.java | 9 +++++++++ .../moulberry/axiom/packet/SetTimePacketListener.java | 9 +++++++++ .../axiom/packet/SetWorldPropertyListener.java | 9 +++++++++ .../axiom/packet/SpawnEntityPacketListener.java | 9 +++++++++ .../packet/SwitchActiveHotbarPacketListener.java | 9 +++++++++ .../axiom/packet/TeleportPacketListener.java | 9 +++++++++ 16 files changed, 144 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java index a792f6f..7f0e771 100644 --- a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java @@ -28,6 +28,14 @@ public class BlueprintRequestPacketListener 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java index 0aca716..7ab549b 100644 --- a/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java @@ -4,6 +4,7 @@ import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.integration.Integration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; @@ -26,6 +27,14 @@ 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java b/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java index 4aa294e..a5ff066 100644 --- a/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java @@ -49,6 +49,14 @@ 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) { if (!this.plugin.hasAxiomPermission(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java index cde69d0..91e754a 100644 --- a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java @@ -6,6 +6,7 @@ import com.moulberry.axiom.integration.Integration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.viaversion.ViaVersionHelper; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -80,6 +81,14 @@ public class ManipulateEntityPacketListener 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java index 91acd37..8140531 100644 --- a/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java @@ -3,6 +3,7 @@ package com.moulberry.axiom.packet; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.marker.MarkerData; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; @@ -24,6 +25,14 @@ 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java index ab39853..343d5cb 100644 --- a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java @@ -7,6 +7,7 @@ import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.viaversion.viaversion.api.Via; import io.netty.buffer.Unpooled; import it.unimi.dsi.fastutil.longs.*; +import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; @@ -41,7 +42,15 @@ public class RequestChunkDataPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player bukkitPlayer, @NotNull byte[] message) { + 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) { ServerPlayer player = ((CraftPlayer)bukkitPlayer).getHandle(); FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); long id = friendlyByteBuf.readLong(); diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java index fa54a97..4032464 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java @@ -5,6 +5,7 @@ import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.integration.Integration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.IdMapper; @@ -68,7 +69,15 @@ public class SetBlockPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player bukkitPlayer, @NotNull byte[] message) { + 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) { if (!this.plugin.canUseAxiom(bukkitPlayer)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java index ce1465a..4bfc76f 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java @@ -6,6 +6,7 @@ import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.View; import com.moulberry.axiom.persistence.UUIDDataType; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; import org.bukkit.entity.Player; import org.bukkit.persistence.PersistentDataContainer; @@ -26,6 +27,14 @@ 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java index cbde259..4f68ed1 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java @@ -3,6 +3,7 @@ package com.moulberry.axiom.packet; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomFlySpeedChangeEvent; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; @@ -19,6 +20,14 @@ 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java index 692db6a..2bed194 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java @@ -3,6 +3,7 @@ package com.moulberry.axiom.packet; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomGameModeChangeEvent; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.level.GameType; import org.bukkit.Bukkit; @@ -21,6 +22,14 @@ 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java index ec532d9..75d38d0 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java @@ -5,6 +5,7 @@ import com.moulberry.axiom.AxiomPaper; 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; import org.bukkit.NamespacedKey; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; @@ -23,6 +24,14 @@ 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) { if (!this.plugin.canUseAxiom(player) || this.plugin.isMismatchedDataVersion(player.getUniqueId())) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java index 5cf48be..3e828c9 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java @@ -4,6 +4,7 @@ import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomTimeChangeEvent; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; @@ -25,6 +26,14 @@ 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java b/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java index a6b4691..5b23f3d 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java @@ -5,6 +5,7 @@ import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry; import com.moulberry.axiom.world_properties.server.ServerWorldPropertyHolder; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import org.bukkit.entity.Player; @@ -20,6 +21,14 @@ 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java index fff7cc3..3437329 100644 --- a/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java @@ -6,6 +6,7 @@ import com.moulberry.axiom.integration.Integration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.viaversion.ViaVersionHelper; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -45,6 +46,14 @@ public class SpawnEntityPacketListener 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) { if (!this.plugin.canUseAxiom(player)) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java index a7b0b63..1527df8 100644 --- a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java @@ -4,6 +4,7 @@ import com.moulberry.axiom.AxiomConstants; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.persistence.ItemStackDataType; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; import org.bukkit.GameMode; import org.bukkit.Material; @@ -25,6 +26,14 @@ 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) { if (!this.plugin.canUseAxiom(player) || this.plugin.isMismatchedDataVersion(player.getUniqueId())) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java b/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java index cc4a91a..4d754a2 100644 --- a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java @@ -4,6 +4,7 @@ import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomUnknownTeleportEvent; import com.moulberry.axiom.event.AxiomTeleportEvent; import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; @@ -24,6 +25,14 @@ 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) { if (!this.plugin.canUseAxiom(player)) { return; }