mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-22 07:28:47 +00:00
添加give命令
This commit is contained in:
parent
1486f3e339
commit
d0e3e86377
@ -8,7 +8,7 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.mcstats.Metrics;
|
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.ConfigManager;
|
||||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||||
import gg.frog.mc.permissionstime.database.SqlManager;
|
import gg.frog.mc.permissionstime.database.SqlManager;
|
||||||
@ -84,7 +84,7 @@ public class PluginMain extends JavaPlugin {
|
|||||||
* 这里可以注册多个,一般注册一个就够用
|
* 这里可以注册多个,一般注册一个就够用
|
||||||
*/
|
*/
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
this.getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(new TheCommand());
|
this.getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(new MainCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigManager getConfigManager() {
|
public ConfigManager getConfigManager() {
|
||||||
|
47
src/main/gg/frog/mc/permissionstime/command/GiveCmd.java
Normal file
47
src/main/gg/frog/mc/permissionstime/command/GiveCmd.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ import gg.frog.mc.permissionstime.config.PluginCfg;
|
|||||||
import gg.frog.mc.permissionstime.database.SqlManager;
|
import gg.frog.mc.permissionstime.database.SqlManager;
|
||||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||||
|
|
||||||
public class TheCommand implements CommandExecutor {
|
public class MainCommand implements CommandExecutor {
|
||||||
|
|
||||||
private PluginMain pm = PluginMain.getInstance();
|
private PluginMain pm = PluginMain.getInstance();
|
||||||
private SqlManager sm = PluginMain.sm;
|
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")) {
|
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."));
|
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));
|
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
if (args[0].equalsIgnoreCase("reload")) {
|
||||||
if (isPlayer) {
|
if (isPlayer) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if (sender.isOp() || player.hasPermission("quickdevdemo.reload")) {
|
if (sender.isOp() || player.hasPermission("permissionstime.reload")) {
|
||||||
pm.getConfigManager().reloadConfig();
|
pm.getConfigManager().reloadConfig();
|
||||||
if(!sm.updateDatabase()){
|
if (!sm.updateDatabase()) {
|
||||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "数据库异常"));
|
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "数据库异常"));
|
||||||
}
|
}
|
||||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
|
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
|
||||||
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
|
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.NO_PERMISSION));
|
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.NO_PERMISSION));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -51,9 +53,25 @@ public class TheCommand implements CommandExecutor {
|
|||||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
|
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else if (args[0].equalsIgnoreCase("give")) {
|
||||||
|
if (hasPermission(sender, isPlayer, "permissionstime.give")) {
|
||||||
|
return GiveCmd.onCommand(sender, command, isPlayer, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
27
src/main/gg/frog/mc/permissionstime/utils/PluginUtil.java
Normal file
27
src/main/gg/frog/mc/permissionstime/utils/PluginUtil.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
pluginPrefix: '&b[&4权限限时&b]&r'
|
pluginPrefix: '&4[&b权限限时&4]&r'
|
||||||
|
@ -13,6 +13,27 @@ permissions:
|
|||||||
description: Gives access to all PermissionsTime commands.
|
description: Gives access to all PermissionsTime commands.
|
||||||
children:
|
children:
|
||||||
permissionstime.reload: true
|
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:
|
permissionstime.reload:
|
||||||
description: Reloads the config file.
|
description: Reloads the config file.
|
||||||
default: op
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user