From 80fcd96ba74ae1fd12ece5974f22e18b8f8a6ddc Mon Sep 17 00:00:00 2001 From: Max Qian Date: Tue, 2 Aug 2016 16:54:15 -0700 Subject: [PATCH] awarp is now an alias of destination and destination permissions --- Resources/plugin.yml | 17 +++-- .../AdvancedPortalsPlugin.java | 1 - .../destinations/Destination.java | 4 ++ .../destinations/DestinationCommand.java | 43 +++++++------ .../destinations/WarpCommand.java | 63 ------------------- 5 files changed, 34 insertions(+), 94 deletions(-) delete mode 100644 src/com/sekwah/advancedportals/destinations/WarpCommand.java diff --git a/Resources/plugin.yml b/Resources/plugin.yml index 07ea1ea..f3a884c 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -10,10 +10,7 @@ commands: usage: / destination: description: Can be used to access portal destinations. - aliases: [desti] - usage: / - awarp: - description: Used to warp to destinations. + aliases: [desti, awarp] usage: / permissions: advancedportals.*: @@ -22,7 +19,8 @@ permissions: advancedportals.createportal: true advancedportals.portal: true advancedportals.build: true - advancedportals.desti.*: true + advancedportals.desti: true + advancedportals.warp.*: true advancedportals.createportal: description: Allows you to create portals default: op @@ -32,10 +30,9 @@ permissions: advancedportals.build: description: Allows you to build in the portal regions default: op - advancedportals.desti.*: + advancedportals.desti: description: Gives access to all desti commands - children: - advancedportals.desti.create: true - advancedportals.desti.create: - description: Allows users to create portal destinations default: op + advancedportals.warp.*: + description: Access to all warps + default: true diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 6d582f4..dde576a 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -56,7 +56,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { new PluginMessages(this); new AdvancedPortalsCommand(this); new DestinationCommand(this); - new WarpCommand(this); new WarpEffects(this); diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index b559b58..17f6506 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -108,6 +108,10 @@ public class Destination { } public static boolean warp(Player player, String name) { + if (!player.hasPermission("advancedportals.warp.*") && !player.hasPermission("advancedportals.warp." + name)) { + player.sendMessage(PluginMessages.customPrefixFail + " You don't have permission to warp to " + name + "!"); + return false; + } ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if (config.getConfig().getString(name + ".world") != null) { Location loc = player.getLocation(); diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 38f9943..4302e4c 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -30,7 +30,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if (args.length > 0) { switch (args[0].toLowerCase()) { case "create": - if (sender.hasPermission("advancedportals.desti.create")) { + if (sender.hasPermission("advancedportals.desti")) { if (args.length > 1) { String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); if (posX == null) { @@ -44,29 +44,25 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { sender.sendMessage(PluginMessages.customPrefixFail + " Please state the name of the destination you would like to create!"); } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to create destinations!"); } break; case "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(PluginMessages.customPrefixFail + " The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); + if (sender.hasPermission("advancedportals.desti")) { + if (args.length > 1) { + String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); + if (posX != null) { + Destination.remove(args[1]); + sender.sendMessage(PluginMessages.customPrefixFail + " The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No destination by that name exists."); + } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No destination by that name exists."); + sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to remove."); } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to remove."); - } - break; - case "goto": - case "warp": - if (args.length > 1) { - Destination.warp((Player) sender, args[1]); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to warp to."); + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to remove destinations!"); } break; case "list": @@ -74,6 +70,9 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { for (String desti : config.getConfig().getKeys(false)) message = message + " " + desti; sender.sendMessage(message); break; + default: + Destination.warp((Player) sender, args[0]); + break; } } else { PluginMessages.UnknownCommand(sender, command); @@ -85,10 +84,14 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { @Override public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { LinkedList autoComplete = new LinkedList(); - - if (sender.hasPermission("AdvancedPortals.CreatePortal")) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + for (String string : config.getConfig().getKeys(false)) { + if (sender.hasPermission("advancedportals.desti.*") | sender.hasPermission("advancedportals.desti." + string)) + autoComplete.add(string); + } + if (sender.hasPermission("advancedportals.desti") | sender.hasPermission("AdvancedPortals.CreatePortal")) { if (args.length == 1) { - autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove")); + autoComplete.addAll(Arrays.asList("create", "remove", "help")); } else if (args[0].toLowerCase().equals("create")) { } } diff --git a/src/com/sekwah/advancedportals/destinations/WarpCommand.java b/src/com/sekwah/advancedportals/destinations/WarpCommand.java deleted file mode 100644 index 77a6e03..0000000 --- a/src/com/sekwah/advancedportals/destinations/WarpCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.sekwah.advancedportals.destinations; - -import com.sekwah.advancedportals.AdvancedPortalsPlugin; -import com.sekwah.advancedportals.ConfigAccessor; -import com.sekwah.advancedportals.PluginMessages; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - -import java.util.LinkedList; -import java.util.List; - -public class WarpCommand implements CommandExecutor, TabCompleter { - - @SuppressWarnings("unused") - private AdvancedPortalsPlugin plugin; - - public WarpCommand(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; - - - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - boolean useWarpCommand = !config.getConfig().getBoolean("DisableWarpCommand"); - //plugin.getCommand("warp").setExecutor(this); - plugin.getCommand("awarp").setExecutor(this); - } - - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { - if (args.length > 0) { - Destination.warp((Player) sender, args[0]); - } else { - PluginMessages.UnknownCommand(sender, command); - } - 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; - } - - -}