Merge pull request #15 from Kikisito/master

1.16 compatibility
This commit is contained in:
Zeshan Aslam 2020-06-25 21:55:44 -04:00 committed by GitHub
commit f4671413b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 9 deletions

View File

@ -1,6 +1,6 @@
name: ActionHealth
main: com.zeshanaslam.actionhealth.Main
version: 3.4.7
version: 3.4.8
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, WorldGuard, mcMMO, MythicMobs, LangUtils]
commands:
Actionhealth:

View File

@ -0,0 +1,35 @@
package com.zeshanaslam.actionhealth.support;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
public class LegacyPreAction {
private final String packageVersion = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
public LegacyPreAction(Player player, String message) throws ClassNotFoundException {
try {
Object chatComponentText = getNMSClass("ChatComponentText").getConstructor(new Class[]{String.class}).newInstance(message);
Object chatMessageType = getNMSClass("ChatMessageType").getField("GAME_INFO").get(null);
Object packetPlayOutChat = getNMSClass("PacketPlayOutChat").getConstructor(new Class[]{getNMSClass("IChatBaseComponent"), getNMSClass("ChatMessageType")}).newInstance(chatComponentText, chatMessageType);
Object getHandle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player);
Object playerConnection = getHandle.getClass().getField("playerConnection").get(getHandle);
playerConnection.getClass().getMethod("sendPacket", new Class[]{getNMSClass("Packet")}).invoke(playerConnection, packetPlayOutChat);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException e) {
e.printStackTrace();
}
}
private Class<?> getNMSClass(String nmsClassName) {
try {
return Class.forName("net.minecraft.server." + packageVersion + "." + nmsClassName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -9,11 +9,11 @@ public class PreAction {
private final String packageVersion = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
public PreAction(Player player, String message) {
public PreAction(Player player, String message) throws ClassNotFoundException {
try {
Object chatComponentText = getNMSClass("ChatComponentText").getConstructor(new Class[]{String.class}).newInstance(message);
Object chatMessageType = getNMSClass("ChatMessageType").getField("GAME_INFO").get(null);
Object packetPlayOutChat = getNMSClass("PacketPlayOutChat").getConstructor(new Class[]{getNMSClass("IChatBaseComponent"), getNMSClass("ChatMessageType")}).newInstance(chatComponentText, chatMessageType);
Object packetPlayOutChat = getNMSClass("PacketPlayOutChat").getConstructor(new Class[]{getNMSClass("IChatBaseComponent"), getNMSClass("ChatMessageType"), Class.forName("java.util.UUID")}).newInstance(chatComponentText, chatMessageType, player.getUniqueId());
Object getHandle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player);
Object playerConnection = getHandle.getClass().getField("playerConnection").get(getHandle);

View File

@ -1,5 +1,6 @@
package com.zeshanaslam.actionhealth.support;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager;
@ -61,7 +62,7 @@ public class WorldGuardAPI {
return;
}
} else {
regionContainer = worldGuardPlugin.getRegionContainer();
regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer();
try {
regionContainerGetMethod = regionContainer.getClass().getMethod("get", World.class);
} catch (Exception ex) {

View File

@ -2,10 +2,7 @@ package com.zeshanaslam.actionhealth.utils;
import com.zeshanaslam.actionhealth.Main;
import com.zeshanaslam.actionhealth.api.HealthSendEvent;
import com.zeshanaslam.actionhealth.support.LangUtilsSupport;
import com.zeshanaslam.actionhealth.support.McMMOSupport;
import com.zeshanaslam.actionhealth.support.MythicMobsSupport;
import com.zeshanaslam.actionhealth.support.PreAction;
import com.zeshanaslam.actionhealth.support.*;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -241,8 +238,10 @@ public class HealthUtil {
message = ChatColor.translateAlternateColorCodes('&', message);
try {
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_")) {
if(plugin.configStore.mcVersion.equals("v1_16_R1")){
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_")) {
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");
Object p = c1.cast(player);