1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-22 07:28:47 +00:00

添加give命令

This commit is contained in:
GeekFrog 2017-07-12 00:11:05 +08:00
parent 1486f3e339
commit d0e3e86377
6 changed files with 121 additions and 8 deletions

View File

@ -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() {

View File

@ -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 + "参数不正确" + "<playerName> <packageName> <time>"));
}
return false;
}
}

View File

@ -11,7 +11,7 @@ import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.database.SqlManager;
import gg.frog.mc.permissionstime.utils.StrUtil;
public class TheCommand implements CommandExecutor {
public class MainCommand implements CommandExecutor {
private PluginMain pm = PluginMain.getInstance();
private SqlManager sm = PluginMain.sm;
@ -28,21 +28,23 @@ public class TheCommand implements CommandExecutor {
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".reload")) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " reload -Reloads the config file."));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".give")) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> - Give player package <time>minutes."));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
return true;
} else {
if (args[0].equalsIgnoreCase("reload")) {
if (isPlayer) {
Player player = (Player) sender;
if (sender.isOp() || player.hasPermission("quickdevdemo.reload")) {
if (sender.isOp() || player.hasPermission("permissionstime.reload")) {
pm.getConfigManager().reloadConfig();
if(!sm.updateDatabase()){
if (!sm.updateDatabase()) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "数据库异常"));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.NO_PERMISSION));
}
} else {
@ -51,9 +53,25 @@ public class TheCommand implements CommandExecutor {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
}
return true;
} else if (args[0].equalsIgnoreCase("give")) {
if (hasPermission(sender, isPlayer, "permissionstime.give")) {
return GiveCmd.onCommand(sender, command, isPlayer, args);
}
}
}
}
return false;
}
private boolean hasPermission(CommandSender sender, boolean isPlayer, String permissionPath) {
if (isPlayer) {
Player player = (Player) sender;
if (sender.isOp() || player.hasPermission(permissionPath)) {
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.NO_PERMISSION));
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,27 @@
package gg.frog.mc.permissionstime.utils;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import gg.frog.mc.permissionstime.PluginMain;
public class PluginUtil {
private static PluginMain pm = PluginMain.getInstance();
public static UUID getPlayerUUIDByName(String name) {
for (Player p : pm.getServer().getOnlinePlayers()) {
if (p.getName().equals(name)) {
return p.getUniqueId();
}
}
for (OfflinePlayer p : pm.getServer().getOfflinePlayers()) {
if (p.getName().equals(name)) {
return p.getUniqueId();
}
}
return null;
}
}

View File

@ -1 +1 @@
pluginPrefix: '&b[&4权限限时&b]&r'
pluginPrefix: '&4[&b权限限时&4]&r'

View File

@ -13,6 +13,27 @@ permissions:
description: Gives access to all PermissionsTime commands.
children:
permissionstime.reload: true
permissionstime.give: true
permissionstime.set: true
permissionstime.remove: true
permissionstime.package: true
permissionstime.reload: true
permissionstime.me:
description: View himself package.
default: default
permissionstime.reload:
description: Reloads the config file.
default: op
permissionstime.give:
description: Give player package <time>minutes.
default: op
permissionstime.set:
description: Set player package <time>minutes.
default: op
permissionstime.remove:
description: Remove player package.
default: op
permissionstime.package:
description: View packages.
default: op