mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-30 07:27:29 +02:00
Make "permlist" command faster, "reload" command limited by
additional permission
This commit is contained in:
parent
094c777068
commit
7f63028be0
10
plugin.yml
10
plugin.yml
@ -13,9 +13,9 @@ commands:
|
||||
description: NoCheat command(s)
|
||||
permission: nocheat.admin.commands
|
||||
usage: |
|
||||
/<command> permlist player [permission] - to list the NoCheat relevant permissions of the player, optionally only those starting with [permission]
|
||||
/<command> reload - to reload NoCheats configuration file(s), without reloading the plugin itself
|
||||
/<command> playerinfo playername - show the collected data NoCheat collected about a player
|
||||
/<command> permlist player [permission]: list NoCheat permissions of player, optionally only if beginning with [permission]
|
||||
/<command> playerinfo player: show the collected data NoCheat collected about a player
|
||||
/<command> reload: fast reload of NoCheats configuration file(s) - needs additional permissions
|
||||
|
||||
permissions:
|
||||
nocheat:
|
||||
@ -27,7 +27,9 @@ permissions:
|
||||
nocheat.admin.chatlog:
|
||||
description: Player can see NoCheats log messages in the ingame chat
|
||||
nocheat.admin.commands:
|
||||
description: allow use of the "nocheat" commands
|
||||
description: allow use of the "nocheat" commands (may be given to players to allow them to check statistics)
|
||||
nocheat.admin.reload:
|
||||
description: allow access to the special "nocheat reload" command (only intended for the actual server administrator)
|
||||
nocheat.checks:
|
||||
description: Allow the player to bypass all checks
|
||||
children:
|
||||
|
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cc.co.evenprime.bukkit</groupId>
|
||||
<artifactId>NoCheat</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.1.2</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>NoCheat</name>
|
||||
<properties>
|
||||
|
@ -41,6 +41,7 @@ import cc.co.evenprime.bukkit.nocheat.debug.LagMeasureTask;
|
||||
public class NoCheat extends JavaPlugin implements Listener {
|
||||
|
||||
private ConfigurationManager conf;
|
||||
private CommandHandler commandHandler;
|
||||
private PlayerManager players;
|
||||
|
||||
private List<EventManager> eventManagers;
|
||||
@ -69,6 +70,8 @@ public class NoCheat extends JavaPlugin implements Listener {
|
||||
// Just to be sure nothing gets left out
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
|
||||
commandHandler = null;
|
||||
|
||||
System.out.println("[NoCheat] version [" + pdfFile.getVersion() + "] is disabled.");
|
||||
}
|
||||
|
||||
@ -77,6 +80,7 @@ public class NoCheat extends JavaPlugin implements Listener {
|
||||
// Then set up in memory per player data storage
|
||||
this.players = new PlayerManager(this);
|
||||
|
||||
this.commandHandler = new CommandHandler(this);
|
||||
// Then read the configuration files
|
||||
this.conf = new ConfigurationManager(this, this.getDataFolder());
|
||||
|
||||
@ -128,7 +132,7 @@ public class NoCheat extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
boolean result = CommandHandler.handleCommand(this, sender, command, label, args);
|
||||
boolean result = commandHandler.handleCommand(this, sender, command, label, args);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -11,12 +11,40 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
|
||||
public class CommandHandler {
|
||||
|
||||
private CommandHandler() {}
|
||||
private final List<Permission> perms;
|
||||
|
||||
public static boolean handleCommand(NoCheat plugin, CommandSender sender, Command command, String label, String[] args) {
|
||||
public CommandHandler(NoCheat plugin) {
|
||||
// Make a copy to allow sorting
|
||||
perms = new LinkedList<Permission>(plugin.getDescription().getPermissions());
|
||||
|
||||
Collections.sort(perms, new Comparator<Permission>() {
|
||||
|
||||
public int compare(Permission o1, Permission o2) {
|
||||
|
||||
String name1 = o1.getName();
|
||||
String name2 = o2.getName();
|
||||
|
||||
if(name1.equals(name2))
|
||||
return 0;
|
||||
|
||||
if(name1.startsWith(name2)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(name2.startsWith(name1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return name1.compareTo(name2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean handleCommand(NoCheat plugin, CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
boolean result = false;
|
||||
// Not our command
|
||||
@ -39,7 +67,7 @@ public class CommandHandler {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean handlePlayerInfoCommand(NoCheat plugin, CommandSender sender, String[] args) {
|
||||
private boolean handlePlayerInfoCommand(NoCheat plugin, CommandSender sender, String[] args) {
|
||||
|
||||
Map<String, Object> map = plugin.getPlayerData(args[1]);
|
||||
String filter = "";
|
||||
@ -57,7 +85,7 @@ public class CommandHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean handlePermlistCommand(NoCheat plugin, CommandSender sender, String[] args) {
|
||||
private boolean handlePermlistCommand(NoCheat plugin, CommandSender sender, String[] args) {
|
||||
|
||||
// Get the player by name
|
||||
Player player = plugin.getServer().getPlayerExact(args[1]);
|
||||
@ -72,32 +100,6 @@ public class CommandHandler {
|
||||
prefix = args[2];
|
||||
}
|
||||
|
||||
// Make a copy to allow sorting
|
||||
List<Permission> perms = new LinkedList<Permission>(plugin.getDescription().getPermissions());
|
||||
|
||||
Collections.sort(perms, new Comparator<Permission>() {
|
||||
|
||||
public int compare(Permission o1, Permission o2) {
|
||||
|
||||
String name1 = o1.getName();
|
||||
String name2 = o2.getName();
|
||||
|
||||
if(name1.equals(name2))
|
||||
return 0;
|
||||
|
||||
if(name1.startsWith(name2)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(name2.startsWith(name1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return name1.compareTo(name2);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
sender.sendMessage("Player " + player.getName() + " has the permission(s):");
|
||||
|
||||
for(Permission permission : perms) {
|
||||
@ -108,11 +110,17 @@ public class CommandHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean handleReloadCommand(NoCheat plugin, CommandSender sender) {
|
||||
private boolean handleReloadCommand(NoCheat plugin, CommandSender sender) {
|
||||
|
||||
// Players need a special permission for this
|
||||
if(!(sender instanceof Player) || sender.hasPermission(Permissions.ADMIN_RELOAD)) {
|
||||
sender.sendMessage("[NoCheat] Reloading configuration");
|
||||
plugin.reloadConfiguration();
|
||||
sender.sendMessage("[NoCheat] Configuration reloaded");
|
||||
}
|
||||
else {
|
||||
sender.sendMessage("You lack the "+Permissions.ADMIN_RELOAD+ " permission to use 'reload'");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ public class Permissions {
|
||||
|
||||
public final static String ADMIN_CHATLOG = ADMIN + ".chatlog";
|
||||
public static final String ADMIN_COMMANDS = ADMIN + ".commands";
|
||||
public static final String ADMIN_RELOAD = ADMIN + ".reload";
|
||||
|
||||
public static final String INVENTORY = CHECKS + ".inventory";
|
||||
public static final String INVENTORY_DROP = INVENTORY + ".drop";
|
||||
|
Loading…
Reference in New Issue
Block a user