From 5430c27999b3197cb6ad4184400d34d954a54081 Mon Sep 17 00:00:00 2001 From: Alastair Date: Tue, 29 Mar 2016 12:38:03 +0100 Subject: [PATCH] cleaned up the code --- .../AdvancedPortalsCommand.java | 1042 ++++++++--------- .../AdvancedPortalsPlugin.java | 149 ++- .../DataCollector/DataCollector.java | 98 +- .../advancedportals/DestinationCommand.java | 285 +++-- .../advancedportals/PluginMessages.java | 22 +- src/com/sekwah/advancedportals/Selection.java | 520 ++++---- .../sekwah/advancedportals/WarpCommand.java | 117 +- .../advancedportals/compat/bukkit/NMS.java | 6 +- .../compat/bukkit/v1_8_R1.java | 30 +- .../compat/bukkit/v1_8_R2.java | 30 +- .../compat/bukkit/v1_8_R3.java | 30 +- .../compat/bukkit/v1_9_R1.java | 30 +- .../destinations/Destination.java | 353 +++--- .../advancedportals/effects/WarpEffects.java | 90 +- .../advancedportals/events/WarpEvent.java | 86 +- .../listeners/FlowStopper.java | 82 +- .../advancedportals/listeners/Listeners.java | 481 ++++---- .../listeners/PortalPlacer.java | 41 +- .../listeners/PortalProtect.java | 136 +-- .../advancedportals/metrics/Metrics.java | 230 ++-- .../portals/AdvancedPortal.java | 86 +- .../advancedportals/portals/ArgRegistry.java | 3 +- .../advancedportals/portals/Portal.java | 777 ++++++------ .../advancedportals/portals/PortalArg.java | 2 +- .../advancedportals/portals/PortalTags.java | 10 +- 25 files changed, 2309 insertions(+), 2427 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index f149510b..b51d1f10 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -20,609 +20,555 @@ import java.util.*; public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { - private AdvancedPortalsPlugin plugin; + private AdvancedPortalsPlugin plugin; - private int portalArgsStringLength = 0; + 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<>(); + // 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; + public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; - plugin.getCommand("advancedportals").setExecutor(this); - } + plugin.getCommand("advancedportals").setExecutor(this); + } - @SuppressWarnings("deprecation") - @Override - public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - 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(); + @SuppressWarnings("deprecation") + @Override + public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + 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(); - String ItemID = config.getConfig().getString("AxeItemId"); + String ItemID = config.getConfig().getString("AxeItemId"); - Material WandMaterial = Material.getMaterial(ItemID); + Material WandMaterial = Material.getMaterial(ItemID); - if(WandMaterial == null){ - WandMaterial = Material.IRON_AXE; - } + 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); + 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("\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(); + 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(); - ItemStack portalBlock = new ItemStack(Material.PORTAL, 1); + ItemStack portalBlock = new ItemStack(Material.PORTAL, 1); - inventory.addItem(portalBlock); + 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; - 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; + sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Block\u00A7a!"); + } else if (args[0].toLowerCase().equals("create")) { + Player player = (Player) sender; + 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<>(); + 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("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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; - extraData.add(new PortalArg("command.1", portalCommand)); - } - } - if(!hasName){ - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that you are creating in the variables!"); - return true; - } + 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("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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; + extraData.add(new PortalArg("command.1", portalCommand)); + } + } + if (!hasName) { + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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()); + 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 + ".pos1.X"); + ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml"); + String destiPosX = desticonfig.getConfig().getString(destination + ".pos1.X"); - if(!Portal.portalExists(portalName)){ + if (!Portal.portalExists(portalName)) { - player.sendMessage(""); - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a]\u00A7e You have created a new portal with the following details:"); - player.sendMessage("\u00A7aname: \u00A7e" + portalName); - if(hasDestination){ - player.sendMessage("\u00A7adestination: \u00A7e" + destination); - } - else if(destiPosX == null){ - player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)"); - } - else{ - player.sendMessage("\u00A7cdestination: \u00A7eN/A (will not work)"); - } + player.sendMessage(""); + player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a]\u00A7e You have created a new portal with the following details:"); + player.sendMessage("\u00A7aname: \u00A7e" + portalName); + if (hasDestination) { + player.sendMessage("\u00A7adestination: \u00A7e" + destination); + } else if (destiPosX == null) { + player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)"); + } else { + player.sendMessage("\u00A7cdestination: \u00A7eN/A (will not work)"); + } - if(isBungeePortal){ - player.sendMessage("\u00A7abungee: \u00A7e" + serverName); - } + if (isBungeePortal) { + player.sendMessage("\u00A7abungee: \u00A7e" + serverName); + } - if(needsPermission){ - player.sendMessage("\u00A7apermission: \u00A7e" + permission); - } - else{ - player.sendMessage("\u00A7apermission: \u00A7e(none needed)"); - } + if (needsPermission) { + player.sendMessage("\u00A7apermission: \u00A7e" + permission); + } else { + player.sendMessage("\u00A7apermission: \u00A7e(none needed)"); + } - if(executesCommand){ - player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); - } + if (executesCommand) { + player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); + } - Material triggerBlockMat = Material.getMaterial(0); - 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") + ")"); + Material triggerBlockMat = Material.getMaterial(0); + 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("\u00A7c[\u00A77AdvancedPortals\u00A7c] A portal by that name already exists!"); - } + 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("\u00A7c[\u00A77AdvancedPortals\u00A7c] A portal by that name already exists!"); + } - // add code to save the portal to the portal config and reload the portals + // 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" - + " 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!"); - } - } - else{ - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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"); - sender.sendMessage(""); - sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); - } - else if(args[0].toLowerCase().equals("select")) { + 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" + + " 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!"); + } + } else { + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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"); + sender.sendMessage(""); + sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); + } else if (args[0].toLowerCase().equals("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!"); - } - } - else{ - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Hit a block inside the portal region to select the portal!"); - player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true)); - } + // 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!"); + } + } else { + player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] 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!"); - } - } - else if(args[0].toLowerCase().equals("gui")){ - Player player = (Player)sender; - 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(""); - plugin.nmsAccess.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + - "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " + args[2] + "\"}}]}", player); - sender.sendMessage(""); - } - } - } - else if(args[0].toLowerCase().equals("edit")) { - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); - if(args.length > 1){ - String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); - if(posX != null){ - portalEditMenu(sender, portalConfig, args[1]); - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c 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){ - portalEditMenu(sender, portalConfig, portalName); - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); - } - } - } - else if(args[0].toLowerCase().equals("rename")) { + } else { + player.removeMetadata("selectingPortal", plugin); + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Portal selection cancelled!"); + } + } else if (args[0].toLowerCase().equals("gui")) { + Player player = (Player) sender; + 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(""); + plugin.nmsAccess.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + + "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " + args[2] + "\"}}]}", player); + sender.sendMessage(""); + } + } + } else if (args[0].toLowerCase().equals("edit")) { + ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + if (args.length > 1) { + String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); + if (posX != null) { + portalEditMenu(sender, portalConfig, args[1]); + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c 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) { + portalEditMenu(sender, portalConfig, portalName); + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); + } + } + } else if (args[0].toLowerCase().equals("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()){ - String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); + // 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()) { + 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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] 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!"); - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); - } - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); - } - } - else if(args[0].toLowerCase().equals("command")) { - Player player = (Player)sender; - 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("\u00A77a[\u00A77eAdvancedPortals\u00A77a] Command added to portal!"); - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Failed to add command to portal!"); - } + 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."); + 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!"); + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); + } + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); + } + } else if (args[0].toLowerCase().equals("command")) { + Player player = (Player) sender; + 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("\u00A77a[\u00A77eAdvancedPortals\u00A77a] Command added to portal!"); + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Failed to add command to portal!"); + } - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must actually specify a command to execute!"); - } + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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")) { - // Show all the commands the portal executes - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); - } - } - else{ + } else if (args[1].toLowerCase().equals("remove")) { + // Specify what line to remove + } 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!"); + } + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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"); - 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!"); - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); - } - } - } - 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] Bukkit 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; - 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!"); - } - } - 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!"); - } - } - else{ - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have both points selected!"); - } - } - } - else if(args[0].toLowerCase().equals("reload")) { - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!"); - Listeners.reloadValues(plugin); - Portal.loadPortals(); - } - else{ - PluginMessages.UnknownCommand(sender, command); - } - } - else{ - PluginMessages.UnknownCommand(sender, command); - } + } + } else if (args[0].toLowerCase().equals("remove")) { + ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + 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!"); + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] 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!"); + } + } + } 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] Bukkit 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; + 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!"); + } + } 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!"); + } + } else { + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have both points selected!"); + } + } + } else if (args[0].toLowerCase().equals("reload")) { + sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!"); + Listeners.reloadValues(plugin); + Portal.loadPortals(); + } else { + PluginMessages.UnknownCommand(sender, command); + } + } else { + PluginMessages.UnknownCommand(sender, command); + } - } - else{ - PluginMessages.NoPermission(sender, command); - } + } else { + PluginMessages.NoPermission(sender, command); + } - return true; - } + return true; + } - 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); - } + 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; - } + } + 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 + 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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Editing: \u00A7e" + portalName); + // 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(" \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")); + 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 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"); - } + 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(""); + 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; + Player player = (Player) sender; - plugin.nmsAccess.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \",\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal gui remove " + portalName + "\"}}" - + ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal show " + portalName + "\"}}" - + ",{\"text\":\" \"},{\"text\":\"\u00A7eRename\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Change the name of the portal\"},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/portal rename \"}}" - + ",{\"text\":\" \"},{\"text\":\"\u00A7eActivate\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(same as entering the portal)\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/warp " + destination + "\"}}]}", player); + plugin.nmsAccess.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \",\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal gui remove " + portalName + "\"}}" + + ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal show " + portalName + "\"}}" + + ",{\"text\":\" \"},{\"text\":\"\u00A7eRename\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Change the name of the portal\"},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/portal rename \"}}" + + ",{\"text\":\" \"},{\"text\":\"\u00A7eActivate\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(same as entering the portal)\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/warp " + destination + "\"}}]}", player); - sender.sendMessage(""); + 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){ - autoComplete.addAll(Arrays.asList("create", "portal", "portalblock", "select", "selector" - , "show", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage")); - } - else if(args[0].toLowerCase().equals("create")){ + @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", "portal", "portalblock", "select", "selector" + , "show", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage")); + } 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; + 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 + // 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; - } - } + 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:");} - if(!hasDestination){autoComplete.add("destination:");autoComplete.add("desti:");} - if(!isBungeePortal){autoComplete.add("bungee:");} - if(!needsPermission){autoComplete.add("permission:");} - if(!hasCommand){autoComplete.add("command:");} - } - } - Collections.sort(autoComplete); - for(Object result: autoComplete.toArray()){ - if(!result.toString().startsWith(args[args.length - 1])){ - autoComplete.remove(result); - } - } - return autoComplete; - } + if (!hasName) { + autoComplete.add("name:"); + } + if (!hasTriggerBlock) { + autoComplete.add("triggerblock:"); + } + if (!hasDestination) { + autoComplete.add("destination:"); + autoComplete.add("desti:"); + } + if (!isBungeePortal) { + autoComplete.add("bungee:"); + } + if (!needsPermission) { + autoComplete.add("permission:"); + } + if (!hasCommand) { + autoComplete.add("command:"); + } + } + } + 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 ""; - } + 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/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index bc008708..17400cec 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -14,100 +14,99 @@ import java.lang.reflect.InvocationTargetException; public class AdvancedPortalsPlugin extends JavaPlugin { - public NMS nmsAccess; + public NMS nmsAccess; - public boolean useCustomPrefix = false; + public boolean useCustomPrefix = false; - public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]"; + public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]"; - public void onEnable() { + public void onEnable() { - try { - Metrics metrics = new Metrics(this); - metrics.start(); - } catch (IOException e) { - // Failed to submit the stats :-( - } + try { + Metrics metrics = new Metrics(this); + metrics.start(); + } catch (IOException e) { + // Failed to submit the stats :-( + } - this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); + this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); - String packageName = getServer().getClass().getPackage().getName(); - String[] packageSplit = packageName.split("\\."); - String version = packageSplit[packageSplit.length - 1]; + String packageName = getServer().getClass().getPackage().getName(); + String[] packageSplit = packageName.split("\\."); + String version = packageSplit[packageSplit.length - 1]; - try { - Class nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version); - if(NMS.class.isAssignableFrom(nmsClass)){ - this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance(); - }else - { - System.out.println("Something went wrong, please notify the author and tell them this version v:" + version); - this.setEnabled(false); - } - } catch (ClassNotFoundException e) { - System.out.println("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version); - this.setEnabled(false); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | - NoSuchMethodException | SecurityException e) { - e.printStackTrace(); - } + try { + Class nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version); + if (NMS.class.isAssignableFrom(nmsClass)) { + this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance(); + } else { + System.out.println("Something went wrong, please notify the author and tell them this version v:" + version); + this.setEnabled(false); + } + } catch (ClassNotFoundException e) { + System.out.println("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version); + this.setEnabled(false); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | + NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } - saveDefaultConfig(); + saveDefaultConfig(); - // thanks to the new config accessor code the config.saveDefaultConfig(); will now - // only copy the file if it doesnt exist! - ConfigAccessor config = new ConfigAccessor(this, "config.yml"); + // 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"); - } + this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix"); + if (useCustomPrefix) { + this.customPrefix = config.getConfig().getString("CustomPrefix"); + } - ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); - portalConfig.saveDefaultConfig(); + ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); + portalConfig.saveDefaultConfig(); - ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); - destinationConfig.saveDefaultConfig(); + ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); + destinationConfig.saveDefaultConfig(); + + new Assets(this); + + // Opens a channel that messages bungeeCord + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - new Assets(this); - - // Opens a channel that messages bungeeCord - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - // Loads the portal and destination editors new Portal(this); new Destination(this); - + new DataCollector(this); - + // These register the commands - new AdvancedPortalsCommand(this); - new DestinationCommand(this); - new WarpCommand(this); + new AdvancedPortalsCommand(this); + new DestinationCommand(this); + new WarpCommand(this); - new WarpEffects(this); - - - // These register the listeners - new Listeners(this); - - new FlowStopper(this); - new PortalProtect(this); - new PortalPlacer(this); - - Selection.LoadData(this); - - DataCollector.setupMetrics(); + new WarpEffects(this); + + + // These register the listeners + new Listeners(this); + + new FlowStopper(this); + new PortalProtect(this); + new PortalPlacer(this); + + Selection.LoadData(this); + + DataCollector.setupMetrics(); + + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); + + } + + + public void onDisable() { + this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!"); + } - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); - } - - - public void onDisable() { - this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!"); - } - - } diff --git a/src/com/sekwah/advancedportals/DataCollector/DataCollector.java b/src/com/sekwah/advancedportals/DataCollector/DataCollector.java index 91ceecdf..b0564c34 100644 --- a/src/com/sekwah/advancedportals/DataCollector/DataCollector.java +++ b/src/com/sekwah/advancedportals/DataCollector/DataCollector.java @@ -9,62 +9,62 @@ import java.util.logging.Level; public class DataCollector { - private static AdvancedPortalsPlugin plugin; + private static AdvancedPortalsPlugin plugin; - public DataCollector(AdvancedPortalsPlugin plugin) { - DataCollector.plugin = plugin; - } - - /** - * - * This is currently being tested as it doesn't fully work at the moment. - * - */ - - /**public static void playerWarped() { - try { - Metrics metrics = new Metrics(plugin); + public DataCollector(AdvancedPortalsPlugin plugin) { + DataCollector.plugin = plugin; + } - Graph TotalWarps = metrics.createGraph("Total Warps"); - - TotalWarps.addPlotter(new Metrics.Plotter("Internal Warps") { + /** + * + * This is currently being tested as it doesn't fully work at the moment. + * + */ - @Override - public int getValue() { - return 1; // number of warps - } + /** + * public static void playerWarped() { + * try { + * Metrics metrics = new Metrics(plugin); + *

+ * Graph TotalWarps = metrics.createGraph("Total Warps"); + *

+ * TotalWarps.addPlotter(new Metrics.Plotter("Internal Warps") { + * + * @Override public int getValue() { + * return 1; // number of warps + * } + *

+ * }); + *

+ * metrics.start(); + * } catch (IOException e) { + * plugin.getLogger().log(Level.SEVERE, "Could not submit data", e); + * } + * } + */ - }); + public static void setupMetrics() { - metrics.start(); - } catch (IOException e) { - plugin.getLogger().log(Level.SEVERE, "Could not submit data", e); - } - }*/ - - public static void setupMetrics() { - - try { - Metrics metrics = new Metrics(plugin); - Graph TotalWarps = metrics.createGraph("Portal Trigger Blocks"); - - /**List MaterialList = new ArrayList(); - for(AdvancedPortal portal : Portal.Portals){ - MaterialList.add(portal.trigger); - }*/ + try { + Metrics metrics = new Metrics(plugin); + Graph TotalWarps = metrics.createGraph("Portal Trigger Blocks"); - /**TotalWarps.addPlotter(new Metrics.Plotter(triggerName) { + /**List MaterialList = new ArrayList(); + for(AdvancedPortal portal : Portal.Portals){ + MaterialList.add(portal.trigger); + }*/ - @Override - public int getValue() { - return 1; // number of portals created - } + /**TotalWarps.addPlotter(new Metrics.Plotter(triggerName) { - });*/ - - } catch (IOException e) { - plugin.getLogger().log(Level.SEVERE, "Could not submit data", e); - } - } + @Override public int getValue() { + return 1; // number of portals created + } + + });*/ + + } catch (IOException e) { + plugin.getLogger().log(Level.SEVERE, "Could not submit data", e); + } + } } diff --git a/src/com/sekwah/advancedportals/DestinationCommand.java b/src/com/sekwah/advancedportals/DestinationCommand.java index 34d551fc..c464d332 100644 --- a/src/com/sekwah/advancedportals/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/DestinationCommand.java @@ -14,163 +14,146 @@ import java.util.List; public class DestinationCommand implements CommandExecutor, TabCompleter { - public static int PortalMessagesDisplay = 0; + public static int PortalMessagesDisplay = 0; - private AdvancedPortalsPlugin plugin; - - public DestinationCommand(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; - - plugin.getCommand("destination").setExecutor(this); + private AdvancedPortalsPlugin plugin; - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + public DestinationCommand(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; - PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); - - - } - + plugin.getCommand("destination").setExecutor(this); - @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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a."); - sender.sendMessage(""); - } - else if(PortalMessagesDisplay == 2){ - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") - + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); - } - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to exemptPlayer to."); - } - } - else if(args[0].toLowerCase().equals("list")) { - List destiList = Destination.destiList(); - if(destiList.size() >= 1){ - if(args.length > 1){ - try - { - int page = Integer.parseInt(args[1]); - if(page * 5 >= destiList.size() - 5){ // add this if statement so that the user cant select a list page higher than the max - if(destiList.size() / 5 == destiList.size()){ - - } - } - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); - for(int i = (page - 1) * 5; i < page * 5; i++){ - if(i > destiList.size()){ - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - return true; - } - catch(Exception e) - { - } - } - - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); - for(int i = 0; i < 5; i++){ - if(i > destiList.size()){ - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); - for(int i = 0; i < 5; i++){ - if(i > destiList.size()){ - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations."); - } - } - } - else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + ", if you do not know what you can put or would like some help with the commands please type /" + command + " help"); - } - return true; - } + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + + PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); - @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; - } + } + + + @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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a."); + sender.sendMessage(""); + } else if (PortalMessagesDisplay == 2) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); + /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") + + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ + } + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); + } + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to exemptPlayer to."); + } + } else if (args[0].toLowerCase().equals("list")) { + List destiList = Destination.destiList(); + if (destiList.size() >= 1) { + if (args.length > 1) { + try { + int page = Integer.parseInt(args[1]); + if (page * 5 >= destiList.size() - 5) { // add this if statement so that the user cant select a list page higher than the max + if (destiList.size() / 5 == destiList.size()) { + + } + } + sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + for (int i = (page - 1) * 5; i < page * 5; i++) { + if (i > destiList.size()) { + break; + } + sender.sendMessage(" \u00A7e" + destiList.get(i)); + } + return true; + } catch (Exception e) { + } + } + + sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + for (int i = 0; i < 5; i++) { + if (i > destiList.size()) { + break; + } + sender.sendMessage(" \u00A7e" + destiList.get(i)); + } + + sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + for (int i = 0; i < 5; i++) { + if (i > destiList.size()) { + break; + } + sender.sendMessage(" \u00A7e" + destiList.get(i)); + } + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations."); + } + } + } else { + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + ", if you do not know what you can put or would like some help with the commands please type /" + command + " help"); + } + return true; + } + + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { + LinkedList autoComplete = new LinkedList(); + + if (sender.hasPermission("AdvancedPortals.CreatePortal")) { + if (args.length == 1) { + autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove")); + } else if (args[0].toLowerCase().equals("create")) { + } + } + Collections.sort(autoComplete); + for (Object result : autoComplete.toArray()) { + if (!result.toString().startsWith(args[args.length - 1])) { + autoComplete.remove(result); + } + } + return autoComplete; + } } diff --git a/src/com/sekwah/advancedportals/PluginMessages.java b/src/com/sekwah/advancedportals/PluginMessages.java index 91e2b9b2..6c4c3170 100644 --- a/src/com/sekwah/advancedportals/PluginMessages.java +++ b/src/com/sekwah/advancedportals/PluginMessages.java @@ -3,17 +3,17 @@ package com.sekwah.advancedportals; import org.bukkit.command.CommandSender; public class PluginMessages { - - // 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("\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!"); - } + // 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("\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!"); + } } diff --git a/src/com/sekwah/advancedportals/Selection.java b/src/com/sekwah/advancedportals/Selection.java index b6142a8e..28d1e0de 100644 --- a/src/com/sekwah/advancedportals/Selection.java +++ b/src/com/sekwah/advancedportals/Selection.java @@ -6,275 +6,269 @@ import org.bukkit.Material; import org.bukkit.entity.Player; public class Selection { - - public static Material blockType = Material.STAINED_GLASS; - public static int timeout = 10; - public static byte metadata = 14; - - @SuppressWarnings("deprecation") - public static void LoadData(AdvancedPortalsPlugin plugin) { - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - - timeout = config.getConfig().getInt("ShowSelectionShowDuration"); - - String BlockID = config.getConfig().getString("ShowSelectionBlockID"); - try - { - blockType = Material.getMaterial(Integer.parseInt(BlockID)); - } - catch(Exception e) - { - blockType = Material.getMaterial(BlockID); - } - - if(blockType == null){ - blockType = Material.STAINED_GLASS; - } - - metadata = (byte) config.getConfig().getInt("ShowSelectionBlockData"); - } - - @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); + + public static Material blockType = Material.STAINED_GLASS; + public static int timeout = 10; + public static byte metadata = 14; + + @SuppressWarnings("deprecation") + public static void LoadData(AdvancedPortalsPlugin plugin) { + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + + timeout = config.getConfig().getInt("ShowSelectionShowDuration"); + + String BlockID = config.getConfig().getString("ShowSelectionBlockID"); + try { + blockType = Material.getMaterial(Integer.parseInt(BlockID)); + } catch (Exception e) { + blockType = Material.getMaterial(BlockID); + } + + if (blockType == null) { + blockType = Material.STAINED_GLASS; + } + + metadata = (byte) config.getConfig().getInt("ShowSelectionBlockData"); + } + + @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; + + int HighX = 0; + 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(); + } 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. */ - - 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; - - int HighX = 0; - 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(); - } - 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. - */ - - 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); - - } + 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); + } - @SuppressWarnings("deprecation") - protected static void Hide(Player player, AdvancedPortalsPlugin plugin, Location pos1, Location pos2) { - - int LowX = pos1.getBlockX(); - int LowY = pos1.getBlockY(); - int LowZ = pos1.getBlockZ(); - - int HighX = pos2.getBlockX(); - int HighY = pos2.getBlockY(); - int HighZ = pos2.getBlockZ(); - - for(int x = LowX; x <= HighX; x++){ - Location loc = new Location(player.getWorld(), x, LowY, LowZ); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int x = LowX; x <= HighX; x++){ - Location loc = new Location(player.getWorld(), x, LowY, HighZ); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int z = LowZ; z <= HighZ; z++){ - Location loc = new Location(player.getWorld(), LowX, LowY, z); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int z = LowZ; z <= HighZ; z++){ - Location loc = new Location(player.getWorld(), HighX, LowY, z); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int y = LowY; y <= HighY; y++){ - Location loc = new Location(player.getWorld(), LowX, y, LowZ); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int y = LowY; y <= HighY; y++){ - Location loc = new Location(player.getWorld(), LowX, y, HighZ); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int y = LowY; y <= HighY; y++){ - Location loc = new Location(player.getWorld(), HighX, y, LowZ); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int y = LowY; y <= HighY; y++){ - Location loc = new Location(player.getWorld(), HighX, y, HighZ); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int x = LowX; x <= HighX; x++){ - Location loc = new Location(player.getWorld(), x, HighY, HighZ); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int x = LowX; x <= HighX; x++){ - Location loc = new Location(player.getWorld(), x, HighY, LowZ); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int z = LowZ; z <= HighZ; z++){ - Location loc = new Location(player.getWorld(), LowX, HighY, z); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - for(int z = LowZ; z <= HighZ; z++){ - Location loc = new Location(player.getWorld(), HighX, HighY, z); - player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); - } - - } + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + Selection.Hide(player, plugin, pos1, pos2); + } + }, timeout * 20); + + } + + @SuppressWarnings("deprecation") + protected static void Hide(Player player, AdvancedPortalsPlugin plugin, Location pos1, Location pos2) { + + int LowX = pos1.getBlockX(); + int LowY = pos1.getBlockY(); + int LowZ = pos1.getBlockZ(); + + int HighX = pos2.getBlockX(); + int HighY = pos2.getBlockY(); + int HighZ = pos2.getBlockZ(); + + for (int x = LowX; x <= HighX; x++) { + Location loc = new Location(player.getWorld(), x, LowY, LowZ); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int x = LowX; x <= HighX; x++) { + Location loc = new Location(player.getWorld(), x, LowY, HighZ); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int z = LowZ; z <= HighZ; z++) { + Location loc = new Location(player.getWorld(), LowX, LowY, z); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int z = LowZ; z <= HighZ; z++) { + Location loc = new Location(player.getWorld(), HighX, LowY, z); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int y = LowY; y <= HighY; y++) { + Location loc = new Location(player.getWorld(), LowX, y, LowZ); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int y = LowY; y <= HighY; y++) { + Location loc = new Location(player.getWorld(), LowX, y, HighZ); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int y = LowY; y <= HighY; y++) { + Location loc = new Location(player.getWorld(), HighX, y, LowZ); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int y = LowY; y <= HighY; y++) { + Location loc = new Location(player.getWorld(), HighX, y, HighZ); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int x = LowX; x <= HighX; x++) { + Location loc = new Location(player.getWorld(), x, HighY, HighZ); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int x = LowX; x <= HighX; x++) { + Location loc = new Location(player.getWorld(), x, HighY, LowZ); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int z = LowZ; z <= HighZ; z++) { + Location loc = new Location(player.getWorld(), LowX, HighY, z); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + for (int z = LowZ; z <= HighZ; z++) { + Location loc = new Location(player.getWorld(), HighX, HighY, z); + player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); + } + + } } diff --git a/src/com/sekwah/advancedportals/WarpCommand.java b/src/com/sekwah/advancedportals/WarpCommand.java index 2113772f..1c6426e7 100644 --- a/src/com/sekwah/advancedportals/WarpCommand.java +++ b/src/com/sekwah/advancedportals/WarpCommand.java @@ -12,70 +12,67 @@ import java.util.List; public class WarpCommand implements CommandExecutor, TabCompleter { - @SuppressWarnings("unused") - private AdvancedPortalsPlugin plugin; - - public WarpCommand(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; + @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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a."); - sender.sendMessage(""); - } - else if(DestinationCommand.PortalMessagesDisplay == 2){ - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") - + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } - } - else{ - sender.sendMessage(""); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you tried to warp to does not exist!"); - sender.sendMessage(""); - } - } - else{ - sender.sendMessage(""); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type a destination after /" + command + "!"); - sender.sendMessage(""); - } - return true; - } + 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 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; - } + @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("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a."); + sender.sendMessage(""); + } else if (DestinationCommand.PortalMessagesDisplay == 2) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); + /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") + + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ + } + } else { + sender.sendMessage(""); + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you tried to warp to does not exist!"); + sender.sendMessage(""); + } + } else { + sender.sendMessage(""); + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type a destination after /" + command + "!"); + sender.sendMessage(""); + } + return true; + } + + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { + LinkedList autoComplete = new LinkedList(); + + /**if(sender.hasPermission("AdvancedPortals.CreatePortal")){ + if(args.length == 1){ + autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove")); + } + else if(args[0].toLowerCase().equals("create")){ + } + } + Collections.sort(autoComplete); + for(Object result: autoComplete.toArray()){ + if(!result.toString().startsWith(args[args.length - 1])){ + autoComplete.remove(result); + } + }*/ + return autoComplete; + } } diff --git a/src/com/sekwah/advancedportals/compat/bukkit/NMS.java b/src/com/sekwah/advancedportals/compat/bukkit/NMS.java index 8d112e5e..b0eedfe2 100644 --- a/src/com/sekwah/advancedportals/compat/bukkit/NMS.java +++ b/src/com/sekwah/advancedportals/compat/bukkit/NMS.java @@ -3,8 +3,8 @@ package com.sekwah.advancedportals.compat.bukkit; import org.bukkit.entity.Player; public interface NMS { - - void sendRawMessage(String rawMessage, Player player); - void sendActionBarMessage(String rawMessage, Player player); + void sendRawMessage(String rawMessage, Player player); + + void sendActionBarMessage(String rawMessage, Player player); } diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java index fd248abc..aa9809ef 100644 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java +++ b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java @@ -8,21 +8,21 @@ import org.bukkit.entity.Player; public class v1_8_R1 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + + @Override + public void sendRawMessage(String rawMessage, Player player) { + IChatBaseComponent comp = ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + @Override + public void sendActionBarMessage(String rawMessage, Player player) { + IChatBaseComponent comp = ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } } diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java index 1935fa89..46e477f4 100644 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java +++ b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java @@ -7,21 +7,21 @@ import org.bukkit.entity.Player; public class v1_8_R2 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + + @Override + public void sendRawMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + @Override + public void sendActionBarMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } } diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java index 591e1acb..ca757288 100644 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java +++ b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java @@ -7,21 +7,21 @@ import org.bukkit.entity.Player; public class v1_8_R3 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + + @Override + public void sendRawMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + @Override + public void sendActionBarMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } } diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java index e9c4bf11..f9614c02 100644 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java +++ b/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java @@ -7,21 +7,21 @@ import org.bukkit.entity.Player; public class v1_9_R1 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + + @Override + public void sendRawMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + @Override + public void sendActionBarMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } } diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 1da44612..d1014a16 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -18,187 +18,184 @@ import java.util.Set; import java.util.logging.Level; public class Destination { - + private static AdvancedPortalsPlugin plugin; - public Destination(AdvancedPortalsPlugin plugin) { - Destination.plugin = plugin; + public Destination(AdvancedPortalsPlugin plugin) { + Destination.plugin = plugin; } - // TODO add permissions for destinations. - - public static void create(Location location, String name){ - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - - config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName()); - - config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX()); - config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY()); - config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ()); - - config.getConfig().set(name.toLowerCase() + ".pos.pitch", location.getPitch()); - config.getConfig().set(name.toLowerCase() + ".pos.yaw", location.getYaw()); - - config.saveConfig(); - } - - public static void move(Location location, String name){ - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - - config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName()); - - config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX()); - config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY()); - config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ()); - - config.getConfig().set(name.toLowerCase() + ".pos.pitch", location.getPitch()); - config.getConfig().set(name.toLowerCase() + ".pos.yaw", location.getYaw()); - - config.saveConfig(); - } - - public static void rename(String oldName, String newName){ - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - - config.getConfig().set(newName.toLowerCase() + ".world", config.getConfig().getString(oldName + ".world")); - - config.getConfig().set(newName.toLowerCase() + ".pos.X", config.getConfig().getDouble(oldName + ".pos.X")); - config.getConfig().set(newName.toLowerCase() + ".pos.Y", config.getConfig().getDouble(oldName + ".pos.Y")); - config.getConfig().set(newName.toLowerCase() + ".pos.Z", config.getConfig().getDouble(oldName + ".pos.Z")); - - config.getConfig().set(newName.toLowerCase() + ".pos.pitch", config.getConfig().getDouble(oldName + ".pos.pitch")); - config.getConfig().set(newName.toLowerCase() + ".pos.yaw", config.getConfig().getDouble(oldName + ".pos.yaw")); + // TODO add permissions for destinations. - remove(oldName); - - config.saveConfig(); - } - - public static void remove(String name){ - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - - config.getConfig().set(name.toLowerCase() + ".world", null); - - config.getConfig().set(name.toLowerCase() + ".pos.X", null); - config.getConfig().set(name.toLowerCase() + ".pos.Y", null); - config.getConfig().set(name.toLowerCase() + ".pos.Z", null); - - config.getConfig().set(name.toLowerCase() + ".pos.pitch", null); - config.getConfig().set(name.toLowerCase() + ".pos.yaw", null); - - config.getConfig().set(name.toLowerCase() + ".pos", null); - - config.getConfig().set(name.toLowerCase(), null); - - config.saveConfig(); - } - - public static boolean warp(Player player, String name, boolean senderror){ - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - if(config.getConfig().getString(name + ".world") != null){ - Location loc = player.getLocation(); - if(Bukkit.getWorld(config.getConfig().getString(name + ".world")) != null){ - loc.setWorld(Bukkit.getWorld(config.getConfig().getString(name + ".world"))); - - loc.setX(config.getConfig().getDouble(name + ".pos.X")); - loc.setY(config.getConfig().getDouble(name + ".pos.Y")); - loc.setZ(config.getConfig().getDouble(name + ".pos.Z")); - - loc.setPitch((float) config.getConfig().getDouble(name + ".pos.pitch")); - loc.setYaw((float) config.getConfig().getDouble(name + ".pos.yaw")); - - WarpEffects.activateParticles(player); - WarpEffects.activateSound(player); - Chunk c = loc.getChunk(); - Entity riding = player.getVehicle(); - if (!c.isLoaded()) c.load(); - if(player.getVehicle() != null){ - riding.eject(); - riding.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); - player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); - riding.setPassenger(player); - } - else{ - player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); - } - WarpEffects.activateParticles(player); - WarpEffects.activateSound(player); - - - return true; - } - else{ - if(senderror){ - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\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; - } - } - else{ - if(senderror){ - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\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; - } - - } - - /** - * 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; - } + public static void create(Location location, String name) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + + config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName()); + + config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX()); + config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY()); + config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ()); + + config.getConfig().set(name.toLowerCase() + ".pos.pitch", location.getPitch()); + config.getConfig().set(name.toLowerCase() + ".pos.yaw", location.getYaw()); + + config.saveConfig(); + } + + public static void move(Location location, String name) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + + config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName()); + + config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX()); + config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY()); + config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ()); + + config.getConfig().set(name.toLowerCase() + ".pos.pitch", location.getPitch()); + config.getConfig().set(name.toLowerCase() + ".pos.yaw", location.getYaw()); + + config.saveConfig(); + } + + public static void rename(String oldName, String newName) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + + config.getConfig().set(newName.toLowerCase() + ".world", config.getConfig().getString(oldName + ".world")); + + config.getConfig().set(newName.toLowerCase() + ".pos.X", config.getConfig().getDouble(oldName + ".pos.X")); + config.getConfig().set(newName.toLowerCase() + ".pos.Y", config.getConfig().getDouble(oldName + ".pos.Y")); + config.getConfig().set(newName.toLowerCase() + ".pos.Z", config.getConfig().getDouble(oldName + ".pos.Z")); + + config.getConfig().set(newName.toLowerCase() + ".pos.pitch", config.getConfig().getDouble(oldName + ".pos.pitch")); + config.getConfig().set(newName.toLowerCase() + ".pos.yaw", config.getConfig().getDouble(oldName + ".pos.yaw")); + + remove(oldName); + + config.saveConfig(); + } + + public static void remove(String name) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + + config.getConfig().set(name.toLowerCase() + ".world", null); + + config.getConfig().set(name.toLowerCase() + ".pos.X", null); + config.getConfig().set(name.toLowerCase() + ".pos.Y", null); + config.getConfig().set(name.toLowerCase() + ".pos.Z", null); + + config.getConfig().set(name.toLowerCase() + ".pos.pitch", null); + config.getConfig().set(name.toLowerCase() + ".pos.yaw", null); + + config.getConfig().set(name.toLowerCase() + ".pos", null); + + config.getConfig().set(name.toLowerCase(), null); + + config.saveConfig(); + } + + public static boolean warp(Player player, String name, boolean senderror) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + if (config.getConfig().getString(name + ".world") != null) { + Location loc = player.getLocation(); + if (Bukkit.getWorld(config.getConfig().getString(name + ".world")) != null) { + loc.setWorld(Bukkit.getWorld(config.getConfig().getString(name + ".world"))); + + loc.setX(config.getConfig().getDouble(name + ".pos.X")); + loc.setY(config.getConfig().getDouble(name + ".pos.Y")); + loc.setZ(config.getConfig().getDouble(name + ".pos.Z")); + + loc.setPitch((float) config.getConfig().getDouble(name + ".pos.pitch")); + loc.setYaw((float) config.getConfig().getDouble(name + ".pos.yaw")); + + WarpEffects.activateParticles(player); + WarpEffects.activateSound(player); + Chunk c = loc.getChunk(); + Entity riding = player.getVehicle(); + if (!c.isLoaded()) c.load(); + if (player.getVehicle() != null) { + riding.eject(); + riding.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); + player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); + riding.setPassenger(player); + } else { + player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); + } + WarpEffects.activateParticles(player); + WarpEffects.activateSound(player); + + + return true; + } else { + if (senderror) { + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\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; + } + } else { + if (senderror) { + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\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; + } + + } + + /** + * 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; + } } diff --git a/src/com/sekwah/advancedportals/effects/WarpEffects.java b/src/com/sekwah/advancedportals/effects/WarpEffects.java index 095bd256..80979208 100644 --- a/src/com/sekwah/advancedportals/effects/WarpEffects.java +++ b/src/com/sekwah/advancedportals/effects/WarpEffects.java @@ -10,54 +10,54 @@ import org.bukkit.entity.Player; public class WarpEffects { - public boolean oldSoundLoc = true; + public static Sound[] sounds = new Sound[1]; + public static boolean soundError = false; + public boolean oldSoundLoc = true; - public static Sound[] sounds = new Sound[1]; + public WarpEffects(AdvancedPortalsPlugin plugin) { + try { + sounds[0] = Sound.valueOf("ENTITY_ENDERMEN_TELEPORT"); + plugin.getLogger().info("Sounds found"); + } catch (IllegalArgumentException e) { + plugin.getLogger().info("Using old effect names"); + try { + sounds[0] = Sound.valueOf("ENDERMAN_TELEPORT"); + } catch (IllegalArgumentException e2) { + plugin.getLogger().warning("There was an error using both the old and new names."); + soundError = true; + } + } + } - public static boolean soundError = false; + public static void activateParticles(Player player) { + Location loc = player.getLocation(); + World world = player.getWorld(); + switch (Assets.currentWarpParticles) { + case 1: + for (int i = 0; i < 10; i++) { + world.playEffect(loc, Effect.ENDER_SIGNAL, 0); + } + loc.add(0D, 1D, 0D); + for (int i = 0; i < 10; i++) { + world.playEffect(loc, Effect.ENDER_SIGNAL, 0); + } + default: + break; + } - public WarpEffects(AdvancedPortalsPlugin plugin) { - try { - sounds[0] = Sound.valueOf("ENTITY_ENDERMEN_TELEPORT"); - plugin.getLogger().info("Sounds found"); - } catch (IllegalArgumentException e) { - plugin.getLogger().info("Using old effect names"); - try { - sounds[0] = Sound.valueOf("ENDERMAN_TELEPORT"); - } catch (IllegalArgumentException e2) { - plugin.getLogger().warning("There was an error using both the old and new names."); - soundError = true; - } - } - } + } - public static void activateParticles(Player player) { - Location loc = player.getLocation(); - World world = player.getWorld(); - switch (Assets.currentWarpParticles){ - case 1: - for(int i = 0; i < 10; i++){ - world.playEffect(loc, Effect.ENDER_SIGNAL, 0); - } - loc.add(0D, 1D, 0D); - for(int i = 0; i < 10; i++){ - world.playEffect(loc, Effect.ENDER_SIGNAL, 0); - } - default: break; - } - - } - - public static void activateSound(Player player) { - if(!soundError){ - Location loc = player.getLocation(); - World world = player.getWorld(); - switch (Assets.currentWarpParticles){ - case 1: - world.playSound(loc, sounds[0], 1F, 1F); - default: break; - } - } - } + public static void activateSound(Player player) { + if (!soundError) { + Location loc = player.getLocation(); + World world = player.getWorld(); + switch (Assets.currentWarpParticles) { + case 1: + world.playSound(loc, sounds[0], 1F, 1F); + default: + break; + } + } + } } diff --git a/src/com/sekwah/advancedportals/events/WarpEvent.java b/src/com/sekwah/advancedportals/events/WarpEvent.java index 828ce270..e38c3904 100644 --- a/src/com/sekwah/advancedportals/events/WarpEvent.java +++ b/src/com/sekwah/advancedportals/events/WarpEvent.java @@ -5,76 +5,76 @@ import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; - + public final class WarpEvent extends Event implements Cancellable { - - /** - * Use listeners so you can add new triggers easier and also other plugins can listen for the event - * and add their own triggers - */ - - + + /** + * Use listeners so you can add new triggers easier and also other plugins can listen for the event + * and add their own triggers + */ + + private static final HandlerList handlers = new HandlerList(); - + private boolean cancelled = false; - private Player player; + private Player player; @SuppressWarnings("unused") - private AdvancedPortal portalData; + private AdvancedPortal portalData; + + private boolean hasWarped = false; - private boolean hasWarped = false; - public WarpEvent(Player player, AdvancedPortal portalData) { - this.player = player; - this.portalData = portalData; + this.player = player; + this.portalData = portalData; } - - + + public static HandlerList getHandlerList() { + return handlers; + } + /** * Returns if the event has been cancelled - * + * * @return cancelled */ public boolean isCancelled() { return cancelled; } - + public void setCancelled(boolean cancel) { cancelled = cancel; } - public AdvancedPortal getPortalData(){return portalData;} - + public AdvancedPortal getPortalData() { + return portalData; + } + /** - * If the - * + * This will return true if another plugin has warped the player(and set this to true) + * + * @return hasWarped + */ + public boolean getHasWarped() { + return hasWarped; + } + + /** + * If the + * * @param warped */ @SuppressWarnings("unused") - public void setHasWarped(boolean warped){ - this.hasWarped = warped; + public void setHasWarped(boolean warped) { + this.hasWarped = warped; } - - /** - * This will return true if another plugin has warped the player(and set this to true) - * - * @return hasWarped - */ - public boolean getHasWarped(){ - return hasWarped; + + public Player getPlayer() { + return player; } - - public Player getPlayer(){ - return player; - } - - + public HandlerList getHandlers() { return handlers; } - - public static HandlerList getHandlerList() { - return handlers; - } } \ No newline at end of file diff --git a/src/com/sekwah/advancedportals/listeners/FlowStopper.java b/src/com/sekwah/advancedportals/listeners/FlowStopper.java index 9e923bee..9a2c37d0 100644 --- a/src/com/sekwah/advancedportals/listeners/FlowStopper.java +++ b/src/com/sekwah/advancedportals/listeners/FlowStopper.java @@ -12,62 +12,62 @@ import org.bukkit.event.block.BlockFromToEvent; public class FlowStopper implements Listener { - @SuppressWarnings("unused") - private final AdvancedPortalsPlugin plugin; + @SuppressWarnings("unused") + private final AdvancedPortalsPlugin plugin; - // 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("�eP... - private boolean WaterFlow = true; + // 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("�eP... + private boolean WaterFlow = true; - public FlowStopper(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; + public FlowStopper(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow"); + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow"); - if(WaterFlow){ - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - } + if (WaterFlow) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + } - @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(); + @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(); - if(!Portal.portalsActive){ - return; - } + if (!Portal.portalsActive) { + return; + } - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(block.getWorld().getName())){ + for (AdvancedPortal portal : Portal.Portals) { + if (portal.worldName.equals(block.getWorld().getName())) { - if((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()){ + if ((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()) { - if((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()){ - - event.setCancelled(true); + if ((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()) { - } - } + event.setCancelled(true); - } - - if(portal.worldName.equals(blockTo.getWorld().getName())){ + } + } - if((portal.pos1.getX() + 3D) >= blockTo.getX() && (portal.pos1.getY() + 3D) >= blockTo.getY() && (portal.pos1.getZ() + 3D) >= blockTo.getZ()){ + } - if((portal.pos2.getX() - 3D) <= blockTo.getX() && (portal.pos2.getY() - 3D) <= blockTo.getY() && (portal.pos2.getZ() - 3D) <= blockTo.getZ()){ - - event.setCancelled(true); + if (portal.worldName.equals(blockTo.getWorld().getName())) { - } - } + if ((portal.pos1.getX() + 3D) >= blockTo.getX() && (portal.pos1.getY() + 3D) >= blockTo.getY() && (portal.pos1.getZ() + 3D) >= blockTo.getZ()) { - } - } - } + if ((portal.pos2.getX() - 3D) <= blockTo.getX() && (portal.pos2.getY() - 3D) <= blockTo.getY() && (portal.pos2.getZ() - 3D) <= blockTo.getZ()) { + + event.setCancelled(true); + + } + } + + } + } + } } diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 6ae6d026..fe9fe42d 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -25,320 +25,305 @@ import org.bukkit.metadata.FixedMetadataValue; public class Listeners implements Listener { - private final AdvancedPortalsPlugin plugin; + // 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; + private static Material WandMaterial; + private static boolean ShowBungeeMessage; + private final AdvancedPortalsPlugin plugin; + private int PortalMessagesDisplay = 2; - private int PortalMessagesDisplay = 2; + @SuppressWarnings("deprecation") + public Listeners(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; - // 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; + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); - private static Material WandMaterial; + String ItemID = config.getConfig().getString("AxeItemId"); - private static boolean ShowBungeeMessage; + PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); - @SuppressWarnings("deprecation") - public Listeners(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; + try { + WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); + } catch (Exception e) { + WandMaterial = Material.getMaterial(ItemID); + } - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } - String ItemID = config.getConfig().getString("AxeItemId"); + @SuppressWarnings("deprecation") + public static void reloadValues(AdvancedPortalsPlugin plugin) { - PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); - try - { - WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); - } - catch(Exception e) - { - WandMaterial = Material.getMaterial(ItemID); - } + ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } + String ItemID = config.getConfig().getString("AxeItemId"); - @SuppressWarnings("deprecation") - public static void reloadValues(AdvancedPortalsPlugin plugin) { + try { + WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); + } catch (Exception e) { + WandMaterial = Material.getMaterial(ItemID); + } + } - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); + @EventHandler(priority = EventPriority.HIGHEST) + public void onMoveEvent(PlayerMoveEvent event) { + // will check if the player is in the portal or not. + if (!Portal.portalsActive) { + return; + } - ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); + Player player = event.getPlayer(); - String ItemID = config.getConfig().getString("AxeItemId"); - - try - { - WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); - } - catch(Exception e) - { - WandMaterial = Material.getMaterial(ItemID); - } - } - - @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(); - - Location fromloc = event.getFrom(); - Location loc = event.getTo(); - // Potentially fixes that stupid error cauzed by a bukkit update. - // Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players. - Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ()); - //System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed - // This is probably the culprite of the bloody problem, setting the location its pointing to the event location - // rather than sorta making a clone of the object. - //System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed - for(AdvancedPortal portal : Portal.Portals){ - if(loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())){ - if(portal.trigger.equals(loc.getBlock().getType()) - || portal.trigger.equals(eyeLoc.getBlock().getType())){ - if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){ - if(portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()){ + Location fromloc = event.getFrom(); + Location loc = event.getTo(); + // Potentially fixes that stupid error cauzed by a bukkit update. + // Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players. + Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ()); + //System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed + // This is probably the culprite of the bloody problem, setting the location its pointing to the event location + // rather than sorta making a clone of the object. + //System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed + for (AdvancedPortal portal : Portal.Portals) { + if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) { + if (portal.trigger.equals(loc.getBlock().getType()) + || portal.trigger.equals(eyeLoc.getBlock().getType())) { + if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) { + if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) { - WarpEvent warpEvent = new WarpEvent(player, portal); - plugin.getServer().getPluginManager().callEvent(warpEvent); + WarpEvent warpEvent = new WarpEvent(player, portal); + plugin.getServer().getPluginManager().callEvent(warpEvent); - if (!event.isCancelled()) { - boolean warped = Portal.activate(player, portal); - if(PortalMessagesDisplay == 1 && warped){ - player.sendMessage(""); - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7."); - player.sendMessage(""); - } - else if(PortalMessagesDisplay == 2 && warped){ - ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") - + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } + if (!event.isCancelled()) { + boolean warped = Portal.activate(player, portal); + if (PortalMessagesDisplay == 1 && warped) { + player.sendMessage(""); + player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7."); + player.sendMessage(""); + } else if (PortalMessagesDisplay == 2 && warped) { + ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); + plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player); + /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ + } - if(warped){ - //event.setFrom(player.getLocation()); - //event.setTo(player.getLocation()); + if (warped) { + //event.setFrom(player.getLocation()); + //event.setTo(player.getLocation()); - //event.setCancelled(true); - } - else{ - player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); - event.setCancelled(true); - } - } + //event.setCancelled(true); + } else { + player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); + event.setCancelled(true); + } + } - if(portal.trigger.equals(Material.PORTAL)){ - if(player.getGameMode().equals(GameMode.CREATIVE)){ - player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - if(player != null && player.isOnline()){ - player.removeMetadata("hasWarped", plugin); - } - } - }, 10); - } - } - else if(portal.trigger.equals(Material.LAVA)){ - player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - player.removeMetadata("lavaWarped", plugin); - player.setFireTicks(0); - } - }, 10); - } + if (portal.trigger.equals(Material.PORTAL)) { + if (player.getGameMode().equals(GameMode.CREATIVE)) { + player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + if (player != null && player.isOnline()) { + player.removeMetadata("hasWarped", plugin); + } + } + }, 10); + } + } else if (portal.trigger.equals(Material.LAVA)) { + player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + player.removeMetadata("lavaWarped", plugin); + player.setFireTicks(0); + } + }, 10); + } - } - } + } + } - } - } - } + } + } + } - } + } - @EventHandler - public void onCombustEntityEvent(EntityCombustEvent event) { - if(!Portal.portalsActive){ - return; - } - Location loc = event.getEntity().getLocation(); - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(loc.getWorld().getName())){ + @EventHandler + public void onCombustEntityEvent(EntityCombustEvent event) { + if (!Portal.portalsActive) { + return; + } + Location loc = event.getEntity().getLocation(); + for (AdvancedPortal portal : Portal.Portals) { + if (portal.worldName.equals(loc.getWorld().getName())) { - if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){ + if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) { - if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){ - event.setCancelled(true); - return; - } - } + if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) { + event.setCancelled(true); + return; + } + } - } - } - } + } + } + } - @EventHandler - public void onDamEvent(EntityDamageEvent event) { - if(!Portal.portalsActive){ - return; - } - //System.out.println(event.getCause()); - if(event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK){ - Location loc = event.getEntity().getLocation(); - if(event.getEntity().hasMetadata("lavaWarped")){ - event.setCancelled(true); - return; - } - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(loc.getWorld().getName())){ + @EventHandler + public void onDamEvent(EntityDamageEvent event) { + if (!Portal.portalsActive) { + return; + } + //System.out.println(event.getCause()); + if (event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK) { + Location loc = event.getEntity().getLocation(); + if (event.getEntity().hasMetadata("lavaWarped")) { + event.setCancelled(true); + return; + } + for (AdvancedPortal portal : Portal.Portals) { + if (portal.worldName.equals(loc.getWorld().getName())) { - if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){ + if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) { - if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){ - event.setCancelled(true); - return; + if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) { + event.setCancelled(true); + return; - } - } + } + } - } - } - } + } + } + } - } + } - @SuppressWarnings("deprecation") - @EventHandler - public void onPortalEvent(PlayerPortalEvent event) { - if(!Portal.portalsActive){ - return; - } - Player player = event.getPlayer(); + @SuppressWarnings("deprecation") + @EventHandler + public void onPortalEvent(PlayerPortalEvent event) { + if (!Portal.portalsActive) { + return; + } + Player player = event.getPlayer(); - if(player.hasMetadata("hasWarped")){ - event.setCancelled(true); - return; - } + if (player.hasMetadata("hasWarped")) { + event.setCancelled(true); + return; + } - Location loc = player.getLocation(); - Object[] portals = Portal.Portals; - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(player.getWorld().getName())){ + Location loc = player.getLocation(); + Object[] portals = Portal.Portals; + for (AdvancedPortal portal : Portal.Portals) { + if (portal.worldName.equals(player.getWorld().getName())) { - if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){ + if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) { - if((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()){ + if ((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()) { - event.setCancelled(true); + event.setCancelled(true); - } - } + } + } - } - } + } + } - } + } - @EventHandler - public void onItemInteract(PlayerInteractEvent event) { + @EventHandler + public void onItemInteract(PlayerInteractEvent event) { - // will detect if the player is using an axe so the points of a portal can be set - // also any other detections such as sign interaction or basic block protection - Player player = event.getPlayer(); + // will detect if the player is using an axe so the points of a portal can be set + // also any other detections such as sign interaction or basic block protection + 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; - } - Block block = event.getClickedBlock(); - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(block.getWorld().getName())){ + 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; + } + Block block = event.getClickedBlock(); + for (AdvancedPortal portal : Portal.Portals) { + if (portal.worldName.equals(block.getWorld().getName())) { - if((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()){ + if ((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()) { - if((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()){ - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\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; + if ((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()) { + player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName); + player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character + event.setCancelled(true); + player.removeMetadata("selectingPortal", plugin); + return; - } - } + } + } - } - } - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); - event.setCancelled(true); - return; - } + } + } + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); + event.setCancelled(true); + return; + } - if(player.hasPermission("AdvancedPortals.CreatePortal")){ + if (player.hasPermission("AdvancedPortals.CreatePortal")) { - // UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally, - // by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used - // as a weapon. - // Null pointer exeption detected here on some servers(try decompiling the jar file to double check) - /*try { + // UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally, + // by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used + // as a weapon. + // Null pointer exeption detected here on some servers(try decompiling the jar file to double check) + /*try { // Use this to surround the code if needed } catch(NullPointerException e){ }*/ - if(event.getItem() != null && event.getPlayer().getItemInHand().getType() == WandMaterial // was type id - && (!UseOnlyServerAxe || (event.getItem().getItemMeta().getDisplayName() != null && event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")))) { + if (event.getItem() != null && event.getPlayer().getItemInHand().getType() == WandMaterial // was type id + && (!UseOnlyServerAxe || (event.getItem().getItemMeta().getDisplayName() != null && event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")))) { - // This checks if the action was a left or right click and if it was directly effecting a block. - if(event.getAction() == Action.LEFT_CLICK_BLOCK) { - Location blockloc = event.getClickedBlock().getLocation(); - // stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will - // have to be selected again if the player joins, also it does not affect any other players. - player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX())); - player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); - player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); - player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); - player.sendMessage("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); + // This checks if the action was a left or right click and if it was directly effecting a block. + if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + Location blockloc = event.getClickedBlock().getLocation(); + // stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will + // have to be selected again if the player joins, also it does not affect any other players. + player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX())); + player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); + player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); + player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); + player.sendMessage("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); - // Stops the event so the block is not damaged - event.setCancelled(true); + // Stops the event so the block is not damaged + event.setCancelled(true); - // Returns the event so no more code is executed(stops unnecessary code being executed) - } - else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { - Location blockloc = event.getClickedBlock().getLocation(); - player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX())); - player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); - player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); - player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); - player.sendMessage("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); + // Returns the event so no more code is executed(stops unnecessary code being executed) + } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Location blockloc = event.getClickedBlock().getLocation(); + player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX())); + player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); + player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); + player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); + player.sendMessage("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); - // Stops the event so the block is not interacted with - event.setCancelled(true); + // Stops the event so the block is not interacted with + event.setCancelled(true); - // Returns the event so no more code is executed(stops unnecessary code being executed) - } + // Returns the event so no more code is executed(stops unnecessary code being executed) + } - } + } - } - - } + } + } } diff --git a/src/com/sekwah/advancedportals/listeners/PortalPlacer.java b/src/com/sekwah/advancedportals/listeners/PortalPlacer.java index 59aab6bf..297fe791 100644 --- a/src/com/sekwah/advancedportals/listeners/PortalPlacer.java +++ b/src/com/sekwah/advancedportals/listeners/PortalPlacer.java @@ -13,40 +13,39 @@ import org.bukkit.event.block.BlockPhysicsEvent; public class PortalPlacer implements Listener { - @SuppressWarnings("unused") - private final AdvancedPortalsPlugin plugin; + @SuppressWarnings("unused") + private final AdvancedPortalsPlugin plugin; private final double PortalProtectionRadius; // 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("�eP... - private boolean PortalPlace = true; - + // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("�eP... + private boolean PortalPlace = true; + public PortalPlacer(AdvancedPortalsPlugin plugin) { this.plugin = plugin; - + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock"); this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius"); - - if(PortalPlace){ + + if (PortalPlace) { plugin.getServer().getPluginManager().registerEvents(this, plugin); } } - @EventHandler(priority = EventPriority.HIGHEST) - public void onBlockPhysics(BlockPhysicsEvent event) { + @EventHandler(priority = EventPriority.HIGHEST) + public void onBlockPhysics(BlockPhysicsEvent event) { Block block = event.getBlock(); - Material material = block.getType(); - if (material == Material.PORTAL) - { - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(block.getWorld().getName())){ + Material material = block.getType(); + if (material == Material.PORTAL) { + for (AdvancedPortal portal : Portal.Portals) { + if (portal.worldName.equals(block.getWorld().getName())) { - if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){ + if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) { - if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){ + if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) { event.setCancelled(true); break; @@ -56,10 +55,10 @@ public class PortalPlacer implements Listener { } } - //event.getChangedType(); - //event.setCancelled(true); - } - } + //event.getChangedType(); + //event.setCancelled(true); + } + } } diff --git a/src/com/sekwah/advancedportals/listeners/PortalProtect.java b/src/com/sekwah/advancedportals/listeners/PortalProtect.java index 5520fc50..93363a49 100644 --- a/src/com/sekwah/advancedportals/listeners/PortalProtect.java +++ b/src/com/sekwah/advancedportals/listeners/PortalProtect.java @@ -16,111 +16,111 @@ import java.util.List; public class PortalProtect implements Listener { - @SuppressWarnings("unused") - private final AdvancedPortalsPlugin plugin; + @SuppressWarnings("unused") + private final AdvancedPortalsPlugin plugin; - // 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("�eP... - private boolean PortalProtect = true; + // 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("�eP... + private boolean PortalProtect = true; + + private double PortalProtectionRadius = 5D; - private double PortalProtectionRadius = 5D; - public PortalProtect(AdvancedPortalsPlugin plugin) { this.plugin = plugin; - + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); this.PortalProtect = config.getConfig().getBoolean("PortalProtection"); - + this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius"); - - if(PortalProtect){ + + if (PortalProtect) { plugin.getServer().getPluginManager().registerEvents(this, plugin); } } - @SuppressWarnings("unused") + @SuppressWarnings("unused") @EventHandler(priority = EventPriority.HIGH) - public void onBlockBreak(BlockBreakEvent event){ + public void onBlockBreak(BlockBreakEvent event) { - if(!Portal.portalsActive){ - return; - } + if (!Portal.portalsActive) { + return; + } - if(!event.getPlayer().hasPermission("advancedportals.build")){ - Block block = event.getBlock(); + if (!event.getPlayer().hasPermission("advancedportals.build")) { + Block block = event.getBlock(); - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(block.getWorld().getName())){ + for (AdvancedPortal portal : Portal.Portals) { + if (portal.worldName.equals(block.getWorld().getName())) { - if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){ + if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) { - if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){ - event.setCancelled(true); + if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) { + event.setCancelled(true); break; - } - } + } + } - } - } - } + } + } + } } - @SuppressWarnings("unused") + @SuppressWarnings("unused") @EventHandler(priority = EventPriority.HIGH) - public void onBlockPlace(BlockPlaceEvent event){ + public void onBlockPlace(BlockPlaceEvent event) { - if(!Portal.portalsActive){ - return; - } - - if(!event.getPlayer().hasPermission("advancedportals.build")){ - Block block = event.getBlock(); + if (!Portal.portalsActive) { + return; + } - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(block.getWorld().getName())){ + if (!event.getPlayer().hasPermission("advancedportals.build")) { + Block block = event.getBlock(); - if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){ + for (AdvancedPortal portal : Portal.Portals) { + if (portal.worldName.equals(block.getWorld().getName())) { - if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){ + if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) { - event.setCancelled(true); + if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) { + + event.setCancelled(true); break; - } - } + } + } - } - } - } + } + } + } } - + @EventHandler(priority = EventPriority.HIGH) - public void onExplosion(EntityExplodeEvent event){ + public void onExplosion(EntityExplodeEvent event) { - if(!Portal.portalsActive){ - return; - } + if (!Portal.portalsActive) { + return; + } - List blockList = event.blockList(); - for (int i = 0; i < blockList.size(); i++) { - Block block = blockList.get(i); - Object[] portals = Portal.Portals; - for(AdvancedPortal portal : Portal.Portals){ // change for format for(int i = 0; i < portals.length; i++){ - if(portal.worldName.equals(block.getWorld().getName())){ + List blockList = event.blockList(); + for (int i = 0; i < blockList.size(); i++) { + Block block = blockList.get(i); + Object[] portals = Portal.Portals; + for (AdvancedPortal portal : Portal.Portals) { // change for format for(int i = 0; i < portals.length; i++){ + if (portal.worldName.equals(block.getWorld().getName())) { - if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){ - - if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){ - blockList.remove(i); - i--; + if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) { - } - - } + if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) { + blockList.remove(i); + i--; - } - } - } + } + + } + + } + } + } } diff --git a/src/com/sekwah/advancedportals/metrics/Metrics.java b/src/com/sekwah/advancedportals/metrics/Metrics.java index 39069ac6..76c017df 100644 --- a/src/com/sekwah/advancedportals/metrics/Metrics.java +++ b/src/com/sekwah/advancedportals/metrics/Metrics.java @@ -132,6 +132,121 @@ public class Metrics { debug = configuration.getBoolean("debug", false); } + /** + * GZip compress a string of bytes + * + * @param input + * @return + */ + public static byte[] gzip(String input) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream gzos = null; + + try { + gzos = new GZIPOutputStream(baos); + gzos.write(input.getBytes("UTF-8")); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (gzos != null) try { + gzos.close(); + } catch (IOException ignore) { + } + } + + return baos.toByteArray(); + } + + /** + * Appends a json encoded key/value pair to the given string builder. + * + * @param json + * @param key + * @param value + * @throws UnsupportedEncodingException + */ + private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException { + boolean isValueNumeric = false; + + try { + if (value.equals("0") || !value.endsWith("0")) { + Double.parseDouble(value); + isValueNumeric = true; + } + } catch (NumberFormatException e) { + isValueNumeric = false; + } + + if (json.charAt(json.length() - 1) != '{') { + json.append(','); + } + + json.append(escapeJSON(key)); + json.append(':'); + + if (isValueNumeric) { + json.append(value); + } else { + json.append(escapeJSON(value)); + } + } + + /** + * Escape a string to create a valid JSON string + * + * @param text + * @return + */ + private static String escapeJSON(String text) { + StringBuilder builder = new StringBuilder(); + + builder.append('"'); + for (int index = 0; index < text.length(); index++) { + char chr = text.charAt(index); + + switch (chr) { + case '"': + case '\\': + builder.append('\\'); + builder.append(chr); + break; + case '\b': + builder.append("\\b"); + break; + case '\t': + builder.append("\\t"); + break; + case '\n': + builder.append("\\n"); + break; + case '\r': + builder.append("\\r"); + break; + default: + if (chr < ' ') { + String t = "000" + Integer.toHexString(chr); + builder.append("\\u" + t.substring(t.length() - 4)); + } else { + builder.append(chr); + } + break; + } + } + builder.append('"'); + + return builder.toString(); + } + + /** + * Encode text as UTF-8 + * + * @param text the text to encode + * @return the encoded text, as UTF-8 + */ + private static String urlEncode(final String text) throws UnsupportedEncodingException { + return URLEncoder.encode(text, "UTF-8"); + } + /** * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics * website. Plotters can be added to the graph object returned. @@ -475,31 +590,6 @@ public class Metrics { } } - /** - * GZip compress a string of bytes - * - * @param input - * @return - */ - public static byte[] gzip(String input) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gzos = null; - - try { - gzos = new GZIPOutputStream(baos); - gzos.write(input.getBytes("UTF-8")); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (gzos != null) try { - gzos.close(); - } catch (IOException ignore) { - } - } - - return baos.toByteArray(); - } - /** * Check if mineshafter is present. If it is, we need to bypass it to send POST requests * @@ -514,96 +604,6 @@ public class Metrics { } } - /** - * Appends a json encoded key/value pair to the given string builder. - * - * @param json - * @param key - * @param value - * @throws UnsupportedEncodingException - */ - private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException { - boolean isValueNumeric = false; - - try { - if (value.equals("0") || !value.endsWith("0")) { - Double.parseDouble(value); - isValueNumeric = true; - } - } catch (NumberFormatException e) { - isValueNumeric = false; - } - - if (json.charAt(json.length() - 1) != '{') { - json.append(','); - } - - json.append(escapeJSON(key)); - json.append(':'); - - if (isValueNumeric) { - json.append(value); - } else { - json.append(escapeJSON(value)); - } - } - - /** - * Escape a string to create a valid JSON string - * - * @param text - * @return - */ - private static String escapeJSON(String text) { - StringBuilder builder = new StringBuilder(); - - builder.append('"'); - for (int index = 0; index < text.length(); index++) { - char chr = text.charAt(index); - - switch (chr) { - case '"': - case '\\': - builder.append('\\'); - builder.append(chr); - break; - case '\b': - builder.append("\\b"); - break; - case '\t': - builder.append("\\t"); - break; - case '\n': - builder.append("\\n"); - break; - case '\r': - builder.append("\\r"); - break; - default: - if (chr < ' ') { - String t = "000" + Integer.toHexString(chr); - builder.append("\\u" + t.substring(t.length() - 4)); - } else { - builder.append(chr); - } - break; - } - } - builder.append('"'); - - return builder.toString(); - } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - */ - private static String urlEncode(final String text) throws UnsupportedEncodingException { - return URLEncoder.encode(text, "UTF-8"); - } - /** * Represents a custom graph on the website */ diff --git a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java b/src/com/sekwah/advancedportals/portals/AdvancedPortal.java index a4b237e6..8bb4b59e 100644 --- a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java +++ b/src/com/sekwah/advancedportals/portals/AdvancedPortal.java @@ -4,57 +4,57 @@ import org.bukkit.Location; import org.bukkit.Material; public class AdvancedPortal { - - public Material trigger = null; - - public String worldName = null; - - public Location pos1 = null; - - public Location pos2 = null; - public String portalName = null; + public Material trigger = null; - // TODO store destinations also as variables like portals - public String destiation = null; // Could possibly store the destination name to stop the server having to read the config file - - public String bungee = null; // Could possibly store the bungee server name to stop the server having to read the config file + public String worldName = null; - // Bungee will be stored inside the destination. + public Location pos1 = null; - public PortalArg[] portalArgs = null; + public Location pos2 = null; - // 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); - this.destiation = destination; - } + public String portalName = null; - public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs){ - this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs); - } + // TODO store destinations also as variables like portals + public String destiation = null; // Could possibly store the destination name to stop the server having to read the config file - public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs){ - this(portalName, trigger, pos1, pos2, worldName, portalArgs); - this.destiation = destination; - } + public String bungee = null; // Could possibly store the bungee server name to stop the server having to read the config file - public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs){ - this.portalName = portalName; - this.trigger = trigger; - this.pos1 = pos1; - this.pos2 = pos2; - this.worldName = worldName; - this.portalArgs = portalArgs; - } + // Bungee will be stored inside the destination. - public String getArg(String arg){ - for(PortalArg portalArg : portalArgs){ - if(arg.equals(portalArg.argName)){ - return portalArg.value; - } - } - return null; - } + public PortalArg[] portalArgs = null; + + // 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); + this.destiation = destination; + } + + public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs) { + this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs); + } + + public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) { + this(portalName, trigger, pos1, pos2, worldName, portalArgs); + this.destiation = destination; + } + + public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) { + this.portalName = portalName; + this.trigger = trigger; + this.pos1 = pos1; + this.pos2 = pos2; + this.worldName = worldName; + this.portalArgs = portalArgs; + } + + public String getArg(String arg) { + for (PortalArg portalArg : portalArgs) { + if (arg.equals(portalArg.argName)) { + return portalArg.value; + } + } + return null; + } } diff --git a/src/com/sekwah/advancedportals/portals/ArgRegistry.java b/src/com/sekwah/advancedportals/portals/ArgRegistry.java index 47fd1576..315f49aa 100644 --- a/src/com/sekwah/advancedportals/portals/ArgRegistry.java +++ b/src/com/sekwah/advancedportals/portals/ArgRegistry.java @@ -2,7 +2,7 @@ package com.sekwah.advancedportals.portals; /** * Created by on 29/02/2016. - * + *

* TODO create argument registry for easier altering and control :) also allows other coders to add custom args * * @author sekwah41 @@ -10,5 +10,4 @@ package com.sekwah.advancedportals.portals; public class ArgRegistry { - } diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index af8a3d83..55591b1f 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -19,430 +19,416 @@ import java.util.logging.Level; public class Portal { - private static AdvancedPortalsPlugin plugin; + public static boolean portalsActive = false; + public static AdvancedPortal[] Portals = new AdvancedPortal[0]; + private static AdvancedPortalsPlugin plugin; + public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml"); + private static boolean ShowBungeeMessage; - public static boolean portalsActive = false; + public Portal(AdvancedPortalsPlugin plugin) { + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); - public static AdvancedPortal[] Portals = new AdvancedPortal[0]; + Portal.plugin = plugin; + Portal.loadPortals(); + } - private static boolean ShowBungeeMessage; + /** + * This can be used to move the get keys to different sections + *

+ * ConfigurationSection section = portalData.getSection("sectionname"); + *

+ * section.getKeys(false); + */ - public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml"); - - public Portal(AdvancedPortalsPlugin plugin) { - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); - - Portal.plugin = plugin; - Portal.loadPortals(); - } - - /** - * This can be used to move the get keys to different sections - * - * ConfigurationSection section = portalData.getSection("sectionname"); - * - * section.getKeys(false); - * - */ - - public static void loadPortals(){ - portalData = new ConfigAccessor(plugin, "portals.yml"); - Set PortalSet = portalData.getConfig().getKeys(false); - if(PortalSet.size() > 0){ - Portals = new AdvancedPortal[PortalSet.toArray().length]; + public static void loadPortals() { + portalData = new ConfigAccessor(plugin, "portals.yml"); + Set PortalSet = portalData.getConfig().getKeys(false); + if (PortalSet.size() > 0) { + Portals = new AdvancedPortal[PortalSet.toArray().length]; /*for(int i = 0; i <= PortalSet.toArray().length - 1; i++){ - Portals[i] = new AdvancedPortal(); + Portals[i] = new AdvancedPortal(); }*/ - int portalId = 0; - for(Object portal: PortalSet.toArray()){ - - ConfigurationSection portalConfigSection = portalData.getConfig().getConfigurationSection(portal.toString()); - - Material blockType = Material.PORTAL; - String BlockID = portalConfigSection.getString("triggerblock"); - - try - { - Integer.parseInt(BlockID); - System.out.println("Block names must be given not IDs"); - } - catch(NumberFormatException e) - { - blockType = Material.getMaterial(BlockID); - } - - if(blockType == null){ - blockType = Material.PORTAL; - } + int portalId = 0; + for (Object portal : PortalSet.toArray()) { - ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs"); + ConfigurationSection portalConfigSection = portalData.getConfig().getConfigurationSection(portal.toString()); + + Material blockType = Material.PORTAL; + String BlockID = portalConfigSection.getString("triggerblock"); + + try { + Integer.parseInt(BlockID); + System.out.println("Block names must be given not IDs"); + } catch (NumberFormatException e) { + blockType = Material.getMaterial(BlockID); + } - ArrayList extraData = new ArrayList<>(); + if (blockType == null) { + blockType = Material.PORTAL; + } - if (portalArgsConf != null) { - Set argsSet = portalArgsConf.getKeys(true); + ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs"); - for(Object argName : argsSet.toArray()){ - if(portalArgsConf.isString(argName.toString())){ - extraData.add(new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString()))); - } - } - } + ArrayList extraData = new ArrayList<>(); + if (portalArgsConf != null) { + Set argsSet = portalArgsConf.getKeys(true); + for (Object argName : argsSet.toArray()) { + if (portalArgsConf.isString(argName.toString())) { + extraData.add(new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString()))); + } + } + } - String worldName = portalData.getConfig().getString(portal.toString() + ".world"); - World world = Bukkit.getWorld(worldName); - Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"), portalData.getConfig().getInt(portal.toString() + ".pos1.Y"), portalData.getConfig().getInt(portal.toString() + ".pos1.Z")); - Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"), portalData.getConfig().getInt(portal.toString() + ".pos2.Y"), portalData.getConfig().getInt(portal.toString() + ".pos2.Z")); + String worldName = portalData.getConfig().getString(portal.toString() + ".world"); - PortalArg[] portalArgs = new PortalArg[extraData.size()]; - extraData.toArray(portalArgs); + World world = Bukkit.getWorld(worldName); + Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"), portalData.getConfig().getInt(portal.toString() + ".pos1.Y"), portalData.getConfig().getInt(portal.toString() + ".pos1.Z")); + Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"), portalData.getConfig().getInt(portal.toString() + ".pos2.Y"), portalData.getConfig().getInt(portal.toString() + ".pos2.Z")); - Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs); + PortalArg[] portalArgs = new PortalArg[extraData.size()]; + extraData.toArray(portalArgs); - Portals[portalId].bungee = portalConfigSection.getString("bungee"); + Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs); - Portals[portalId].destiation = portalConfigSection.getString("destination"); + Portals[portalId].bungee = portalConfigSection.getString("bungee"); - portalId++; - } - portalsActive = true; - } - else{ - portalsActive = false; - } + Portals[portalId].destiation = portalConfigSection.getString("destination"); - } + portalId++; + } + portalsActive = true; + } else { + portalsActive = false; + } - public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, PortalArg... extraData) { - return create(pos1, pos2, name, destination, triggerBlock, null, extraData); - } + } - public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, String serverName, PortalArg... portalArgs) { + public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, PortalArg... extraData) { + return create(pos1, pos2, name, destination, triggerBlock, null, extraData); + } - if(!pos1.getWorld().equals(pos2.getWorld())){ - plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!"); - return "\u00A7cPortal creation error, pos1 and pos2 must be in the same world!"; - } + public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, String serverName, PortalArg... portalArgs) { - int LowX = 0; - int LowY = 0; - int LowZ = 0; + if (!pos1.getWorld().equals(pos2.getWorld())) { + plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!"); + return "\u00A7cPortal creation error, pos1 and pos2 must be in the same world!"; + } - int HighX = 0; - int HighY = 0; - int HighZ = 0; + int LowX = 0; + int LowY = 0; + int LowZ = 0; - if(pos1.getX() > pos2.getX()){ - LowX = (int) pos2.getX(); - HighX = (int) pos1.getX(); - } - else{ - LowX = (int) pos1.getX(); - HighX = (int) pos2.getX(); - } - if(pos1.getY() > pos2.getY()){ - LowY = (int) pos2.getY(); - HighY = (int) pos1.getY(); - } - else{ - LowY = (int) pos1.getY(); - HighY = (int) pos2.getY(); - } - if(pos1.getZ() > pos2.getZ()){ - LowZ = (int) pos2.getZ(); - HighZ = (int) pos1.getZ(); - } - else{ - LowZ = (int) pos1.getZ(); - HighZ = (int) pos2.getZ(); - } - - Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ); - Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ); - - if(checkPortalOverlap(checkpos1, checkpos2)){ - plugin.getLogger().log(Level.WARNING, "Portals must not overlap!"); - return "\u00A7cPortal creation error, portals must not overlap!"; - } + int HighX = 0; + int HighY = 0; + int HighZ = 0; - portalData.getConfig().set(name + ".world", pos1.getWorld().getName()); + if (pos1.getX() > pos2.getX()) { + LowX = (int) pos2.getX(); + HighX = (int) pos1.getX(); + } else { + LowX = (int) pos1.getX(); + HighX = (int) pos2.getX(); + } + if (pos1.getY() > pos2.getY()) { + LowY = (int) pos2.getY(); + HighY = (int) pos1.getY(); + } else { + LowY = (int) pos1.getY(); + HighY = (int) pos2.getY(); + } + if (pos1.getZ() > pos2.getZ()) { + LowZ = (int) pos2.getZ(); + HighZ = (int) pos1.getZ(); + } else { + LowZ = (int) pos1.getZ(); + HighZ = (int) pos2.getZ(); + } + + Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ); + Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ); + + if (checkPortalOverlap(checkpos1, checkpos2)) { + plugin.getLogger().log(Level.WARNING, "Portals must not overlap!"); + return "\u00A7cPortal creation error, portals must not overlap!"; + } + + portalData.getConfig().set(name + ".world", pos1.getWorld().getName()); + + portalData.getConfig().set(name + ".triggerblock", checkMaterial(triggerBlock)); + + portalData.getConfig().set(name + ".destination", destination); + + portalData.getConfig().set(name + ".bungee", serverName); + + portalData.getConfig().set(name + ".pos1.X", HighX); + portalData.getConfig().set(name + ".pos1.Y", HighY); + portalData.getConfig().set(name + ".pos1.Z", HighZ); + + portalData.getConfig().set(name + ".pos2.X", LowX); + portalData.getConfig().set(name + ".pos2.Y", LowY); + portalData.getConfig().set(name + ".pos2.Z", LowZ); + + for (PortalArg arg : portalArgs) { + portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value); + } + + portalData.saveConfig(); + + loadPortals(); + + return "\u00A7aPortal creation successful!"; + } + + // make this actually work! + private static boolean checkPortalOverlap(Location pos1, Location pos2) { + + if (portalsActive) { + int portalId = 0; + for (@SuppressWarnings("unused") Object portal : Portal.Portals) { + if (Portals[portalId].worldName.equals(pos2.getWorld().getName())) { // checks that the cubes arnt overlapping by seeing if all 4 corners are not in side another + if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())) { + return true; + } + + if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())) { + return true; + } + + if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())) { + return true; + } + + if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())) { + return true; + } + + if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())) { + return true; + } + + if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())) { + return true; + } + + if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())) { + return true; + } + + if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())) { + return true; + } + } + portalId++; + } + } + return false; + } + + private static boolean checkOverLapPortal(Location pos1, Location pos2, int posX, int posY, int posZ) { + if (pos1.getX() >= posX && pos1.getY() >= posX && pos1.getZ() >= posZ) { + if ((pos2.getX()) <= posX && pos2.getY() <= posY && pos2.getZ() <= posZ) { + return true; + + } + } + return false; + } - portalData.getConfig().set(name + ".triggerblock", checkMaterial(triggerBlock)); + private static String checkMaterial(Material triggerBlock) { + if (triggerBlock.equals(Material.WATER)) { + return "STATIONARY_WATER"; + } else if (triggerBlock.equals(Material.LAVA)) { + return "STATIONARY_LAVA"; + } + return triggerBlock.toString(); + } - portalData.getConfig().set(name + ".destination", destination); + @SuppressWarnings("deprecation") + public static String create(Location pos1, Location pos2, String name, String destination, String serverName, PortalArg... extraData) { // add stuff for destination names or coordinates + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - portalData.getConfig().set(name + ".bungee", serverName); + Material triggerBlockType; + String BlockID = config.getConfig().getString("DefaultPortalTriggerBlock"); + try { + triggerBlockType = Material.getMaterial(Integer.parseInt(BlockID)); + } catch (Exception e) { + triggerBlockType = Material.getMaterial(BlockID); + } - portalData.getConfig().set(name + ".pos1.X", HighX); - portalData.getConfig().set(name + ".pos1.Y", HighY); - portalData.getConfig().set(name + ".pos1.Z", HighZ); + if (triggerBlockType == null) { + triggerBlockType = Material.PORTAL; + } - portalData.getConfig().set(name + ".pos2.X", LowX); - portalData.getConfig().set(name + ".pos2.Y", LowY); - portalData.getConfig().set(name + ".pos2.Z", LowZ); + // TODO add a for loop which scans through the addArgs and adds them to the portalData so that the application can use them - for(PortalArg arg: portalArgs){ - portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value); - } + String result = create(pos1, pos2, name, destination, triggerBlockType, serverName, extraData); - portalData.saveConfig(); + return result; + } - loadPortals(); + public static void redefine(Location pos1, Location pos2, String name) { - return "\u00A7aPortal creation successful!"; - } + portalData.getConfig().set(name + ".pos1.X", pos1.getX()); + portalData.getConfig().set(name + ".pos1.Y", pos1.getY()); + portalData.getConfig().set(name + ".pos1.Z", pos1.getZ()); - // make this actually work! - private static boolean checkPortalOverlap(Location pos1, Location pos2) { + portalData.getConfig().set(name + ".pos2.X", pos2.getX()); + portalData.getConfig().set(name + ".pos2.Y", pos2.getY()); + portalData.getConfig().set(name + ".pos2.Z", pos2.getZ()); - if(portalsActive){ - int portalId = 0; - for(@SuppressWarnings("unused") Object portal : Portal.Portals){ - if(Portals[portalId].worldName.equals(pos2.getWorld().getName())){ // checks that the cubes arnt overlapping by seeing if all 4 corners are not in side another - if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())){return true;} + portalData.saveConfig(); - if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())){return true;} - - if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())){return true;} - - if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())){return true;} - - if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())){return true;} - - if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())){return true;} + loadPortals(); - if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())){return true;} - - if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())){return true;} - } - portalId++; - } - } - return false; - } - - private static boolean checkOverLapPortal(Location pos1, Location pos2, int posX, int posY, int posZ) { - if(pos1.getX() >= posX && pos1.getY() >= posX && pos1.getZ() >= posZ){ - if((pos2.getX()) <= posX && pos2.getY() <= posY && pos2.getZ() <= posZ){ - return true; + } - } - } - return false; - } + public static String getDestination(String portalName) { + return portalData.getConfig().getString(portalName + ".destination"); + } - private static String checkMaterial(Material triggerBlock) { - if(triggerBlock.equals(Material.WATER)){ - return "STATIONARY_WATER"; - } - else if(triggerBlock.equals(Material.LAVA)){ - return "STATIONARY_LAVA"; - } - return triggerBlock.toString(); - } + public static void remove(String name) { - @SuppressWarnings("deprecation") - public static String create(Location pos1, Location pos2, String name, String destination, String serverName, PortalArg... extraData) { // add stuff for destination names or coordinates - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + Object[] keys = portalData.getConfig().getKeys(true).toArray(); + for (int i = keys.length - 1; i >= 0; i--) { + String key = keys[i].toString(); + if (key.startsWith(name + ".")) { + portalData.getConfig().set(key, null); + } + } + portalData.getConfig().set(name, null); - Material triggerBlockType; - String BlockID = config.getConfig().getString("DefaultPortalTriggerBlock"); - try - { - triggerBlockType = Material.getMaterial(Integer.parseInt(BlockID)); - } - catch(Exception e) - { - triggerBlockType = Material.getMaterial(BlockID); - } + // TODO add code to check if people have the portal selected and notify if removed. - if(triggerBlockType == null){ - triggerBlockType = Material.PORTAL; - } + /**Set keys = portalData.getConfig().getKeys(true); + for(String key: keys){ + if(key.startsWith(name)){ + portalData.getConfig().set(key, null); + } + }*/ - // TODO add a for loop which scans through the addArgs and adds them to the portalData so that the application can use them + /**portalData.getConfig().set(name + ".world", null); + portalData.getConfig().set(name + ".triggerblock", null); + portalData.getConfig().set(name + ".destination", null); - String result = create(pos1, pos2, name, destination, triggerBlockType, serverName, extraData); + portalData.getConfig().set(name + ".pos1.X", null); + portalData.getConfig().set(name + ".pos1.Y", null); + portalData.getConfig().set(name + ".pos1.Z", null); - return result; - } + portalData.getConfig().set(name + ".pos2.X", null); + portalData.getConfig().set(name + ".pos2.Y", null); + portalData.getConfig().set(name + ".pos2.Z", null); - public static void redefine(Location pos1, Location pos2, String name){ + portalData.getConfig().set(name + ".pos1", null); + portalData.getConfig().set(name + ".pos2", null); - portalData.getConfig().set(name + ".pos1.X", pos1.getX()); - portalData.getConfig().set(name + ".pos1.Y", pos1.getY()); - portalData.getConfig().set(name + ".pos1.Z", pos1.getZ()); + portalData.getConfig().set(name, null);*/ - portalData.getConfig().set(name + ".pos2.X", pos2.getX()); - portalData.getConfig().set(name + ".pos2.Y", pos2.getY()); - portalData.getConfig().set(name + ".pos2.Z", pos2.getZ()); + portalData.saveConfig(); - portalData.saveConfig(); + loadPortals(); + } - loadPortals(); + public static boolean portalExists(String portalName) { - } + String posX = portalData.getConfig().getString(portalName + ".pos1.X"); - public static String getDestination(String portalName){ - return portalData.getConfig().getString(portalName + ".destination"); - } + return posX != null; + } - public static void remove(String name){ + public static boolean activate(Player player, String portalName) { + for (AdvancedPortal portal : Portal.Portals) { + if (portal.portalName.equals(portalName)) return activate(player, portal); + } + plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName); + return false; + } - Object[] keys = portalData.getConfig().getKeys(true).toArray(); - for(int i = keys.length - 1; i >= 0; i--){ - String key = keys[i].toString(); - if(key.startsWith(name + ".")){ - portalData.getConfig().set(key, null); - } - } - portalData.getConfig().set(name, null); + public static boolean activate(Player player, AdvancedPortal portal) { - // TODO add code to check if people have the portal selected and notify if removed. + // add other variables or filter code here, or somehow have a way to register them - /**Set keys = portalData.getConfig().getKeys(true); - for(String key: keys){ - if(key.startsWith(name)){ - portalData.getConfig().set(key, null); - } - }*/ - - /**portalData.getConfig().set(name + ".world", null); - portalData.getConfig().set(name + ".triggerblock", null); - portalData.getConfig().set(name + ".destination", null); - - portalData.getConfig().set(name + ".pos1.X", null); - portalData.getConfig().set(name + ".pos1.Y", null); - portalData.getConfig().set(name + ".pos1.Z", null); - - portalData.getConfig().set(name + ".pos2.X", null); - portalData.getConfig().set(name + ".pos2.Y", null); - portalData.getConfig().set(name + ".pos2.Z", null); - - portalData.getConfig().set(name + ".pos1", null); - portalData.getConfig().set(name + ".pos2", null); - - portalData.getConfig().set(name, null);*/ - - portalData.saveConfig(); - - loadPortals(); - } - - public static boolean portalExists(String portalName){ - - String posX = portalData.getConfig().getString(portalName + ".pos1.X"); - - if(posX == null){ - return false; - } - else{ - return true; - } - } - - public static boolean activate(Player player, String portalName) { - for(AdvancedPortal portal : Portal.Portals){ - if(portal.portalName.equals(portalName)) return activate(player, portal); - } - plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName); - return false; - } - - public static boolean activate(Player player, AdvancedPortal portal) { - - // add other variables or filter code here, or somehow have a way to register them - - String permission = portal.getArg("permission"); + String permission = portal.getArg("permission"); /*if((permission == null || (permission != null && player.hasPermission(permission)) || player.isOp())){*/ - if(!((permission != null && player.hasPermission(permission)) || player.isOp())){ - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to use this portal!"); - return false; - } + if (!((permission != null && player.hasPermission(permission)) || player.isOp())) { + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to use this portal!"); + return false; + } - if(portal.bungee != null){ - if(ShowBungeeMessage){ - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\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()); - return false; + if (portal.bungee != null) { + if (ShowBungeeMessage) { + player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\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()); + return false; - } - else{ - boolean showFailMessage = true; + } else { + boolean showFailMessage = true; - if(portal.getArg("command.1") != null){ - showFailMessage = false; - int commandLine = 1; - String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine); - do{ - // (?i) makes the search case insensitive - command = command.replaceAll("@player", player.getName()); - plugin.getLogger().log(Level.SEVERE, "Portal command: " + command); - if(command.startsWith("#")){ - command = command.substring(1); - plugin.getLogger().log(Level.SEVERE, "Portal command: " + command); - plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); - } - else if(command.startsWith("!")){ - command = command.substring(1); - boolean wasOp = player.isOp(); - try{ - player.setOp(true); - player.performCommand(command); - } - finally { - player.setOp(wasOp); - } - } - else if(command.startsWith("^")){ - command = command.substring(1); - PermissionAttachment permissionAttachment = null; - try{ - permissionAttachment = player.addAttachment(plugin, "*", true); - player.performCommand(command); - } - finally { - player.removeAttachment(permissionAttachment); - } - } - else{ - player.performCommand(command); - } - command = portal.getArg("command." + ++commandLine); - }while(command != null); - } - //plugin.getLogger().info(portal.portalName + ":" + portal.destiation); - 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("\u00A7c[\u00A77AdvancedPortals\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) { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you are trying to use doesn't have a destination!"); - plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp " - + "attempt and either the data is corrupt or portal doesn't exist!"); - } - return false; - } + if (portal.getArg("command.1") != null) { + showFailMessage = false; + int commandLine = 1; + String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine); + do { + // (?i) makes the search case insensitive + command = command.replaceAll("@player", player.getName()); + plugin.getLogger().log(Level.SEVERE, "Portal command: " + command); + if (command.startsWith("#")) { + command = command.substring(1); + plugin.getLogger().log(Level.SEVERE, "Portal command: " + command); + plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); + } else if (command.startsWith("!")) { + command = command.substring(1); + boolean wasOp = player.isOp(); + try { + player.setOp(true); + player.performCommand(command); + } finally { + player.setOp(wasOp); + } + } else if (command.startsWith("^")) { + command = command.substring(1); + PermissionAttachment permissionAttachment = null; + try { + permissionAttachment = player.addAttachment(plugin, "*", true); + player.performCommand(command); + } finally { + player.removeAttachment(permissionAttachment); + } + } else { + player.performCommand(command); + } + command = portal.getArg("command." + ++commandLine); + } while (command != null); + } + //plugin.getLogger().info(portal.portalName + ":" + portal.destiation); + 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("\u00A7c[\u00A77AdvancedPortals\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) { + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you are trying to use doesn't have a destination!"); + plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp " + + "attempt and either the data is corrupt or portal doesn't exist!"); + } + return false; + } /*if(configDesti.getConfig().getString(destiName + ".world") != null){ String permission = portalData.getConfig().getString(portalName + ".portalArgs.permission"); @@ -462,52 +448,49 @@ public class Portal { return false; }*/ - } - } + } + } - public static void rename(String oldName, String newName){ + public static void rename(String oldName, String newName) { - // set it so it gets all data from one and puts it into another place + // set it so it gets all data from one and puts it into another place - ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); + ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); - Set keys = config.getConfig().getKeys(true); - for(String key: keys){ - if(key.startsWith(oldName + ".")){ - if(config.getConfig().getString(key) != null){ - try - { - int intData = Integer.parseInt(config.getConfig().getString(key)); - config.getConfig().set(key.replace(oldName + ".", newName + "."), intData); - } - catch(Exception e) - { - config.getConfig().set(key.replace(oldName + ".", newName + "."), config.getConfig().getString(key)); - } + Set keys = config.getConfig().getKeys(true); + for (String key : keys) { + if (key.startsWith(oldName + ".")) { + if (config.getConfig().getString(key) != null) { + try { + int intData = Integer.parseInt(config.getConfig().getString(key)); + config.getConfig().set(key.replace(oldName + ".", newName + "."), intData); + } catch (Exception e) { + config.getConfig().set(key.replace(oldName + ".", newName + "."), config.getConfig().getString(key)); + } - } - } - } + } + } + } - config.saveConfig(); + config.saveConfig(); - remove(oldName); + remove(oldName); - } + } - public static boolean addCommand(String portalName, String portalCommand) { - ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); - if(portalExists(portalName)){ - int commandLine = 0; - while(config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null); //Loops increasing commandLine till 1 is null - config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand); - config.saveConfig(); - loadPortals(); - return true; - } - else{ - return false; - } - } + public static boolean addCommand(String portalName, String portalCommand) { + ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); + if (portalExists(portalName)) { + int commandLine = 0; + while (config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null) + ; //Loops increasing commandLine till 1 is null + config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand); + config.saveConfig(); + loadPortals(); + return true; + } else { + return false; + } + } } diff --git a/src/com/sekwah/advancedportals/portals/PortalArg.java b/src/com/sekwah/advancedportals/portals/PortalArg.java index 5738c044..c095ea8a 100644 --- a/src/com/sekwah/advancedportals/portals/PortalArg.java +++ b/src/com/sekwah/advancedportals/portals/PortalArg.java @@ -6,7 +6,7 @@ public class PortalArg { public final String value; //public final int type; - public PortalArg(String argName, String value/*, int type*/){ + public PortalArg(String argName, String value/*, int type*/) { this.argName = argName; this.value = value; // may be used if values need to be 100% not string diff --git a/src/com/sekwah/advancedportals/portals/PortalTags.java b/src/com/sekwah/advancedportals/portals/PortalTags.java index 492f6823..e98ca23f 100644 --- a/src/com/sekwah/advancedportals/portals/PortalTags.java +++ b/src/com/sekwah/advancedportals/portals/PortalTags.java @@ -6,7 +6,7 @@ import java.util.Map; /** * Created by on 29/03/2016. - * + *

* TODO add all the normal tags then add the extradata tags * * @author sekwah41 @@ -15,12 +15,12 @@ public class PortalTags { // TODO create a list or hashmap of tags to check for. - public Map tagDesc = new HashMap(); + public Map tagDesc = new HashMap(); public ArrayList tags = new ArrayList(); - public void registerTag(String tagName){ + public void registerTag(String tagName) { this.registerTag(tagName, false); } @@ -31,11 +31,11 @@ public class PortalTags { * @param tagName * @param description */ - public void registerTag(String tagName, boolean multiWord, String description){ + public void registerTag(String tagName, boolean multiWord, String description) { this.registerTag(tagName, multiWord); } - public void registerTag(String tagName, boolean multiWord){ + public void registerTag(String tagName, boolean multiWord) { }