Started rewrite of action health
This commit is contained in:
parent
6f68fc521a
commit
51f5cee3f8
|
@ -0,0 +1,3 @@
|
||||||
|
ActionHealth.iml
|
||||||
|
.idea/*
|
||||||
|
libs/*
|
|
@ -0,0 +1,6 @@
|
||||||
|
name: ActionHealth
|
||||||
|
main: com.zeshanaslam.actionhealth.Main
|
||||||
|
version: 5.0
|
||||||
|
commands:
|
||||||
|
Actionhealth:
|
||||||
|
description: Reloads the plugin
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String> worlds = new ArrayList<>();
|
||||||
|
public HashMap<String, String> 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_");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue