use of fr.neatmonster.nocheatplus.checks.ViolationHistory in project NoCheatPlus by NoCheatPlus.
the class RemovePlayerCommand method onCommand.
@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length < 2 || args.length > 3)
return false;
String playerName = args[1];
final CheckType checkType;
if (args.length == 3) {
try {
checkType = CheckType.valueOf(args[2].toUpperCase().replace('-', '_').replace('.', '_'));
} catch (Exception e) {
sender.sendMessage(TAG + "Could not interpret: " + args[2]);
sender.sendMessage(TAG + "Check type should be one of: " + StringUtil.join(Arrays.asList(CheckType.values()), " | "));
return true;
}
} else
checkType = CheckType.ALL;
if (playerName.equals("*")) {
DataManager.clearData(checkType);
sender.sendMessage(TAG + "Removed all data and history: " + checkType);
return true;
}
final Player player = DataManager.getPlayer(playerName);
if (player != null)
playerName = player.getName();
ViolationHistory hist = ViolationHistory.getHistory(playerName, false);
boolean somethingFound = false;
if (hist != null) {
somethingFound = hist.remove(checkType);
if (checkType == CheckType.ALL) {
somethingFound = true;
ViolationHistory.removeHistory(playerName);
}
}
if (DataManager.removeExecutionHistory(checkType, playerName)) {
somethingFound = true;
}
if (DataManager.removeData(playerName, checkType)) {
somethingFound = true;
}
if (somethingFound) {
sender.sendMessage(TAG + "Issued history and data removal (" + checkType + "): " + playerName);
} else
sender.sendMessage(TAG + "Nothing found (" + checkType + "): " + playerName + " (spelled correctly?)");
return true;
}
use of fr.neatmonster.nocheatplus.checks.ViolationHistory in project NoCheatPlus by NoCheatPlus.
the class InfoCommand method handleInfoCommand.
/**
* Handle the '/nocheatplus info' command.
*
* @param sender
* the sender
* @param playerName
* the player name
* @return true, if successful
*/
private void handleInfoCommand(final CommandSender sender, String playerName) {
final Player player = DataManager.getPlayer(playerName);
if (player != null)
playerName = player.getName();
final ViolationHistory history = ViolationHistory.getHistory(playerName, false);
final boolean known = player != null || history != null;
if (history == null) {
sender.sendMessage(TAG + "No entries for " + playerName + "'s violations... " + (known ? "" : "(exact spelling?)") + ".");
return;
}
final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
final ViolationLevel[] violations = history.getViolationLevels();
if (violations.length > 0) {
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations...");
final String c = (sender instanceof Player) ? ChatColor.GRAY.toString() : "";
for (final ViolationLevel violationLevel : violations) {
final long time = violationLevel.time;
final String[] parts = violationLevel.check.split("\\.");
final String check = parts[parts.length - 1].toLowerCase();
final String parent = parts[parts.length - 2].toLowerCase();
final long sumVL = Math.round(violationLevel.sumVL);
final long maxVL = Math.round(violationLevel.maxVL);
final long avVl = Math.round(violationLevel.sumVL / (double) violationLevel.nVL);
sender.sendMessage(TAG + "[" + dateFormat.format(new Date(time)) + "] " + parent + "." + check + " VL " + sumVL + c + " (n" + violationLevel.nVL + "a" + avVl + "m" + maxVL + ")");
}
} else
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations... nothing to display.");
}
Aggregations