Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.21 #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'com.zeshanaslam'
version = '3.5.9'
version = '3.6.0'
Aurelien30000 marked this conversation as resolved.
Show resolved Hide resolved

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ConfigStore {
public List<String> worlds = new ArrayList<>();
public HashMap<String, String> translate = new HashMap<>();
public List<String> regions = new ArrayList<>();
public String mcRemappedPackage;
public String mcVersion;
public boolean useOldMethods;
public boolean showOnLook;
Expand Down Expand Up @@ -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");
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/com/zeshanaslam/actionhealth/utils/HealthUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand All @@ -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);

Expand All @@ -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);
Expand Down