diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dff3046 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +ActionHealth.iml +.idea/* +libs/* \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..ff4ed3b --- /dev/null +++ b/plugin.yml @@ -0,0 +1,6 @@ +name: ActionHealth +main: com.zeshanaslam.actionhealth.Main +version: 5.0 +commands: + Actionhealth: + description: Reloads the plugin \ No newline at end of file diff --git a/src/com/zeshanaslam/actionhealth/HealthUtil.java b/src/com/zeshanaslam/actionhealth/HealthUtil.java new file mode 100644 index 0000000..123a4f5 --- /dev/null +++ b/src/com/zeshanaslam/actionhealth/HealthUtil.java @@ -0,0 +1,54 @@ +package com.zeshanaslam.actionhealth; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +public class HealthUtil { + + private Main plugin; + + public HealthUtil(Main plugin) { + this.plugin = plugin; + } + + private void sendActionBar(Player player, String message) { + if (player.hasMetadata("NPC")) { + return; + } + + message = ChatColor.translateAlternateColorCodes('&', message); + + try { + Class c1 = Class.forName("org.bukkit.craftbukkit." + plugin.settingsManager.mcVersion + ".entity.CraftPlayer"); + Object p = c1.cast(player); + Object ppoc; + Class c4 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".PacketPlayOutChat"); + Class c5 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".Packet"); + + if (plugin.settingsManager.useOldMethods) { + Class c2 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".ChatSerializer"); + Class c3 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".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); + } else { + Class c2 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".ChatComponentText"); + Class c3 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".IChatBaseComponent"); + Object o = c2.getConstructor(new Class[]{String.class}).newInstance(message); + ppoc = c4.getConstructor(new Class[]{c3, byte.class}).newInstance(o, (byte) 2); + } + + Method m1 = c1.getDeclaredMethod("getHandle"); + Object h = m1.invoke(p); + Field f1 = h.getClass().getDeclaredField("playerConnection"); + Object pc = f1.get(h); + Method m5 = pc.getClass().getDeclaredMethod("sendPacket", c5); + m5.invoke(pc, ppoc); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/src/com/zeshanaslam/actionhealth/Main.java b/src/com/zeshanaslam/actionhealth/Main.java new file mode 100644 index 0000000..32700c8 --- /dev/null +++ b/src/com/zeshanaslam/actionhealth/Main.java @@ -0,0 +1,24 @@ +package com.zeshanaslam.actionhealth; + +import org.bukkit.plugin.java.JavaPlugin; + +public class Main extends JavaPlugin { + + public SettingsManager settingsManager; + + @Override + public void onEnable() + { + saveDefaultConfig(); + + // Load config settings + settingsManager = new SettingsManager(this); + + + } + + @Override + public void onDisable() { + + } +} diff --git a/src/com/zeshanaslam/actionhealth/SettingsManager.java b/src/com/zeshanaslam/actionhealth/SettingsManager.java new file mode 100644 index 0000000..af4f36b --- /dev/null +++ b/src/com/zeshanaslam/actionhealth/SettingsManager.java @@ -0,0 +1,56 @@ +package com.zeshanaslam.actionhealth; + +import org.bukkit.Bukkit; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class SettingsManager { + + public String healthMessage; + public boolean usePerms; + public boolean showMobs; + public boolean showPlayers; + public boolean delay; + public boolean checkPvP; + public boolean limitHealth; + public boolean stripName; + public String filledHeartIcon; + public String halfHeartIcon; + public String emptyHeartIcon; + public List worlds = new ArrayList<>(); + public HashMap translate = new HashMap<>(); + + public String mcVersion; + public boolean useOldMethods; + + public SettingsManager(Main plugin) { + healthMessage = plugin.getConfig().getString("Health Message"); + usePerms = plugin.getConfig().getBoolean("Use Permissions"); + showMobs = plugin.getConfig().getBoolean("Show Mob"); + showPlayers = plugin.getConfig().getBoolean("Show Player"); + delay = plugin.getConfig().getBoolean("Delay Message"); + checkPvP = plugin.getConfig().getBoolean("Region PvP"); + limitHealth = plugin.getConfig().getBoolean("Limit Health"); + stripName = plugin.getConfig().getBoolean("Strip Name"); + filledHeartIcon = plugin.getConfig().getString("Full Health Icon"); + halfHeartIcon = plugin.getConfig().getString("Half Health Icon"); + emptyHeartIcon = plugin.getConfig().getString("Empty Health Icon"); + if (plugin.getConfig().getBoolean("Name Change")) { + for (String s : plugin.getConfig().getStringList("Name")) + { + String[] split = s.split(" = "); + translate.put(split[0], split[1]); + } + } + + worlds = plugin.getConfig().getStringList("Disabled worlds"); + + // Check if using protocol build + mcVersion = Bukkit.getServer().getClass().getPackage().getName(); + mcVersion = mcVersion.substring(mcVersion.lastIndexOf(".") + 1); + + useOldMethods = mcVersion.equalsIgnoreCase("v1_8_R1") || mcVersion.equalsIgnoreCase("v1_7_"); + } +}