Added support for 1.8 as it was broken, need to fully test with 1.12 and a few other versions before release

This commit is contained in:
sekwah 2018-04-07 03:30:55 +01:00
parent 7a4046f3f9
commit 6d6a483275
2 changed files with 20 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import java.lang.reflect.Method;
public class CraftBukkit {
private final AdvancedPortalsPlugin plugin;
private Constructor<?> reallyOldChatConstructor;
private Method chatMessageTypeMethod;
@ -39,10 +40,11 @@ public class CraftBukkit {
this.plugin = plugin;
try {
// CraftBukkit Ahoy!
String craftBukkitPackage = "org.bukkit.craftbukkit." + bukkitImpl + ".";
String minecraftPackage = "net.minecraft.server." + bukkitImpl + ".";
this.plugin.getLogger().info("Bukkit version detected " + bukkitImpl);
Class<?> chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); // string to packet methods
Class<?> chatSerialClass = this.findClass(chatBaseComponent, "ChatSerializer");
@ -64,9 +66,15 @@ public class CraftBukkit {
this.serializeMessage = chatSerialClass.getMethod("a", String.class);
}
else{
plugin.getLogger().info("Even older version detected, changing chat method.");
plugin.getLogger().info("Attempting support for 1.8");
try {
this.reallyOldChatConstructor = Class.forName(minecraftPackage + "ChatMessage").getConstructor(String.class, Object[].class);
}
catch (ClassNotFoundException e) {
plugin.getLogger().info("Fallback (I forget what version uses this but it was here for a reason)");
this.serializeMessage = chatBaseComponent.getMethod("a", String.class);
}
}
this.playerGetHandle = Class.forName(craftBukkitPackage + "entity.CraftPlayer").getMethod("getHandle");
this.playerConnection = Class.forName(minecraftPackage + "EntityPlayer").getField("playerConnection"); // get player connection
@ -97,9 +105,15 @@ public class CraftBukkit {
public void sendMessage(String rawMessage, Player player, byte msgType) {
try {
Object comp = this.serializeMessage.invoke(null,rawMessage); // convert string into bytes
Object comp;
if(this.reallyOldChatConstructor != null) {
comp = this.reallyOldChatConstructor.newInstance(rawMessage,new Object[]{});
}
else {
comp = this.serializeMessage.invoke(null,"{\"text\":\"" + rawMessage + "\"}");
}
Object packet;
if(useEnumType){
if(this.useEnumType){
packet = this.chatPacketConstructor.newInstance(comp, this.chatMessageTypeMethod.invoke(null,msgType)); // convert bytes into packet
}
else{

View File

@ -138,7 +138,7 @@ public class Destination {
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.");
player.sendMessage("");
} else if (PortalMessagesDisplay == 2) {
plugin.compat.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player);
plugin.compat.sendActionBarMessage("\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.", player);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}