mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-02-19 13:11:43 +01:00
Add command "ncp debug player (player1) ...".
This is the first simple version, just setting debug for all checks for the player(s). It can only be undone by removing the data, e.g. with "ncp remove (player)", reloading does it too, but is much heavier.
This commit is contained in:
parent
256d06b67c
commit
5f9764dabc
@ -25,6 +25,7 @@ import fr.neatmonster.nocheatplus.command.admin.LagCommand;
|
||||
import fr.neatmonster.nocheatplus.command.admin.ReloadCommand;
|
||||
import fr.neatmonster.nocheatplus.command.admin.RemovePlayerCommand;
|
||||
import fr.neatmonster.nocheatplus.command.admin.VersionCommand;
|
||||
import fr.neatmonster.nocheatplus.command.admin.debug.DebugCommand;
|
||||
import fr.neatmonster.nocheatplus.command.admin.exemption.ExemptCommand;
|
||||
import fr.neatmonster.nocheatplus.command.admin.exemption.ExemptionsCommand;
|
||||
import fr.neatmonster.nocheatplus.command.admin.exemption.UnexemptCommand;
|
||||
@ -103,6 +104,7 @@ public class NoCheatPlusCommand extends BaseCommand{
|
||||
new AllowLoginCommand(plugin),
|
||||
new LogCommand(plugin),
|
||||
new ResetCommand(plugin),
|
||||
new DebugCommand(plugin),
|
||||
}){
|
||||
addSubCommands(cmd);
|
||||
rootLabels.add(cmd.label);
|
||||
|
@ -25,13 +25,14 @@ public class CommandsCommand extends BaseCommand {
|
||||
"/<command> delay [delay=(ticks)] (command)...: delay a command",
|
||||
"/<command> denylogin [delay=(ticks)] (player) (minutes) [(reason)...]",
|
||||
"More administrative commands:",
|
||||
"/<command> log counters: Show some stats/debug counters summary.",
|
||||
"/<command> reset counters: Reset some stats/debug counters",
|
||||
"/<command> debug player (player): Log debug info for the player.",
|
||||
"/<command> denylist: Show players, currently denied to log in.",
|
||||
"/<command> allowlogin (player): Allow a player to login again.",
|
||||
"/<command> exemptions (player): Show exemptions.",
|
||||
"/<command> exempt (player) [(check type)]: Exempt a player.",
|
||||
"/<command> unexempt (player) [(check type)]: Unexempt a player.",
|
||||
"/<command> log counters: Show some stats/debug counters summary.",
|
||||
"/<command> reset counters: Reset some stats/debug counters",
|
||||
};
|
||||
|
||||
final String allCommands;
|
||||
|
@ -59,13 +59,18 @@ public class ReloadCommand extends BaseCommand {
|
||||
|
||||
// Remove all cached configs.
|
||||
DataManager.clearConfigs(); // There you have to add XConfig.clear() form now on.
|
||||
|
||||
// Remove some checks data.
|
||||
// TODO: Better concept (INotifyReload).
|
||||
for (final CheckType checkType : new CheckType[]{
|
||||
CheckType.BLOCKBREAK, CheckType.FIGHT,
|
||||
}){
|
||||
DataManager.clearData(checkType);
|
||||
}
|
||||
|
||||
// Reset debug flags to default (temp, heavy).
|
||||
DataManager.restoreDefaultDebugFlags();
|
||||
|
||||
// Tell the registered listeners to adapt to new config, first sort them (!).
|
||||
Collections.sort(notifyReload, Order.cmpSetupOrder);
|
||||
for (final INotifyReload component : notifyReload){
|
||||
|
@ -0,0 +1,16 @@
|
||||
package fr.neatmonster.nocheatplus.command.admin.debug;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import fr.neatmonster.nocheatplus.command.BaseCommand;
|
||||
import fr.neatmonster.nocheatplus.permissions.Permissions;
|
||||
|
||||
public class DebugCommand extends BaseCommand {
|
||||
|
||||
public DebugCommand(JavaPlugin access) {
|
||||
super(access, "debug", Permissions.COMMAND_DEBUG);
|
||||
addSubCommands(new DebugPlayerCommand(access));
|
||||
// TODO: Sub command check, plus check type, plus -(-)off switch
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package fr.neatmonster.nocheatplus.command.admin.debug;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
|
||||
import fr.neatmonster.nocheatplus.checks.access.ICheckData;
|
||||
import fr.neatmonster.nocheatplus.command.BaseCommand;
|
||||
import fr.neatmonster.nocheatplus.players.DataManager;
|
||||
|
||||
public class DebugPlayerCommand extends BaseCommand {
|
||||
|
||||
public DebugPlayerCommand(JavaPlugin plugin) {
|
||||
super(plugin, "player", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return null; // Tab-complete player names.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
|
||||
|
||||
// TODO: This is a minimal version just to turn it on (!). Further: check types, -off.
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
final String name = args[i];
|
||||
final Player player = DataManager.getPlayer(name);
|
||||
if (player == null) {
|
||||
sender.sendMessage("Not online: " + name);
|
||||
} else {
|
||||
setDebugAll(player);
|
||||
sender.sendMessage("Set all checks to debug for player: " + player.getName());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setDebugAll(final Player player) {
|
||||
for (final CheckType type : CheckType.values()) {
|
||||
CheckDataFactory factory = type.getDataFactory();
|
||||
if (factory != null) {
|
||||
ICheckData data = factory.getData(player);
|
||||
if (data != null) {
|
||||
data.setDebug(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -23,7 +23,10 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationHistory;
|
||||
import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory;
|
||||
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
|
||||
import fr.neatmonster.nocheatplus.checks.access.ICheckConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.access.ICheckData;
|
||||
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceConfig;
|
||||
@ -33,6 +36,7 @@ import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
|
||||
import fr.neatmonster.nocheatplus.checks.fight.FightConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
|
||||
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
|
||||
import fr.neatmonster.nocheatplus.components.ComponentRegistry;
|
||||
import fr.neatmonster.nocheatplus.components.ComponentWithName;
|
||||
import fr.neatmonster.nocheatplus.components.ConsistencyChecker;
|
||||
@ -297,6 +301,40 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, Compon
|
||||
instance.playerData.clear(); // TODO
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the default debug flags within player data, as given in
|
||||
* corresponding configurations. This only yields the correct result, if the
|
||||
* the data uses the same configuration for initialization which is
|
||||
* registered under the same check type.
|
||||
*/
|
||||
public static void restoreDefaultDebugFlags() {
|
||||
final Player[] players = BridgeMisc.getOnlinePlayers();
|
||||
for (final CheckType checkType : CheckType.values()) {
|
||||
final CheckConfigFactory configFactory = checkType.getConfigFactory();
|
||||
if (configFactory == null) {
|
||||
continue;
|
||||
}
|
||||
final CheckDataFactory dataFactory = checkType.getDataFactory();
|
||||
if (dataFactory == null) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < players.length; i++) {
|
||||
final Player player = players[i];
|
||||
final ICheckConfig config = configFactory.getConfig(player);
|
||||
if (config == null) {
|
||||
continue;
|
||||
}
|
||||
final ICheckData data = dataFactory.getData(player);
|
||||
if (data == null) {
|
||||
continue;
|
||||
}
|
||||
if (config.getDebug() != data.getDebug()) {
|
||||
data.setDebug(config.getDebug());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the player data for a given player and a given check type. CheckType.ALL and null will be interpreted as removing all data.<br>
|
||||
|
@ -313,6 +313,8 @@ permissions:
|
||||
description: Show various stats/debugging information. [Incomplete, experimental.]
|
||||
nocheatplus.command.reset:
|
||||
description: Reset statistics or debugging counters.
|
||||
nocheatplus.command.debug:
|
||||
description: Start logging debug information for a player (lots of output, log file).
|
||||
# Legacy:
|
||||
nocheatplus.command.tempkick:
|
||||
description: Obsolete, use nocheatplus.command.denylogin instead.
|
||||
|
Loading…
Reference in New Issue
Block a user