From dde8aa252bfce72c5c745d7393c9e7887267d9b0 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Wed, 29 May 2024 14:43:48 -0400 Subject: [PATCH] Only get package name for 1.8, part 2. See #2216 --- .../pikamug/quests/nms/BukkitActionBarProvider.java | 11 ++++++----- .../me/pikamug/quests/nms/BukkitTitleProvider.java | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/me/pikamug/quests/nms/BukkitActionBarProvider.java b/core/src/main/java/me/pikamug/quests/nms/BukkitActionBarProvider.java index 5210383d9..af665246f 100644 --- a/core/src/main/java/me/pikamug/quests/nms/BukkitActionBarProvider.java +++ b/core/src/main/java/me/pikamug/quests/nms/BukkitActionBarProvider.java @@ -18,19 +18,20 @@ public abstract class BukkitActionBarProvider { private static BukkitActionBarProvider loaded; static { - final String internalsName = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + final String bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0]; try { - final String packageName = BukkitActionBarProvider.class.getPackage().getName(); - if (internalsName.startsWith("v1_8_R")) { + final String packageName = BukkitParticleProvider.class.getPackage().getName(); + if (bukkitVersion.startsWith("1.8.") || bukkitVersion.equals("1.8")) { + final String internalsName = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; loaded = (BukkitActionBarProvider) Class.forName(packageName + ".BukkitActionBarProvider_" + internalsName) .newInstance(); } else { - // Should not be an issue because single thread, alternatives welcome! + // Referencing subclass should not be an issue because single thread, alternatives welcome! loaded = new BukkitActionBarProvider_Modern(); } } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | ClassCastException exception) { - Bukkit.getLogger().severe("[Quests] No valid action bar implementation for version " + internalsName); + Bukkit.getLogger().severe("[Quests] No valid action bar implementation for version " + bukkitVersion); } } diff --git a/core/src/main/java/me/pikamug/quests/nms/BukkitTitleProvider.java b/core/src/main/java/me/pikamug/quests/nms/BukkitTitleProvider.java index 95bac632c..4263e3409 100644 --- a/core/src/main/java/me/pikamug/quests/nms/BukkitTitleProvider.java +++ b/core/src/main/java/me/pikamug/quests/nms/BukkitTitleProvider.java @@ -18,19 +18,20 @@ public abstract class BukkitTitleProvider { private static BukkitTitleProvider loaded; static { - final String internalsName = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + final String bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0]; try { - final String packageName = BukkitTitleProvider.class.getPackage().getName(); - if (internalsName.startsWith("v1_8_R")) { + final String packageName = BukkitParticleProvider.class.getPackage().getName(); + if (bukkitVersion.startsWith("1.8.") || bukkitVersion.equals("1.8")) { + final String internalsName = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; loaded = (BukkitTitleProvider) Class.forName(packageName + ".BukkitTitleProvider_" + internalsName) .newInstance(); } else { - // Should not be an issue because single thread, alternatives welcome! + // Referencing subclass should not be an issue because single thread, alternatives welcome! loaded = new BukkitTitleProvider_Modern(); } } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | ClassCastException exception) { - Bukkit.getLogger().severe("[Quests] No valid title implementation for version " + internalsName); + Bukkit.getLogger().severe("[Quests] No valid title implementation for version " + bukkitVersion); } }