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/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/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 9c39f46..80699b6 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,25 +221,25 @@ 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] + "\"}}, " + + 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(""); } @@ -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,26 @@ 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"); - break; - case "bukkitpage": - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] 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) { @@ -372,29 +375,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 +447,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")); @@ -482,7 +485,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 b80110b..ce88875 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -1,8 +1,8 @@ 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.compat.CraftBukkit; +import com.sekwah.advancedportals.destinations.*; import com.sekwah.advancedportals.effects.WarpEffects; import com.sekwah.advancedportals.listeners.*; import com.sekwah.advancedportals.metrics.Metrics; @@ -10,17 +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 boolean useCustomPrefix = false; - - public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]"; - - public String customPrefixFail = "\u00A7c[\u00A77AdvancedPortals\u00A7c]"; + public CraftBukkit compat = null; public void onEnable() { @@ -36,77 +29,67 @@ 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(this, 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 AdvancedPortalsCommand(this); - new DestinationCommand(this); - new WarpCommand(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 | 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"); + this.setEnabled(false); } saveDefaultConfig(); // 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/DestinationCommand.java b/src/com/sekwah/advancedportals/DestinationCommand.java deleted file mode 100644 index 22e7253..0000000 --- a/src/com/sekwah/advancedportals/DestinationCommand.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.sekwah.advancedportals; - -import com.sekwah.advancedportals.destinations.Destination; -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.Arrays; -import java.util.Collections; -import java.util.LinkedList; -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")) { - 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] + "!"); - 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!"); - } - } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); - } - } else if (args[0].toLowerCase().equals("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("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); - } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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."); - } - } else if (args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("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."); - } - } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to exemptPlayer to."); - } - } else if (args[0].toLowerCase().equals("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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] 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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] 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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] 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("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations."); - } - } - } 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"); - } - 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; - } - - -} diff --git a/src/com/sekwah/advancedportals/PluginMessages.java b/src/com/sekwah/advancedportals/PluginMessages.java index 6c4c317..def3a7b 100644 --- a/src/com/sekwah/advancedportals/PluginMessages.java +++ b/src/com/sekwah/advancedportals/PluginMessages.java @@ -3,17 +3,30 @@ 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/WarpCommand.java b/src/com/sekwah/advancedportals/WarpCommand.java deleted file mode 100644 index 6823a76..0000000 --- a/src/com/sekwah/advancedportals/WarpCommand.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.sekwah.advancedportals; - -import com.sekwah.advancedportals.destinations.Destination; -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) { - 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(""); - } - } else { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7c You need to type a destination after /" + command + "!"); - sender.sendMessage(""); - } - 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; - } - - -} diff --git a/src/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/com/sekwah/advancedportals/compat/CraftBukkit.java new file mode 100644 index 0000000..a6cfa20 --- /dev/null +++ b/src/com/sekwah/advancedportals/compat/CraftBukkit.java @@ -0,0 +1,112 @@ +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. + * + * 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 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. + + 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, NoSuchMethodException { + + this.craftPlayer = Class.forName(craftBukkitPackage + "entity.CraftPlayer"); + + this.chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); + + this.chatMessageMethod = this.findClass(chatBaseComponent, "ChatSerializer").getMethod("a", String.class); + + this.chatPacket = Class.forName(minecraftPackage + "PacketPlayOutChat"); + + this.packet = Class.forName(minecraftPackage + "Packet"); + + } + + 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); + + Object handle = this.craftPlayer.getMethod("getHandle").invoke(player); + + 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(); + } + + /*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 Class findClass(Class classObj, String className){ + for(Class classes : classObj.getDeclaredClasses()){ + if(classes.getSimpleName().equals(className)){ + return classes; + } + } + return null; + } + + +} 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 0aec1a7..2d3bdfb 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; @@ -24,12 +25,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 +107,11 @@ public class Destination { config.saveConfig(); } - public static boolean warp(Player player, String name, boolean senderror) { + 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(); @@ -137,79 +144,27 @@ public class Destination { WarpEffects.activateParticles(player); WarpEffects.activateSound(player); + if (PortalMessagesDisplay == 1) { + player.sendMessage(""); + player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."); + player.sendMessage(""); + } else if (PortalMessagesDisplay == 2) { + plugin.compat.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player); + /**plugin.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(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 { - 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(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!"); } - - } - - /** - * 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); - - } - - 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; + return false; } } diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java new file mode 100644 index 0000000..53f0e49 --- /dev/null +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -0,0 +1,117 @@ +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.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class DestinationCommand implements CommandExecutor, TabCompleter { + + private AdvancedPortalsPlugin plugin; + + public DestinationCommand(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; + + plugin.getCommand("destination").setExecutor(this); + } + + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + if (args.length > 0) { switch (args[0].toLowerCase()) { + case "create": + if (sender.hasPermission("advancedportals.desti")) { + if (args.length > 1) { + String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); + if (posX == null) { + 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(PluginMessages.customPrefixFail + " A destination by that name already exists!"); + } + } else { + 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 destinations!"); + } + break; + case "remove": + ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml"); + 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 + " You need to state the name of the destination you wish to remove."); + } + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to remove destinations!"); + } + break; + case "list": + String message = PluginMessages.customPrefix + " \u00A77Destinations \u00A7c:\u00A7a"; + 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; + } + } else { + PluginMessages.UnknownCommand(sender, command); + } + return true; + } + + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { + LinkedList autoComplete = new LinkedList(); + 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", "remove", "help")); + } 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; + } + + +} diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 564485e..9b708b9 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; @@ -83,22 +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()) { - 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 (portal.trigger.equals(Material.PORTAL)) { if (player.getGameMode().equals(GameMode.CREATIVE)) { player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); @@ -108,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); } @@ -182,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 942a3a4..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"); @@ -439,14 +440,10 @@ 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) { - 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!"); }