Wrap inventory packet lisetner in a try{}

This commit is contained in:
libraryaddict 2024-06-30 22:42:32 +12:00
parent d602793339
commit 410c53c18d

View File

@ -33,6 +33,7 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
@Override @Override
public void onPacketPlayReceive(PacketPlayReceiveEvent event) { public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
try {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
@ -40,7 +41,6 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
if (event.getPacketType() != Client.CLICK_WINDOW && event.getPacketType() != Client.CREATIVE_INVENTORY_ACTION) { if (event.getPacketType() != Client.CLICK_WINDOW && event.getPacketType() != Client.CREATIVE_INVENTORY_ACTION) {
return; return;
} }
if (!Bukkit.isPrimaryThread()) { if (!Bukkit.isPrimaryThread()) {
PacketPlayReceiveEvent cloned = event.clone(); PacketPlayReceiveEvent cloned = event.clone();
new BukkitRunnable() { new BukkitRunnable() {
@ -84,8 +84,8 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
if (DisguiseUtilities.shouldBeHiddenSelfDisguise(item) && item.getType() != Material.ELYTRA) { if (DisguiseUtilities.shouldBeHiddenSelfDisguise(item) && item.getType() != Material.ELYTRA) {
int stateId = NmsVersion.v1_17.isSupported() ? ReflectionManager.getIncrementedStateId(player) : 0; int stateId = NmsVersion.v1_17.isSupported() ? ReflectionManager.getIncrementedStateId(player) : 0;
WrapperPlayServerSetSlot packet = WrapperPlayServerSetSlot packet = new WrapperPlayServerSetSlot(0, stateId, slot,
new WrapperPlayServerSetSlot(0, stateId, slot, com.github.retrooper.packetevents.protocol.item.ItemStack.EMPTY); com.github.retrooper.packetevents.protocol.item.ItemStack.EMPTY);
PacketEvents.getAPI().getPlayerManager().sendPacketSilently(player, packet); PacketEvents.getAPI().getPlayerManager().sendPacketSilently(player, packet);
} }
@ -148,8 +148,8 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
if (disguise.isHidingArmorFromSelf()) { if (disguise.isHidingArmorFromSelf()) {
int stateId = NmsVersion.v1_17.isSupported() ? ReflectionManager.getIncrementedStateId(player) : 0; int stateId = NmsVersion.v1_17.isSupported() ? ReflectionManager.getIncrementedStateId(player) : 0;
WrapperPlayServerSetSlot newPacket = WrapperPlayServerSetSlot newPacket = new WrapperPlayServerSetSlot(0, stateId, slot,
new WrapperPlayServerSetSlot(0, stateId, slot, com.github.retrooper.packetevents.protocol.item.ItemStack.EMPTY); com.github.retrooper.packetevents.protocol.item.ItemStack.EMPTY);
PacketEvents.getAPI().getPlayerManager().sendPacketSilently(player, newPacket); PacketEvents.getAPI().getPlayerManager().sendPacketSilently(player, newPacket);
} }
@ -171,10 +171,15 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
} }
} }
} }
} catch (Throwable ex) {
ex.printStackTrace();
event.setCancelled(true);
}
} }
@Override @Override
public void onPacketPlaySend(PacketPlaySendEvent event) { public void onPacketPlaySend(PacketPlaySendEvent event) {
try {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
@ -283,5 +288,9 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
} }
} }
} }
} catch (Throwable ex) {
ex.printStackTrace();
event.setCancelled(true);
}
} }
} }