Search in sources :

Example 1 with IRemoveData

use of fr.neatmonster.nocheatplus.components.registry.feature.IRemoveData in project NoCheatPlus by NoCheatPlus.

the class PlayerDataManager method handleSystemTimeRanBackwards.

/**
 * Adjust to the system time having run backwards. This is much like
 * clearData(CheckType.ALL), with the exception of calling
 * ICanHandleTimeRunningBackwards.handleTimeRanBackwards for data instances
 * which implement this.
 */
public void handleSystemTimeRanBackwards() {
    // Collect data factories and clear execution history.
    for (final CheckType type : CheckTypeUtil.getWithDescendants(CheckType.ALL)) {
        final Map<String, ExecutionHistory> map = executionHistories.get(type);
        if (map != null) {
            map.clear();
        }
    }
    for (final IRemoveData rmd : iRemoveData) {
        if (rmd instanceof ICanHandleTimeRunningBackwards) {
            ((ICanHandleTimeRunningBackwards) rmd).handleTimeRanBackwards();
        } else {
            rmd.removeAllData();
        }
    }
    ViolationHistory.clear(CheckType.ALL);
    // PlayerData
    // TODO: Register explicitly (adding IDataOnTimeRanBackwards)?
    Collection<Class<? extends IData>> dataTypes = factoryRegistry.getGroupedTypes(IData.class);
    for (final Entry<UUID, PlayerData> entry : playerData.iterable()) {
        entry.getValue().handleTimeRanBackwards(dataTypes);
    }
}
Also used : IHaveCheckType(fr.neatmonster.nocheatplus.components.registry.feature.IHaveCheckType) CheckType(fr.neatmonster.nocheatplus.checks.CheckType) IData(fr.neatmonster.nocheatplus.components.data.IData) IRemoveData(fr.neatmonster.nocheatplus.components.registry.feature.IRemoveData) ICanHandleTimeRunningBackwards(fr.neatmonster.nocheatplus.components.data.ICanHandleTimeRunningBackwards) UUID(java.util.UUID)

Example 2 with IRemoveData

use of fr.neatmonster.nocheatplus.components.registry.feature.IRemoveData in project NoCheatPlus by NoCheatPlus.

the class PlayerDataManager method clearData.

@Override
public void clearData(final CheckType checkType) {
    final CheckRemovalSpec removalSpec = new CheckRemovalSpec(checkType, true, this);
    final boolean hasComplete = !removalSpec.completeRemoval.isEmpty();
    final boolean hasSub = !removalSpec.subCheckRemoval.isEmpty();
    if (hasComplete || hasSub) {
        for (final Entry<UUID, PlayerData> entry : playerData.iterable()) {
            final IPlayerData pData = entry.getValue();
            if (hasComplete) {
                pData.removeAllGenericInstances(removalSpec.completeRemoval);
            }
            if (hasSub) {
                pData.removeSubCheckData(removalSpec.subCheckRemoval, removalSpec.checkTypes);
            }
        // TODO: Remove the PlayerData instance, if suitable?
        }
    }
    // TODO: IRemoveData - why register here at all ?
    for (final IRemoveData rmd : iRemoveData) {
        if (checkType == CheckType.ALL) {
            // Not sure this is really good, though.
            rmd.removeAllData();
        } else if (rmd instanceof IHaveCheckType) {
            final CheckType refType = ((IHaveCheckType) rmd).getCheckType();
            if (refType == checkType || CheckTypeUtil.isAncestor(checkType, refType)) {
                rmd.removeAllData();
            }
        }
    }
    for (final CheckType type : removalSpec.checkTypes) {
        final Map<String, ExecutionHistory> map = executionHistories.get(type);
        if (map != null) {
            map.clear();
        }
    }
    ViolationHistory.clear(checkType);
    // TODO: PlayerData removal should have other mechanisms (stages).
    if (checkType == CheckType.ALL) {
        bulkPlayerDataRemoval.addAll(playerData.getKeys());
        // Only removes offline player data.
        doBulkPlayerDataRemoval();
    }
}
Also used : IHaveCheckType(fr.neatmonster.nocheatplus.components.registry.feature.IHaveCheckType) CheckRemovalSpec(fr.neatmonster.nocheatplus.components.registry.factory.RichFactoryRegistry.CheckRemovalSpec) IHaveCheckType(fr.neatmonster.nocheatplus.components.registry.feature.IHaveCheckType) CheckType(fr.neatmonster.nocheatplus.checks.CheckType) IRemoveData(fr.neatmonster.nocheatplus.components.registry.feature.IRemoveData) UUID(java.util.UUID)

Aggregations

CheckType (fr.neatmonster.nocheatplus.checks.CheckType)2 IHaveCheckType (fr.neatmonster.nocheatplus.components.registry.feature.IHaveCheckType)2 IRemoveData (fr.neatmonster.nocheatplus.components.registry.feature.IRemoveData)2 UUID (java.util.UUID)2 ICanHandleTimeRunningBackwards (fr.neatmonster.nocheatplus.components.data.ICanHandleTimeRunningBackwards)1 IData (fr.neatmonster.nocheatplus.components.data.IData)1 CheckRemovalSpec (fr.neatmonster.nocheatplus.components.registry.factory.RichFactoryRegistry.CheckRemovalSpec)1