From e3ff485b094f9084f320992d90cedd98bbbf0da4 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Mon, 23 Jul 2018 01:43:29 +0100 Subject: [PATCH] Changed build system --- .gitignore | 12 +- .travis.yml | 3 + build.gradle | 45 + gradle.properties | 3 + pom.xml | 42 - .../AdvancedPortalsCommand.java | 1488 ++++++++--------- .../AdvancedPortalsPlugin.java | 0 .../advancedportals/ConfigAccessor.java | 0 .../advancedportals/PluginMessages.java | 0 .../com/sekwah/advancedportals/Selection.java | 0 .../com/sekwah/advancedportals/Settings.java | 0 .../advancedportals/api/events/WarpEvent.java | 0 .../api/portaldata/PortalArg.java | 0 .../api/portaldata/PortalTags.java | 0 .../api/registry/TagRegistry.java | 0 .../api/warphandler/ActivationData.java | 0 .../api/warphandler/TagHandler.java | 0 .../advancedportals/compat/CraftBukkit.java | 0 .../destinations/Destination.java | 0 .../destinations/DestinationCommand.java | 0 .../destinations/PortalWarp.java | 0 .../advancedportals/effects/WarpEffects.java | 0 .../listeners/BungeeListener.java | 0 .../listeners/FlowStopper.java | 0 .../advancedportals/listeners/Listeners.java | 0 .../listeners/PortalPlacer.java | 0 .../listeners/PortalProtect.java | 0 .../advancedportals/metrics/Metrics.java | 0 .../portals/AdvancedPortal.java | 0 .../advancedportals/portals/Portal.java | 0 {Resources => src/main/resources}/config.yml | 0 .../main/resources}/destinations.yml | 0 {Resources => src/main/resources}/plugin.yml | 0 {Resources => src/main/resources}/portals.yml | 0 34 files changed, 800 insertions(+), 793 deletions(-) create mode 100644 build.gradle create mode 100644 gradle.properties delete mode 100644 pom.xml rename src/{ => main/java}/com/sekwah/advancedportals/AdvancedPortalsCommand.java (98%) rename src/{ => main/java}/com/sekwah/advancedportals/AdvancedPortalsPlugin.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/ConfigAccessor.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/PluginMessages.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/Selection.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/Settings.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/api/events/WarpEvent.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/api/portaldata/PortalArg.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/api/portaldata/PortalTags.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/api/registry/TagRegistry.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/api/warphandler/ActivationData.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/api/warphandler/TagHandler.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/compat/CraftBukkit.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/destinations/Destination.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/destinations/DestinationCommand.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/destinations/PortalWarp.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/effects/WarpEffects.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/listeners/BungeeListener.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/listeners/FlowStopper.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/listeners/Listeners.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/listeners/PortalPlacer.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/listeners/PortalProtect.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/metrics/Metrics.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/portals/AdvancedPortal.java (100%) rename src/{ => main/java}/com/sekwah/advancedportals/portals/Portal.java (100%) rename {Resources => src/main/resources}/config.yml (100%) rename {Resources => src/main/resources}/destinations.yml (100%) rename {Resources => src/main/resources}/plugin.yml (100%) rename {Resources => src/main/resources}/portals.yml (100%) diff --git a/.gitignore b/.gitignore index 40f7ae1..39ad847 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,16 @@ *.class .* -/target/ /build/ -/classes/ -/run/ -/logs/ +/target/ # Package Files # -*.jar *.war *.ear *.iml - +*.iws *.ipr -*.iws +logs/ +classes/ +run/ diff --git a/.travis.yml b/.travis.yml index dff5f3a..1bb1241 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,4 @@ language: java +cache: + directories: + - $HOME/.m2 diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..8c20c3f --- /dev/null +++ b/build.gradle @@ -0,0 +1,45 @@ +apply plugin: 'java' +apply plugin: 'maven' +apply plugin: 'idea' +apply plugin: 'eclipse' + +group = 'com.sekwah.advancedportals' +version = '0.0.42-snapshot' + +description = "" + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +configurations { + // configuration that holds jars to copy into lib + includeLibs +} + +repositories { + maven { url "http://repo.maven.apache.org/maven2" } + maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" } +} + +// includeLibs just says to include the library in the final jar +dependencies { + compile "org.bukkit:bukkit:1.12.1-R0.1-SNAPSHOT" +} + + +// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run +// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start +task runJar() { + doLast { + javaexec { + main "-jar" + args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar" + jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -DIReallyKnowWhatIAmDoingISwear=true" + workingDir "${System.env.MC_SERVER_LOC}" + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..6d84430 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +# https://docs.gradle.org/current/userguide/build_environment.html +# Disable with --no-build-cache +org.gradle.caching=true \ No newline at end of file diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 4fbea12..0000000 --- a/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - 4.0.0 - com.sekwah.advancedportals - Advanced-Portals - - ${basedir}/src/ - - - ${basedir}/Resources - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - 0.0.41-snapshot - - UTF-8 - 1.7 - 1.7 - - - - - - org.bukkit - bukkit - 1.12.1-R0.1-SNAPSHOT - provided - - - - \ No newline at end of file diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/main/java/com/sekwah/advancedportals/AdvancedPortalsCommand.java similarity index 98% rename from src/com/sekwah/advancedportals/AdvancedPortalsCommand.java rename to src/main/java/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 1095a42..5330b4a 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/main/java/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -1,745 +1,745 @@ -package com.sekwah.advancedportals; - -import com.sekwah.advancedportals.api.events.WarpEvent; -import com.sekwah.advancedportals.api.portaldata.PortalArg; -import com.sekwah.advancedportals.listeners.Listeners; -import com.sekwah.advancedportals.portals.AdvancedPortal; -import com.sekwah.advancedportals.portals.Portal; -import org.bukkit.*; -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 org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.material.Wool; -import org.bukkit.metadata.FixedMetadataValue; - -import java.util.*; - -public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { - - private final ArrayList blockMaterialList = new ArrayList<>(); - private AdvancedPortalsPlugin plugin; - - private int portalArgsStringLength = 0; - - // TODO recode the portal args to be put into a hashmap and use a string array - // to store all possible portal arguments. Makes code shorter and possibly more efficient. - //private HashMap portalArgs = new HashMap<>(); - - public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; - - - for(Material material : Material.values()) { - this.blockMaterialList.add("triggerblock:" + material.name()); - } - plugin.getCommand("advancedportals").setExecutor(this); - } - - @SuppressWarnings("deprecation") - @Override - public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { - //System.out.printf("%s %s %s %s%n", sender, cmd, command, args ); - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); - if(!(sender instanceof Player)) { - sender.sendMessage(PluginMessages.customPrefixFail + " You cannot use commands with the console."); - return true; - } - Player player = (Player) sender; - PlayerInventory inventory = player.getInventory(); - - if (sender.hasPermission("advancedportals.portal")) { - if (args.length > 0) { switch (args[0].toLowerCase()) { - case "wand": - case "warp": - if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")){ - for (AdvancedPortal portal: Portal.portals){ - if (args[1].equalsIgnoreCase(portal.getName())){ - - if (portal.inPortal.contains(player.getUniqueId())) return true; - WarpEvent warpEvent = new WarpEvent(player, portal); - plugin.getServer().getPluginManager().callEvent(warpEvent); - - if (!warpEvent.isCancelled()) Portal.activate(player, portal); - break; - } - } - } - sendMenu(player, "Help Menu: Warp", "\u00A76/" + command + " warp \u00A7a- teleport to warp name"); - break; - case "selector": - String ItemID = config.getConfig().getString("AxeItemId"); - - - Material WandMaterial = Material.getMaterial(ItemID); - - if (WandMaterial == null) { - WandMaterial = Material.IRON_AXE; - } - - ItemStack regionselector = new ItemStack(WandMaterial); - ItemMeta selectorname = regionselector.getItemMeta(); - selectorname.setDisplayName("\u00A7ePortal Region Selector"); - selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help" - , "\u00A7r create portals bistowed upon it!")); - regionselector.setItemMeta(selectorname); - - inventory.addItem(regionselector); - sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); - break; - case "portalblock": - // TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. - // Also do this for other blocks such as gateways and end portals just in case they want it. - ItemStack portalBlock = new Wool(DyeColor.PURPLE).toItemStack(1); - ItemMeta blockName = portalBlock.getItemMeta(); - blockName.setDisplayName("\u00A75Portal Block Placer"); - blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", - "\u00A7rRight Click: Place portal block", - "\u00A7rLeft Click: Rotate portal block")); - portalBlock.setItemMeta(blockName); - inventory.addItem(portalBlock); - - sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); - break; - case "endportalblock": - // TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. - // Also do this for other blocks such as gateways and end portals just in case they want it. - portalBlock = new Wool(DyeColor.BLACK).toItemStack(1); - blockName = portalBlock.getItemMeta(); - blockName.setDisplayName("\u00A78End Portal Block Placer"); - blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", - "\u00A7rRight Click: Place portal block")); - portalBlock.setItemMeta(blockName); - inventory.addItem(portalBlock); - sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); - break; - case "gatewayblock": - // TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. - // Also do this for other blocks such as gateways and end portals just in case they want it. - portalBlock = new Wool(DyeColor.BLACK).toItemStack(1); - blockName = portalBlock.getItemMeta(); - blockName.setDisplayName("\u00A78Gateway Block Placer"); - blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", - "\u00A7rRight Click: Place portal block")); - portalBlock.setItemMeta(blockName); - inventory.addItem(portalBlock); - - sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); - break; - case "create": - 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())) { - if (args.length >= 2) { // may make this next piece of code more efficient, maybe check against a list of available variables or something - // TODO change system to use arrays and hashmaps - boolean hasName = false; - boolean hasTriggerBlock = false; - boolean hasDestination = false; - boolean isBungeePortal = false; - boolean needsPermission = false; - boolean executesCommand = false; - String destination = null; - String portalName = null; - String triggerBlock = null; - String serverName = null; - String permission = null; - String portalCommand = null; - - ArrayList extraData = new ArrayList<>(); - - for (int i = 1; i < args.length; i++) { - if (args[i].toLowerCase().startsWith("name:") && args[i].length() > 5) { - hasName = true; - portalName = args[i].replaceFirst("name:", ""); - } else if (args[i].toLowerCase().startsWith("name:")) { - 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; - destination = args[i].toLowerCase().replaceFirst("destination:", ""); - } else if (args[i].toLowerCase().startsWith("desti:") && args[i].length() > 6) { - hasDestination = true; - destination = args[i].toLowerCase().replaceFirst("desti:", ""); - } else if (args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13) { - hasTriggerBlock = true; - triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); - } else if (args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13) { - hasTriggerBlock = true; - triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); - } else if (args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7) { // not completely implemented - isBungeePortal = true; - serverName = args[i].toLowerCase().replaceFirst("bungee:", ""); - //extraData.add(new PortalArgs("bungee", serverName)); - } else if (args[i].toLowerCase().startsWith("permission:") && args[i].length() > 11) { // not completely implemented - needsPermission = true; - permission = args[i].toLowerCase().replaceFirst("permission:", ""); - extraData.add(new PortalArg("permission", permission)); - } else if (args[i].toLowerCase().startsWith("command:") && args[i].length() > 8) { // not completely implemented - executesCommand = true; - portalCommand = parseArgVariable(args, i, "command:"); - i += this.portalArgsStringLength - 1; - if(portalCommand.startsWith("#") && !(this.plugin.getSettings().hasCommandLevel("c") - && (sender.hasPermission("advancedportals.createportal.commandlevel.console")) - || (this.plugin.getSettings().hasCommandLevel("k") && sender.isOp()))) { - player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a console command portal!"); - return true; - } - else if(portalCommand.startsWith("!") && !(this.plugin.getSettings().hasCommandLevel("o") - && (sender.hasPermission("advancedportals.createportal.commandlevel.op")) - || (this.plugin.getSettings().hasCommandLevel("p") && sender.isOp()))) { - player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a op command portal!"); - return true; - } - else if(portalCommand.startsWith("^") && !(this.plugin.getSettings().hasCommandLevel("p") - && (sender.hasPermission("advancedportals.createportal.commandlevel.perms")) - || (this.plugin.getSettings().hasCommandLevel("e") && sender.isOp()))) { - player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a all perms command portal!"); - return true; - } - extraData.add(new PortalArg("command.1", portalCommand)); - } - } - if (!hasName) { - player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that you are creating in the variables!"); - return true; - } - - World world = org.bukkit.Bukkit.getWorld(player.getMetadata("Pos1World").get(0).asString()); - Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), player.getMetadata("Pos1Y").get(0).asInt(), player.getMetadata("Pos1Z").get(0).asInt()); - Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), player.getMetadata("Pos2Y").get(0).asInt(), player.getMetadata("Pos2Z").get(0).asInt()); - - ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml"); - String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X"); - - if (!Portal.portalExists(portalName)) { - - player.sendMessage(""); - player.sendMessage(PluginMessages.customPrefix + "\u00A7e You have created a new portal with the following details:"); - player.sendMessage("\u00A7aname: \u00A7e" + portalName); - if (hasDestination) { - if (destiPosX == null) { - player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)"); - return true; - } - else{ - player.sendMessage("\u00A7adestination: \u00A7e" + destination); - } - - } else { - player.sendMessage("\u00A7cdestination: \u00A7eN/A (will not teleport to a location)"); - } - - if (isBungeePortal) { - player.sendMessage("\u00A7abungee: \u00A7e" + serverName); - } - - if (needsPermission) { - player.sendMessage("\u00A7apermission: \u00A7e" + permission); - } else { - player.sendMessage("\u00A7apermission: \u00A7e(none needed)"); - } - - if (executesCommand) { - player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); - } - - Material triggerBlockMat; - if (hasTriggerBlock) { - triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase()); - if (triggerBlockMat != null) { - player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase()); - PortalArg[] portalArgs = new PortalArg[extraData.size()]; - portalArgs = extraData.toArray(portalArgs); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName, portalArgs)); - } else { - hasTriggerBlock = false; - ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); - player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); - - player.sendMessage("\u00A7cThe block " + triggerBlock.toUpperCase() + " is not a valid block name in minecraft so the trigger block has been set to the default!"); - PortalArg[] portalArgs = new PortalArg[extraData.size()]; - portalArgs = extraData.toArray(portalArgs); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); - } - } else { - ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); - player.sendMessage("\u00A7atriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); - PortalArg[] portalArgs = new PortalArg[extraData.size()]; - portalArgs = extraData.toArray(portalArgs); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); - } - } else { - 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(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(PluginMessages.customPrefixFail + " The points you have selected need to be in the same world!"); - } - } else { - player.sendMessage(PluginMessages.customPrefixFail + " You need to have two points selected to make a portal!"); - } - break; - case "variables" : - sender.sendMessage(PluginMessages.customPrefix + " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command"); - sender.sendMessage(""); - sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); - break; - case "select": - // TODO finish the select command and the hit block to replace! - if (!player.hasMetadata("selectingPortal")) { - if (args.length > 1) { - if (Portal.portalExists(args[1])) { - player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); - player.sendMessage(PluginMessages.customPrefix + " You have selected\u00A7e " + args[1] + "\u00A7a."); - } else { - 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(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(PluginMessages.customPrefixFail + " Portal selection cancelled!"); - } - break; - case "unselect": - if(player.hasMetadata("selectedPortal")){ - player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e" + player.getMetadata("selectedPortal").get(0).asString() - + "\u00A7a."); - } - else{ - player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!"); - } - case "gui" : - if (args.length > 1) { - if (args[1].toLowerCase().equals("remove") && args.length > 2) { - sender.sendMessage(""); - sender.sendMessage(PluginMessages.customPrefixFail + " Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); - sender.sendMessage(""); - 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(""); - } - } - break; - case "edit": - if (args.length > 1) { - if (Portal.portalExists(args[1])) { - player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); - portalEditMenu(sender, portalConfig, args[1]); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); - } - } else { - if (player.hasMetadata("selectedPortal")) { - String portalName = player.getMetadata("selectedPortal").get(0).asString(); - String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); - if (posX != null) { - portalEditMenu(sender, portalConfig, portalName); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); - player.removeMetadata("selectedPortal", plugin); - } - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); - } - } - break; - case "rename": - - // not finished yet / - if (args.length > 1) { - if (player.hasMetadata("selectedPortal")) { - String portalName = player.getMetadata("selectedPortal").get(0).asString(); - if (portalName.toLowerCase() != args[1].toLowerCase()) { - String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); - - String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); - if (posX != null && newPortalPosX == null) { - Portal.rename(portalName, args[1]); - 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(PluginMessages.customPrefixFail + " There is already a portal with the name \u00A7e" + args[1] + "\u00A7c!"); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); - player.removeMetadata("selectedPortal", plugin); - } - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " The portal you have selected is already called that!"); - } - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); - } - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); - } - break; - case "command": - if (player.hasMetadata("selectedPortal")) { - String portalName = player.getMetadata("selectedPortal").get(0).asString(); - if (args.length > 1) { - // TODO add the command autocompletes, add, remove and show - if (args[1].toLowerCase().equals("add")) { - if (args.length > 2) { - String portalCommand = args[2]; - for (int i = 3; i < args.length; i++) { - portalCommand += args[i]; - } - if (Portal.addCommand(portalName, portalCommand)) { - sender.sendMessage(PluginMessages.customPrefixFail + " Command added to portal!"); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " Failed to add command to portal!"); - } - - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You must actually specify a command to execute!"); - } - - } else if (args[1].toLowerCase().equals("remove")) { - // Specify what line to remove - } else if (args[1].toLowerCase().equals("show")) { - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); - } - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); - } - } else { - - } - break; - case "remove": - if (args.length > 1) { - String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); - if (posX != null) { - Portal.remove(args[1]); - sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A7e" + args[1] + "\u00A7c has been removed!"); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); - } - } else { - if (player.hasMetadata("selectedPortal")) { - String portalName = player.getMetadata("selectedPortal").get(0).asString(); - String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); - if (posX != null) { - Portal.remove(portalName); - sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A77" + portalName + "\u00A7c has been removed!"); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); - player.removeMetadata("selectedPortal", plugin); - } - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); - } - } - break; - case "help": - helpCommand(sender, command, args); - break; - case "show": - if (args.length > 1) { - String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); - if (posX != null) { - Selection.show(player, this.plugin, args[1]); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); - } - } else { - if (player.hasMetadata("selectedPortal")) { - 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(PluginMessages.customPrefix + " Your currently selected area has been shown, it will dissapear shortly!"); - Selection.show(player, this.plugin, null); - } - } else { - player.sendMessage(PluginMessages.customPrefixFail + " No regions selected!"); - } - } - break; - case "reload": - sender.sendMessage(PluginMessages.customPrefix + " Reloaded values!"); - Listeners.reloadValues(plugin); - Portal.loadPortals(); - break; - case "list" : - String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a"; - LinkedList portals = new LinkedList<>(); - for (AdvancedPortal portal : Portal.portals) { - portals.add(portal.getName()); - } - Collections.sort(portals); - for (Object portalName : portals.toArray()) { - message = message + " " + portalName; - } - player.sendMessage(message); - break; - default: - PluginMessages.UnknownCommand(sender, command); - } - } else { - PluginMessages.UnknownCommand(sender, command); - } - } else { - PluginMessages.NoPermission(sender, command); - } - - return true; - } - - private void helpCommand(CommandSender sender, String command, String[] args) { - // Add pages if there starts to become too many - if(args.length == 1) { - sendMenu(sender, "Help Menu", - "\u00A76/" + command + " selector \u00A7a- gives you a region selector", - "\u00A76/" + command + " create \u00A7c[tags] \u00A7a- creates a portal with a selection ", - "\u00A76/" + command + " portalblock \u00A7a- gives you a portal block", - "\u00A76/" + command + " endportalblock \u00A7a- gives you an end portal block", - "\u00A76/" + command + " gatewayblock \u00A7a- gives you a gateway block", - "\u00A76/" + command + " select \u00A7a- selects an existing portal", - "\u00A76/" + command + " unselect \u00A7a- unselects the current portal", - "\u00A76/" + command + " command \u00A7a- adds or removes commands from the selected portal", - "\u00A76/" + command + " help \u00A7a- shows this help section", - "\u00A76/" + command + " help \u00A7a- shows help for the specified arg", - "\u00A76/" + command + " remove \u00A7a- removes a portal", - "\u00A76/" + command + " list \u00A7a- lists all the current portals", - "\u00A76/" + command + " warp \u00A7a- teleport to warp name", - "\u00A76/" + command + " variables \u00A7a- lists all available tags"); - } - else if(args.length > 1){ - if(args[1].toLowerCase().equals("help")) { - sendMenu(sender, "Help Command", - "Shows the help section. You can also use a single argument after it to show the " + - "help section for the corresponding command."); - } - else if(args[1].toLowerCase().equals("portalblock")) { - sendMenu(sender, "Help Command", - "Gives you a special wool block to place portal blocks.", - "", - "\u00A7eLeft Click: \u00A76Rotates the hit portal block", - "\u00A7eRight Click: \u00A76Placed a portal block"); - } - else if(args[1].toLowerCase().equals("endportalblock")) { - sendMenu(sender, "Help Command", - "Gives you a special wool block to place end portal blocks.", - "", - "\u00A7eRight Click: \u00A76Placed a end portal block"); - } - else if(args[1].toLowerCase().equals("gatewayblock")) { - sendMenu(sender, "Help Command", - "Gives you a special wool block to place gateway blocks.", - "", - "\u00A7eRight Click: \u00A76Placed a gateway block"); - } - else{ - sender.sendMessage(PluginMessages.customPrefix + " Either \u00A7e" + args[1] + "\u00A7a is not a command or a help page has not been added yet."); - } - } - } - - private void sendMenu(CommandSender sender, String title, String... lines) { - sender.sendMessage(PluginMessages.customPrefix + " " + title); - sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); - for(String line : lines){ - sender.sendMessage("\u00A7a" + line); - } - sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); - } - - private String parseArgVariable(String[] args, int currentArg, String argStarter) { - String variableString = args[currentArg].replaceFirst(argStarter, ""); - this.portalArgsStringLength = 1; - if (variableString.charAt(0) == '"') { - variableString = variableString.substring(1, variableString.length()); - if (variableString.charAt(variableString.length() - 1) != '"') { - currentArg++; - for (; currentArg < args.length; currentArg++) { - variableString += " " + args[currentArg]; - this.portalArgsStringLength += 1; - if (variableString.charAt(variableString.length() - 1) == '"') { - variableString = variableString.substring(0, variableString.length() - 1); - break; - } - } - } else { - variableString = variableString.substring(0, variableString.length() - 1); - } - - } - return variableString; - } - - private void portalEditMenu(CommandSender sender, ConfigAccessor portalConfig, String portalName) { - // make the text gui with the json message for a list of edit commands to be clicked or hovered - // put \" for a " in the json messages - // sadly there is no newline code so these three lines will have to be copied and pasted for each line - - // use the usual messages for normal lines but anything that needs special features make sure you use the - // chat steriliser - sender.sendMessage(""); - 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")); - - String destination = portalConfig.getConfig().getString(portalName + ".destination"); - if (destination != null) { - sender.sendMessage(" \u00A7adestination\u00A7e: " + destination); - } else { - sender.sendMessage(" \u00A7cdestination\u00A7e: null"); - } - - String trigger = portalConfig.getConfig().getString(portalName + ".triggerblock"); - if (trigger != null) { - sender.sendMessage(" \u00A7atriggerBlock\u00A7e: " + trigger); - } else { - sender.sendMessage(" \u00A7ctriggerBlock\u00A7e: null"); - } - - if (portalConfig.getConfig().getString(portalName + ".portalArgs.command.1") != null) { - int commands = 0; - String command = portalConfig.getConfig().getString(portalName + ".portalArgs.command.1"); - // TODO possibly change code so it counds number of subvalues rather than a loop. - while (command != null) { - command = portalConfig.getConfig().getString(portalName + ".portalArgs.command." + ++commands); - } - if (--commands > 1) { - sender.sendMessage(" \u00A7acommands\u00A7e: " + commands + " commands"); - } else { - sender.sendMessage(" \u00A7acommands\u00A7e: " + commands + " command"); - } - } else { - sender.sendMessage(" \u00A7ccommands\u00A7e: none"); - } - sender.sendMessage(""); - - Player player = (Player) sender; - - plugin.compat.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \"," + - "\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal gui remove " + portalName + "\"}}" - + ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"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\":\"\u00A7eTeleport\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(If there is one)\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/desti warp " + destination + "\"}}]}", player); - - sender.sendMessage(""); - - } - - @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 || (args.length == 2 && args[0].toLowerCase().equals("help"))) { - autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "unselect", "command", "selector" - , "show", "gatewayblock", "endportalblock", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage", "warp")); - } else if (args[0].toLowerCase().equals("create")) { - - boolean hasName = false; - boolean hasTriggerBlock = false; - boolean hasDestination = false; - boolean isBungeePortal = false; - boolean needsPermission = false; - boolean hasCommand = false; - - - // TODO change auto complete when quotes are opened and closed. Such as autocomplete @Player and stuff when specifying commands - - for (int i = 1; i < args.length; i++) { - String argTag = getTag(args[i].toLowerCase()); - if (argTag.length() + 1 < args[i].length()) { - switch (argTag) { - case "name": - hasName = true; - break; - case "destination": - hasDestination = true; - break; - case "desti": - hasDestination = true; - break; - case "triggerblock": - hasTriggerBlock = true; - break; - case "bungee": - isBungeePortal = true; - break; - case "permission": - needsPermission = true; - break; - case "command": - hasCommand = true; - break; - } - } - - } - - if (!hasName) { - autoComplete.add("name:"); - } - if (!hasTriggerBlock) { - autoComplete.add("triggerblock:"); - autoComplete.addAll(this.blockMaterialList); - } - if (!hasDestination) { - autoComplete.add("destination:"); - autoComplete.add("desti:"); - } - if (!isBungeePortal) { - autoComplete.add("bungee:"); - } - if (!needsPermission) { - autoComplete.add("permission:"); - } - if (!hasCommand) { - autoComplete.add("command:"); - } - } - } - if (args.length == 2 && args[0].equalsIgnoreCase("warp")){ - for (AdvancedPortal portal :Portal.portals){ - String perm = portal.getArg("permission"); - if (perm == null || sender.hasPermission(perm)){ - autoComplete.add(portal.getName()); - } - } - } - Collections.sort(autoComplete); - for (Object result : autoComplete.toArray()) { - if (!result.toString().startsWith(args[args.length - 1])) { - autoComplete.remove(result); - } - } - return autoComplete; - } - - private String getTag(String arg) { - int indexOfSplitter = arg.indexOf(':'); - if (indexOfSplitter > 0) { - return arg.substring(0, indexOfSplitter); - } - return ""; - } - +package com.sekwah.advancedportals; + +import com.sekwah.advancedportals.api.events.WarpEvent; +import com.sekwah.advancedportals.api.portaldata.PortalArg; +import com.sekwah.advancedportals.listeners.Listeners; +import com.sekwah.advancedportals.portals.AdvancedPortal; +import com.sekwah.advancedportals.portals.Portal; +import org.bukkit.*; +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 org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.material.Wool; +import org.bukkit.metadata.FixedMetadataValue; + +import java.util.*; + +public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { + + private final ArrayList blockMaterialList = new ArrayList<>(); + private AdvancedPortalsPlugin plugin; + + private int portalArgsStringLength = 0; + + // TODO recode the portal args to be put into a hashmap and use a string array + // to store all possible portal arguments. Makes code shorter and possibly more efficient. + //private HashMap portalArgs = new HashMap<>(); + + public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; + + + for(Material material : Material.values()) { + this.blockMaterialList.add("triggerblock:" + material.name()); + } + plugin.getCommand("advancedportals").setExecutor(this); + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { + //System.out.printf("%s %s %s %s%n", sender, cmd, command, args ); + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + if(!(sender instanceof Player)) { + sender.sendMessage(PluginMessages.customPrefixFail + " You cannot use commands with the console."); + return true; + } + Player player = (Player) sender; + PlayerInventory inventory = player.getInventory(); + + if (sender.hasPermission("advancedportals.portal")) { + if (args.length > 0) { switch (args[0].toLowerCase()) { + case "wand": + case "warp": + if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")){ + for (AdvancedPortal portal: Portal.portals){ + if (args[1].equalsIgnoreCase(portal.getName())){ + + if (portal.inPortal.contains(player.getUniqueId())) return true; + WarpEvent warpEvent = new WarpEvent(player, portal); + plugin.getServer().getPluginManager().callEvent(warpEvent); + + if (!warpEvent.isCancelled()) Portal.activate(player, portal); + break; + } + } + } + sendMenu(player, "Help Menu: Warp", "\u00A76/" + command + " warp \u00A7a- teleport to warp name"); + break; + case "selector": + String ItemID = config.getConfig().getString("AxeItemId"); + + + Material WandMaterial = Material.getMaterial(ItemID); + + if (WandMaterial == null) { + WandMaterial = Material.IRON_AXE; + } + + ItemStack regionselector = new ItemStack(WandMaterial); + ItemMeta selectorname = regionselector.getItemMeta(); + selectorname.setDisplayName("\u00A7ePortal Region Selector"); + selectorname.setLore(Arrays.asList("\u00A7rThis wand with has the power to help" + , "\u00A7r create portals bistowed upon it!")); + regionselector.setItemMeta(selectorname); + + inventory.addItem(regionselector); + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); + break; + case "portalblock": + // TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. + // Also do this for other blocks such as gateways and end portals just in case they want it. + ItemStack portalBlock = new Wool(DyeColor.PURPLE).toItemStack(1); + ItemMeta blockName = portalBlock.getItemMeta(); + blockName.setDisplayName("\u00A75Portal Block Placer"); + blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", + "\u00A7rRight Click: Place portal block", + "\u00A7rLeft Click: Rotate portal block")); + portalBlock.setItemMeta(blockName); + inventory.addItem(portalBlock); + + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); + break; + case "endportalblock": + // TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. + // Also do this for other blocks such as gateways and end portals just in case they want it. + portalBlock = new Wool(DyeColor.BLACK).toItemStack(1); + blockName = portalBlock.getItemMeta(); + blockName.setDisplayName("\u00A78End Portal Block Placer"); + blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", + "\u00A7rRight Click: Place portal block")); + portalBlock.setItemMeta(blockName); + inventory.addItem(portalBlock); + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); + break; + case "gatewayblock": + // TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. + // Also do this for other blocks such as gateways and end portals just in case they want it. + portalBlock = new Wool(DyeColor.BLACK).toItemStack(1); + blockName = portalBlock.getItemMeta(); + blockName.setDisplayName("\u00A78Gateway Block Placer"); + blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", + "\u00A7rRight Click: Place portal block")); + portalBlock.setItemMeta(blockName); + inventory.addItem(portalBlock); + + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); + break; + case "create": + 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())) { + if (args.length >= 2) { // may make this next piece of code more efficient, maybe check against a list of available variables or something + // TODO change system to use arrays and hashmaps + boolean hasName = false; + boolean hasTriggerBlock = false; + boolean hasDestination = false; + boolean isBungeePortal = false; + boolean needsPermission = false; + boolean executesCommand = false; + String destination = null; + String portalName = null; + String triggerBlock = null; + String serverName = null; + String permission = null; + String portalCommand = null; + + ArrayList extraData = new ArrayList<>(); + + for (int i = 1; i < args.length; i++) { + if (args[i].toLowerCase().startsWith("name:") && args[i].length() > 5) { + hasName = true; + portalName = args[i].replaceFirst("name:", ""); + } else if (args[i].toLowerCase().startsWith("name:")) { + 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; + destination = args[i].toLowerCase().replaceFirst("destination:", ""); + } else if (args[i].toLowerCase().startsWith("desti:") && args[i].length() > 6) { + hasDestination = true; + destination = args[i].toLowerCase().replaceFirst("desti:", ""); + } else if (args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13) { + hasTriggerBlock = true; + triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); + } else if (args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13) { + hasTriggerBlock = true; + triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); + } else if (args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7) { // not completely implemented + isBungeePortal = true; + serverName = args[i].toLowerCase().replaceFirst("bungee:", ""); + //extraData.add(new PortalArgs("bungee", serverName)); + } else if (args[i].toLowerCase().startsWith("permission:") && args[i].length() > 11) { // not completely implemented + needsPermission = true; + permission = args[i].toLowerCase().replaceFirst("permission:", ""); + extraData.add(new PortalArg("permission", permission)); + } else if (args[i].toLowerCase().startsWith("command:") && args[i].length() > 8) { // not completely implemented + executesCommand = true; + portalCommand = parseArgVariable(args, i, "command:"); + i += this.portalArgsStringLength - 1; + if(portalCommand.startsWith("#") && !(this.plugin.getSettings().hasCommandLevel("c") + && (sender.hasPermission("advancedportals.createportal.commandlevel.console")) + || (this.plugin.getSettings().hasCommandLevel("k") && sender.isOp()))) { + player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a console command portal!"); + return true; + } + else if(portalCommand.startsWith("!") && !(this.plugin.getSettings().hasCommandLevel("o") + && (sender.hasPermission("advancedportals.createportal.commandlevel.op")) + || (this.plugin.getSettings().hasCommandLevel("p") && sender.isOp()))) { + player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a op command portal!"); + return true; + } + else if(portalCommand.startsWith("^") && !(this.plugin.getSettings().hasCommandLevel("p") + && (sender.hasPermission("advancedportals.createportal.commandlevel.perms")) + || (this.plugin.getSettings().hasCommandLevel("e") && sender.isOp()))) { + player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a all perms command portal!"); + return true; + } + extraData.add(new PortalArg("command.1", portalCommand)); + } + } + if (!hasName) { + player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that you are creating in the variables!"); + return true; + } + + World world = org.bukkit.Bukkit.getWorld(player.getMetadata("Pos1World").get(0).asString()); + Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), player.getMetadata("Pos1Y").get(0).asInt(), player.getMetadata("Pos1Z").get(0).asInt()); + Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), player.getMetadata("Pos2Y").get(0).asInt(), player.getMetadata("Pos2Z").get(0).asInt()); + + ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml"); + String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X"); + + if (!Portal.portalExists(portalName)) { + + player.sendMessage(""); + player.sendMessage(PluginMessages.customPrefix + "\u00A7e You have created a new portal with the following details:"); + player.sendMessage("\u00A7aname: \u00A7e" + portalName); + if (hasDestination) { + if (destiPosX == null) { + player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)"); + return true; + } + else{ + player.sendMessage("\u00A7adestination: \u00A7e" + destination); + } + + } else { + player.sendMessage("\u00A7cdestination: \u00A7eN/A (will not teleport to a location)"); + } + + if (isBungeePortal) { + player.sendMessage("\u00A7abungee: \u00A7e" + serverName); + } + + if (needsPermission) { + player.sendMessage("\u00A7apermission: \u00A7e" + permission); + } else { + player.sendMessage("\u00A7apermission: \u00A7e(none needed)"); + } + + if (executesCommand) { + player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); + } + + Material triggerBlockMat; + if (hasTriggerBlock) { + triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase()); + if (triggerBlockMat != null) { + player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase()); + PortalArg[] portalArgs = new PortalArg[extraData.size()]; + portalArgs = extraData.toArray(portalArgs); + player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName, portalArgs)); + } else { + hasTriggerBlock = false; + ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); + player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); + + player.sendMessage("\u00A7cThe block " + triggerBlock.toUpperCase() + " is not a valid block name in minecraft so the trigger block has been set to the default!"); + PortalArg[] portalArgs = new PortalArg[extraData.size()]; + portalArgs = extraData.toArray(portalArgs); + player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); + } + } else { + ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); + player.sendMessage("\u00A7atriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); + PortalArg[] portalArgs = new PortalArg[extraData.size()]; + portalArgs = extraData.toArray(portalArgs); + player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); + } + } else { + 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(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(PluginMessages.customPrefixFail + " The points you have selected need to be in the same world!"); + } + } else { + player.sendMessage(PluginMessages.customPrefixFail + " You need to have two points selected to make a portal!"); + } + break; + case "variables" : + sender.sendMessage(PluginMessages.customPrefix + " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command"); + sender.sendMessage(""); + sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); + break; + case "select": + // TODO finish the select command and the hit block to replace! + if (!player.hasMetadata("selectingPortal")) { + if (args.length > 1) { + if (Portal.portalExists(args[1])) { + player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); + player.sendMessage(PluginMessages.customPrefix + " You have selected\u00A7e " + args[1] + "\u00A7a."); + } else { + 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(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(PluginMessages.customPrefixFail + " Portal selection cancelled!"); + } + break; + case "unselect": + if(player.hasMetadata("selectedPortal")){ + player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e" + player.getMetadata("selectedPortal").get(0).asString() + + "\u00A7a."); + } + else{ + player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!"); + } + case "gui" : + if (args.length > 1) { + if (args[1].toLowerCase().equals("remove") && args.length > 2) { + sender.sendMessage(""); + sender.sendMessage(PluginMessages.customPrefixFail + " Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); + sender.sendMessage(""); + 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(""); + } + } + break; + case "edit": + if (args.length > 1) { + if (Portal.portalExists(args[1])) { + player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); + portalEditMenu(sender, portalConfig, args[1]); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); + } + } else { + if (player.hasMetadata("selectedPortal")) { + String portalName = player.getMetadata("selectedPortal").get(0).asString(); + String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); + if (posX != null) { + portalEditMenu(sender, portalConfig, portalName); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); + player.removeMetadata("selectedPortal", plugin); + } + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); + } + } + break; + case "rename": + + // not finished yet / + if (args.length > 1) { + if (player.hasMetadata("selectedPortal")) { + String portalName = player.getMetadata("selectedPortal").get(0).asString(); + if (portalName.toLowerCase() != args[1].toLowerCase()) { + String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); + + String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); + if (posX != null && newPortalPosX == null) { + Portal.rename(portalName, args[1]); + 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(PluginMessages.customPrefixFail + " There is already a portal with the name \u00A7e" + args[1] + "\u00A7c!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); + player.removeMetadata("selectedPortal", plugin); + } + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you have selected is already called that!"); + } + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); + } + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); + } + break; + case "command": + if (player.hasMetadata("selectedPortal")) { + String portalName = player.getMetadata("selectedPortal").get(0).asString(); + if (args.length > 1) { + // TODO add the command autocompletes, add, remove and show + if (args[1].toLowerCase().equals("add")) { + if (args.length > 2) { + String portalCommand = args[2]; + for (int i = 3; i < args.length; i++) { + portalCommand += args[i]; + } + if (Portal.addCommand(portalName, portalCommand)) { + sender.sendMessage(PluginMessages.customPrefixFail + " Command added to portal!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " Failed to add command to portal!"); + } + + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " You must actually specify a command to execute!"); + } + + } else if (args[1].toLowerCase().equals("remove")) { + // Specify what line to remove + } else if (args[1].toLowerCase().equals("show")) { + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); + } + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); + } + } else { + + } + break; + case "remove": + if (args.length > 1) { + String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); + if (posX != null) { + Portal.remove(args[1]); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A7e" + args[1] + "\u00A7c has been removed!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); + } + } else { + if (player.hasMetadata("selectedPortal")) { + String portalName = player.getMetadata("selectedPortal").get(0).asString(); + String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); + if (posX != null) { + Portal.remove(portalName); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A77" + portalName + "\u00A7c has been removed!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); + player.removeMetadata("selectedPortal", plugin); + } + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); + } + } + break; + case "help": + helpCommand(sender, command, args); + break; + case "show": + if (args.length > 1) { + String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); + if (posX != null) { + Selection.show(player, this.plugin, args[1]); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); + } + } else { + if (player.hasMetadata("selectedPortal")) { + 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(PluginMessages.customPrefix + " Your currently selected area has been shown, it will dissapear shortly!"); + Selection.show(player, this.plugin, null); + } + } else { + player.sendMessage(PluginMessages.customPrefixFail + " No regions selected!"); + } + } + break; + case "reload": + sender.sendMessage(PluginMessages.customPrefix + " Reloaded values!"); + Listeners.reloadValues(plugin); + Portal.loadPortals(); + break; + case "list" : + String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a"; + LinkedList portals = new LinkedList<>(); + for (AdvancedPortal portal : Portal.portals) { + portals.add(portal.getName()); + } + Collections.sort(portals); + for (Object portalName : portals.toArray()) { + message = message + " " + portalName; + } + player.sendMessage(message); + break; + default: + PluginMessages.UnknownCommand(sender, command); + } + } else { + PluginMessages.UnknownCommand(sender, command); + } + } else { + PluginMessages.NoPermission(sender, command); + } + + return true; + } + + private void helpCommand(CommandSender sender, String command, String[] args) { + // Add pages if there starts to become too many + if(args.length == 1) { + sendMenu(sender, "Help Menu", + "\u00A76/" + command + " selector \u00A7a- gives you a region selector", + "\u00A76/" + command + " create \u00A7c[tags] \u00A7a- creates a portal with a selection ", + "\u00A76/" + command + " portalblock \u00A7a- gives you a portal block", + "\u00A76/" + command + " endportalblock \u00A7a- gives you an end portal block", + "\u00A76/" + command + " gatewayblock \u00A7a- gives you a gateway block", + "\u00A76/" + command + " select \u00A7a- selects an existing portal", + "\u00A76/" + command + " unselect \u00A7a- unselects the current portal", + "\u00A76/" + command + " command \u00A7a- adds or removes commands from the selected portal", + "\u00A76/" + command + " help \u00A7a- shows this help section", + "\u00A76/" + command + " help \u00A7a- shows help for the specified arg", + "\u00A76/" + command + " remove \u00A7a- removes a portal", + "\u00A76/" + command + " list \u00A7a- lists all the current portals", + "\u00A76/" + command + " warp \u00A7a- teleport to warp name", + "\u00A76/" + command + " variables \u00A7a- lists all available tags"); + } + else if(args.length > 1){ + if(args[1].toLowerCase().equals("help")) { + sendMenu(sender, "Help Command", + "Shows the help section. You can also use a single argument after it to show the " + + "help section for the corresponding command."); + } + else if(args[1].toLowerCase().equals("portalblock")) { + sendMenu(sender, "Help Command", + "Gives you a special wool block to place portal blocks.", + "", + "\u00A7eLeft Click: \u00A76Rotates the hit portal block", + "\u00A7eRight Click: \u00A76Placed a portal block"); + } + else if(args[1].toLowerCase().equals("endportalblock")) { + sendMenu(sender, "Help Command", + "Gives you a special wool block to place end portal blocks.", + "", + "\u00A7eRight Click: \u00A76Placed a end portal block"); + } + else if(args[1].toLowerCase().equals("gatewayblock")) { + sendMenu(sender, "Help Command", + "Gives you a special wool block to place gateway blocks.", + "", + "\u00A7eRight Click: \u00A76Placed a gateway block"); + } + else{ + sender.sendMessage(PluginMessages.customPrefix + " Either \u00A7e" + args[1] + "\u00A7a is not a command or a help page has not been added yet."); + } + } + } + + private void sendMenu(CommandSender sender, String title, String... lines) { + sender.sendMessage(PluginMessages.customPrefix + " " + title); + sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); + for(String line : lines){ + sender.sendMessage("\u00A7a" + line); + } + sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); + } + + private String parseArgVariable(String[] args, int currentArg, String argStarter) { + String variableString = args[currentArg].replaceFirst(argStarter, ""); + this.portalArgsStringLength = 1; + if (variableString.charAt(0) == '"') { + variableString = variableString.substring(1, variableString.length()); + if (variableString.charAt(variableString.length() - 1) != '"') { + currentArg++; + for (; currentArg < args.length; currentArg++) { + variableString += " " + args[currentArg]; + this.portalArgsStringLength += 1; + if (variableString.charAt(variableString.length() - 1) == '"') { + variableString = variableString.substring(0, variableString.length() - 1); + break; + } + } + } else { + variableString = variableString.substring(0, variableString.length() - 1); + } + + } + return variableString; + } + + private void portalEditMenu(CommandSender sender, ConfigAccessor portalConfig, String portalName) { + // make the text gui with the json message for a list of edit commands to be clicked or hovered + // put \" for a " in the json messages + // sadly there is no newline code so these three lines will have to be copied and pasted for each line + + // use the usual messages for normal lines but anything that needs special features make sure you use the + // chat steriliser + sender.sendMessage(""); + 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")); + + String destination = portalConfig.getConfig().getString(portalName + ".destination"); + if (destination != null) { + sender.sendMessage(" \u00A7adestination\u00A7e: " + destination); + } else { + sender.sendMessage(" \u00A7cdestination\u00A7e: null"); + } + + String trigger = portalConfig.getConfig().getString(portalName + ".triggerblock"); + if (trigger != null) { + sender.sendMessage(" \u00A7atriggerBlock\u00A7e: " + trigger); + } else { + sender.sendMessage(" \u00A7ctriggerBlock\u00A7e: null"); + } + + if (portalConfig.getConfig().getString(portalName + ".portalArgs.command.1") != null) { + int commands = 0; + String command = portalConfig.getConfig().getString(portalName + ".portalArgs.command.1"); + // TODO possibly change code so it counds number of subvalues rather than a loop. + while (command != null) { + command = portalConfig.getConfig().getString(portalName + ".portalArgs.command." + ++commands); + } + if (--commands > 1) { + sender.sendMessage(" \u00A7acommands\u00A7e: " + commands + " commands"); + } else { + sender.sendMessage(" \u00A7acommands\u00A7e: " + commands + " command"); + } + } else { + sender.sendMessage(" \u00A7ccommands\u00A7e: none"); + } + sender.sendMessage(""); + + Player player = (Player) sender; + + plugin.compat.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \"," + + "\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal gui remove " + portalName + "\"}}" + + ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"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\":\"\u00A7eTeleport\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(If there is one)\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/desti warp " + destination + "\"}}]}", player); + + sender.sendMessage(""); + + } + + @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 || (args.length == 2 && args[0].toLowerCase().equals("help"))) { + autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "unselect", "command", "selector" + , "show", "gatewayblock", "endportalblock", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage", "warp")); + } else if (args[0].toLowerCase().equals("create")) { + + boolean hasName = false; + boolean hasTriggerBlock = false; + boolean hasDestination = false; + boolean isBungeePortal = false; + boolean needsPermission = false; + boolean hasCommand = false; + + + // TODO change auto complete when quotes are opened and closed. Such as autocomplete @Player and stuff when specifying commands + + for (int i = 1; i < args.length; i++) { + String argTag = getTag(args[i].toLowerCase()); + if (argTag.length() + 1 < args[i].length()) { + switch (argTag) { + case "name": + hasName = true; + break; + case "destination": + hasDestination = true; + break; + case "desti": + hasDestination = true; + break; + case "triggerblock": + hasTriggerBlock = true; + break; + case "bungee": + isBungeePortal = true; + break; + case "permission": + needsPermission = true; + break; + case "command": + hasCommand = true; + break; + } + } + + } + + if (!hasName) { + autoComplete.add("name:"); + } + if (!hasTriggerBlock) { + autoComplete.add("triggerblock:"); + autoComplete.addAll(this.blockMaterialList); + } + if (!hasDestination) { + autoComplete.add("destination:"); + autoComplete.add("desti:"); + } + if (!isBungeePortal) { + autoComplete.add("bungee:"); + } + if (!needsPermission) { + autoComplete.add("permission:"); + } + if (!hasCommand) { + autoComplete.add("command:"); + } + } + } + if (args.length == 2 && args[0].equalsIgnoreCase("warp")){ + for (AdvancedPortal portal :Portal.portals){ + String perm = portal.getArg("permission"); + if (perm == null || sender.hasPermission(perm)){ + autoComplete.add(portal.getName()); + } + } + } + Collections.sort(autoComplete); + for (Object result : autoComplete.toArray()) { + if (!result.toString().startsWith(args[args.length - 1])) { + autoComplete.remove(result); + } + } + return autoComplete; + } + + private String getTag(String arg) { + int indexOfSplitter = arg.indexOf(':'); + if (indexOfSplitter > 0) { + return arg.substring(0, indexOfSplitter); + } + return ""; + } + } \ No newline at end of file diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/main/java/com/sekwah/advancedportals/AdvancedPortalsPlugin.java similarity index 100% rename from src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java rename to src/main/java/com/sekwah/advancedportals/AdvancedPortalsPlugin.java diff --git a/src/com/sekwah/advancedportals/ConfigAccessor.java b/src/main/java/com/sekwah/advancedportals/ConfigAccessor.java similarity index 100% rename from src/com/sekwah/advancedportals/ConfigAccessor.java rename to src/main/java/com/sekwah/advancedportals/ConfigAccessor.java diff --git a/src/com/sekwah/advancedportals/PluginMessages.java b/src/main/java/com/sekwah/advancedportals/PluginMessages.java similarity index 100% rename from src/com/sekwah/advancedportals/PluginMessages.java rename to src/main/java/com/sekwah/advancedportals/PluginMessages.java diff --git a/src/com/sekwah/advancedportals/Selection.java b/src/main/java/com/sekwah/advancedportals/Selection.java similarity index 100% rename from src/com/sekwah/advancedportals/Selection.java rename to src/main/java/com/sekwah/advancedportals/Selection.java diff --git a/src/com/sekwah/advancedportals/Settings.java b/src/main/java/com/sekwah/advancedportals/Settings.java similarity index 100% rename from src/com/sekwah/advancedportals/Settings.java rename to src/main/java/com/sekwah/advancedportals/Settings.java diff --git a/src/com/sekwah/advancedportals/api/events/WarpEvent.java b/src/main/java/com/sekwah/advancedportals/api/events/WarpEvent.java similarity index 100% rename from src/com/sekwah/advancedportals/api/events/WarpEvent.java rename to src/main/java/com/sekwah/advancedportals/api/events/WarpEvent.java diff --git a/src/com/sekwah/advancedportals/api/portaldata/PortalArg.java b/src/main/java/com/sekwah/advancedportals/api/portaldata/PortalArg.java similarity index 100% rename from src/com/sekwah/advancedportals/api/portaldata/PortalArg.java rename to src/main/java/com/sekwah/advancedportals/api/portaldata/PortalArg.java diff --git a/src/com/sekwah/advancedportals/api/portaldata/PortalTags.java b/src/main/java/com/sekwah/advancedportals/api/portaldata/PortalTags.java similarity index 100% rename from src/com/sekwah/advancedportals/api/portaldata/PortalTags.java rename to src/main/java/com/sekwah/advancedportals/api/portaldata/PortalTags.java diff --git a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java b/src/main/java/com/sekwah/advancedportals/api/registry/TagRegistry.java similarity index 100% rename from src/com/sekwah/advancedportals/api/registry/TagRegistry.java rename to src/main/java/com/sekwah/advancedportals/api/registry/TagRegistry.java diff --git a/src/com/sekwah/advancedportals/api/warphandler/ActivationData.java b/src/main/java/com/sekwah/advancedportals/api/warphandler/ActivationData.java similarity index 100% rename from src/com/sekwah/advancedportals/api/warphandler/ActivationData.java rename to src/main/java/com/sekwah/advancedportals/api/warphandler/ActivationData.java diff --git a/src/com/sekwah/advancedportals/api/warphandler/TagHandler.java b/src/main/java/com/sekwah/advancedportals/api/warphandler/TagHandler.java similarity index 100% rename from src/com/sekwah/advancedportals/api/warphandler/TagHandler.java rename to src/main/java/com/sekwah/advancedportals/api/warphandler/TagHandler.java diff --git a/src/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/main/java/com/sekwah/advancedportals/compat/CraftBukkit.java similarity index 100% rename from src/com/sekwah/advancedportals/compat/CraftBukkit.java rename to src/main/java/com/sekwah/advancedportals/compat/CraftBukkit.java diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/main/java/com/sekwah/advancedportals/destinations/Destination.java similarity index 100% rename from src/com/sekwah/advancedportals/destinations/Destination.java rename to src/main/java/com/sekwah/advancedportals/destinations/Destination.java diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/main/java/com/sekwah/advancedportals/destinations/DestinationCommand.java similarity index 100% rename from src/com/sekwah/advancedportals/destinations/DestinationCommand.java rename to src/main/java/com/sekwah/advancedportals/destinations/DestinationCommand.java diff --git a/src/com/sekwah/advancedportals/destinations/PortalWarp.java b/src/main/java/com/sekwah/advancedportals/destinations/PortalWarp.java similarity index 100% rename from src/com/sekwah/advancedportals/destinations/PortalWarp.java rename to src/main/java/com/sekwah/advancedportals/destinations/PortalWarp.java diff --git a/src/com/sekwah/advancedportals/effects/WarpEffects.java b/src/main/java/com/sekwah/advancedportals/effects/WarpEffects.java similarity index 100% rename from src/com/sekwah/advancedportals/effects/WarpEffects.java rename to src/main/java/com/sekwah/advancedportals/effects/WarpEffects.java diff --git a/src/com/sekwah/advancedportals/listeners/BungeeListener.java b/src/main/java/com/sekwah/advancedportals/listeners/BungeeListener.java similarity index 100% rename from src/com/sekwah/advancedportals/listeners/BungeeListener.java rename to src/main/java/com/sekwah/advancedportals/listeners/BungeeListener.java diff --git a/src/com/sekwah/advancedportals/listeners/FlowStopper.java b/src/main/java/com/sekwah/advancedportals/listeners/FlowStopper.java similarity index 100% rename from src/com/sekwah/advancedportals/listeners/FlowStopper.java rename to src/main/java/com/sekwah/advancedportals/listeners/FlowStopper.java diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/main/java/com/sekwah/advancedportals/listeners/Listeners.java similarity index 100% rename from src/com/sekwah/advancedportals/listeners/Listeners.java rename to src/main/java/com/sekwah/advancedportals/listeners/Listeners.java diff --git a/src/com/sekwah/advancedportals/listeners/PortalPlacer.java b/src/main/java/com/sekwah/advancedportals/listeners/PortalPlacer.java similarity index 100% rename from src/com/sekwah/advancedportals/listeners/PortalPlacer.java rename to src/main/java/com/sekwah/advancedportals/listeners/PortalPlacer.java diff --git a/src/com/sekwah/advancedportals/listeners/PortalProtect.java b/src/main/java/com/sekwah/advancedportals/listeners/PortalProtect.java similarity index 100% rename from src/com/sekwah/advancedportals/listeners/PortalProtect.java rename to src/main/java/com/sekwah/advancedportals/listeners/PortalProtect.java diff --git a/src/com/sekwah/advancedportals/metrics/Metrics.java b/src/main/java/com/sekwah/advancedportals/metrics/Metrics.java similarity index 100% rename from src/com/sekwah/advancedportals/metrics/Metrics.java rename to src/main/java/com/sekwah/advancedportals/metrics/Metrics.java diff --git a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java b/src/main/java/com/sekwah/advancedportals/portals/AdvancedPortal.java similarity index 100% rename from src/com/sekwah/advancedportals/portals/AdvancedPortal.java rename to src/main/java/com/sekwah/advancedportals/portals/AdvancedPortal.java diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/main/java/com/sekwah/advancedportals/portals/Portal.java similarity index 100% rename from src/com/sekwah/advancedportals/portals/Portal.java rename to src/main/java/com/sekwah/advancedportals/portals/Portal.java diff --git a/Resources/config.yml b/src/main/resources/config.yml similarity index 100% rename from Resources/config.yml rename to src/main/resources/config.yml diff --git a/Resources/destinations.yml b/src/main/resources/destinations.yml similarity index 100% rename from Resources/destinations.yml rename to src/main/resources/destinations.yml diff --git a/Resources/plugin.yml b/src/main/resources/plugin.yml similarity index 100% rename from Resources/plugin.yml rename to src/main/resources/plugin.yml diff --git a/Resources/portals.yml b/src/main/resources/portals.yml similarity index 100% rename from Resources/portals.yml rename to src/main/resources/portals.yml