From 6d6a48327560882e92f17968606de3a5aaea5942 Mon Sep 17 00:00:00 2001 From: sekwah Date: Sat, 7 Apr 2018 03:30:55 +0100 Subject: [PATCH] Added support for 1.8 as it was broken, need to fully test with 1.12 and a few other versions before release --- .../advancedportals/compat/CraftBukkit.java | 24 +++++++++++++++---- .../destinations/Destination.java | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/com/sekwah/advancedportals/compat/CraftBukkit.java index ed83695..a2c2775 100644 --- a/src/com/sekwah/advancedportals/compat/CraftBukkit.java +++ b/src/com/sekwah/advancedportals/compat/CraftBukkit.java @@ -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,8 +66,14 @@ public class CraftBukkit { this.serializeMessage = chatSerialClass.getMethod("a", String.class); } else{ - plugin.getLogger().info("Even older version detected, changing chat method."); - this.serializeMessage = chatBaseComponent.getMethod("a", String.class); + 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"); @@ -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{ diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 34d6fb0..a071ddb 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -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);*/ }