Deprecate CheckType.removeData(String, CheckType), move to DataManager.

This commit is contained in:
asofold 2012-11-03 10:22:21 +01:00
parent 2e87c821b5
commit 17395cb742
3 changed files with 37 additions and 25 deletions

View File

@ -1,8 +1,5 @@
package fr.neatmonster.nocheatplus.checks;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory;
@ -23,7 +20,7 @@ import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryData;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
import fr.neatmonster.nocheatplus.hooks.APIUtils;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.players.Permissions;
/*
@ -238,29 +235,12 @@ public enum CheckType {
/**
* 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>
* @deprecated Will be removed, use DataManager.removeData instead.
* @param playerName
* @param checkType
* @return If any data was present.
*/
public static boolean removeData(final String playerName, CheckType checkType) {
if (checkType == null) checkType = ALL;
// Attempt for direct removal.
CheckDataFactory dataFactory = checkType.getDataFactory();
if (dataFactory != null) return dataFactory.removeData(playerName) != null;
// Remove all for which it seems necessary.
final Set<CheckDataFactory> factories = new HashSet<CheckDataFactory>();
for (CheckType otherType : CheckType.values()){
if (checkType == ALL || APIUtils.isParent(checkType, otherType)){
final CheckDataFactory otherFactory = otherType.getDataFactory();
if (otherFactory != null) factories.add(otherFactory);
}
}
boolean had = false;
for (final CheckDataFactory otherFactory : factories){
if (otherFactory.removeData(playerName) != null) had = true;
}
return had;
public static boolean removeData(final String playerName, final CheckType checkType) {
return DataManager.removeData(playerName, checkType);
}
}

View File

@ -61,7 +61,7 @@ public class RemovePlayerCommand extends NCPCommand {
if (DataManager.removeExecutionHistory(checkType, playerName)) histRemoved = true;
final boolean dataRemoved = CheckType.removeData(playerName, checkType) || DataManager.clearComponentData(checkType, playerName);
final boolean dataRemoved = DataManager.removeData(playerName, checkType);
if (dataRemoved || histRemoved){
String which;

View File

@ -197,6 +197,38 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo
ViolationHistory.clear(checkType);
}
/**
* 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>
* @param playerName
* @param checkType
* @return If any data was present.
*/
public static boolean removeData(final String playerName, CheckType checkType) {
if (checkType == null) checkType = CheckType.ALL;
// Attempt for direct removal.
CheckDataFactory dataFactory = checkType.getDataFactory();
if (dataFactory != null) return dataFactory.removeData(playerName) != null;
// Remove all for which it seems necessary.
final Set<CheckDataFactory> factories = new HashSet<CheckDataFactory>();
for (CheckType otherType : CheckType.values()){
if (checkType == CheckType.ALL || APIUtils.isParent(checkType, otherType)){
final CheckDataFactory otherFactory = otherType.getDataFactory();
if (otherFactory != null) factories.add(otherFactory);
}
}
boolean had = false;
for (final CheckDataFactory otherFactory : factories){
if (otherFactory.removeData(playerName) != null) had = true;
}
// Check extended registered components.
if (clearComponentData(checkType, playerName)) had = true;
return had;
}
/**
* Clear player related data, only for registered components (not execution history, violation history, normal check data).<br>
* That should at least go for chat engione data.