From 360618cd961a3616939e69cf7826d1e7f88f8379 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Mon, 23 Jul 2018 04:26:55 +0100 Subject: [PATCH] Fixed issues with release for 1.13 The original release works but was a little rushed, the action text interaction didn't work and water was replacing itself to STATIONARY_WATER --- build.gradle | 2 +- out/production/resources/plugin.yml | 3 +- .../AdvancedPortalsCommand.java | 12 ++--- .../advancedportals/compat/CraftBukkit.java | 52 +++---------------- .../advancedportals/portals/Portal.java | 15 +----- src/main/resources/plugin.yml | 2 +- 6 files changed, 19 insertions(+), 67 deletions(-) diff --git a/build.gradle b/build.gradle index fe261da8..44912886 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'idea' apply plugin: 'eclipse' group = 'com.sekwah.advancedportals' -version = '0.0.42-snapshot' +version = '0.0.43-snapshot' description = "" diff --git a/out/production/resources/plugin.yml b/out/production/resources/plugin.yml index a66e0bf7..1b4decf2 100644 --- a/out/production/resources/plugin.yml +++ b/out/production/resources/plugin.yml @@ -1,8 +1,9 @@ main: com.sekwah.advancedportals.AdvancedPortalsPlugin name: AdvancedPortals -version: 0.0.41 +version: 0.0.42 author: sekwah41 description: An advanced portals plugin for bukkit. +api-version: 1.13 commands: advancedportals: description: The main command for the advanced portals diff --git a/src/main/java/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/main/java/com/sekwah/advancedportals/AdvancedPortalsCommand.java index cad87555..8c30fe70 100644 --- a/src/main/java/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/main/java/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -317,7 +317,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } break; case "unselect": - if(player.hasMetadata("selectedPortal")){ + if(player.getMetadata("selectedPortal").size() != 0){ player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e" + player.getMetadata("selectedPortal").get(0).asString() + "\u00A7a."); } @@ -347,7 +347,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); } } else { - if (player.hasMetadata("selectedPortal")) { + if (player.getMetadata("selectedPortal").size() != 0) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); if (posX != null) { @@ -365,7 +365,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { // not finished yet / if (args.length > 1) { - if (player.hasMetadata("selectedPortal")) { + if (player.getMetadata("selectedPortal").size() != 0) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); if (portalName.toLowerCase() != args[1].toLowerCase()) { String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); @@ -392,7 +392,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } break; case "command": - if (player.hasMetadata("selectedPortal")) { + if (player.getMetadata("selectedPortal").size() != 0) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); if (args.length > 1) { // TODO add the command autocompletes, add, remove and show @@ -435,7 +435,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); } } else { - if (player.hasMetadata("selectedPortal")) { + if (player.getMetadata("selectedPortal").size() != 0) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); if (posX != null) { @@ -462,7 +462,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); } } else { - if (player.hasMetadata("selectedPortal")) { + if (player.getMetadata("selectedPortal").size() != 0) { player.sendMessage(PluginMessages.customPrefix + " Your currently selected portal has been shown, it will dissapear shortly!"); Selection.show(player, this.plugin, player.getMetadata("selectedPortal").get(0).asString()); } else if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { diff --git a/src/main/java/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/main/java/com/sekwah/advancedportals/compat/CraftBukkit.java index a2c27756..f5f12c2b 100644 --- a/src/main/java/com/sekwah/advancedportals/compat/CraftBukkit.java +++ b/src/main/java/com/sekwah/advancedportals/compat/CraftBukkit.java @@ -30,8 +30,6 @@ public class CraftBukkit { private Field playerConnection; private Method sendPacket; - private boolean useEnumType = false; - // Classes so it doesnt keep fetching them. @@ -48,33 +46,14 @@ public class CraftBukkit { Class chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); // string to packet methods Class chatSerialClass = this.findClass(chatBaseComponent, "ChatSerializer"); - try{ - Class chatMessageTypeClass = Class.forName(minecraftPackage + "ChatMessageType"); + Class chatMessageTypeClass = Class.forName(minecraftPackage + "ChatMessageType"); - this.chatMessageTypeMethod = chatMessageTypeClass.getMethod("a", byte.class); + this.chatMessageTypeMethod = chatMessageTypeClass.getMethod("a", byte.class); - this.chatPacketConstructor = Class.forName(minecraftPackage + "PacketPlayOutChat").getConstructor(chatBaseComponent, chatMessageTypeClass); + this.chatPacketConstructor = Class.forName(minecraftPackage + "PacketPlayOutChat").getConstructor(chatBaseComponent, chatMessageTypeClass); - useEnumType = true; - } - catch(ClassNotFoundException e) { - plugin.getLogger().info("Old version detected, changing chat method"); - this.chatPacketConstructor = Class.forName(minecraftPackage + "PacketPlayOutChat").getConstructor(chatBaseComponent, byte.class); - } - if(chatSerialClass != null){ - this.serializeMessage = chatSerialClass.getMethod("a", String.class); - } - else{ - 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.serializeMessage = chatSerialClass.getMethod("a", String.class); this.playerGetHandle = Class.forName(craftBukkitPackage + "entity.CraftPlayer").getMethod("getHandle"); this.playerConnection = Class.forName(minecraftPackage + "EntityPlayer").getField("playerConnection"); // get player connection @@ -100,25 +79,13 @@ public class CraftBukkit { } public void sendActionBarMessage(String rawMessage, Player player) { - this.sendMessage(rawMessage,player, (byte) 2); + this.sendMessage("{\"text\":\"" + rawMessage + "\"}",player, (byte) 2); } public void sendMessage(String rawMessage, Player player, byte msgType) { try { - Object comp; - if(this.reallyOldChatConstructor != null) { - comp = this.reallyOldChatConstructor.newInstance(rawMessage,new Object[]{}); - } - else { - comp = this.serializeMessage.invoke(null,"{\"text\":\"" + rawMessage + "\"}"); - } - Object packet; - if(this.useEnumType){ - packet = this.chatPacketConstructor.newInstance(comp, this.chatMessageTypeMethod.invoke(null,msgType)); // convert bytes into packet - } - else{ - packet = this.chatPacketConstructor.newInstance(comp, msgType); // convert bytes into packet - } + Object comp = this.serializeMessage.invoke(null, rawMessage); + Object packet = this.chatPacketConstructor.newInstance(comp, this.chatMessageTypeMethod.invoke(null,msgType)); // convert bytes into packet Object handle = this.playerGetHandle.invoke(player); Object playerConnection = this.playerConnection.get(handle); // get players connection @@ -127,11 +94,6 @@ public class CraftBukkit { this.plugin.getLogger().warning("Error creating raw message, something must be wrong with reflection"); e.printStackTrace(); } - - /*IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/ } diff --git a/src/main/java/com/sekwah/advancedportals/portals/Portal.java b/src/main/java/com/sekwah/advancedportals/portals/Portal.java index f5b36a13..0fe6fba4 100644 --- a/src/main/java/com/sekwah/advancedportals/portals/Portal.java +++ b/src/main/java/com/sekwah/advancedportals/portals/Portal.java @@ -186,7 +186,7 @@ public class Portal { portalData.getConfig().set(name + ".world", pos1.getWorld().getName()); - portalData.getConfig().set(name + ".triggerblock", checkMaterial(triggerBlock)); + portalData.getConfig().set(name + ".triggerblock", triggerBlock.toString()); portalData.getConfig().set(name + ".destination", destination); @@ -264,15 +264,6 @@ public class Portal { return false; } - private static String checkMaterial(Material triggerBlock) { - if (triggerBlock.equals(Material.WATER)) { - return "STATIONARY_WATER"; - } else if (triggerBlock.equals(Material.LAVA)) { - return "STATIONARY_LAVA"; - } - return triggerBlock.toString(); - } - @SuppressWarnings("deprecation") public static String create(Location pos1, Location pos2, String name, String destination, String serverName, PortalArg... extraData) { // add stuff for destination names or coordinates ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); @@ -535,9 +526,7 @@ public class Portal { } public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) { - if (portal.getTrigger().equals(loc.getBlock().getType())) - return locationInPortal(portal, loc, 0); - return false; + return portal.getTrigger().equals(loc.getBlock().getType()) && locationInPortal(portal, loc, 0); } public static boolean inPortalRegion(Location loc, int additionalArea) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1b4decf2..8493a97c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: com.sekwah.advancedportals.AdvancedPortalsPlugin name: AdvancedPortals -version: 0.0.42 +version: 0.0.43 author: sekwah41 description: An advanced portals plugin for bukkit. api-version: 1.13