From dc8a301ff29170963149ab55e9b7d5066392b0d7 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Mon, 20 Apr 2020 13:20:27 +0100 Subject: [PATCH] Fixed #187 as well as adds bungeecommand --- .../bukkit/AdvancedPortalsCommand.java | 1001 +++++++++-------- .../advancedportals/bukkit/Settings.java | 32 +- .../listeners/PluginMessageReceiver.java | 7 +- .../bukkit/portals/Portal.java | 19 +- .../bungee/AdvancedPortalsPlugin.java | 3 +- .../bungee/listener/EventListener.java | 6 +- .../listener/PluginMessageReceiver.java | 31 +- src/main/resources/bungee.yml | 2 +- src/main/resources/config.yml | 18 +- src/main/resources/plugin.yml | 10 +- 10 files changed, 591 insertions(+), 538 deletions(-) diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java b/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java index 8e7eabb..7e50068 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java @@ -62,555 +62,560 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (sender.hasPermission("advancedportals.portal")) { if (args.length > 0) { switch (args[0].toLowerCase()) { - case "warp": - if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")) { - for (AdvancedPortal portal : Portal.portals) { - if (args[1].equalsIgnoreCase(portal.getName())) { + case "warp": + if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")) { + for (AdvancedPortal portal : Portal.portals) { + if (args[1].equalsIgnoreCase(portal.getName())) { - if (portal.inPortal.contains(player.getUniqueId())) - return true; - WarpEvent warpEvent = new WarpEvent(player, portal); - plugin.getServer().getPluginManager().callEvent(warpEvent); + if (portal.inPortal.contains(player.getUniqueId())) + return true; + WarpEvent warpEvent = new WarpEvent(player, portal); + plugin.getServer().getPluginManager().callEvent(warpEvent); - if (!warpEvent.isCancelled()) - Portal.activate(player, portal); - break; + if (!warpEvent.isCancelled()) + Portal.activate(player, portal); + break; + } } } - } - sendMenu(player, "Help Menu: Warp", - "\u00A76/" + command + " warp \u00A7a- teleport to warp name"); - break; - case "wand": - case "selector": - String ItemID = config.getConfig().getString("AxeItemId"); + sendMenu(player, "Help Menu: Warp", + "\u00A76/" + command + " warp \u00A7a- teleport to warp name"); + break; + case "wand": + case "selector": + 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 bestowed 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 bestowed upon it!")); + regionselector.setItemMeta(selectorname); - inventory.addItem(regionselector); - sender.sendMessage(PluginMessages.customPrefix - + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); - break; - case "portalblock": - // TODO change this to a purple wool block and give it a name with a color. Then - // listen to when its placed. - // Also do this for other blocks such as gateways and end portals just in case - // they want it. - ItemStack portalBlock = new Wool(DyeColor.PURPLE).toItemStack(1); - ItemMeta blockName = portalBlock.getItemMeta(); - blockName.setDisplayName("\u00A75Portal Block Placer"); - blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", - "\u00A7rRight Click: Place portal block", "\u00A7rLeft Click: Rotate portal block")); - portalBlock.setItemMeta(blockName); - inventory.addItem(portalBlock); + inventory.addItem(regionselector); + sender.sendMessage(PluginMessages.customPrefix + + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); + break; + case "portalblock": + // TODO change this to a purple wool block and give it a name with a color. Then + // listen to when its placed. + // Also do this for other blocks such as gateways and end portals just in case + // they want it. + ItemStack portalBlock = new Wool(DyeColor.PURPLE).toItemStack(1); + ItemMeta blockName = portalBlock.getItemMeta(); + blockName.setDisplayName("\u00A75Portal Block Placer"); + blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", + "\u00A7rRight Click: Place portal block", "\u00A7rLeft Click: Rotate portal block")); + portalBlock.setItemMeta(blockName); + inventory.addItem(portalBlock); - sender.sendMessage( - PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); - break; - case "endportalblock": - // TODO change this to a purple wool block and give it a name with a color. Then - // listen to when its placed. - // Also do this for other blocks such as gateways and end portals just in case - // they want it. - portalBlock = new Wool(DyeColor.BLACK).toItemStack(1); - blockName = portalBlock.getItemMeta(); - blockName.setDisplayName("\u00A78End Portal Block Placer"); - blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", - "\u00A7rRight Click: Place portal block")); - portalBlock.setItemMeta(blockName); - inventory.addItem(portalBlock); - sender.sendMessage( - PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); - break; - case "gatewayblock": - // TODO change this to a purple wool block and give it a name with a color. Then - // listen to when its placed. - // Also do this for other blocks such as gateways and end portals just in case - // they want it. - portalBlock = new Wool(DyeColor.BLACK).toItemStack(1); - blockName = portalBlock.getItemMeta(); - blockName.setDisplayName("\u00A78Gateway Block Placer"); - blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", - "\u00A7rRight Click: Place portal block")); - portalBlock.setItemMeta(blockName); - inventory.addItem(portalBlock); + sender.sendMessage( + PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); + break; + case "endportalblock": + // TODO change this to a purple wool block and give it a name with a color. Then + // listen to when its placed. + // Also do this for other blocks such as gateways and end portals just in case + // they want it. + portalBlock = new Wool(DyeColor.BLACK).toItemStack(1); + blockName = portalBlock.getItemMeta(); + blockName.setDisplayName("\u00A78End Portal Block Placer"); + blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", + "\u00A7rRight Click: Place portal block")); + portalBlock.setItemMeta(blockName); + inventory.addItem(portalBlock); + sender.sendMessage( + PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); + break; + case "gatewayblock": + // TODO change this to a purple wool block and give it a name with a color. Then + // listen to when its placed. + // Also do this for other blocks such as gateways and end portals just in case + // they want it. + portalBlock = new Wool(DyeColor.BLACK).toItemStack(1); + blockName = portalBlock.getItemMeta(); + blockName.setDisplayName("\u00A78Gateway Block Placer"); + blockName.setLore(Arrays.asList("\u00A7rThis wool is made of a magical substance", + "\u00A7rRight Click: Place portal block")); + portalBlock.setItemMeta(blockName); + inventory.addItem(portalBlock); - sender.sendMessage( - PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); - break; - case "create": - if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { - if (player.getMetadata("Pos1World").get(0).asString() - .equals(player.getMetadata("Pos2World").get(0).asString()) - && player.getMetadata("Pos1World").get(0).asString() - .equals(player.getLocation().getWorld().getName())) { - if (args.length >= 2) { // may make this next piece of code more efficient, maybe check - // against a list of available variables or something - // TODO change system to use arrays and hashmaps - boolean hasName = false; - boolean hasTriggerBlock = false; - boolean hasDestination = false; - boolean isBungeePortal = false; - boolean needsPermission = false; - boolean executesCommand = false; - String destination = null; - String portalName = null; - String triggerBlock = null; - String serverName = null; - String permission = null; - String portalCommand = null; + sender.sendMessage( + PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); + break; + case "create": + if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { + if (player.getMetadata("Pos1World").get(0).asString() + .equals(player.getMetadata("Pos2World").get(0).asString()) + && player.getMetadata("Pos1World").get(0).asString() + .equals(player.getLocation().getWorld().getName())) { + if (args.length >= 2) { // may make this next piece of code more efficient, maybe check + // against a list of available variables or something + // TODO change system to use arrays and hashmaps + boolean hasName = false; + boolean hasTriggerBlock = false; + boolean hasDestination = false; + boolean isBungeePortal = false; + boolean needsPermission = false; + boolean executesCommand = false; + String destination = null; + String portalName = null; + String triggerBlock = null; + String serverName = null; + String permission = null; + String portalCommand = null; - ArrayList extraData = new ArrayList<>(); + ArrayList extraData = new ArrayList<>(); - // Is completely changed in the recode but for now im leaving it as this - // horrible mess... - for (int i = 1; i < args.length; i++) { - if (startsWithPortalArg("name:", args[i])) { - portalName = args[i].replaceFirst("name:", ""); - if (portalName.equals("")) { - player.sendMessage(PluginMessages.customPrefixFail - + " You must include a name for the portal that isnt nothing!"); - return true; + // Is completely changed in the recode but for now im leaving it as this + // horrible mess... + for (int i = 1; i < args.length; i++) { + if (startsWithPortalArg("name:", args[i])) { + portalName = args[i].replaceFirst("name:", ""); + if (portalName.equals("")) { + player.sendMessage(PluginMessages.customPrefixFail + + " You must include a name for the portal that isnt nothing!"); + return true; + } + hasName = true; + portalName = args[i].replaceFirst("name:", ""); + } else if (startsWithPortalArg("destination:", args[i])) { + hasDestination = true; + destination = args[i].toLowerCase().replaceFirst("destination:", ""); + } else if (startsWithPortalArg("desti:", args[i])) { + hasDestination = true; + destination = args[i].toLowerCase().replaceFirst("desti:", ""); + } else if (startsWithPortalArg("triggerblock:", args[i])) { + hasTriggerBlock = true; + triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); + } else if (startsWithPortalArg("triggerblock:", args[i])) { + hasTriggerBlock = true; + triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); + } else if (this.startsWithPortalArg("bungee:", args[i])) { + isBungeePortal = true; + serverName = args[i].substring("bungee:".length()); + } else if (startsWithPortalArg("permission:", args[i])) { + needsPermission = true; + permission = args[i].toLowerCase().replaceFirst("permission:", ""); + extraData.add(new PortalArg("permission", permission)); + } else if (startsWithPortalArg("delayed:", args[i])) { + boolean delayed = Boolean + .parseBoolean(args[i].toLowerCase().replaceFirst("delayed:", "")); + extraData.add(new PortalArg("delayed", Boolean.toString(delayed))); + } else if (startsWithPortalArg("message:", args[i])) { + String message = parseArgVariable(args, i, "message:"); + if (message == null) { + player.sendMessage( + PluginMessages.customPrefixFail + " Message quotes not closed!"); + return true; + } + extraData.add(new PortalArg("message", message)); + } else if (startsWithPortalArg("command:", args[i])) { + executesCommand = true; + portalCommand = parseArgVariable(args, i, "command:"); + if (portalCommand == null) { + player.sendMessage( + PluginMessages.customPrefixFail + " Command quotes not closed!"); + return true; + } + i += this.portalArgsStringLength - 1; + if (portalCommand.startsWith("#") + && !(this.plugin.getSettings().enabledCommandLevel("c") + && (sender.hasPermission( + "advancedportals.createportal.commandlevel.console") + || sender.isOp()))) { + player.sendMessage(PluginMessages.customPrefixFail + + " You need permission to make a console command portal!"); + return true; + } else if (portalCommand.startsWith("!") + && !(this.plugin.getSettings().enabledCommandLevel("o") + && (sender.hasPermission( + "advancedportals.createportal.commandlevel.op") + || sender.isOp()))) { + player.sendMessage(PluginMessages.customPrefixFail + + " You need permission to make a op command portal!"); + return true; + } else if (portalCommand.startsWith("%") + && !(this.plugin.getSettings().enabledCommandLevel("b") + && (sender.hasPermission( + "advancedportals.createportal.commandlevel.bungee") + || sender.isOp()))) { + player.sendMessage(PluginMessages.customPrefixFail + + " You need permission to make a bungee command portal!"); + return true; + } else if (portalCommand.startsWith("^") + && !(this.plugin.getSettings().enabledCommandLevel("p") + && (sender.hasPermission( + "advancedportals.createportal.commandlevel.perms") + || sender.isOp()))) { + player.sendMessage(PluginMessages.customPrefixFail + + " You need permission to make a all perms command portal!"); + return true; + } + extraData.add(new PortalArg("command.1", portalCommand)); + } else if (startsWithPortalArg("cooldowndelay:", args[i])) { + String cooldownDelay = parseArgVariable(args, i, "cooldowndelay:"); + extraData.add(new PortalArg("cooldowndelay", cooldownDelay)); + } else if (startsWithPortalArg("leavedesti:", args[i])) { + String leaveDesti = parseArgVariable(args, i, "leavedesti:"); + extraData.add(new PortalArg("leavedesti", leaveDesti)); } - hasName = true; - portalName = args[i].replaceFirst("name:", ""); - } else if (startsWithPortalArg("destination:", args[i])) { - hasDestination = true; - destination = args[i].toLowerCase().replaceFirst("destination:", ""); - } else if (startsWithPortalArg("desti:", args[i])) { - hasDestination = true; - destination = args[i].toLowerCase().replaceFirst("desti:", ""); - } else if (startsWithPortalArg("triggerblock:", args[i])) { - hasTriggerBlock = true; - triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); - } else if (startsWithPortalArg("triggerblock:", args[i])) { - hasTriggerBlock = true; - triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); - } else if (this.startsWithPortalArg("bungee:", args[i])) { - isBungeePortal = true; - serverName = args[i].substring("bungee:".length()); - } else if (startsWithPortalArg("permission:", args[i])) { - needsPermission = true; - permission = args[i].toLowerCase().replaceFirst("permission:", ""); - extraData.add(new PortalArg("permission", permission)); - } else if (startsWithPortalArg("delayed:", args[i])) { - boolean delayed = Boolean - .parseBoolean(args[i].toLowerCase().replaceFirst("delayed:", "")); - extraData.add(new PortalArg("delayed", Boolean.toString(delayed))); - } else if (startsWithPortalArg("message:", args[i])) { - String message = parseArgVariable(args, i, "message:"); - if (message == null) { - player.sendMessage( - PluginMessages.customPrefixFail + " Message quotes not closed!"); - return true; - } - extraData.add(new PortalArg("message", message)); - } else if (startsWithPortalArg("command:", args[i])) { - executesCommand = true; - portalCommand = parseArgVariable(args, i, "command:"); - if (portalCommand == null) { - player.sendMessage( - PluginMessages.customPrefixFail + " Command quotes not closed!"); - return true; - } - i += this.portalArgsStringLength - 1; - if (portalCommand.startsWith("#") - && !(this.plugin.getSettings().hasCommandLevel("c") - && (sender.hasPermission( - "advancedportals.createportal.commandlevel.console")) - || (this.plugin.getSettings().hasCommandLevel("k") - && sender.isOp()))) { - player.sendMessage(PluginMessages.customPrefixFail - + " You need permission to make a console command portal!"); - return true; - } else if (portalCommand.startsWith("!") - && !(this.plugin.getSettings().hasCommandLevel("o") - && (sender.hasPermission( - "advancedportals.createportal.commandlevel.op")) - || (this.plugin.getSettings().hasCommandLevel("p") - && sender.isOp()))) { - player.sendMessage(PluginMessages.customPrefixFail - + " You need permission to make a op command portal!"); - return true; - } else if (portalCommand.startsWith("^") - && !(this.plugin.getSettings().hasCommandLevel("p") - && (sender.hasPermission( - "advancedportals.createportal.commandlevel.perms")) - || (this.plugin.getSettings().hasCommandLevel("e") - && sender.isOp()))) { - player.sendMessage(PluginMessages.customPrefixFail - + " You need permission to make a all perms command portal!"); - return true; - } - extraData.add(new PortalArg("command.1", portalCommand)); - } else if (startsWithPortalArg("cooldowndelay:", args[i])) { - String cooldownDelay = parseArgVariable(args, i, "cooldowndelay:"); - extraData.add(new PortalArg("cooldowndelay", cooldownDelay)); - } else if (startsWithPortalArg("leavedesti:", args[i])) { - String leaveDesti = parseArgVariable(args, i, "leavedesti:"); - extraData.add(new PortalArg("leavedesti", leaveDesti)); } - } - if (!hasName) { - player.sendMessage(PluginMessages.customPrefixFail - + " You must include a name for the portal that you are creating in the variables!"); - return true; - } + if (!hasName) { + player.sendMessage(PluginMessages.customPrefixFail + + " You must include a name for the portal that you are creating in the variables!"); + return true; + } - World world = org.bukkit.Bukkit - .getWorld(player.getMetadata("Pos1World").get(0).asString()); - Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), - player.getMetadata("Pos1Y").get(0).asInt(), - player.getMetadata("Pos1Z").get(0).asInt()); - Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), - player.getMetadata("Pos2Y").get(0).asInt(), - player.getMetadata("Pos2Z").get(0).asInt()); + World world = org.bukkit.Bukkit + .getWorld(player.getMetadata("Pos1World").get(0).asString()); + Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), + player.getMetadata("Pos1Y").get(0).asInt(), + player.getMetadata("Pos1Z").get(0).asInt()); + Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), + player.getMetadata("Pos2Y").get(0).asInt(), + player.getMetadata("Pos2Z").get(0).asInt()); - ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml"); - String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X"); + ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml"); + String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X"); - if (!Portal.portalExists(portalName)) { + if (!Portal.portalExists(portalName)) { + + player.sendMessage(""); + player.sendMessage(PluginMessages.customPrefix + + "\u00A7e You have created a new portal with the following details:"); + player.sendMessage("\u00A7aname: \u00A7e" + portalName); + if (hasDestination) { + if (!isBungeePortal && destiPosX == null) { + player.sendMessage("\u00A7cdestination: \u00A7e" + destination + + " (destination does not exist)"); + return true; + } else { + player.sendMessage("\u00A7adestination: \u00A7e" + destination); + } - player.sendMessage(""); - player.sendMessage(PluginMessages.customPrefix - + "\u00A7e You have created a new portal with the following details:"); - player.sendMessage("\u00A7aname: \u00A7e" + portalName); - if (hasDestination) { - if (!isBungeePortal && destiPosX == null) { - player.sendMessage("\u00A7cdestination: \u00A7e" + destination - + " (destination does not exist)"); - return true; } else { - player.sendMessage("\u00A7adestination: \u00A7e" + destination); + player.sendMessage( + "\u00A7cdestination: \u00A7eN/A (will not teleport to a location)"); } - } else { - player.sendMessage( - "\u00A7cdestination: \u00A7eN/A (will not teleport to a location)"); - } - - if (isBungeePortal) { - player.sendMessage("\u00A7abungee: \u00A7e" + serverName); - } - - if (needsPermission) { - player.sendMessage("\u00A7apermission: \u00A7e" + permission); - } else { - player.sendMessage("\u00A7apermission: \u00A7e(none needed)"); - } - - for (PortalArg portalArg : extraData) { - if (!ignoreExtras.contains(portalArg.argName)) { - player.sendMessage( - "\u00A7a" + portalArg.argName + ": \u00A7e" + portalArg.value); + if (isBungeePortal) { + player.sendMessage("\u00A7abungee: \u00A7e" + serverName); } - } - if (executesCommand) { - player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); - } + if (needsPermission) { + player.sendMessage("\u00A7apermission: \u00A7e" + permission); + } else { + player.sendMessage("\u00A7apermission: \u00A7e(none needed)"); + } - if (hasTriggerBlock) { - Set materialSet = Portal - .getMaterialSet(triggerBlock.toUpperCase().split(",")); - if (materialSet.size() != 0) { - player.sendMessage( - "\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase()); - PortalArg[] portalArgs = new PortalArg[extraData.size()]; - portalArgs = extraData.toArray(portalArgs); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, - materialSet, serverName, portalArgs)); + for (PortalArg portalArg : extraData) { + if (!ignoreExtras.contains(portalArg.argName)) { + player.sendMessage( + "\u00A7a" + portalArg.argName + ": \u00A7e" + portalArg.value); + } + } + + if (executesCommand) { + player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); + } + + if (hasTriggerBlock) { + Set materialSet = Portal + .getMaterialSet(triggerBlock.toUpperCase().split(",")); + if (materialSet.size() != 0) { + player.sendMessage( + "\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase()); + PortalArg[] portalArgs = new PortalArg[extraData.size()]; + portalArgs = extraData.toArray(portalArgs); + player.sendMessage(Portal.create(pos1, pos2, portalName, destination, + materialSet, serverName, portalArgs)); + } else { + ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); + player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); + + player.sendMessage("\u00A7c" + triggerBlock.toUpperCase() + + " no valid blocks were listed so the default has been set."); + 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("\u00A7ctriggerBlock: \u00A7edefault(" + player.sendMessage("\u00A7atriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); - - player.sendMessage("\u00A7c" + triggerBlock.toUpperCase() - + " no valid blocks were listed so the default has been set."); 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)); + sender.sendMessage( + PluginMessages.customPrefixFail + " A portal by that name already exists!"); } + + // add code to save the portal to the portal config and reload the portals + + player.sendMessage(""); } else { - sender.sendMessage( - PluginMessages.customPrefixFail + " A portal by that name already exists!"); + player.sendMessage(PluginMessages.customPrefixFail + + " You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c" + + " for a full list of currently available variables and an example command!"); } - - // add code to save the portal to the portal config and reload the portals - - player.sendMessage(""); } else { player.sendMessage(PluginMessages.customPrefixFail - + " You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c" - + " for a full list of currently available variables and an example command!"); + + " The points you have selected need to be in the same world!"); } } else { player.sendMessage(PluginMessages.customPrefixFail - + " The points you have selected need to be in the same world!"); + + " You need to have two points selected to make a portal!"); } - } else { - player.sendMessage(PluginMessages.customPrefixFail - + " You need to have two points selected to make a portal!"); - } - break; - case "variables": - sender.sendMessage(PluginMessages.customPrefix - + " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay, leavedesti"); - sender.sendMessage(""); - sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); - break; - case "select": - // TODO finish the select command and the hit block to replace! - if (!player.hasMetadata("selectingPortal")) { + break; + case "variables": + sender.sendMessage(PluginMessages.customPrefix + + " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay, leavedesti"); + sender.sendMessage(""); + sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); + break; + case "select": + // TODO finish the select command and the hit block to replace! + if (!player.hasMetadata("selectingPortal")) { + if (args.length > 1) { + if (Portal.portalExists(args[1])) { + player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); + player.sendMessage(PluginMessages.customPrefix + " You have selected\u00A7e " + args[1] + + "\u00A7a."); + } else { + player.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + + args[1] + + "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!"); + } + } else { + player.sendMessage(PluginMessages.customPrefix + + " Hit a block inside the portal region to select the portal!"); + player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true)); + } + + } else { + player.removeMetadata("selectingPortal", plugin); + player.sendMessage(PluginMessages.customPrefixFail + " Portal selection cancelled!"); + } + break; + case "unselect": + if (player.getMetadata("selectedPortal").size() != 0) { + player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e" + + player.getMetadata("selectedPortal").get(0).asString() + "\u00A7a."); + } else { + player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!"); + } + case "gui": + if (args.length > 1) { + if (args[1].toLowerCase().equals("remove") && args.length > 2) { + sender.sendMessage(""); + sender.sendMessage(PluginMessages.customPrefixFail + + " Are you sure you would like to remove the portal \u00A7e" + args[2] + + "\u00A7c?"); + sender.sendMessage(""); + plugin.compat.sendRawMessage( + "{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\"," + + "\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + + args[2] + "\"}}, " + + "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"}" + + ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " + + args[2] + "\"}}]}", + player); + sender.sendMessage(""); + } + } + break; + case "edit": if (args.length > 1) { if (Portal.portalExists(args[1])) { player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); - player.sendMessage(PluginMessages.customPrefix + " You have selected\u00A7e " + args[1] - + "\u00A7a."); + portalEditMenu(sender, portalConfig, args[1]); } else { - player.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" - + args[1] - + "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + + args[1] + "\u00A7c exists!"); } } else { - player.sendMessage(PluginMessages.customPrefix - + " Hit a block inside the portal region to select the portal!"); - player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true)); - } - - } else { - player.removeMetadata("selectingPortal", plugin); - player.sendMessage(PluginMessages.customPrefixFail + " Portal selection cancelled!"); - } - break; - case "unselect": - if (player.getMetadata("selectedPortal").size() != 0) { - player.sendMessage(PluginMessages.customPrefix + " You have unselected\u00A7e" - + player.getMetadata("selectedPortal").get(0).asString() + "\u00A7a."); - } else { - player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!"); - } - case "gui": - if (args.length > 1) { - if (args[1].toLowerCase().equals("remove") && args.length > 2) { - sender.sendMessage(""); - sender.sendMessage(PluginMessages.customPrefixFail - + " Are you sure you would like to remove the portal \u00A7e" + args[2] - + "\u00A7c?"); - sender.sendMessage(""); - plugin.compat.sendRawMessage( - "{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\"," - + "\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " - + args[2] + "\"}}, " - + "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"}" - + ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " - + args[2] + "\"}}]}", - player); - sender.sendMessage(""); - } - } - break; - case "edit": - if (args.length > 1) { - if (Portal.portalExists(args[1])) { - player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); - portalEditMenu(sender, portalConfig, args[1]); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" - + args[1] + "\u00A7c exists!"); - } - } else { - if (player.getMetadata("selectedPortal").size() != 0) { - String portalName = player.getMetadata("selectedPortal").get(0).asString(); - String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); - if (posX != null) { - portalEditMenu(sender, portalConfig, portalName); - } else { - sender.sendMessage(PluginMessages.customPrefixFail - + " The portal you had selected no longer seems to exist!"); - player.removeMetadata("selectedPortal", plugin); - } - } else { - sender.sendMessage( - PluginMessages.customPrefixFail + " No portal has been defined or selected!"); - } - } - break; - case "rename": - - // not finished yet / - if (args.length > 1) { - if (player.getMetadata("selectedPortal").size() != 0) { - String portalName = player.getMetadata("selectedPortal").get(0).asString(); - if (portalName.toLowerCase() != args[1].toLowerCase()) { + if (player.getMetadata("selectedPortal").size() != 0) { + String portalName = player.getMetadata("selectedPortal").get(0).asString(); String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); - - String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); - if (posX != null && newPortalPosX == null) { - Portal.rename(portalName, args[1]); - sender.sendMessage(PluginMessages.customPrefix + " The portal \u00A7e" + portalName - + "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a."); - player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); - } else if (newPortalPosX != null) { - sender.sendMessage(PluginMessages.customPrefixFail - + " There is already a portal with the name \u00A7e" + args[1] - + "\u00A7c!"); + if (posX != null) { + portalEditMenu(sender, portalConfig, portalName); } else { sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); player.removeMetadata("selectedPortal", plugin); } } else { - sender.sendMessage(PluginMessages.customPrefixFail - + " The portal you have selected is already called that!"); + sender.sendMessage( + PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } - } else { - sender.sendMessage( - PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } - } else { - sender.sendMessage(PluginMessages.customPrefixFail - + " You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); - } - break; - case "command": - if (player.getMetadata("selectedPortal").size() != 0) { - String portalName = player.getMetadata("selectedPortal").get(0).asString(); - if (args.length > 1) { - // TODO add the command autocompletes, add, remove and show - if (args[1].toLowerCase().equals("add")) { - if (args.length > 2) { - String portalCommand = args[2]; - for (int i = 3; i < args.length; i++) { - portalCommand += args[i]; - } - if (Portal.addCommand(portalName, portalCommand)) { - sender.sendMessage( - PluginMessages.customPrefixFail + " Command added to portal!"); - } else { - sender.sendMessage( - PluginMessages.customPrefixFail + " Failed to add command to portal!"); - } + break; + case "rename": + // not finished yet / + if (args.length > 1) { + if (player.getMetadata("selectedPortal").size() != 0) { + String portalName = player.getMetadata("selectedPortal").get(0).asString(); + if (portalName.toLowerCase() != args[1].toLowerCase()) { + String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); + + String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); + if (posX != null && newPortalPosX == null) { + Portal.rename(portalName, args[1]); + sender.sendMessage(PluginMessages.customPrefix + " The portal \u00A7e" + portalName + + "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a."); + player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); + } else if (newPortalPosX != null) { + sender.sendMessage(PluginMessages.customPrefixFail + + " There is already a portal with the name \u00A7e" + args[1] + + "\u00A7c!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + + " The portal you had selected no longer seems to exist!"); + player.removeMetadata("selectedPortal", plugin); + } } else { sender.sendMessage(PluginMessages.customPrefixFail - + " You must actually specify a command to execute!"); + + " The portal you have selected is already called that!"); } - - } else if (args[1].toLowerCase().equals("remove")) { - // Specify what line to remove - } else if (args[1].toLowerCase().equals("show")) { } else { - sender.sendMessage(PluginMessages.customPrefixFail - + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); + sender.sendMessage( + PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } } else { sender.sendMessage(PluginMessages.customPrefixFail - + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); + + " You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); } - } else { - - } - break; - case "remove": - if (args.length > 1) { - String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); - if (posX != null) { - Portal.remove(args[1]); - sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A7e" + args[1] - + "\u00A7c has been removed!"); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); - } - } else { + break; + case "command": if (player.getMetadata("selectedPortal").size() != 0) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); - String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); - if (posX != null) { - Portal.remove(portalName); - sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A77" + portalName - + "\u00A7c has been removed!"); + if (args.length > 1) { + // TODO add the command autocompletes, add, remove and show + if (args[1].toLowerCase().equals("add")) { + if (args.length > 2) { + String portalCommand = args[2]; + for (int i = 3; i < args.length; i++) { + portalCommand += args[i]; + } + if (Portal.addCommand(portalName, portalCommand)) { + sender.sendMessage( + PluginMessages.customPrefixFail + " Command added to portal!"); + } else { + sender.sendMessage( + PluginMessages.customPrefixFail + " Failed to add command to portal!"); + } + + } else { + sender.sendMessage(PluginMessages.customPrefixFail + + " You must actually specify a command to execute!"); + } + + } else if (args[1].toLowerCase().equals("remove")) { + // Specify what line to remove + } else if (args[1].toLowerCase().equals("show")) { + } else { + sender.sendMessage(PluginMessages.customPrefixFail + + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); + } } else { sender.sendMessage(PluginMessages.customPrefixFail - + " The portal you had selected no longer seems to exist!"); - player.removeMetadata("selectedPortal", plugin); + + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); } } else { - sender.sendMessage( - PluginMessages.customPrefixFail + " No portal has been defined or selected!"); + } - } - break; - case "help": - helpCommand(sender, command, args); - break; - case "show": - if (args.length > 1) { - String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); - if (posX != null) { - Selection.show(player, this.plugin, args[1]); + break; + case "remove": + if (args.length > 1) { + String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); + if (posX != null) { + Portal.remove(args[1]); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A7e" + args[1] + + "\u00A7c has been removed!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); + } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); + if (player.getMetadata("selectedPortal").size() != 0) { + String portalName = player.getMetadata("selectedPortal").get(0).asString(); + String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); + if (posX != null) { + Portal.remove(portalName); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A77" + portalName + + "\u00A7c has been removed!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + + " The portal you had selected no longer seems to exist!"); + player.removeMetadata("selectedPortal", plugin); + } + } else { + sender.sendMessage( + PluginMessages.customPrefixFail + " No portal has been defined or selected!"); + } } - } else { - if (player.getMetadata("selectedPortal").size() != 0) { - player.sendMessage(PluginMessages.customPrefix - + " Your currently selected portal has been shown, it will dissapear shortly!"); - Selection.show(player, this.plugin, player.getMetadata("selectedPortal").get(0).asString()); - } else if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { - if (player.getMetadata("Pos1World").get(0).asString() - .equals(player.getMetadata("Pos2World").get(0).asString()) - && player.getMetadata("Pos1World").get(0).asString() - .equals(player.getLocation().getWorld().getName())) { + break; + case "help": + helpCommand(sender, command, args); + break; + case "show": + if (args.length > 1) { + String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); + if (posX != null) { + Selection.show(player, this.plugin, args[1]); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); + } + } else { + if (player.getMetadata("selectedPortal").size() != 0) { player.sendMessage(PluginMessages.customPrefix - + " Your currently selected area has been shown, it will dissapear shortly!"); - Selection.show(player, this.plugin, null); + + " Your currently selected portal has been shown, it will dissapear shortly!"); + Selection.show(player, this.plugin, player.getMetadata("selectedPortal").get(0).asString()); + } else if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { + if (player.getMetadata("Pos1World").get(0).asString() + .equals(player.getMetadata("Pos2World").get(0).asString()) + && player.getMetadata("Pos1World").get(0).asString() + .equals(player.getLocation().getWorld().getName())) { + player.sendMessage(PluginMessages.customPrefix + + " Your currently selected area has been shown, it will dissapear shortly!"); + Selection.show(player, this.plugin, null); + } + } else { + player.sendMessage(PluginMessages.customPrefixFail + " No regions selected!"); } - } else { - player.sendMessage(PluginMessages.customPrefixFail + " No regions selected!"); } - } - break; - case "reload": - sender.sendMessage(PluginMessages.customPrefix + " Reloaded values!"); - Listeners.reloadValues(plugin); - Portal.loadPortals(); - break; - case "list": - String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a"; - LinkedList portals = new LinkedList<>(); - for (AdvancedPortal portal : Portal.portals) { - portals.add(portal.getName()); - } - Collections.sort(portals); - for (Object portalName : portals.toArray()) { - message = message + " " + portalName; - } - player.sendMessage(message); - break; - default: - PluginMessages.UnknownCommand(sender, command); + break; + case "reload": + sender.sendMessage(PluginMessages.customPrefix + " Reloaded values!"); + Listeners.reloadValues(plugin); + Portal.loadPortals(); + break; + case "list": + String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a"; + LinkedList portals = new LinkedList<>(); + for (AdvancedPortal portal : Portal.portals) { + portals.add(portal.getName()); + } + Collections.sort(portals); + for (Object portalName : portals.toArray()) { + message = message + " " + portalName; + } + player.sendMessage(message); + break; + default: + PluginMessages.UnknownCommand(sender, command); } } else { PluginMessages.UnknownCommand(sender, command); @@ -794,33 +799,33 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { 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 "delayed": - hasDelay = true; - break; - case "command": - hasCommand = true; - break; - case "cooldowndelay": - hasCooldownDelay = true; - break; + 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 "delayed": + hasDelay = true; + break; + case "command": + hasCommand = true; + break; + case "cooldowndelay": + hasCooldownDelay = true; + break; } } diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/Settings.java b/src/main/java/com/sekwah/advancedportals/bukkit/Settings.java index 0f6f2a9..a706bc9 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/Settings.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/Settings.java @@ -1,5 +1,7 @@ package com.sekwah.advancedportals.bukkit; +import static com.sekwah.advancedportals.bukkit.Settings.PortalConfigOption.*; + /** * This contains generally used settings mostly */ @@ -11,12 +13,34 @@ public class Settings { private String commandLevels = "n"; + public enum PortalConfigOption { + COMMAND_LEVELS("CommandLevels"), + WARP_PARTICLES("WarpParticles"), + WARP_SOUND("WarpSound"); + + private final String target; + + PortalConfigOption(String target) { + this.target = target; + } + + public String value() { + return this.target; + } + } + public Settings(AdvancedPortalsPlugin plugin) { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - currentWarpParticles = config.getConfig().getInt("WarpParticles"); - currentWarpSound = config.getConfig().getInt("WarpSound"); + currentWarpParticles = config.getConfig().getInt(WARP_PARTICLES.value()); + currentWarpSound = config.getConfig().getInt(WARP_SOUND.value()); - commandLevels = config.getConfig().getString("CommandLevels", "opchek"); + commandLevels = config.getConfig().getString(COMMAND_LEVELS.value(), "opcb"); + + assert commandLevels != null; + if(commandLevels.equals("opchek")) { + commandLevels = "opcb"; + config.getConfig().set(COMMAND_LEVELS.value(), "opcb"); + } if(commandLevels.contains("n") || commandLevels.equals("")) { commandLevels = "n"; } @@ -26,7 +50,7 @@ public class Settings { return this.commandLevels; } - public boolean hasCommandLevel(String level){ + public boolean enabledCommandLevel(String level){ return this.commandLevels.contains(level); } diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java b/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java index 7d54610..fb5e65d 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java @@ -29,14 +29,11 @@ public class PluginMessageReceiver implements PluginMessageListener { String subchannel = in.readUTF(); if (subchannel.equals("BungeePortal")) { - String targetPlayerUUID = in.readUTF(); String targetDestination = in.readUTF(); - Player msgPlayer = plugin.getServer().getPlayer(UUID.fromString(targetPlayerUUID)); - - if (msgPlayer != null) { + if (player != null) { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, - () -> Destination.warp(msgPlayer, targetDestination, false, true), + () -> Destination.warp(player, targetDestination, false, true), 20L ); } diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java b/src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java index 96286c0..9080b43 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java @@ -8,7 +8,6 @@ import com.sekwah.advancedportals.bukkit.PluginMessages; import com.sekwah.advancedportals.bukkit.api.portaldata.PortalArg; import com.sekwah.advancedportals.bukkit.destinations.Destination; import com.sekwah.advancedportals.bukkit.effects.WarpEffects; -import com.sekwah.advancedportals.bukkit.listeners.Listeners; import org.bukkit.*; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -486,7 +485,6 @@ public class Portal { ByteArrayDataOutput outForList = ByteStreams.newDataOutput(); outForList.writeUTF("PortalEnter"); outForList.writeUTF(bungeeServer); - outForList.writeUTF(player.getUniqueId().toString()); outForList.writeUTF(portal.getDestiation()); player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray()); @@ -530,7 +528,7 @@ public class Portal { // (?i) makes the search case insensitive command = command.replaceAll("@player", player.getName()); plugin.getLogger().log(Level.INFO, "Portal command: " + command); - if (command.startsWith("#") && plugin.getSettings().hasCommandLevel("c")) { + if (command.startsWith("#") && plugin.getSettings().enabledCommandLevel("c")) { command = command.substring(1); plugin.getLogger().log(Level.INFO, "Portal command: " + command); try { @@ -538,7 +536,7 @@ public class Portal { } catch (Exception e) { plugin.getLogger().warning("Error while executing: " + command); } - } else if (command.startsWith("!") && plugin.getSettings().hasCommandLevel("o")) { + } else if (command.startsWith("!") && plugin.getSettings().enabledCommandLevel("o")) { command = command.substring(1); boolean wasOp = player.isOp(); try { @@ -548,7 +546,7 @@ public class Portal { } finally { player.setOp(wasOp); } - } else if (command.startsWith("^")) { + } else if (command.startsWith("^") && plugin.getSettings().enabledCommandLevel("p")) { command = command.substring(1); PermissionAttachment permissionAttachment = null; try { @@ -558,9 +556,16 @@ public class Portal { } finally { player.removeAttachment(permissionAttachment); } + } else if (command.startsWith("%") && plugin.getSettings().enabledCommandLevel("b")) { + command = command.substring(1); + ByteArrayDataOutput outForList = ByteStreams.newDataOutput(); + outForList.writeUTF("BungeeCommand"); + outForList.writeUTF(player.getUniqueId().toString()); + outForList.writeUTF(command); + player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray()); } else { - player.chat("/" + command); - // player.performCommand(command); + player.chat("/" + command); + // player.performCommand(command); } command = portal.getArg("command." + ++commandLine); } while (command != null); diff --git a/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsPlugin.java b/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsPlugin.java index c2d8687..a735534 100644 --- a/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsPlugin.java +++ b/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsPlugin.java @@ -5,12 +5,13 @@ import com.sekwah.advancedportals.bungee.listener.PluginMessageReceiver; import net.md_5.bungee.api.plugin.Plugin; import java.util.HashMap; +import java.util.UUID; public class AdvancedPortalsPlugin extends Plugin { public String channelName = "mc:advancedportals"; - public HashMap PlayerDestiMap = new HashMap<>(); + public HashMap PlayerDestiMap = new HashMap<>(); // key: UUID (string) // value: [0] targetServer, [1] targetDestination diff --git a/src/main/java/com/sekwah/advancedportals/bungee/listener/EventListener.java b/src/main/java/com/sekwah/advancedportals/bungee/listener/EventListener.java index b22bf09..7d8948e 100644 --- a/src/main/java/com/sekwah/advancedportals/bungee/listener/EventListener.java +++ b/src/main/java/com/sekwah/advancedportals/bungee/listener/EventListener.java @@ -7,6 +7,8 @@ import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; +import java.util.UUID; + public class EventListener implements Listener { private AdvancedPortalsPlugin plugin; @@ -14,10 +16,11 @@ public class EventListener implements Listener { @EventHandler public void onPlayerSwitchServer(ServerSwitchEvent event) { - String uuid = event.getPlayer().getUniqueId().toString(); + UUID uuid = event.getPlayer().getUniqueId(); if (plugin.PlayerDestiMap.containsKey(uuid)) { String[] val = plugin.PlayerDestiMap.get(uuid); + // key: UUID (string) // value: [0] targetServer, [1] targetDestination @@ -26,7 +29,6 @@ public class EventListener implements Listener { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("BungeePortal"); - out.writeUTF(uuid); out.writeUTF(val[1]); event.getPlayer().getServer().getInfo().sendData(plugin.channelName, out.toByteArray()); diff --git a/src/main/java/com/sekwah/advancedportals/bungee/listener/PluginMessageReceiver.java b/src/main/java/com/sekwah/advancedportals/bungee/listener/PluginMessageReceiver.java index 749addd..4f899d9 100644 --- a/src/main/java/com/sekwah/advancedportals/bungee/listener/PluginMessageReceiver.java +++ b/src/main/java/com/sekwah/advancedportals/bungee/listener/PluginMessageReceiver.java @@ -3,9 +3,13 @@ package com.sekwah.advancedportals.bungee.listener; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; + +import java.util.UUID; import java.util.concurrent.TimeUnit; public class PluginMessageReceiver implements Listener { @@ -22,16 +26,33 @@ public class PluginMessageReceiver implements Listener { if (subChannel.equalsIgnoreCase("PortalEnter")) { String targetServer = in.readUTF(); - String targetPlayerUUID = in.readUTF(); String targetDestination = in.readUTF(); + UUID uuid; - plugin.PlayerDestiMap.put(targetPlayerUUID, new String[]{targetServer, targetDestination}); + if ( event.getReceiver() instanceof ProxiedPlayer ) + { + ProxiedPlayer receiver = (ProxiedPlayer) event.getReceiver(); + uuid = receiver.getUniqueId(); + } + else { + plugin.getLogger().warning("There has been an issue getting the player for the teleport request."); + return; + } + plugin.PlayerDestiMap.put(uuid, new String[]{targetServer, targetDestination}); plugin.getProxy().getScheduler().schedule(plugin, () -> { - if (plugin.PlayerDestiMap.containsKey(targetPlayerUUID)) { - plugin.PlayerDestiMap.remove(targetPlayerUUID); - } + plugin.PlayerDestiMap.remove(uuid); }, 20, TimeUnit.SECONDS); } + else if (subChannel.equalsIgnoreCase("BungeeCommand")) { + String targetPlayerUUID = in.readUTF(); + String command = in.readUTF(); + ProxiedPlayer player = plugin.getProxy().getPlayer(UUID.fromString(targetPlayerUUID)); + if (player != null) { + // To send command to server the player is currently on + //player.chat("/" + command); + plugin.getProxy().getPluginManager().dispatchCommand(player, command); + } + } } } diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml index 6ae4d32..f144073 100644 --- a/src/main/resources/bungee.yml +++ b/src/main/resources/bungee.yml @@ -1,4 +1,4 @@ main: com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin name: AdvancedPortals -version: 0.4.0 +version: 0.5.0 author: sekwah41 diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f13a166..2c0a0f4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -73,18 +73,12 @@ ThrowbackAmount: 0.7 # How fast to throw them back, 0 or lower to disable throwb # We have no plans to further this but if anyone has any tips feel free to contact us here https://discord.gg/25QZVVn DisableGatewayBeam: false -# Letters are flags. Include them to activate. n always disables everything, remove if you want it to work. -# Lettering may not make too much sense but meh its useful. Examples are "ocpk" or "cop" (doesnt matter order) -# -# Remember enabling this means potentially admins could leave a portal lying around which could let them reop themselves. -# If you think this may be an issue use a permission plugin and specifically give the users you trust permissions. +# Enable or disable special command portals # # n Disabled none, best just put this to really make sure the fact none are here is specified. It disables any others too -# o Admin Heighten Enabled Permission advancedportals.createportal.commandlevel.op -# p Perm Heighten Enabled Permission advancedportals.createportal.commandlevel.perms -# c Console Heighten Enabled Permission advancedportals.createportal.commandlevel.console -# h Ops can create admin commands without special perms -# e Ops can create all perm commands without special perms -# k Ops can create console commands without special perms +# o enable op command portals +# p enable permission command portals +# c enable console command portals +# b enable bungee command portals # -CommandLevels: opchek +CommandLevels: opcb diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 592066a..904f077 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin name: AdvancedPortals -version: 0.4.0 +version: 0.5.0 author: sekwah41 description: An advanced portals plugin for bukkit. api-version: 1.13 @@ -30,14 +30,18 @@ permissions: default: false children: advancedportals.createportal.commandlevel.op: true + advancedportals.createportal.commandlevel.bungee: true advancedportals.createportal.commandlevel.perms: true advancedportals.createportal.commandlevel.console: true advancedportals.createportal.commandlevel.op: - description: Allows you to increase the users level temporaily to op + description: Allows you to run portal commands as op default: false advancedportals.createportal.commandlevel.perms: - description: Allows you to increase the users level temporaily to have all perms + description: Allows you to run portal commands with * permission default: false + advancedportals.createportal.commandlevel.bungee: + description: Allows you to run portal commands through bungee + default: false advancedportals.createportal.commandlevel.console: description: Executes command in the console default: false