From d0e3e863770421d512682a034c51b2196c2548dc Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Wed, 12 Jul 2017 00:11:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0give=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frog/mc/permissionstime/PluginMain.java | 4 +- .../mc/permissionstime/command/GiveCmd.java | 47 +++++++++++++++++++ .../{TheCommand.java => MainCommand.java} | 26 ++++++++-- .../mc/permissionstime/utils/PluginUtil.java | 27 +++++++++++ src/resources/config.yml | 2 +- src/resources/plugin.yml | 23 ++++++++- 6 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 src/main/gg/frog/mc/permissionstime/command/GiveCmd.java rename src/main/gg/frog/mc/permissionstime/command/{TheCommand.java => MainCommand.java} (70%) create mode 100644 src/main/gg/frog/mc/permissionstime/utils/PluginUtil.java diff --git a/src/main/gg/frog/mc/permissionstime/PluginMain.java b/src/main/gg/frog/mc/permissionstime/PluginMain.java index bfbab8f..7bc7d0d 100644 --- a/src/main/gg/frog/mc/permissionstime/PluginMain.java +++ b/src/main/gg/frog/mc/permissionstime/PluginMain.java @@ -8,7 +8,7 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import org.mcstats.Metrics; -import gg.frog.mc.permissionstime.command.TheCommand; +import gg.frog.mc.permissionstime.command.MainCommand; import gg.frog.mc.permissionstime.config.ConfigManager; import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.database.SqlManager; @@ -84,7 +84,7 @@ public class PluginMain extends JavaPlugin { * 这里可以注册多个,一般注册一个就够用 */ private void registerCommands() { - this.getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(new TheCommand()); + this.getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(new MainCommand()); } public ConfigManager getConfigManager() { diff --git a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java new file mode 100644 index 0000000..5fa17ac --- /dev/null +++ b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java @@ -0,0 +1,47 @@ +package gg.frog.mc.permissionstime.command; + +import java.util.UUID; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +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.model.cfg.PermissionPackageBean; +import gg.frog.mc.permissionstime.utils.PluginUtil; +import gg.frog.mc.permissionstime.utils.StrUtil; + +public class GiveCmd { + + private static PluginMain pm = PluginMain.getInstance(); + private static SqlManager sm = PluginMain.sm; + + public static boolean onCommand(CommandSender sender, Command command, boolean isPlayer, String[] args) { + if (args.length == 4) { + String playerName = args[1]; + String packageName = args[2]; + String time = args[3]; + PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); + if (pack != null) { + UUID uuid = PluginUtil.getPlayerUUIDByName(playerName); + if (uuid != null) { + if (PluginCfg.IS_DEBUG) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time)); + } + return true; + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'" + playerName + "'的玩家")); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'" + packageName + "'的权限包")); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确" + "