diff --git a/.gitignore b/.gitignore index 0f182a0..8977793 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *.class +.* +/target/ # Package Files # *.jar diff --git a/Resources/plugin.yml b/Resources/plugin.yml index 07ea1ea..f3a884c 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -10,10 +10,7 @@ commands: usage: / destination: description: Can be used to access portal destinations. - aliases: [desti] - usage: / - awarp: - description: Used to warp to destinations. + aliases: [desti, awarp] usage: / permissions: advancedportals.*: @@ -22,7 +19,8 @@ permissions: advancedportals.createportal: true advancedportals.portal: true advancedportals.build: true - advancedportals.desti.*: true + advancedportals.desti: true + advancedportals.warp.*: true advancedportals.createportal: description: Allows you to create portals default: op @@ -32,10 +30,9 @@ permissions: advancedportals.build: description: Allows you to build in the portal regions default: op - advancedportals.desti.*: + advancedportals.desti: description: Gives access to all desti commands - children: - advancedportals.desti.create: true - advancedportals.desti.create: - description: Allows users to create portal destinations default: op + advancedportals.warp.*: + description: Access to all warps + default: true diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 8f230eb..80699b6 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -2,6 +2,7 @@ package com.sekwah.advancedportals; 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.Location; import org.bukkit.Material; @@ -38,12 +39,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + Player player = (Player) sender; + PlayerInventory inventory = player.getInventory(); if (sender.hasPermission("advancedportals.portal")) { - if (args.length > 0) { - if (args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")) { - Player player = (Player) sender; - PlayerInventory inventory = player.getInventory(); - + if (args.length > 0) { switch (args[0].toLowerCase()) { + case "wand": + case "selector": String ItemID = config.getConfig().getString("AxeItemId"); @@ -61,18 +63,17 @@ 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!"); - } else if (args[0].toLowerCase().equals("portal") || args[0].toLowerCase().equals("portalblock")) { - Player player = (Player) sender; - PlayerInventory inventory = player.getInventory(); - + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); + break; + case "portal": + case "portalblock": ItemStack portalBlock = new ItemStack(Material.PORTAL, 1); inventory.addItem(portalBlock); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Block\u00A7a!"); - } else if (args[0].toLowerCase().equals("create")) { - Player player = (Player) sender; + 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 @@ -97,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; @@ -127,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; } @@ -141,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); @@ -191,67 +192,66 @@ 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!"); } - } else if (args[0].toLowerCase().equals("variables")) { - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Currently available variables: name, triggerBlock, destination"); + break; + case "variables" : + sender.sendMessage(PluginMessages.customPrefix + " Currently available variables: name, triggerBlock, destination"); sender.sendMessage(""); sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); - } else if (args[0].toLowerCase().equals("select")) { - + break; + case "select": // TODO finish the select command and the hit block to replace! - Player player = (Player) sender; if (!player.hasMetadata("selectingPortal")) { if (args.length > 1) { 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!"); } - } else if (args[0].toLowerCase().equals("gui")) { - Player player = (Player) sender; + 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.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(""); } } - } else if (args[0].toLowerCase().equals("edit")) { - Player player = (Player) sender; - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + 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("\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,19 +260,18 @@ 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!"); } } - } else if (args[0].toLowerCase().equals("rename")) { + break; + case "rename": // not finished yet / - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); if (args.length > 1) { - Player player = (Player) sender; if (player.hasMetadata("selectedPortal")) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); if (portalName.toLowerCase() != args[1].toLowerCase()) { @@ -281,25 +280,25 @@ 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!"); } - } else if (args[0].toLowerCase().equals("command")) { - Player player = (Player) sender; + break; + case "command": if (player.hasMetadata("selectedPortal")) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); if (args.length > 1) { @@ -311,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")) { @@ -325,80 +324,91 @@ 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 { } - } else if (args[0].toLowerCase().equals("remove")) { - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + 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("\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 { - Player player = (Player) sender; 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("\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!"); } } - } else if (args[0].toLowerCase().equals("help")) { - 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"); - } else if (args[0].toLowerCase().equals("bukkitpage")) { - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] CraftBukkit page: http://bit.ly/adv-portals!"); - } else if (args[0].toLowerCase().equals("helppage")) { - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Help page: http://bit.ly/portals-help!"); - } else if (args[0].toLowerCase().equals("show")) { - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); - Player player = (Player) sender; + break; + case "help": + 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) { String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); 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("Pos1World") && player.hasMetadata("Pos2World")) { + 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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected area has been shown, it will dissapear shortly!"); - Selection.Show(player, this.plugin); - } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The points you have selected need to be in the same world!"); + 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] You need to have both points selected!"); + player.sendMessage(PluginMessages.customPrefixFail + " No regions selected!"); } } - } else if (args[0].toLowerCase().equals("reload")) { - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!"); + break; + case "reload": + sender.sendMessage(PluginMessages.customPrefix + " Reloaded values!"); Listeners.reloadValues(plugin); Portal.loadPortals(); - } else { + break; + case "list" : + String message = PluginMessages.customPrefix + " \u00A7c:\u00A7a"; + for (AdvancedPortal portal : Portal.Portals) { + message = message + " " + portal.portalName; + } + player.sendMessage(message); + break; + default: PluginMessages.UnknownCommand(sender, command); } } else { PluginMessages.UnknownCommand(sender, command); } - } else { PluginMessages.NoPermission(sender, command); } @@ -437,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")); diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index ede6fba..ce88875 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -2,7 +2,7 @@ package com.sekwah.advancedportals; import com.sekwah.advancedportals.DataCollector.DataCollector; import com.sekwah.advancedportals.compat.CraftBukkit; -import com.sekwah.advancedportals.destinations.Destination; +import com.sekwah.advancedportals.destinations.*; import com.sekwah.advancedportals.effects.WarpEffects; import com.sekwah.advancedportals.listeners.*; import com.sekwah.advancedportals.metrics.Metrics; @@ -13,12 +13,6 @@ import java.io.IOException; public class AdvancedPortalsPlugin extends JavaPlugin { - public boolean useCustomPrefix = false; - - public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]"; - - public String customPrefixFail = "\u00A7c[\u00A77AdvancedPortals\u00A7c]"; - public CraftBukkit compat = null; public void onEnable() { @@ -55,10 +49,11 @@ public class AdvancedPortalsPlugin extends JavaPlugin { new DataCollector(this); + // These register the commands + new PluginMessages(this); new AdvancedPortalsCommand(this); new DestinationCommand(this); - new WarpCommand(this); new WarpEffects(this); @@ -95,14 +90,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { // thanks to the new config accessor code the config.saveDefaultConfig(); will now // only copy the file if it doesnt exist! - ConfigAccessor config = new ConfigAccessor(this, "config.yml"); - - this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix"); - if (useCustomPrefix) { - this.customPrefix = config.getConfig().getString("CustomPrefix").replaceAll("&", "\u00A7"); - this.customPrefixFail = config.getConfig().getString("CustomPrefixFail").replaceAll("&", "\u00A7"); - } - } diff --git a/src/com/sekwah/advancedportals/DestinationCommand.java b/src/com/sekwah/advancedportals/DestinationCommand.java deleted file mode 100644 index 6ebb05a..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.compat.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/Selection.java b/src/com/sekwah/advancedportals/Selection.java index 28d1e0d..d617ca1 100644 --- a/src/com/sekwah/advancedportals/Selection.java +++ b/src/com/sekwah/advancedportals/Selection.java @@ -34,85 +34,6 @@ public class Selection { @SuppressWarnings("deprecation") public static void Show(final Player player, final AdvancedPortalsPlugin plugin, String portalName) { - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); - - int LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X"); - int LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y"); - int LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z"); - - int HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X"); - int HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y"); - int HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z"); - - final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ); - final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ); - - /* - * There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements - * then i will change it, but for now its the best way i can think of for doing this. - */ - - for (int x = LowX; x <= HighX; x++) { - Location loc = new Location(player.getWorld(), x, LowY, LowZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int x = LowX; x <= HighX; x++) { - Location loc = new Location(player.getWorld(), x, LowY, HighZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int z = LowZ; z <= HighZ; z++) { - Location loc = new Location(player.getWorld(), LowX, LowY, z); - player.sendBlockChange(loc, blockType, metadata); - } - for (int z = LowZ; z <= HighZ; z++) { - Location loc = new Location(player.getWorld(), HighX, LowY, z); - player.sendBlockChange(loc, blockType, metadata); - } - for (int y = LowY; y <= HighY; y++) { - Location loc = new Location(player.getWorld(), LowX, y, LowZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int y = LowY; y <= HighY; y++) { - Location loc = new Location(player.getWorld(), LowX, y, HighZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int y = LowY; y <= HighY; y++) { - Location loc = new Location(player.getWorld(), HighX, y, LowZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int y = LowY; y <= HighY; y++) { - Location loc = new Location(player.getWorld(), HighX, y, HighZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int x = LowX; x <= HighX; x++) { - Location loc = new Location(player.getWorld(), x, HighY, HighZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int x = LowX; x <= HighX; x++) { - Location loc = new Location(player.getWorld(), x, HighY, LowZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int z = LowZ; z <= HighZ; z++) { - Location loc = new Location(player.getWorld(), LowX, HighY, z); - player.sendBlockChange(loc, blockType, metadata); - } - for (int z = LowZ; z <= HighZ; z++) { - Location loc = new Location(player.getWorld(), HighX, HighY, z); - player.sendBlockChange(loc, blockType, metadata); - } - - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - Selection.Hide(player, plugin, pos1, pos2); - } - }, timeout * 20); - - } - - @SuppressWarnings("deprecation") - public static void Show(final Player player, final AdvancedPortalsPlugin plugin) { - int LowX = 0; int LowY = 0; int LowZ = 0; @@ -121,31 +42,43 @@ public class Selection { int HighY = 0; int HighZ = 0; - if (player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()) { - LowX = player.getMetadata("Pos2X").get(0).asInt(); - HighX = player.getMetadata("Pos1X").get(0).asInt(); + if (portalName != null) { + ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + + LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X"); + LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y"); + LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z"); + + HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X"); + HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y"); + HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z"); } else { - LowX = player.getMetadata("Pos1X").get(0).asInt(); - HighX = player.getMetadata("Pos2X").get(0).asInt(); - } - if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) { - LowY = player.getMetadata("Pos2Y").get(0).asInt(); - HighY = player.getMetadata("Pos1Y").get(0).asInt(); - } else { - LowY = player.getMetadata("Pos1Y").get(0).asInt(); - HighY = player.getMetadata("Pos2Y").get(0).asInt(); - } - if (player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()) { - LowZ = player.getMetadata("Pos2Z").get(0).asInt(); - HighZ = player.getMetadata("Pos1Z").get(0).asInt(); - } else { - LowZ = player.getMetadata("Pos1Z").get(0).asInt(); - HighZ = player.getMetadata("Pos2Z").get(0).asInt(); + if (player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()) { + LowX = player.getMetadata("Pos2X").get(0).asInt(); + HighX = player.getMetadata("Pos1X").get(0).asInt(); + } else { + LowX = player.getMetadata("Pos1X").get(0).asInt(); + HighX = player.getMetadata("Pos2X").get(0).asInt(); + } + if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) { + LowY = player.getMetadata("Pos2Y").get(0).asInt(); + HighY = player.getMetadata("Pos1Y").get(0).asInt(); + } else { + LowY = player.getMetadata("Pos1Y").get(0).asInt(); + HighY = player.getMetadata("Pos2Y").get(0).asInt(); + } + if (player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()) { + LowZ = player.getMetadata("Pos2Z").get(0).asInt(); + HighZ = player.getMetadata("Pos1Z").get(0).asInt(); + } else { + LowZ = player.getMetadata("Pos1Z").get(0).asInt(); + HighZ = player.getMetadata("Pos2Z").get(0).asInt(); + } } final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ); final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ); - + /* * There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements * then i will change it, but for now its the best way i can think of for doing this. diff --git a/src/com/sekwah/advancedportals/WarpCommand.java b/src/com/sekwah/advancedportals/WarpCommand.java deleted file mode 100644 index 5ec9d62..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.compat.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/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/FlowStopper.java b/src/com/sekwah/advancedportals/listeners/FlowStopper.java index eb3ed4d..6942db7 100644 --- a/src/com/sekwah/advancedportals/listeners/FlowStopper.java +++ b/src/com/sekwah/advancedportals/listeners/FlowStopper.java @@ -32,22 +32,8 @@ public class FlowStopper implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onBlockFromTo(BlockFromToEvent event) { - // when checking positions check the block and the to block - Block blockTo = event.getToBlock(); - Block block = event.getBlock(); - - - int floodRegion = 3; - - AdvancedPortal inPortal = Portal.blockLocationInPortal(block.getLocation(), floodRegion); - if(inPortal != null){ + if (Portal.inPortalRegion(event.getBlock().getLocation(), 3) | Portal.inPortalRegion(event.getToBlock().getLocation(), 3)) event.setCancelled(true); - } - - inPortal = Portal.blockLocationInPortal(blockTo.getLocation(), floodRegion); - if(inPortal != null){ - event.setCancelled(true); - } } diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index d153d43..9b708b9 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -2,11 +2,11 @@ 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; import org.bukkit.*; -import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -15,40 +15,18 @@ import org.bukkit.event.block.Action; import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.metadata.FixedMetadataValue; -import java.util.HashMap; - public class Listeners implements Listener { - - // TODO rewrite and remove unneeded listeners and also fix the warp delay using a hashmap of users last attempt times. - - - // TODO rewrite listeners and take into account the portal cooldown and what happens if they start in a portal (or are warped into a portal). - // The needed config values will be stored so they are easier to access later // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP... private static boolean UseOnlyServerAxe = false; - - /** - * Can't enter another portal until this time has passed. - */ - private HashMap hasPortalCooldown = new HashMap(); - - /** - * Cant use portals until they leave one. - */ - private HashMap hasPortalImmunity = new HashMap(); - private static Material WandMaterial; - - //private static boolean ShowBungeeMessage; - + private static boolean ShowBungeeMessage; private final AdvancedPortalsPlugin plugin; - private int PortalMessagesDisplay = 2; @SuppressWarnings("deprecation") @@ -77,7 +55,7 @@ public class Listeners implements Listener { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); - //ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); + ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); String ItemID = config.getConfig().getString("AxeItemId"); @@ -88,63 +66,43 @@ public class Listeners implements Listener { } } + @EventHandler + public void onJoinEvent(PlayerJoinEvent event) { + Portal.cooldown.put(event.getPlayer(), System.currentTimeMillis()); + } @EventHandler(priority = EventPriority.HIGHEST) public void onMoveEvent(PlayerMoveEvent event) { + // will check if the player is in the portal or not. + if (!Portal.portalsActive) { + return; + } Player player = event.getPlayer(); - - /** - * use to find speed and possibly launch backwards if they should not enter the portal yet (stops so many repeated enter attempts) - */ - Location fromloc = event.getFrom(); + //Location fromloc = event.getFrom(); Location loc = event.getTo(); - - AdvancedPortal inPortal = Portal.playerInPortal(player); - if(inPortal != null){ - WarpEvent warpEvent = new WarpEvent(player, inPortal); - plugin.getServer().getPluginManager().callEvent(warpEvent); - - if (!event.isCancelled()) { - boolean warped = Portal.activate(player, inPortal); - if (PortalMessagesDisplay == 1 && warped) { - player.sendMessage(""); - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + inPortal.destiation.replaceAll("_", " ") + "\u00A7."); - player.sendMessage(""); - } else if (PortalMessagesDisplay == 2 && warped) { - ConfigAccessor config = new ConfigAccessor(plugin, "inPortals.yml"); - plugin.compat.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + inPortal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player); + 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)) { + if (portal.trigger.equals(Material.PORTAL)) { + if (player.getGameMode().equals(GameMode.CREATIVE)) { + player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10); + } + } else if (portal.trigger.equals(Material.LAVA)) { + player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); } - if (!warped) { - player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); - - event.setCancelled(true); - - } - } - if (inPortal.trigger.equals(Material.PORTAL)) { - if (player.getGameMode().equals(GameMode.CREATIVE)) { - player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10); - } - } else if (inPortal.trigger.equals(Material.LAVA)) { - 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); } } - @EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST) - public void onPlayerTeleport(PlayerTeleportEvent event){ - Player player = event.getPlayer(); - //plugin.getLogger().info(String.valueOf(event.getCause())); - AdvancedPortal inPortal = Portal.playerInPortal(player); - if(inPortal != null){ - event.setCancelled(true); - } - } - // These are here because java 7 can only take finals straight into a runnable class RemoveLavaData implements Runnable{ @@ -181,57 +139,26 @@ public class Listeners implements Listener { @EventHandler public void onCombustEntityEvent(EntityCombustEvent event) { - Location loc = event.getEntity().getLocation(); - - AdvancedPortal inPortal = Portal.locationInPortal(loc,3); - if(inPortal != null){ + if (Portal.inPortalTriggerRegion(event.getEntity().getLocation())) event.setCancelled(true); - } } @EventHandler public void onDamEvent(EntityDamageEvent event) { - - //System.out.println(event.getCause()); if (event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK) { - - - if (event.getEntity().hasMetadata("lavaWarped")) { + if (event.getEntity().hasMetadata("lavaWarped") | Portal.inPortalTriggerRegion(event.getEntity().getLocation())) event.setCancelled(true); - return; - } - - Location loc = event.getEntity().getLocation(); - - AdvancedPortal inPortal = Portal.locationInPortal(loc,3); - if(inPortal != null){ - event.setCancelled(true); - return; - } } - } // https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerTeleportEvent.TeleportCause.html // Also listen to this possibly. - @SuppressWarnings("deprecation") @EventHandler public void onPortalEvent(PlayerPortalEvent event) { - Player player = event.getPlayer(); - - if (player.hasMetadata("hasWarped")) { + if (player.hasMetadata("hasWarped") | Portal.inPortalTriggerRegion(player.getLocation())) event.setCancelled(true); - return; - } - - AdvancedPortal inPortal = Portal.playerInPortal(player); - if(inPortal != null){ - event.setCancelled(true); - } - - } @EventHandler @@ -242,23 +169,16 @@ public class Listeners implements Listener { Player player = event.getPlayer(); if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { - if (!Portal.portalsActive) { - player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled."); - event.setCancelled(true); - player.removeMetadata("selectingPortal", plugin); - return; + for (AdvancedPortal portal : Portal.Portals) { + if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) { + 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; + } } - - Block block = event.getClickedBlock(); - AdvancedPortal inPortal = Portal.blockLocationInPortal(block.getLocation()); - if(inPortal != null){ - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have selected: \u00A7e" + inPortal.portalName); - player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, inPortal.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/listeners/PortalPlacer.java b/src/com/sekwah/advancedportals/listeners/PortalPlacer.java index 6679947..73c7c09 100644 --- a/src/com/sekwah/advancedportals/listeners/PortalPlacer.java +++ b/src/com/sekwah/advancedportals/listeners/PortalPlacer.java @@ -2,7 +2,6 @@ package com.sekwah.advancedportals.listeners; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; -import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; import org.bukkit.Material; import org.bukkit.block.Block; @@ -39,16 +38,7 @@ public class PortalPlacer implements Listener { public void onBlockPhysics(BlockPhysicsEvent event) { Block block = event.getBlock(); Material material = block.getType(); - if (material == Material.PORTAL) { - - AdvancedPortal inPortal = Portal.blockLocationInPortal(block.getLocation(), PortalProtectionRadius); - if(inPortal != null){ - event.setCancelled(true); - } - //event.getChangedType(); - //event.setCancelled(true); - } + if (material == Material.PORTAL && Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius)) + event.setCancelled(true); } - - } diff --git a/src/com/sekwah/advancedportals/listeners/PortalProtect.java b/src/com/sekwah/advancedportals/listeners/PortalProtect.java index 19e3af8..dc2a1a8 100644 --- a/src/com/sekwah/advancedportals/listeners/PortalProtect.java +++ b/src/com/sekwah/advancedportals/listeners/PortalProtect.java @@ -38,40 +38,18 @@ public class PortalProtect implements Listener { } } - @SuppressWarnings("unused") @EventHandler(priority = EventPriority.HIGH) public void onBlockBreak(BlockBreakEvent event) { - - if (!Portal.portalsActive) { - return; - } - - if (!event.getPlayer().hasPermission("advancedportals.build")) { - Block block = event.getBlock(); - - AdvancedPortal inPortal = Portal.locationInPortal(block.getLocation(), PortalProtectionRadius); - if(inPortal != null){ - event.setCancelled(true); - } - } + if (!event.getPlayer().hasPermission("advancedportals.build") + && Portal.inPortalRegion(event.getBlock().getLocation(), PortalProtectionRadius)) + event.setCancelled(true); } - @SuppressWarnings("unused") @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { - - if (!Portal.portalsActive) { - return; - } - - if (!event.getPlayer().hasPermission("advancedportals.build")) { - Block block = event.getBlock(); - - AdvancedPortal inPortal = Portal.locationInPortal(block.getLocation(), PortalProtectionRadius); - if(inPortal != null){ - event.setCancelled(true); - } - } + if (!event.getPlayer().hasPermission("advancedportals.build") + && Portal.inPortalRegion(event.getBlock().getLocation(), PortalProtectionRadius)) + event.setCancelled(true); } @EventHandler(priority = EventPriority.HIGH) @@ -84,9 +62,7 @@ public class PortalProtect implements Listener { List blockList = event.blockList(); for (int i = 0; i < blockList.size(); i++) { Block block = blockList.get(i); - - AdvancedPortal inPortal = Portal.locationInPortal(block.getLocation(), PortalProtectionRadius); - if(inPortal != null){ + if (Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius)) { blockList.remove(i); i--; } diff --git a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java b/src/com/sekwah/advancedportals/portals/AdvancedPortal.java index eb712aa..3f8453d 100644 --- a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java +++ b/src/com/sekwah/advancedportals/portals/AdvancedPortal.java @@ -1,8 +1,10 @@ package com.sekwah.advancedportals.portals; import com.sekwah.advancedportals.api.portaldata.PortalArg; +import java.util.HashSet; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.Player; public class AdvancedPortal { @@ -25,6 +27,8 @@ public class AdvancedPortal { public PortalArg[] portalArgs = null; + public HashSet inPortal = new HashSet(); + // TODO think of relaying out the data input to a more logical format. public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs) { this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs); diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 6bda89e..35f4f11 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -4,8 +4,10 @@ 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; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -15,28 +17,24 @@ import org.bukkit.permissions.PermissionAttachment; import com.sekwah.advancedportals.api.portaldata.PortalArg; import java.util.ArrayList; +import java.util.HashMap; import java.util.Set; import java.util.logging.Level; public class Portal { - - /** - * Maybe change to get portals active so it cant be changed by plugins :P - */ + public static HashMap cooldown = new HashMap(); + // Config values public static boolean portalsActive = false; - - /** - * possibly create a hashmap of portals and worlds for quicker access (it might not be tho) - */ - public static AdvancedPortal[] Portals = new AdvancedPortal[0]; private static AdvancedPortalsPlugin plugin; public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml"); private static boolean ShowBungeeMessage; + private static int cooldelay = 5; public Portal(AdvancedPortalsPlugin plugin) { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); + cooldelay = config.getConfig().getInt("Cooldown"); Portal.plugin = plugin; Portal.loadPortals(); @@ -363,7 +361,7 @@ public class Portal { // add other variables or filter code here, or somehow have a way to register them // TODO on load and unload recode the permissions to try to register themselves - // https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/PluginManager.html#addPermission(org.CraftBukkit.permissions.Permission) + // https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/PluginManager.html#addPermission(org.bukkit.permissions.Permission) // check they havent been registered before too and store a list of ones made by this plugin to remove when portals are unloaded. // When a portal is added or removed it reloads all portals(i think) so add code for unloading too. @@ -371,10 +369,18 @@ 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; } + if (cooldown.get(player) != null) { + int diff = (int) ((System.currentTimeMillis() - cooldown.get(player)) / 1000); + if (diff < cooldelay) { + player.sendMessage(ChatColor.RED + "Please wait " + ChatColor.YELLOW + (cooldelay - diff) + ChatColor.RED + " seconds until attempting to teleport again."); + return false; + } + } + cooldown.put(player, System.currentTimeMillis()); boolean showFailMessage = true; if (portal.getArg("command.1") != null) { @@ -389,7 +395,7 @@ public class Portal { command = command.substring(1); plugin.getLogger().log(Level.INFO, "Portal command: " + command); try{ - plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); + plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); } catch(Exception e){ plugin.getLogger().warning("Error while executing: " + command); @@ -421,25 +427,19 @@ 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"); out.writeUTF(portal.bungee); player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); // Down to bungee to sort out the teleporting but yea theoretically they should warp. - return true; } else if (portal.destiation != null) { ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml"); 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!"); - return false; } } else { if (showFailMessage) { @@ -447,8 +447,8 @@ public class Portal { 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!"); } - return false; } + return false; } public static void rename(String oldName, String newName) { @@ -494,6 +494,36 @@ public class Portal { } } + public static boolean inPortalTriggerRegion(Location loc) { + for (AdvancedPortal portal : Portal.Portals) + if (Portal.locationInPortalTrigger(portal, loc)) + return true; + return false; + } + + public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) { + if (portal.trigger.equals(loc.getBlock().getType())) + return locationInPortal(portal, loc, 0); + return false; + } + + public static boolean inPortalRegion(Location loc, int additionalArea) { + for (AdvancedPortal portal : Portal.Portals) + if (Portal.locationInPortal(portal, loc, additionalArea)) + return true; + return false; + } + + public static boolean locationInPortal(AdvancedPortal portal, Location loc, int additionalArea) { + if (!portalsActive) + return false; + if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) + if ((portal.pos1.getX() + 1 + additionalArea) >= loc.getX() && (portal.pos1.getY() + 1 + additionalArea) > loc.getY() && (portal.pos1.getZ() + 1 + additionalArea) >= loc.getZ()) + if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) + return true; + return false; + } + public static AdvancedPortal locationInPortal(Location loc){ return locationInPortal(loc, 0); }