From d4894ca4b5252a8b0ef8703a7ea67d5afe99056b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 17 Mar 2023 13:15:56 +0100 Subject: [PATCH] Fix #3260 --- .../ArmorToggleListener.java | 16 ---------------- .../bukkit/platform/BukkitViaLoader.java | 12 +++++++++++- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_19_4To1_19_3/ArmorToggleListener.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_19_4To1_19_3/ArmorToggleListener.java index 574b1d664..3fcdd2996 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_19_4To1_19_3/ArmorToggleListener.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_19_4To1_19_3/ArmorToggleListener.java @@ -31,28 +31,12 @@ import org.bukkit.inventory.PlayerInventory; public final class ArmorToggleListener extends ViaBukkitListener { - private static final boolean ENABLED = hasEquipmentSlot(); - public ArmorToggleListener(final ViaVersionPlugin plugin) { super(plugin, Protocol1_19_4To1_19_3.class); } - private static boolean hasEquipmentSlot() { - // Doesn't exist on 1.8 - try { - Material.class.getMethod("getEquipmentSlot"); - return true; - } catch (final NoSuchMethodException e) { - return false; - } - } - @EventHandler(priority = EventPriority.MONITOR) public void itemUse(final PlayerInteractEvent event) { - if (!ENABLED) { - return; - } - final Player player = event.getPlayer(); final ItemStack item = event.getItem(); if (item == null || event.getHand() == null || !isOnPipe(player)) { diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java index 62c17976a..36e2dc14a 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java @@ -52,6 +52,7 @@ import java.util.concurrent.TimeUnit; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.scheduler.BukkitTask; public class BukkitViaLoader implements ViaPlatformLoader { @@ -144,7 +145,7 @@ public class BukkitViaLoader implements ViaPlatformLoader { } } - if (serverProtocolVersion < ProtocolVersion.v1_19_4.getVersion() && plugin.getConf().isArmorToggleFix()) { + if (serverProtocolVersion < ProtocolVersion.v1_19_4.getVersion() && plugin.getConf().isArmorToggleFix() && hasGetHandMethod()) { new ArmorToggleListener(plugin).register(); } @@ -195,6 +196,15 @@ public class BukkitViaLoader implements ViaPlatformLoader { } } + private boolean hasGetHandMethod() { + try { + PlayerInteractEvent.class.getDeclaredMethod("getHand"); + return true; + } catch (NoSuchMethodException e) { + return false; + } + } + @Override public void unload() { for (BukkitTask task : tasks) {