From f00284314fd813d10bfdbcf2ae01b1666ca630d3 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Wed, 12 Jul 2017 05:21:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E5=8C=85=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20give=E5=8A=9F=E8=83=BD=20=E9=85=8D=E7=BD=AEBUG=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../mc/permissionstime/command/GiveCmd.java | 33 +++-- .../permissionstime/command/MainCommand.java | 54 ++++++-- .../permissionstime/command/PackagesCmd.java | 32 +++++ .../permissionstime/config/ConfigManager.java | 6 +- .../permissionstime/config/PackagesCfg.java | 6 +- .../database/IPlayerDataService.java | 38 ++++-- .../permissionstime/database/SqlManager.java | 17 ++- .../impl/SqlitePlayerDataService.java | 119 +++++++++++++++--- .../model/cfg/PermissionPackageBean.java | 27 +++- .../model/db/PlayerDataBean.java | 40 ++++-- .../mc/permissionstime/utils/StrUtil.java | 2 +- .../utils/config/PluginConfig.java | 38 +++--- src/resources/packages.yml | 6 +- src/resources/plugin.yml | 11 +- 15 files changed, 334 insertions(+), 97 deletions(-) create mode 100644 src/main/gg/frog/mc/permissionstime/command/PackagesCmd.java diff --git a/pom.xml b/pom.xml index fdc5768..b6162b4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 gg.frog.mc permissionstime - 0.0.1-SNAPSHOT + 0.0.1-TEST jar PermissionsTime 支持跨服的权限限时插件 diff --git a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java index 5fa17ac..a1a220d 100644 --- a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java @@ -2,12 +2,9 @@ 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; @@ -17,30 +14,44 @@ 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) { + + public static boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) { if (args.length == 4) { String playerName = args[1]; String packageName = args[2]; String time = args[3]; + int days; + try { + days = Integer.parseInt(time); + if (days <= 0) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数")); + return false; + } + } catch (Exception e) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数")); + return false; + } 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)); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + "天")); + } + if (sm.giveTime(uuid.toString(), packageName, days)) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "给予玩家{0} {1}天的{2}", playerName, time, pack.getDisplayName())); + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未给予玩家{0} {1}天的{2}", playerName, time, pack.getDisplayName())); } - return true; } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'" + playerName + "'的玩家")); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'{0}'的玩家", playerName)); } } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'" + packageName + "'的权限包")); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'{0}'的权限包", packageName)); } } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确" + "