From db76bc6ef2acd2529ff7049c96b6a73b6d0723ee Mon Sep 17 00:00:00 2001 From: Max Qian Date: Mon, 1 Aug 2016 18:53:56 -0700 Subject: [PATCH 1/8] Refactor Destinations --- .../AdvancedPortalsPlugin.java | 2 +- .../destinations/Destination.java | 71 +++++-------------- .../DestinationCommand.java | 53 +++++--------- .../{ => destinations}/WarpCommand.java | 27 ++----- .../advancedportals/listeners/Listeners.java | 14 +--- .../advancedportals/portals/Portal.java | 4 -- 6 files changed, 45 insertions(+), 126 deletions(-) rename src/com/sekwah/advancedportals/{ => destinations}/DestinationCommand.java (70%) rename src/com/sekwah/advancedportals/{ => destinations}/WarpCommand.java (52%) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index b80110b..bb9d4b7 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -2,7 +2,7 @@ package com.sekwah.advancedportals; import com.sekwah.advancedportals.DataCollector.DataCollector; import com.sekwah.advancedportals.compat.bukkit.NMS; -import com.sekwah.advancedportals.destinations.Destination; +import com.sekwah.advancedportals.destinations.*; import com.sekwah.advancedportals.effects.WarpEffects; import com.sekwah.advancedportals.listeners.*; import com.sekwah.advancedportals.metrics.Metrics; diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 0aec1a7..43b4dac 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -24,12 +24,14 @@ public class Destination { private static AdvancedPortalsPlugin plugin; private static boolean TeleportRiding = false; + public static int PortalMessagesDisplay = 0; public Destination(AdvancedPortalsPlugin plugin) { Destination.plugin = plugin; ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); TeleportRiding = config.getConfig().getBoolean("WarpRiddenEntity"); + PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); } // TODO add permissions for destinations. @@ -104,7 +106,7 @@ public class Destination { config.saveConfig(); } - public static boolean warp(Player player, String name, boolean senderror) { + public static boolean warp(Player player, String name) { ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if (config.getConfig().getString(name + ".world") != null) { Location loc = player.getLocation(); @@ -137,63 +139,28 @@ public class Destination { WarpEffects.activateParticles(player); WarpEffects.activateSound(player); + if (PortalMessagesDisplay == 1) { + player.sendMessage(""); + player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."); + player.sendMessage(""); + } else if (PortalMessagesDisplay == 2) { + plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\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);*/ + } return true; } else { - if (senderror) { - player.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!"); - plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world " - + config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!"); - } - return false; + player.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!"); + plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world " + + config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!"); } } else { - if (senderror) { - player.sendMessage(plugin.customPrefixFail + "\u00A7c There has been a problem warping you to the selected destination!"); - plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp " - + "attempt and either the data is corrupt or that destination doesn't exist!"); - } - return false; + player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); + plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp " + + "attempt and either the data is corrupt or that destination doesn't exist!"); } - - } - - /** - * Same as other warp but changes sender to player for you. - * - * @param player the player being warped - * @param name name of the warp - * @return returns if the player has warped - */ - public static boolean warp(Player player, String name) { - return warp(player, name, true); - - } - - /** - * Same as other warp but changes sender to player for you. - * - * @param sender the player being warped - * @param name name of the warp - * @return returns if the player has warped - */ - public static boolean warp(CommandSender sender, String name, boolean senderror) { - Player player = (Player) sender; - return warp(player, name, senderror); - - } - - /** - * Same as other warp but changes sender to player for you. - * - * @param sender the player being warped - * @param name name of the warp - * @return returns if the player has warped - */ - public static boolean warp(CommandSender sender, String name) { - Player player = (Player) sender; - return warp(player, name, true); - + return false; } public static List destiList() { diff --git a/src/com/sekwah/advancedportals/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java similarity index 70% rename from src/com/sekwah/advancedportals/DestinationCommand.java rename to src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 22e7253..e9199cb 100644 --- a/src/com/sekwah/advancedportals/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -1,6 +1,8 @@ -package com.sekwah.advancedportals; +package com.sekwah.advancedportals.destinations; -import com.sekwah.advancedportals.destinations.Destination; +import com.sekwah.advancedportals.AdvancedPortalsPlugin; +import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -14,30 +16,22 @@ import java.util.List; public class DestinationCommand implements CommandExecutor, TabCompleter { - public static int PortalMessagesDisplay = 0; - private AdvancedPortalsPlugin plugin; public DestinationCommand(AdvancedPortalsPlugin plugin) { this.plugin = plugin; plugin.getCommand("destination").setExecutor(this); - - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - - PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); - - } @Override public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { - if (args.length > 0) { - if (args[0].toLowerCase().equals("create")) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + if (args.length > 0) { switch (args[0].toLowerCase()) { + case "create": if (sender.hasPermission("advancedportals.desti.create")) { if (args.length > 1) { - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); if (posX == null) { sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!"); @@ -52,7 +46,8 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } else { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); } - } else if (args[0].toLowerCase().equals("remove")) { + break; + case "remove": ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml"); if (args.length > 1) { String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); @@ -65,29 +60,16 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } else { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to remove."); } - } else if (args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("warp")) { + break; + case "goto": + case "warp": if (args.length > 1) { - //System.out.println(args[1]); - ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml"); - if (configDesti.getConfig().getString(args[1] + ".world") != null) { - Destination.warp(sender, args[1]); - if (PortalMessagesDisplay == 1) { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a."); - sender.sendMessage(""); - } else if (PortalMessagesDisplay == 2) { - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); - /**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);*/ - } - } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); - } + Destination.warp((Player) sender, args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to exemptPlayer to."); + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to warp to."); } - } else if (args[0].toLowerCase().equals("list")) { + break; + case "list": List destiList = Destination.destiList(); if (destiList.size() >= 1) { if (args.length > 1) { @@ -128,9 +110,10 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } else { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations."); } + break; } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + ", if you do not know what you can put or would like some help with the commands please type /" + command + " help"); + PluginMessages.UnknownCommand(sender, command); } return true; } diff --git a/src/com/sekwah/advancedportals/WarpCommand.java b/src/com/sekwah/advancedportals/destinations/WarpCommand.java similarity index 52% rename from src/com/sekwah/advancedportals/WarpCommand.java rename to src/com/sekwah/advancedportals/destinations/WarpCommand.java index 6823a76..77a6e03 100644 --- a/src/com/sekwah/advancedportals/WarpCommand.java +++ b/src/com/sekwah/advancedportals/destinations/WarpCommand.java @@ -1,6 +1,8 @@ -package com.sekwah.advancedportals; +package com.sekwah.advancedportals.destinations; -import com.sekwah.advancedportals.destinations.Destination; +import com.sekwah.advancedportals.AdvancedPortalsPlugin; +import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -29,26 +31,9 @@ public class WarpCommand implements CommandExecutor, TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { if (args.length > 0) { - if (Destination.warp(sender, args[0], false)) { - if (DestinationCommand.PortalMessagesDisplay == 1) { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a."); - sender.sendMessage(""); - } else if (DestinationCommand.PortalMessagesDisplay == 2) { - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); - /**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);*/ - } - } else { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you tried to warp to does not exist!"); - sender.sendMessage(""); - } + Destination.warp((Player) sender, args[0]); } else { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7c You need to type a destination after /" + command + "!"); - sender.sendMessage(""); + PluginMessages.UnknownCommand(sender, command); } return true; } diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 564485e..a0dc58b 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -86,19 +86,7 @@ public class Listeners implements Listener { WarpEvent warpEvent = new WarpEvent(player, portal); plugin.getServer().getPluginManager().callEvent(warpEvent); if (portal.inPortal.contains(player)) return; - if (!event.isCancelled()) { - boolean warped = Portal.activate(player, portal); - if (PortalMessagesDisplay == 1 && warped) { - player.sendMessage(""); - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7."); - player.sendMessage(""); - } else if (PortalMessagesDisplay == 2 && warped) { - ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") - + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } - } + if (!event.isCancelled()) Portal.activate(player, portal); if (portal.trigger.equals(Material.PORTAL)) { if (player.getGameMode().equals(GameMode.CREATIVE)) { player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 942a3a4..e60d203 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -439,10 +439,6 @@ public class Portal { if (configDesti.getConfig().getString(portal.destiation + ".world") != null) { boolean warped = Destination.warp(player, portal.destiation); return warped; - } else { - player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); - plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp " - + "attempt and either the data is corrupt or that destination listed doesn't exist!"); } } else { if (showFailMessage) { From 75d5fef5b08e0139261b13368e29b8907597d694 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Mon, 1 Aug 2016 20:51:16 -0700 Subject: [PATCH 2/8] Everything should be using customPrefixes now --- .../AdvancedPortalsCommand.java | 86 +++++++++---------- .../AdvancedPortalsPlugin.java | 15 +--- .../advancedportals/PluginMessages.java | 18 +++- .../destinations/Destination.java | 7 +- .../destinations/DestinationCommand.java | 24 +++--- .../advancedportals/listeners/Listeners.java | 5 +- .../advancedportals/portals/Portal.java | 7 +- 7 files changed, 83 insertions(+), 79 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 9c39f46..bbcf3f7 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -63,7 +63,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { regionselector.setItemMeta(selectorname); inventory.addItem(regionselector); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Region Selector\u00A7a!"); + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); break; case "portal": case "portalblock": @@ -71,7 +71,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { inventory.addItem(portalBlock); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Block\u00A7a!"); + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); break; case "create": if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { @@ -98,7 +98,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { hasName = true; portalName = args[i].replaceFirst("name:", ""); } else if (args[i].toLowerCase().startsWith("name:")) { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that isnt nothing!"); + player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that isnt nothing!"); return true; } else if (args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12) { hasDestination = true; @@ -128,7 +128,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } } if (!hasName) { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that you are creating in the variables!"); + player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that you are creating in the variables!"); return true; } @@ -142,7 +142,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (!Portal.portalExists(portalName)) { player.sendMessage(""); - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a]\u00A7e You have created a new portal with the following details:"); + player.sendMessage(PluginMessages.customPrefix + "\u00A7e You have created a new portal with the following details:"); player.sendMessage("\u00A7aname: \u00A7e" + portalName); if (hasDestination) { player.sendMessage("\u00A7adestination: \u00A7e" + destination); @@ -192,25 +192,25 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] A portal by that name already exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " A portal by that name already exists!"); } // add code to save the portal to the portal config and reload the portals player.sendMessage(""); } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c" + player.sendMessage(PluginMessages.customPrefixFail + " You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c" + " for a full list of currently available variables and an example command!"); } } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The points you have selected need to be in the same world!"); + player.sendMessage(PluginMessages.customPrefixFail + " The points you have selected need to be in the same world!"); } } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have two points selected to make a portal!"); + player.sendMessage(PluginMessages.customPrefixFail + " You need to have two points selected to make a portal!"); } break; case "variables" : - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Currently available variables: name, triggerBlock, destination"); + sender.sendMessage(PluginMessages.customPrefix + " Currently available variables: name, triggerBlock, destination"); sender.sendMessage(""); sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); break; @@ -221,23 +221,23 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (Portal.portalExists(args[1])) { player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!"); + player.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!"); } } else { - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Hit a block inside the portal region to select the portal!"); + player.sendMessage(PluginMessages.customPrefix + " Hit a block inside the portal region to select the portal!"); player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true)); } } else { player.removeMetadata("selectingPortal", plugin); - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Portal selection cancelled!"); + player.sendMessage(PluginMessages.customPrefixFail + " Portal selection cancelled!"); } break; case "gui" : if (args.length > 1) { if (args[1].toLowerCase().equals("remove") && args.length > 2) { sender.sendMessage(""); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); + sender.sendMessage(PluginMessages.customPrefixFail + " Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); sender.sendMessage(""); plugin.nmsAccess.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " + args[2] + "\"}}]}", player); @@ -251,7 +251,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); portalEditMenu(sender, portalConfig, args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); } } else { if (player.hasMetadata("selectedPortal")) { @@ -260,11 +260,11 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (posX != null) { portalEditMenu(sender, portalConfig, portalName); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); player.removeMetadata("selectedPortal", plugin); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } } break; @@ -280,22 +280,22 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); if (posX != null && newPortalPosX == null) { Portal.rename(portalName, args[1]); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] The portal \u00A7e" + portalName + "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a."); + sender.sendMessage(PluginMessages.customPrefix + " The portal \u00A7e" + portalName + "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a."); player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); } else if (newPortalPosX != null) { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There is already a portal with the name \u00A7e" + args[1] + "\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " There is already a portal with the name \u00A7e" + args[1] + "\u00A7c!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); player.removeMetadata("selectedPortal", plugin); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you have selected is already called that!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you have selected is already called that!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); } break; case "command": @@ -310,13 +310,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { portalCommand += args[i]; } if (Portal.addCommand(portalName, portalCommand)) { - sender.sendMessage("\u00A77a[\u00A77eAdvancedPortals\u00A77a] Command added to portal!"); + sender.sendMessage(PluginMessages.customPrefixFail + " Command added to portal!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Failed to add command to portal!"); + sender.sendMessage(PluginMessages.customPrefixFail + " Failed to add command to portal!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must actually specify a command to execute!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You must actually specify a command to execute!"); } } else if (args[1].toLowerCase().equals("remove")) { @@ -324,10 +324,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } else if (args[1].toLowerCase().equals("show")) { // Show all the commands the portal executes } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); } } else { @@ -338,9 +338,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); if (posX != null) { Portal.remove(args[1]); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal \u00A7e" + args[1] + "\u00A7c has been removed!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A7e" + args[1] + "\u00A7c has been removed!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); } } else { if (player.hasMetadata("selectedPortal")) { @@ -348,23 +348,23 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); if (posX != null) { Portal.remove(portalName); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal \u00A77" + portalName + "\u00A7c has been removed!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A77" + portalName + "\u00A7c has been removed!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); player.removeMetadata("selectedPortal", plugin); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } } break; case "help": case "helppage": - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Still designing in game help page :("); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] For now please use the wiki http://bit.ly/portals-help"); + sender.sendMessage(PluginMessages.customPrefix + " Still designing in game help page :("); + sender.sendMessage(PluginMessages.customPrefix + " For now please use the wiki http://bit.ly/portals-help"); break; case "bukkitpage": - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Bukkit page: http://bit.ly/adv-portals!"); + sender.sendMessage(PluginMessages.customPrefix + " Bukkit page: http://bit.ly/adv-portals!"); break; case "show": if (args.length > 1) { @@ -372,29 +372,29 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (posX != null) { Selection.Show(player, this.plugin, args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); } } else { if (player.hasMetadata("selectedPortal")) { - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected portal has been shown, it will dissapear shortly!"); + 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")) { if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) { - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected area has been shown, it will dissapear shortly!"); + player.sendMessage(PluginMessages.customPrefix + " Your currently selected area has been shown, it will dissapear shortly!"); Selection.Show(player, this.plugin, null); } } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No regions selected!"); + player.sendMessage(PluginMessages.customPrefixFail + " No regions selected!"); } } break; case "reload": - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!"); + sender.sendMessage(PluginMessages.customPrefix + " Reloaded values!"); Listeners.reloadValues(plugin); Portal.loadPortals(); break; case "list" : - String message = "\u00A7eAdvancedPortals\u00A7a :"; + String message = PluginMessages.customPrefix + " \u00A7c:\u00A7a"; for (AdvancedPortal portal : Portal.Portals) { message = message + " " + portal.portalName; } @@ -444,7 +444,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { // use the usual messages for normal lines but anything that needs special features make sure you use the // chat steriliser sender.sendMessage(""); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Editing: \u00A7e" + portalName); + sender.sendMessage(PluginMessages.customPrefix + " Editing: \u00A7e" + portalName); sender.sendMessage(" \u00A7apos1\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos1.X") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Z")); sender.sendMessage(" \u00A7apos2\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos2.X") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Z")); diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index bb9d4b7..6d582f4 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -16,12 +16,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { public NMS nmsAccess; - public boolean useCustomPrefix = false; - - public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]"; - - public String customPrefixFail = "\u00A7c[\u00A77AdvancedPortals\u00A7c]"; - public void onEnable() { try { @@ -59,6 +53,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { new DataCollector(this); // These register the commands + new PluginMessages(this); new AdvancedPortalsCommand(this); new DestinationCommand(this); new WarpCommand(this); @@ -99,14 +94,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { // thanks to the new config accessor code the config.saveDefaultConfig(); will now // only copy the file if it doesnt exist! - ConfigAccessor config = new ConfigAccessor(this, "config.yml"); - - this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix"); - if (useCustomPrefix) { - this.customPrefix = config.getConfig().getString("CustomPrefix").replaceAll("&", "\u00A7"); - this.customPrefixFail = config.getConfig().getString("CustomPrefixFail").replaceAll("&", "\u00A7"); - } - } diff --git a/src/com/sekwah/advancedportals/PluginMessages.java b/src/com/sekwah/advancedportals/PluginMessages.java index 6c4c317..374fd7c 100644 --- a/src/com/sekwah/advancedportals/PluginMessages.java +++ b/src/com/sekwah/advancedportals/PluginMessages.java @@ -3,17 +3,31 @@ package com.sekwah.advancedportals; import org.bukkit.command.CommandSender; public class PluginMessages { + private AdvancedPortalsPlugin plugin; + public boolean useCustomPrefix = false; + public static String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]"; + public static String customPrefixFail = "\u00A7c[\u00A77AdvancedPortals\u00A7c]"; + + public PluginMessages (AdvancedPortalsPlugin plugin) { + this.plugin = plugin; + ConfigAccessor config = new ConfigAccessor(this.plugin, "config.yml"); + this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix"); + if (useCustomPrefix) { + PluginMessages.customPrefixFail = config.getConfig().getString("CustomPrefix").replaceAll("&", "\u00A7"); + PluginMessages.customPrefixFail = config.getConfig().getString("CustomPrefixFail").replaceAll("&", "\u00A7"); + } + } // This class is so then the common messages in commands or just messages over the commands are the same and can be // easily changed. public static void UnknownCommand(CommandSender sender, String command) { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + "\n"); + sender.sendMessage(customPrefixFail + " You need to type something after /" + command + "\n"); sender.sendMessage("\u00A7cIf you do not know what you can put or would like some help with the commands please type \u00A7e" + '"' + "\u00A7e/" + command + " help" + '"' + "\u00A7c\n"); } public static void NoPermission(CommandSender sender, String command) { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to perform that command!"); + sender.sendMessage(customPrefixFail + " You do not have permission to perform that command!"); } } diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 43b4dac..5c1f901 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -2,6 +2,7 @@ package com.sekwah.advancedportals.destinations; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import com.sekwah.advancedportals.effects.WarpEffects; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -141,7 +142,7 @@ public class Destination { if (PortalMessagesDisplay == 1) { player.sendMessage(""); - player.sendMessage(plugin.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(""); } else if (PortalMessagesDisplay == 2) { plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player); @@ -151,12 +152,12 @@ public class Destination { return true; } else { - player.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!"); + player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!"); plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world " + config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!"); } } else { - player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); + player.sendMessage(PluginMessages.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp " + "attempt and either the data is corrupt or that destination doesn't exist!"); } diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index e9199cb..b3e9af3 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -34,17 +34,17 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { if (args.length > 1) { String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); if (posX == null) { - sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!"); + sender.sendMessage(PluginMessages.customPrefix + " You have created a new destination called \u00A7e" + args[1] + "!"); Player player = sender.getServer().getPlayer(sender.getName()); Destination.create(player.getLocation(), args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] A destination by that name already exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " A destination by that name already exists!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Please state the name of the destination you would like to create!"); + sender.sendMessage(PluginMessages.customPrefixFail + " Please state the name of the destination you would like to create!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); } break; case "remove": @@ -53,12 +53,12 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); if (posX != null) { Destination.remove(args[1]); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); + sender.sendMessage(PluginMessages.customPrefixFail + " No destination by that name exists."); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to remove."); + sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to remove."); } break; case "goto": @@ -66,7 +66,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { if (args.length > 1) { Destination.warp((Player) sender, args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to warp to."); + sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to warp to."); } break; case "list": @@ -80,7 +80,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } } - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); for (int i = (page - 1) * 5; i < page * 5; i++) { if (i > destiList.size()) { break; @@ -92,7 +92,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } } - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); for (int i = 0; i < 5; i++) { if (i > destiList.size()) { break; @@ -100,7 +100,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { sender.sendMessage(" \u00A7e" + destiList.get(i)); } - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); for (int i = 0; i < 5; i++) { if (i > destiList.size()) { break; @@ -108,7 +108,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { sender.sendMessage(" \u00A7e" + destiList.get(i)); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations."); + sender.sendMessage(PluginMessages.customPrefixFail + " There are currently no defined destinations."); } break; } diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index a0dc58b..8a02a3d 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -2,6 +2,7 @@ package com.sekwah.advancedportals.listeners; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import com.sekwah.advancedportals.api.events.WarpEvent; import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; @@ -170,14 +171,14 @@ public class Listeners implements Listener { if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { for (AdvancedPortal portal : Portal.Portals) { if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) { - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have selected: \u00A7e" + portal.portalName); + player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have selected: \u00A7e" + portal.portalName); player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character event.setCancelled(true); player.removeMetadata("selectingPortal", plugin); return; } } - player.sendMessage(plugin.customPrefixFail + "\u00A7c No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); + player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); event.setCancelled(true); return; } diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index e60d203..fef52e0 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import com.sekwah.advancedportals.destinations.Destination; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -368,7 +369,7 @@ public class Portal { /*if((permission == null || (permission != null && player.hasPermission(permission)) || player.isOp())){*/ // 3 checks, 1st is if it doesnt need perms. 2nd is if it does do they have it. And third is are they op. if (!(permission == null || (permission != null && player.hasPermission(permission)) || player.isOp())) { - player.sendMessage(plugin.customPrefix + "\u00A7c You do not have permission to use this portal!"); + player.sendMessage(PluginMessages.customPrefix + "\u00A7c You do not have permission to use this portal!"); return false; } @@ -426,7 +427,7 @@ public class Portal { //plugin.getLogger().info(portal.portalName + ":" + portal.destiation); if (portal.bungee != null) { if (ShowBungeeMessage) { - player.sendMessage(plugin.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a."); + player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a."); } ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); @@ -442,7 +443,7 @@ public class Portal { } } else { if (showFailMessage) { - player.sendMessage(plugin.customPrefix + "\u00A7c The portal you are trying to use doesn't have a destination!"); + player.sendMessage(PluginMessages.customPrefix + "\u00A7c The portal you are trying to use doesn't have a destination!"); plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp " + "attempt and either the data is corrupt or portal doesn't exist!"); } From f5f7464c24f66b76b8f186369c24a8ec1c71cd6d Mon Sep 17 00:00:00 2001 From: Max Qian Date: Mon, 1 Aug 2016 22:28:12 -0700 Subject: [PATCH 3/8] Add desti list --- .../destinations/Destination.java | 17 -------- .../destinations/DestinationCommand.java | 43 ++----------------- 2 files changed, 3 insertions(+), 57 deletions(-) diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 5c1f901..b559b58 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -163,21 +163,4 @@ public class Destination { } return false; } - - public static List destiList() { - - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - - LinkedList destiList = new LinkedList<>(); - - Set destiSet = config.getConfig().getKeys(false); - if (destiSet.size() > 0) { - for (Object desti : destiSet.toArray()) { - destiSet.add(desti.toString()); - } - } - - Collections.sort(destiList); - return destiList; - } } diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index b3e9af3..38f9943 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -70,46 +70,9 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } break; case "list": - List destiList = Destination.destiList(); - if (destiList.size() >= 1) { - if (args.length > 1) { - try { - int page = Integer.parseInt(args[1]); - if (page * 5 >= destiList.size() - 5) { // add this if statement so that the user cant select a list page higher than the max - if (destiList.size() / 5 == destiList.size()) { - - } - } - sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); - for (int i = (page - 1) * 5; i < page * 5; i++) { - if (i > destiList.size()) { - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - return true; - } catch (Exception e) { - } - } - - sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); - for (int i = 0; i < 5; i++) { - if (i > destiList.size()) { - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - - sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); - for (int i = 0; i < 5; i++) { - if (i > destiList.size()) { - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " There are currently no defined destinations."); - } + String message = PluginMessages.customPrefix + " \u00A77Destinations \u00A7c:\u00A7a"; + for (String desti : config.getConfig().getKeys(false)) message = message + " " + desti; + sender.sendMessage(message); break; } } else { From fa9c1bdf9e781829e3ae4cc7a5a979b6ca6b2ce9 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Tue, 2 Aug 2016 15:59:15 -0700 Subject: [PATCH 4/8] Always do portal/lava check on move event --- src/com/sekwah/advancedportals/listeners/Listeners.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 8a02a3d..9b708b9 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -84,10 +84,6 @@ public class Listeners implements Listener { Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ()); for (AdvancedPortal portal : Portal.Portals) { if (Portal.locationInPortalTrigger(portal, loc) | Portal.locationInPortalTrigger(portal, eyeLoc)) { - WarpEvent warpEvent = new WarpEvent(player, portal); - plugin.getServer().getPluginManager().callEvent(warpEvent); - if (portal.inPortal.contains(player)) return; - if (!event.isCancelled()) Portal.activate(player, portal); if (portal.trigger.equals(Material.PORTAL)) { if (player.getGameMode().equals(GameMode.CREATIVE)) { player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); @@ -97,6 +93,10 @@ public class Listeners implements Listener { player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); } + if (portal.inPortal.contains(player)) return; + WarpEvent warpEvent = new WarpEvent(player, portal); + plugin.getServer().getPluginManager().callEvent(warpEvent); + if (!event.isCancelled()) Portal.activate(player, portal); portal.inPortal.add(player); } else portal.inPortal.remove(player); } From 80fcd96ba74ae1fd12ece5974f22e18b8f8a6ddc Mon Sep 17 00:00:00 2001 From: Max Qian Date: Tue, 2 Aug 2016 16:54:15 -0700 Subject: [PATCH 5/8] awarp is now an alias of destination and destination permissions --- Resources/plugin.yml | 17 +++-- .../AdvancedPortalsPlugin.java | 1 - .../destinations/Destination.java | 4 ++ .../destinations/DestinationCommand.java | 43 +++++++------ .../destinations/WarpCommand.java | 63 ------------------- 5 files changed, 34 insertions(+), 94 deletions(-) delete mode 100644 src/com/sekwah/advancedportals/destinations/WarpCommand.java diff --git a/Resources/plugin.yml b/Resources/plugin.yml index 07ea1ea..f3a884c 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -10,10 +10,7 @@ commands: usage: / destination: description: Can be used to access portal destinations. - aliases: [desti] - usage: / - awarp: - description: Used to warp to destinations. + aliases: [desti, awarp] usage: / permissions: advancedportals.*: @@ -22,7 +19,8 @@ permissions: advancedportals.createportal: true advancedportals.portal: true advancedportals.build: true - advancedportals.desti.*: true + advancedportals.desti: true + advancedportals.warp.*: true advancedportals.createportal: description: Allows you to create portals default: op @@ -32,10 +30,9 @@ permissions: advancedportals.build: description: Allows you to build in the portal regions default: op - advancedportals.desti.*: + advancedportals.desti: description: Gives access to all desti commands - children: - advancedportals.desti.create: true - advancedportals.desti.create: - description: Allows users to create portal destinations default: op + advancedportals.warp.*: + description: Access to all warps + default: true diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 6d582f4..dde576a 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -56,7 +56,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { new PluginMessages(this); new AdvancedPortalsCommand(this); new DestinationCommand(this); - new WarpCommand(this); new WarpEffects(this); diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index b559b58..17f6506 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -108,6 +108,10 @@ public class Destination { } public static boolean warp(Player player, String name) { + if (!player.hasPermission("advancedportals.warp.*") && !player.hasPermission("advancedportals.warp." + name)) { + player.sendMessage(PluginMessages.customPrefixFail + " You don't have permission to warp to " + name + "!"); + return false; + } ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if (config.getConfig().getString(name + ".world") != null) { Location loc = player.getLocation(); diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 38f9943..4302e4c 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -30,7 +30,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if (args.length > 0) { switch (args[0].toLowerCase()) { case "create": - if (sender.hasPermission("advancedportals.desti.create")) { + if (sender.hasPermission("advancedportals.desti")) { if (args.length > 1) { String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); if (posX == null) { @@ -44,29 +44,25 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { sender.sendMessage(PluginMessages.customPrefixFail + " Please state the name of the destination you would like to create!"); } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to create destinations!"); } break; case "remove": ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml"); - if (args.length > 1) { - String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); - if (posX != null) { - Destination.remove(args[1]); - sender.sendMessage(PluginMessages.customPrefixFail + " The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); + if (sender.hasPermission("advancedportals.desti")) { + if (args.length > 1) { + String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); + if (posX != null) { + Destination.remove(args[1]); + sender.sendMessage(PluginMessages.customPrefixFail + " The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No destination by that name exists."); + } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No destination by that name exists."); + sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to remove."); } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to remove."); - } - break; - case "goto": - case "warp": - if (args.length > 1) { - Destination.warp((Player) sender, args[1]); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to warp to."); + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to remove destinations!"); } break; case "list": @@ -74,6 +70,9 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { for (String desti : config.getConfig().getKeys(false)) message = message + " " + desti; sender.sendMessage(message); break; + default: + Destination.warp((Player) sender, args[0]); + break; } } else { PluginMessages.UnknownCommand(sender, command); @@ -85,10 +84,14 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { @Override public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { LinkedList autoComplete = new LinkedList(); - - if (sender.hasPermission("AdvancedPortals.CreatePortal")) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + for (String string : config.getConfig().getKeys(false)) { + if (sender.hasPermission("advancedportals.desti.*") | sender.hasPermission("advancedportals.desti." + string)) + autoComplete.add(string); + } + if (sender.hasPermission("advancedportals.desti") | sender.hasPermission("AdvancedPortals.CreatePortal")) { if (args.length == 1) { - autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove")); + autoComplete.addAll(Arrays.asList("create", "remove", "help")); } else if (args[0].toLowerCase().equals("create")) { } } diff --git a/src/com/sekwah/advancedportals/destinations/WarpCommand.java b/src/com/sekwah/advancedportals/destinations/WarpCommand.java deleted file mode 100644 index 77a6e03..0000000 --- a/src/com/sekwah/advancedportals/destinations/WarpCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.sekwah.advancedportals.destinations; - -import com.sekwah.advancedportals.AdvancedPortalsPlugin; -import com.sekwah.advancedportals.ConfigAccessor; -import com.sekwah.advancedportals.PluginMessages; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - -import java.util.LinkedList; -import java.util.List; - -public class WarpCommand implements CommandExecutor, TabCompleter { - - @SuppressWarnings("unused") - private AdvancedPortalsPlugin plugin; - - public WarpCommand(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; - - - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - boolean useWarpCommand = !config.getConfig().getBoolean("DisableWarpCommand"); - //plugin.getCommand("warp").setExecutor(this); - plugin.getCommand("awarp").setExecutor(this); - } - - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { - if (args.length > 0) { - Destination.warp((Player) sender, args[0]); - } else { - PluginMessages.UnknownCommand(sender, command); - } - return true; - } - - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { - LinkedList autoComplete = new LinkedList(); - - /**if(sender.hasPermission("AdvancedPortals.CreatePortal")){ - if(args.length == 1){ - autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove")); - } - else if(args[0].toLowerCase().equals("create")){ - } - } - Collections.sort(autoComplete); - for(Object result: autoComplete.toArray()){ - if(!result.toString().startsWith(args[args.length - 1])){ - autoComplete.remove(result); - } - }*/ - return autoComplete; - } - - -} From e4d187be5278482dbd082da24e03ee9044d70ecd Mon Sep 17 00:00:00 2001 From: Alastair Date: Tue, 2 Aug 2016 22:47:26 +0000 Subject: [PATCH 6/8] Removed craftbukkit folder and started remaking the compatability file --- .../AdvancedPortalsCommand.java | 4 +- .../AdvancedPortalsPlugin.java | 87 +++++++++---------- .../advancedportals/compat/CraftBukkit.java | 69 +++++++++++++++ .../advancedportals/compat/bukkit/NMS.java | 10 --- .../compat/bukkit/v1_10_R1.java | 27 ------ .../compat/bukkit/v1_8_R1.java | 28 ------ .../compat/bukkit/v1_8_R2.java | 27 ------ .../compat/bukkit/v1_8_R3.java | 27 ------ .../compat/bukkit/v1_9_R1.java | 27 ------ .../compat/bukkit/v1_9_R2.java | 27 ------ .../destinations/Destination.java | 2 +- 11 files changed, 114 insertions(+), 221 deletions(-) create mode 100644 src/com/sekwah/advancedportals/compat/CraftBukkit.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/NMS.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index bbcf3f7..32b494d 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -239,7 +239,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage(""); sender.sendMessage(PluginMessages.customPrefixFail + " Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); sender.sendMessage(""); - plugin.nmsAccess.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + + plugin.compat.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " + args[2] + "\"}}]}", player); sender.sendMessage(""); } @@ -482,7 +482,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { Player player = (Player) sender; - plugin.nmsAccess.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \",\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal gui remove " + portalName + "\"}}" + plugin.compat.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \",\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal gui remove " + portalName + "\"}}" + ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal show " + portalName + "\"}}" + ",{\"text\":\" \"},{\"text\":\"\u00A7eRename\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Change the name of the portal\"},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/portal rename \"}}" + ",{\"text\":\" \"},{\"text\":\"\u00A7eActivate\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(same as entering the portal)\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/warp " + destination + "\"}}]}", player); diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index dde576a..a16705f 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -1,7 +1,7 @@ package com.sekwah.advancedportals; import com.sekwah.advancedportals.DataCollector.DataCollector; -import com.sekwah.advancedportals.compat.bukkit.NMS; +import com.sekwah.advancedportals.compat.CraftBukkit; import com.sekwah.advancedportals.destinations.*; import com.sekwah.advancedportals.effects.WarpEffects; import com.sekwah.advancedportals.listeners.*; @@ -10,11 +10,10 @@ import com.sekwah.advancedportals.portals.Portal; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; public class AdvancedPortalsPlugin extends JavaPlugin { - public NMS nmsAccess; + public CraftBukkit compat = null; public void onEnable() { @@ -30,63 +29,61 @@ public class AdvancedPortalsPlugin extends JavaPlugin { String version = packageSplit[packageSplit.length - 1]; try { - Class nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version); - if (NMS.class.isAssignableFrom(nmsClass)) { - this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance(); + + this.compat = new CraftBukkit(version); + + ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); + portalConfig.saveDefaultConfig(); + + ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); + destinationConfig.saveDefaultConfig(); + + new Assets(this); + + // Opens a channel that messages bungeeCord + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + + // Loads the portal and destination editors + new Portal(this); + new Destination(this); + + new DataCollector(this); - ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); - portalConfig.saveDefaultConfig(); + // These register the commands + new PluginMessages(this); + new AdvancedPortalsCommand(this); + new DestinationCommand(this); - ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); - destinationConfig.saveDefaultConfig(); - - new Assets(this); - - // Opens a channel that messages bungeeCord - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - - // Loads the portal and destination editors - new Portal(this); - new Destination(this); - - new DataCollector(this); - - // These register the commands - new PluginMessages(this); - new AdvancedPortalsCommand(this); - new DestinationCommand(this); - - new WarpEffects(this); + new WarpEffects(this); - // These register the listeners - new Listeners(this); + // These register the listeners + new Listeners(this); - new FlowStopper(this); - new PortalProtect(this); - new PortalPlacer(this); + new FlowStopper(this); + new PortalProtect(this); + new PortalPlacer(this); - Selection.LoadData(this); + Selection.LoadData(this); - DataCollector.setupMetrics(); + DataCollector.setupMetrics(); - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); - this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); + this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); - } else { - this.getLogger().warning("Something went wrong, please notify the author and tell them this version v:" + version); - this.setEnabled(false); - } } catch (ClassNotFoundException e) { - this.getLogger().warning("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version); + this.getLogger().warning("This version of craftbukkit is not yet supported, please notify sekwah and tell him about this version v:" + version); this.setEnabled(false); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | - NoSuchMethodException | SecurityException e) { + } catch (IllegalArgumentException | + NoSuchFieldException | SecurityException e) { e.printStackTrace(); + this.getLogger().warning("Something went wrong, please notify sekwah and tell him about this version v:" + version); + this.getLogger().warning("Along with the above stacktrace"); + this.setEnabled(false); } saveDefaultConfig(); diff --git a/src/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/com/sekwah/advancedportals/compat/CraftBukkit.java new file mode 100644 index 0000000..481b464 --- /dev/null +++ b/src/com/sekwah/advancedportals/compat/CraftBukkit.java @@ -0,0 +1,69 @@ +package com.sekwah.advancedportals.compat; + +import org.bukkit.entity.Player; + +import java.lang.reflect.Field; + +/** + * Created by on 02/08/2016. + * + * I don't think there will be any others supported other than bukkit but if there are its not just the compat that will + * need to change. + * + * @author sekwah41 + */ +public class CraftBukkit { + + private final String craftBukkitVer; + + private final String craftBukkitPackage; + + private final String minecraftPackage; + + + // Classes so it doesnt keep fetching them. + private Class chatBaseComponent; + private Class chatSerializer; + + public CraftBukkit(String craftBukkitVer) throws ClassNotFoundException, NoSuchFieldException { + this.craftBukkitVer = craftBukkitVer; + this.craftBukkitPackage = "org.bukkit.craftbukkit." + craftBukkitVer; + this.minecraftPackage = "net.minecraft.server." + craftBukkitVer; + + + this.setupCompat(); + } + + private void setupCompat() throws ClassNotFoundException, NoSuchFieldException { + this.chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); + Field modfield = chatBaseComponent.getDeclaredField("modifiers"); + chatBaseComponent.getDeclaredClasses(); + + } + + // Convert to reflection + public void sendRawMessage(String rawMessage, Player player) { + + try { + + Class nmsClass = Class.forName(minecraftPackage + "IChatBaseComponent"); + + } catch (ClassNotFoundException e) { + 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);*/ + } + + public void sendActionBarMessage(String rawMessage, Player player) { + /*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) 2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/ + } + + +} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/NMS.java b/src/com/sekwah/advancedportals/compat/bukkit/NMS.java deleted file mode 100644 index b0eedfe..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/NMS.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import org.bukkit.entity.Player; - -public interface NMS { - - void sendRawMessage(String rawMessage, Player player); - - void sendActionBarMessage(String rawMessage, Player player); -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java deleted file mode 100644 index 9df7f3e..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_10_R1.IChatBaseComponent; -import net.minecraft.server.v1_10_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_10_R1 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - 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); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - 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) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java deleted file mode 100644 index aa9809e..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_8_R1.ChatSerializer; -import net.minecraft.server.v1_8_R1.IChatBaseComponent; -import net.minecraft.server.v1_8_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_8_R1 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = 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); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = 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) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java deleted file mode 100644 index 46e477f..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_8_R2.IChatBaseComponent; -import net.minecraft.server.v1_8_R2.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_8_R2 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - 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); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - 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) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java deleted file mode 100644 index ca75728..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_8_R3.IChatBaseComponent; -import net.minecraft.server.v1_8_R3.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_8_R3 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - 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); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - 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) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java deleted file mode 100644 index f9614c0..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_9_R1.IChatBaseComponent; -import net.minecraft.server.v1_9_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_9_R1 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - 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); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - 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) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java deleted file mode 100644 index 2e4b573..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_9_R2.IChatBaseComponent; -import net.minecraft.server.v1_9_R2.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_9_R2 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - 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); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - 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) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 17f6506..2d3bdfb 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -149,7 +149,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.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player); + plugin.compat.sendActionBarMessage("{\"text\":\"\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);*/ } From 62037634bc9dac48d70180225012a443969bdb45 Mon Sep 17 00:00:00 2001 From: Alastair Date: Wed, 3 Aug 2016 03:30:59 +0000 Subject: [PATCH 7/8] Removed dependency on craftbukkit by using reflection. (Took a while to learn and sort out :P but should be useful for the future anyway so its time well spent :D) --- pom.xml | 7 +- .../AdvancedPortalsPlugin.java | 4 +- .../advancedportals/compat/CraftBukkit.java | 81 ++++++++++++++----- 3 files changed, 68 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index c2dc481..0676248 100644 --- a/pom.xml +++ b/pom.xml @@ -29,12 +29,13 @@ 1.10.2-R0.1-SNAPSHOT provided - - + + + \ No newline at end of file diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index a16705f..ce88875 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -30,7 +30,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { try { - this.compat = new CraftBukkit(version); + this.compat = new CraftBukkit(this, version); ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); portalConfig.saveDefaultConfig(); @@ -79,7 +79,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { this.getLogger().warning("This version of craftbukkit is not yet supported, please notify sekwah and tell him about this version v:" + version); this.setEnabled(false); } catch (IllegalArgumentException | - NoSuchFieldException | SecurityException e) { + NoSuchFieldException | SecurityException | NoSuchMethodException e) { e.printStackTrace(); this.getLogger().warning("Something went wrong, please notify sekwah and tell him about this version v:" + version); this.getLogger().warning("Along with the above stacktrace"); diff --git a/src/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/com/sekwah/advancedportals/compat/CraftBukkit.java index 481b464..a6cfa20 100644 --- a/src/com/sekwah/advancedportals/compat/CraftBukkit.java +++ b/src/com/sekwah/advancedportals/compat/CraftBukkit.java @@ -1,8 +1,12 @@ package com.sekwah.advancedportals.compat; +import com.sekwah.advancedportals.AdvancedPortalsPlugin; import org.bukkit.entity.Player; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; /** * Created by on 02/08/2016. @@ -14,41 +18,77 @@ import java.lang.reflect.Field; */ public class CraftBukkit { - private final String craftBukkitVer; - private final String craftBukkitPackage; private final String minecraftPackage; + private final AdvancedPortalsPlugin plugin; + + private Method chatMessageMethod; + + private Class craftPlayer; + + private Class chatPacket; + + private Class chatBaseComponent; + + private Class packet; + // Classes so it doesnt keep fetching them. - private Class chatBaseComponent; - private Class chatSerializer; - public CraftBukkit(String craftBukkitVer) throws ClassNotFoundException, NoSuchFieldException { - this.craftBukkitVer = craftBukkitVer; - this.craftBukkitPackage = "org.bukkit.craftbukkit." + craftBukkitVer; - this.minecraftPackage = "net.minecraft.server." + craftBukkitVer; + public CraftBukkit(AdvancedPortalsPlugin plugin, String craftBukkitVer) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException { + this.craftBukkitPackage = "org.bukkit.craftbukkit." + craftBukkitVer + "."; + + this.minecraftPackage = "net.minecraft.server." + craftBukkitVer + "."; + + this.plugin = plugin; this.setupCompat(); } - private void setupCompat() throws ClassNotFoundException, NoSuchFieldException { + private void setupCompat() throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException { + + this.craftPlayer = Class.forName(craftBukkitPackage + "entity.CraftPlayer"); + this.chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); - Field modfield = chatBaseComponent.getDeclaredField("modifiers"); - chatBaseComponent.getDeclaredClasses(); + + this.chatMessageMethod = this.findClass(chatBaseComponent, "ChatSerializer").getMethod("a", String.class); + + this.chatPacket = Class.forName(minecraftPackage + "PacketPlayOutChat"); + + this.packet = Class.forName(minecraftPackage + "Packet"); } - // Convert to reflection public void sendRawMessage(String rawMessage, Player player) { + this.sendMessage(rawMessage,player, (byte) 1); + } + public void sendActionBarMessage(String rawMessage, Player player) { + this.sendMessage(rawMessage,player, (byte) 2); + } + + public void sendMessage(String rawMessage, Player player, byte msgType) { try { + Object comp = this.chatMessageMethod.invoke(null,rawMessage); - Class nmsClass = Class.forName(minecraftPackage + "IChatBaseComponent"); + Object handle = this.craftPlayer.getMethod("getHandle").invoke(player); - } catch (ClassNotFoundException e) { + Field playerConnectionObj = handle.getClass().getDeclaredField("playerConnection"); + + Constructor packetConstructor = this.chatPacket.getConstructor(this.chatBaseComponent, byte.class); + + Object packet = packetConstructor.newInstance(comp, msgType); + + Object playerConnection = playerConnectionObj.get(handle); + + playerConnection.getClass().getMethod("sendPacket", this.packet).invoke(playerConnection, packet); + + } catch (IllegalAccessException |InvocationTargetException | NoSuchMethodException | NoSuchFieldException + | InstantiationException e) { + this.plugin.getLogger().warning("Error creating raw message, something must be wrong with reflection"); e.printStackTrace(); } @@ -58,11 +98,14 @@ public class CraftBukkit { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/ } - public void sendActionBarMessage(String rawMessage, Player player) { - /*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) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/ + + public Class findClass(Class classObj, String className){ + for(Class classes : classObj.getDeclaredClasses()){ + if(classes.getSimpleName().equals(className)){ + return classes; + } + } + return null; } From 109cd04034d09dd123180fac09bb42683f655f4d Mon Sep 17 00:00:00 2001 From: Max Qian Date: Tue, 2 Aug 2016 20:31:16 -0700 Subject: [PATCH 8/8] Add Help Messages --- .../advancedportals/AdvancedPortalsCommand.java | 15 +++++++++------ .../sekwah/advancedportals/PluginMessages.java | 1 - .../destinations/DestinationCommand.java | 9 +++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 32b494d..80699b6 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -359,12 +359,15 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } break; case "help": - case "helppage": - sender.sendMessage(PluginMessages.customPrefix + " Still designing in game help page :("); - sender.sendMessage(PluginMessages.customPrefix + " For now please use the wiki http://bit.ly/portals-help"); - break; - case "bukkitpage": - sender.sendMessage(PluginMessages.customPrefix + " Bukkit page: http://bit.ly/adv-portals!"); + sender.sendMessage(PluginMessages.customPrefix + " Help Menu"); + sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); + sender.sendMessage("\u00A76/" + command + " selector \u00A7a- gives you a region selector"); + sender.sendMessage("\u00A76/" + command + " create \u00A7c[tags] \u00A7a- creates a portal with a selection "); + sender.sendMessage("\u00A76/" + command + " portal \u00A7a- gives you a portal block"); + sender.sendMessage("\u00A76/" + command + " select \u00A7a- selects an existing portal"); + sender.sendMessage("\u00A76/" + command + " remove \u00A7a- removes a portal"); + sender.sendMessage("\u00A76/" + command + " variables \u00A7a- lists all available tags"); + sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); break; case "show": if (args.length > 1) { diff --git a/src/com/sekwah/advancedportals/PluginMessages.java b/src/com/sekwah/advancedportals/PluginMessages.java index 374fd7c..def3a7b 100644 --- a/src/com/sekwah/advancedportals/PluginMessages.java +++ b/src/com/sekwah/advancedportals/PluginMessages.java @@ -29,5 +29,4 @@ public class PluginMessages { public static void NoPermission(CommandSender sender, String command) { sender.sendMessage(customPrefixFail + " You do not have permission to perform that command!"); } - } diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 4302e4c..53f0e49 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -70,6 +70,15 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { for (String desti : config.getConfig().getKeys(false)) message = message + " " + desti; sender.sendMessage(message); break; + case "help": + sender.sendMessage(PluginMessages.customPrefix + " Destination Help Menu"); + sender.sendMessage("\u00A7e\u00A7m----------------------------"); + sender.sendMessage("\u00A76/" + command + " \u00A7c[name] \u00A7a- teleport to destination"); + sender.sendMessage("\u00A76/" + command + " create \u00A7c[name] \u00A7a- create destination at your location"); + sender.sendMessage("\u00A76/" + command + " remove \u00A7c[name] \u00A7a- remove destination"); + sender.sendMessage("\u00A76/" + command + " list \u00A7a- list all destinations"); + sender.sendMessage("\u00A7e\u00A7m----------------------------"); + break; default: Destination.warp((Player) sender, args[0]); break;