Search in sources :

Example 1 with ICanHandleTimeRunningBackwards

use of fr.neatmonster.nocheatplus.components.data.ICanHandleTimeRunningBackwards in project NoCheatPlus by NoCheatPlus.

the class PlayerData method handleTimeRanBackwards.

public void handleTimeRanBackwards(final Collection<Class<? extends IData>> dataTypes) {
    // Permissions.
    final Iterator<Entry<Integer, PermissionNode>> it = permissions.iterator();
    final long timeNow = System.currentTimeMillis();
    while (it.hasNext()) {
        final PermissionNode node = it.next().getValue();
        switch(node.getFetchingPolicy()) {
            case INTERVAL:
                node.invalidate();
                break;
            default:
                if (node.getLastFetch() > timeNow) {
                    node.setState(node.getLastState(), timeNow);
                }
                break;
        }
    }
    // TODO: Register explicitly or not? (+ auto register?)...
    for (final Class<? extends IData> type : dataTypes) {
        final IData obj = dataCache.get(type);
        if (obj != null && obj instanceof ICanHandleTimeRunningBackwards) {
            ((ICanHandleTimeRunningBackwards) obj).handleTimeRanBackwards();
        }
    }
}
Also used : Entry(java.util.Map.Entry) IData(fr.neatmonster.nocheatplus.components.data.IData) ICanHandleTimeRunningBackwards(fr.neatmonster.nocheatplus.components.data.ICanHandleTimeRunningBackwards) PermissionNode(fr.neatmonster.nocheatplus.permissions.PermissionNode)

Example 2 with ICanHandleTimeRunningBackwards

use of fr.neatmonster.nocheatplus.components.data.ICanHandleTimeRunningBackwards 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)

Aggregations

ICanHandleTimeRunningBackwards (fr.neatmonster.nocheatplus.components.data.ICanHandleTimeRunningBackwards)2 IData (fr.neatmonster.nocheatplus.components.data.IData)2 CheckType (fr.neatmonster.nocheatplus.checks.CheckType)1 IHaveCheckType (fr.neatmonster.nocheatplus.components.registry.feature.IHaveCheckType)1 IRemoveData (fr.neatmonster.nocheatplus.components.registry.feature.IRemoveData)1 PermissionNode (fr.neatmonster.nocheatplus.permissions.PermissionNode)1 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1