From 5b403da9669762b373f6c6f168f60a8e148ce6d5 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Sat, 31 Aug 2019 09:17:30 +0200 Subject: [PATCH] Fix hitbox listener for for 1.8.0 servers --- .../multiversion/PlayerSneakListener.java | 14 ++++++++++---- .../bukkit/platform/BukkitViaLoader.java | 7 ++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java index a44dc1e74..7ec2d281a 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java @@ -31,18 +31,24 @@ public class PlayerSneakListener extends ViaBukkitListener { private boolean is1_14Fix; private boolean useCache; - public PlayerSneakListener(ViaVersionPlugin plugin, boolean is1_9Fix, boolean is1_14Fix) { + public PlayerSneakListener(ViaVersionPlugin plugin, boolean is1_9Fix, boolean is1_14Fix) throws ReflectiveOperationException { super(plugin, null); this.is1_9Fix = is1_9Fix; this.is1_14Fix = is1_14Fix; + + final String packageName = plugin.getServer().getClass().getPackage().getName(); + getHandle = Class.forName(packageName + ".entity.CraftPlayer").getMethod("getHandle"); + try { - getHandle = Class.forName(plugin.getServer().getClass().getPackage().getName() + ".entity.CraftPlayer").getMethod("getHandle"); - setSize = Class.forName(plugin.getServer().getClass().getPackage().getName() + setSize = Class.forName(packageName .replace("org.bukkit.craftbukkit", "net.minecraft.server") + ".EntityPlayer").getMethod("setSize", Float.TYPE, Float.TYPE); } catch (ClassNotFoundException | NoSuchMethodException e) { - e.printStackTrace(); + // Don't catch this one + setSize = Class.forName(packageName + .replace("org.bukkit.craftbukkit", "net.minecraft.server") + ".EntityPlayer").getMethod("a", Float.TYPE, Float.TYPE); } + // From 1.9 upwards the server hitbox is set in every entity tick, so we have to reset it everytime if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_9.getId()) { sneaking = new WeakHashMap<>(); diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java index b2e3e82e8..feb7acdfc 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java @@ -82,7 +82,12 @@ public class BukkitViaLoader implements ViaPlatformLoader { if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getId()) { boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId(); if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) { - storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register(); + try { + storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register(); + } catch (ReflectiveOperationException e) { + Via.getPlatform().getLogger().warning("Could not load hitbox fix - please report this on our GitHub"); + e.printStackTrace(); + } } }