mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-14 06:36:32 +01:00
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:
parent
7a4046f3f9
commit
6d6a483275
@ -19,6 +19,7 @@ import java.lang.reflect.Method;
|
|||||||
public class CraftBukkit {
|
public class CraftBukkit {
|
||||||
|
|
||||||
private final AdvancedPortalsPlugin plugin;
|
private final AdvancedPortalsPlugin plugin;
|
||||||
|
private Constructor<?> reallyOldChatConstructor;
|
||||||
|
|
||||||
private Method chatMessageTypeMethod;
|
private Method chatMessageTypeMethod;
|
||||||
|
|
||||||
@ -39,10 +40,11 @@ public class CraftBukkit {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// CraftBukkit Ahoy!
|
|
||||||
String craftBukkitPackage = "org.bukkit.craftbukkit." + bukkitImpl + ".";
|
String craftBukkitPackage = "org.bukkit.craftbukkit." + bukkitImpl + ".";
|
||||||
String minecraftPackage = "net.minecraft.server." + 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<?> chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); // string to packet methods
|
||||||
Class<?> chatSerialClass = this.findClass(chatBaseComponent, "ChatSerializer");
|
Class<?> chatSerialClass = this.findClass(chatBaseComponent, "ChatSerializer");
|
||||||
|
|
||||||
@ -64,8 +66,14 @@ public class CraftBukkit {
|
|||||||
this.serializeMessage = chatSerialClass.getMethod("a", String.class);
|
this.serializeMessage = chatSerialClass.getMethod("a", String.class);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
plugin.getLogger().info("Even older version detected, changing chat method.");
|
plugin.getLogger().info("Attempting support for 1.8");
|
||||||
this.serializeMessage = chatBaseComponent.getMethod("a", String.class);
|
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.playerGetHandle = Class.forName(craftBukkitPackage + "entity.CraftPlayer").getMethod("getHandle");
|
||||||
@ -97,9 +105,15 @@ public class CraftBukkit {
|
|||||||
|
|
||||||
public void sendMessage(String rawMessage, Player player, byte msgType) {
|
public void sendMessage(String rawMessage, Player player, byte msgType) {
|
||||||
try {
|
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;
|
Object packet;
|
||||||
if(useEnumType){
|
if(this.useEnumType){
|
||||||
packet = this.chatPacketConstructor.newInstance(comp, this.chatMessageTypeMethod.invoke(null,msgType)); // convert bytes into packet
|
packet = this.chatPacketConstructor.newInstance(comp, this.chatMessageTypeMethod.invoke(null,msgType)); // convert bytes into packet
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -138,7 +138,7 @@ public class Destination {
|
|||||||
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.");
|
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.");
|
||||||
player.sendMessage("");
|
player.sendMessage("");
|
||||||
} else if (PortalMessagesDisplay == 2) {
|
} 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("_", " ")
|
/**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);*/
|
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user