1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2025-09-06 11:06:58 +00:00

设置、移除、测试权限组添加

This commit is contained in:
GeekFrog
2017-07-13 07:17:41 +08:00
parent 193f0a7dc4
commit e0e3ce448c
13 changed files with 347 additions and 79 deletions

View File

@ -2,6 +2,7 @@ package gg.frog.mc.permissionstime.command;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import gg.frog.mc.permissionstime.PluginMain;
@ -11,44 +12,58 @@ import gg.frog.mc.permissionstime.database.SqlManager;
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
import gg.frog.mc.permissionstime.utils.StrUtil;
public class GiveCmd {
public class GiveCmd implements Runnable {
private PluginMain pm;
private SqlManager sm;
private String[] args;
private CommandSender sender;
public GiveCmd(PluginMain pm) {
public GiveCmd(PluginMain pm, CommandSender sender, String[] args) {
this.pm = pm;
this.sm = pm.getSqlManager();
this.sender = sender;
this.args = args;
}
public boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) {
@Override
public void run() {
if (args.length == 4) {
String playerName = args[1];
String packageName = args[2];
String time = args[3];
int days;
int days = 0;
try {
days = Integer.parseInt(time);
if (days <= 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数"));
return false;
return;
}
} catch (Exception e) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数"));
return false;
return;
}
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) {
UUID uuid = pm.getPlayerUUIDByName(playerName);
if (uuid != null) {
OfflinePlayer player = pm.getOfflinePlayer(playerName);
if (player != null) {
UUID uuid = player.getUniqueId();
if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + ""));
}
if (sm.giveTime(uuid.toString(), packageName, days)) {
if (player.isOnline()) {
for (String groupName : pack.getGroups()) {
if (!pm.getPermission().playerAddGroup(null, player, groupName)) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "权限组{0}添加失败", groupName));
}
}
}
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()));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName));
}
@ -58,6 +73,5 @@ public class GiveCmd {
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确"));
}
return false;
}
}