From 411e78b88ab4360ffb91bcc0c5ff8c6b573f4e30 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Mon, 17 Jul 2017 10:29:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E8=A1=A5?= =?UTF-8?q?=E5=85=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../permissionstime/command/MainCommand.java | 66 ++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 14898dd..e79b2ac 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 gg.frog.mc permissionstime - 0.1.1-TEST + 0.1.1-SNAPSHOT jar PermissionsTime 支持跨服的权限限时插件 diff --git a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java index 130257c..04b542d 100644 --- a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java +++ b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java @@ -1,18 +1,24 @@ package gg.frog.mc.permissionstime.command; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryView; import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.config.LangCfg; +import gg.frog.mc.permissionstime.config.PackagesCfg; import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.database.SqlManager; import gg.frog.mc.permissionstime.utils.StrUtil; -public class MainCommand implements CommandExecutor { +public class MainCommand implements CommandExecutor, TabCompleter { private PluginMain pm; private SqlManager sm; @@ -110,7 +116,7 @@ public class MainCommand implements CommandExecutor { private void getHelp(CommandSender sender, boolean isPlayer) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&a===== " + pm.PLUGIN_NAME + " Version:" + pm.PLUGIN_VERSION + (pm.getDescription().getCommands().containsKey("pt") ? " Aliases:/pt" : "") + " =====")); - if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me")) { + if (isPlayer && (sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) { sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " me \n - View self package.")); } if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages")) { @@ -145,4 +151,60 @@ public class MainCommand implements CommandExecutor { } return true; } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + List tipList = new ArrayList(); + boolean isPlayer = false; + if (sender instanceof Player) { + isPlayer = true; + } + if (args.length == 1) { + args[0] = args[0].toLowerCase(Locale.ENGLISH); + if ("me".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) { + tipList.add("me"); + } + if ("packages".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages"))) { + tipList.add("packages"); + } + if ("give".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give"))) { + tipList.add("give"); + } + if ("set".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + "set"))) { + tipList.add("set"); + } + if ("remove".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove"))) { + tipList.add("remove"); + } + if ("removeall".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall"))) { + tipList.add("removeall"); + } + if ("reload".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload"))) { + tipList.add("reload"); + } + } else if (args.length == 2) { + args[0] = args[0].toLowerCase(Locale.ENGLISH); + args[1] = args[1].toLowerCase(Locale.ENGLISH); + if ("packages".equals(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) { + for (String name : PackagesCfg.PACKAGES.keySet()) { + if (name.startsWith(args[1])) { + tipList.add(name); + } + } + } else if ("give".equals(args[0]) || "set".equals(args[0]) || "remove".equals(args[0]) || "removeall".equals(args[0])) { + return null; + } + } else if (args.length == 3) { + args[0] = args[0].toLowerCase(Locale.ENGLISH); + args[2] = args[2].toLowerCase(Locale.ENGLISH); + if ("give".equals(args[0]) || "set".equals(args[0]) || "remove".equals(args[0])) { + for (String name : PackagesCfg.PACKAGES.keySet()) { + if (name.startsWith(args[2])) { + tipList.add(name); + } + } + } + } + return tipList; + } }