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

Add try-catch to all bukkit plugin message handlers to kick player

Dieser Commit ist enthalten in:
Moulberry 2024-05-04 22:10:26 +08:00
Ursprung 1962e877c6
Commit cdee54d807
16 geänderte Dateien mit 144 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -8,6 +8,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;
@ -42,7 +43,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();

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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_R3.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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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_R3.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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}