Add: /ncp remove * [<check type>]

This commit is contained in:
asofold 2012-09-29 20:57:44 +02:00
parent 5b1eb3121e
commit 7962962a40
12 changed files with 110 additions and 2 deletions

View File

@ -165,6 +165,12 @@ public class ViolationHistory {
public static ViolationHistory removeHistory(final String playerName){
return violationHistories.remove(playerName);
}
public static void clear(final CheckType checkType){
for (ViolationHistory hist : violationHistories.values()){
hist.remove(checkType);
}
}
/** The violation levels for every check. */
private final List<ViolationLevel> violationLevels = new ArrayList<ViolationLevel>();

View File

@ -44,4 +44,9 @@ public interface CheckDataFactory {
*/
public ICheckData removeData(final String playerName);
/**
* Remove all data for all players.
*/
public void removeAllData();
}

View File

@ -44,6 +44,11 @@ public class BlockBreakData extends ACheckData {
public ICheckData removeData(final String playerName) {
return BlockBreakData.removeData(playerName);
}
@Override
public void removeAllData() {
clear();
}
};
/** The map containing the data per players. */
@ -65,6 +70,10 @@ public class BlockBreakData extends ACheckData {
public static ICheckData removeData(final String playerName) {
return playersMap.remove(playerName);
}
public static void clear(){
playersMap.clear();
}
// Violation levels.
public double directionVL;

View File

@ -42,6 +42,11 @@ public class BlockInteractData extends ACheckData {
public ICheckData removeData(final String playerName) {
return BlockInteractData.removeData(playerName);
}
@Override
public void removeAllData() {
clear();
}
};
/** The map containing the data per players. */
@ -63,6 +68,10 @@ public class BlockInteractData extends ACheckData {
public static ICheckData removeData(final String playerName) {
return playersMap.remove(playerName);
}
public static void clear(){
playersMap.clear();
}
// Violation levels.
public double directionVL;

View File

@ -42,6 +42,11 @@ public class BlockPlaceData extends ACheckData {
public ICheckData removeData(final String playerName) {
return BlockPlaceData.removeData(playerName);
}
@Override
public void removeAllData() {
clear();
}
};
/** The map containing the data per players. */
@ -63,6 +68,10 @@ public class BlockPlaceData extends ACheckData {
public static ICheckData removeData(final String playerName) {
return playersMap.remove(playerName);
}
public static void clear(){
playersMap.clear();
}
// Violation levels.
public double directionVL;

View File

@ -35,6 +35,11 @@ public class ChatData extends AsyncCheckData {
public ICheckData removeData(final String playerName) {
return ChatData.removeData(playerName);
}
@Override
public void removeAllData() {
clear();
}
};
/** The map containing the data per players. */
@ -47,15 +52,19 @@ public class ChatData extends AsyncCheckData {
* the player
* @return the data
*/
public synchronized static ChatData getData(final Player player) {
public static synchronized ChatData getData(final Player player) {
if (!playersMap.containsKey(player.getName()))
playersMap.put(player.getName(), new ChatData());
return playersMap.get(player.getName());
}
public synchronized static ICheckData removeData(final String playerName) {
public static synchronized ICheckData removeData(final String playerName) {
return playersMap.remove(playerName);
}
public static synchronized void clear(){
playersMap.clear();
}
// Violation levels.
public double captchaVL;

View File

@ -23,6 +23,11 @@ public class CombinedData extends ACheckData {
public ICheckData removeData(final String playerName) {
return CombinedData.removeData(playerName);
}
@Override
public void removeAllData() {
clear();
}
};
private static final Map<String, CombinedData> playersMap = new HashMap<String, CombinedData>();
@ -40,6 +45,10 @@ public class CombinedData extends ACheckData {
public static ICheckData removeData(final String playerName) {
return playersMap.remove(playerName);
}
public static void clear(){
playersMap.clear();
}
public double improbableVL = 0;
public double speedVL = 0;

View File

@ -38,6 +38,11 @@ public class FightData extends ACheckData {
public ICheckData removeData(final String playerName) {
return FightData.removeData(playerName);
}
@Override
public void removeAllData() {
clear();
}
};
/** The map containing the data per players. */
@ -59,6 +64,10 @@ public class FightData extends ACheckData {
public static ICheckData removeData(final String playerName) {
return playersMap.remove(playerName);
}
public static void clear(){
playersMap.clear();
}
// Violation levels.
public double angleVL;

View File

@ -36,6 +36,11 @@ public class InventoryData extends ACheckData {
public ICheckData removeData(final String playerName) {
return InventoryData.removeData(playerName);
}
@Override
public void removeAllData() {
clear();
}
};
/** The map containing the data per players. */
@ -57,6 +62,10 @@ public class InventoryData extends ACheckData {
public static ICheckData removeData(final String playerName) {
return playersMap.remove(playerName);
}
public static void clear(){
playersMap.clear();
}
// Violation levels.
public double dropVL;

View File

@ -37,6 +37,11 @@ public class MovingData extends ACheckData {
public ICheckData removeData(final String playerName) {
return MovingData.removeData(playerName);
}
@Override
public void removeAllData() {
clear();
}
};
/** The map containing the data per players. */
@ -58,6 +63,10 @@ public class MovingData extends ACheckData {
public static ICheckData removeData(final String playerName) {
return playersMap.remove(playerName);
}
public static void clear(){
playersMap.clear();
}
// Violation levels.
public double creativeFlyVL = 0D;

View File

@ -40,6 +40,12 @@ public class RemovePlayerCommand extends NCPCommand {
}
else checkType = CheckType.ALL;
if (playerName.equals("*")){
DataManager.clear(checkType);
sender.sendMessage(TAG + "Removed all data and history: " + checkType);
return true;
}
final Player player = Bukkit.getPlayerExact(playerName);
if (player != null) playerName = player.getName();

View File

@ -1,6 +1,7 @@
package fr.neatmonster.nocheatplus.players;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@ -122,4 +123,22 @@ public class DataManager implements Listener, INotifyReload, INeedConfig{
}
return removed;
}
/**
* Remove data and history of all players for the given check type and sub checks.
* @param checkType
*/
public static void clear(final CheckType checkType) {
final Set<CheckDataFactory> factories = new HashSet<CheckDataFactory>();
for (final CheckType type : APIUtils.getWithChildren(checkType)){
final Map<String, ExecutionHistory> map = instance.executionHistories.get(type);
if (map != null) map.clear();
final CheckDataFactory factory = type.getDataFactory();
if (factory != null) factories.add(factory);
}
for (final CheckDataFactory factory : factories){
factory.removeAllData();
}
ViolationHistory.clear(checkType);
}
}