From beff4767c4410284e4697ab767baf52cdf3ebadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Wed, 10 Jul 2024 17:05:35 +0200 Subject: [PATCH 1/2] feat: Update to 1.21 --- build.gradle | 2 +- .../actionhealth/config/ConfigStore.java | 9 ++++-- .../actionhealth/utils/HealthUtil.java | 31 ++++++++++--------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index db094cc..ce61a46 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'com.zeshanaslam' -version = '3.5.9' +version = '3.6.0' repositories { mavenCentral() diff --git a/src/main/java/com/zeshanaslam/actionhealth/config/ConfigStore.java b/src/main/java/com/zeshanaslam/actionhealth/config/ConfigStore.java index 1d28300..baaf4b1 100644 --- a/src/main/java/com/zeshanaslam/actionhealth/config/ConfigStore.java +++ b/src/main/java/com/zeshanaslam/actionhealth/config/ConfigStore.java @@ -35,6 +35,7 @@ public class ConfigStore { public List worlds = new ArrayList<>(); public HashMap translate = new HashMap<>(); public List regions = new ArrayList<>(); + public String mcRemappedPackage; public String mcVersion; public boolean useOldMethods; public boolean showOnLook; @@ -110,10 +111,12 @@ public ConfigStore(Main plugin) { worlds = plugin.getConfig().getStringList("Disabled worlds"); // Check if using protocol build - mcVersion = Bukkit.getServer().getClass().getPackage().getName(); - mcVersion = mcVersion.substring(mcVersion.lastIndexOf(".") + 1); + mcRemappedPackage = Bukkit.getServer().getClass().getPackage().getName(); + mcRemappedPackage = mcRemappedPackage.substring(mcRemappedPackage.lastIndexOf(".") + 1); + mcVersion = Bukkit.getBukkitVersion(); + mcVersion = mcVersion.split("-")[0]; - useOldMethods = mcVersion.equalsIgnoreCase("v1_8_R1") || mcVersion.equalsIgnoreCase("v1_7_"); + useOldMethods = mcRemappedPackage.equalsIgnoreCase("v1_8_R1") || mcRemappedPackage.equalsIgnoreCase("v1_7_"); if (plugin.getConfig().contains("Remember Toggle")) { rememberToggle = plugin.getConfig().getBoolean("Remember Toggle"); diff --git a/src/main/java/com/zeshanaslam/actionhealth/utils/HealthUtil.java b/src/main/java/com/zeshanaslam/actionhealth/utils/HealthUtil.java index 5c54e47..6628b5b 100644 --- a/src/main/java/com/zeshanaslam/actionhealth/utils/HealthUtil.java +++ b/src/main/java/com/zeshanaslam/actionhealth/utils/HealthUtil.java @@ -242,7 +242,7 @@ private String getNameReflection(LivingEntity entity) { Method getName = null; try { if (entity.getCustomName() == null) - getName = entity.getClass().getMethod("getName", (Class[]) null); + getName = entity.getClass().getMethod("getName"); } catch (NoSuchMethodException | SecurityException ignored) { } @@ -268,21 +268,22 @@ public void sendActionBar(Player player, String message) { message = ChatColor.translateAlternateColorCodes('&', message); try { - if (plugin.configStore.mcVersion.contains("v1_17") || plugin.configStore.mcVersion.contains("v1_18") || plugin.configStore.mcVersion.contains("v1_19") || plugin.configStore.mcVersion.contains("v1_20")) { + if (plugin.configStore.mcRemappedPackage.contains("v1_17") || plugin.configStore.mcRemappedPackage.contains("v1_18") || plugin.configStore.mcRemappedPackage.contains("v1_19") || plugin.configStore.mcRemappedPackage.contains("v1_20") + || plugin.configStore.mcVersion.contains("1.21")) { new NewAction(player, message); - } else if (plugin.configStore.mcVersion.contains("v1_16")) { + } else if (plugin.configStore.mcRemappedPackage.contains("v1_16")) { new PreAction(player, message); - } else if (plugin.configStore.mcVersion.equals("v1_12_R1") || plugin.configStore.mcVersion.startsWith("v1_13") || plugin.configStore.mcVersion.startsWith("v1_14_") || plugin.configStore.mcVersion.startsWith("v1_15_")) { + } else if (plugin.configStore.mcRemappedPackage.equals("v1_12_R1") || plugin.configStore.mcRemappedPackage.startsWith("v1_13") || plugin.configStore.mcRemappedPackage.startsWith("v1_14_") || plugin.configStore.mcRemappedPackage.startsWith("v1_15_")) { new LegacyPreAction(player, message); - } else if (!(plugin.configStore.mcVersion.equalsIgnoreCase("v1_8_R1") || plugin.configStore.mcVersion.contains("v1_7_"))) { - Class c1 = Class.forName("org.bukkit.craftbukkit." + plugin.configStore.mcVersion + ".entity.CraftPlayer"); + } else if (!(plugin.configStore.mcRemappedPackage.equalsIgnoreCase("v1_8_R1") || plugin.configStore.mcRemappedPackage.contains("v1_7_"))) { + Class c1 = Class.forName("org.bukkit.craftbukkit." + plugin.configStore.mcRemappedPackage + ".entity.CraftPlayer"); Object p = c1.cast(player); Object ppoc; - Class c4 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".PacketPlayOutChat"); - Class c5 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".Packet"); + Class c4 = Class.forName("net.minecraft.server." + plugin.configStore.mcRemappedPackage + ".PacketPlayOutChat"); + Class c5 = Class.forName("net.minecraft.server." + plugin.configStore.mcRemappedPackage + ".Packet"); - Class c2 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".ChatComponentText"); - Class c3 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".IChatBaseComponent"); + Class c2 = Class.forName("net.minecraft.server." + plugin.configStore.mcRemappedPackage + ".ChatComponentText"); + Class c3 = Class.forName("net.minecraft.server." + plugin.configStore.mcRemappedPackage + ".IChatBaseComponent"); Object o = c2.getConstructor(new Class[]{String.class}).newInstance(message); ppoc = c4.getConstructor(new Class[]{c3, byte.class}).newInstance(o, (byte) 2); @@ -295,14 +296,14 @@ public void sendActionBar(Player player, String message) { Method sendPacket = playerConnection.getClass().getDeclaredMethod("sendPacket", c5); sendPacket.invoke(playerConnection, ppoc); } else { - Class c1 = Class.forName("org.bukkit.craftbukkit." + plugin.configStore.mcVersion + ".entity.CraftPlayer"); + Class c1 = Class.forName("org.bukkit.craftbukkit." + plugin.configStore.mcRemappedPackage + ".entity.CraftPlayer"); Object p = c1.cast(player); Object ppoc; - Class c4 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".PacketPlayOutChat"); - Class c5 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".Packet"); + Class c4 = Class.forName("net.minecraft.server." + plugin.configStore.mcRemappedPackage + ".PacketPlayOutChat"); + Class c5 = Class.forName("net.minecraft.server." + plugin.configStore.mcRemappedPackage + ".Packet"); - Class c2 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".ChatSerializer"); - Class c3 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".IChatBaseComponent"); + Class c2 = Class.forName("net.minecraft.server." + plugin.configStore.mcRemappedPackage + ".ChatSerializer"); + Class c3 = Class.forName("net.minecraft.server." + plugin.configStore.mcRemappedPackage + ".IChatBaseComponent"); Method m3 = c2.getDeclaredMethod("a", String.class); Object cbc = c3.cast(m3.invoke(c2, "{\"text\": \"" + message + "\"}")); ppoc = c4.getConstructor(new Class[]{c3, byte.class}).newInstance(cbc, (byte) 2); From 5654d7c45520b259f3a60f84670481986eb34e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= <43724816+Aurelien30000@users.noreply.github.com> Date: Sun, 22 Dec 2024 18:53:22 +0100 Subject: [PATCH 2/2] fix: Bump minor version only Co-authored-by: Joo200 --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ce61a46..19d5450 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,8 @@ plugins { } group = 'com.zeshanaslam' -version = '3.6.0' +version = '3.5.10' + repositories { mavenCentral()