Beispiel #1
0
 /**
  * Check the logged out players for if any data can be removed.<br>
  * Currently only "dumb" full removal is performed. Later it is thinkable to remove "as much as
  * reasonable".
  */
 public void checkExpiration() {
   if (durExpireData <= 0) return;
   final long now = System.currentTimeMillis();
   final Set<CheckDataFactory> factories = new LinkedHashSet<CheckDataFactory>();
   final Set<Entry<String, Long>> entries = lastLogout.entrySet();
   final Iterator<Entry<String, Long>> iterator = entries.iterator();
   while (iterator.hasNext()) {
     final Entry<String, Long> entry = iterator.next();
     final long ts = entry.getValue();
     if (now - ts <= durExpireData) break;
     final String playerName = entry.getKey();
     if (deleteData) {
       factories.clear();
       for (final CheckType type : CheckType.values()) {
         final CheckDataFactory factory = type.getDataFactory();
         if (factory != null) factories.add(factory);
       }
       for (final CheckDataFactory factory : factories) {
         factory.removeData(playerName);
       }
       clearComponentData(CheckType.ALL, playerName);
     }
     if (deleteData || deleteHistory) removeExecutionHistory(CheckType.ALL, playerName);
     if (deleteHistory) ViolationHistory.removeHistory(playerName);
     iterator.remove();
   }
 }
Beispiel #2
0
 /**
  * Check if the supposed parent is ancestor of the supposed child. Does not check versus the
  * supposed child directly.
  *
  * @param supposedParent the supposed parent
  * @param supposedChild the supposed child
  * @return true, if is parent
  */
 public static final boolean isParent(
     final CheckType supposedParent, final CheckType supposedChild) {
   CheckType parent = supposedChild.getParent();
   while (parent != null)
     if (parent == supposedParent) return true;
     else parent = parent.getParent();
   return false;
 }
Beispiel #3
0
 static {
   final Map<CheckType, Set<CheckType>> map = new HashMap<CheckType, Set<CheckType>>();
   for (final CheckType type : CheckType.values()) map.put(type, new HashSet<CheckType>());
   for (final CheckType type : CheckType.values())
     for (final CheckType other : CheckType.values())
       if (isParent(other, type)) map.get(other).add(type);
   for (final CheckType parent : map.keySet())
     childrenMap.put(parent, map.get(parent).toArray(new CheckType[] {}));
 }
Beispiel #4
0
 /**
  * Remove data and history of all players for the given check type and sub checks.
  *
  * @param checkType
  */
 public static void clearData(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();
   }
   for (final IRemoveData rmd : instance.iRemoveData) {
     if (rmd instanceof IHaveCheckType) {
       final CheckType refType = ((IHaveCheckType) rmd).getCheckType();
       if (refType == checkType || APIUtils.isParent(checkType, refType)) rmd.removeAllData();
     }
   }
   ViolationHistory.clear(checkType);
 }
 /** Remove all exemptions. */
 public static final void clear() {
   // Use put with a new map to keep entries to stay thread safe.
   for (final CheckType checkType : CheckType.values()) {
     if (APIUtils.needsSynchronization(checkType)) {
       exempted.put(checkType, Collections.synchronizedSet(new HashSet<UUID>()));
     } else {
       exempted.put(checkType, new HashSet<UUID>());
     }
   }
 }
Beispiel #6
0
  /**
   * 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 Exact player name.
   * @param checkType Check type to remove data for, null is regarded as ALL.
   * @return If any data was present.
   */
  public static boolean removeData(final String playerName, CheckType checkType) {
    if (checkType == null) checkType = CheckType.ALL;
    boolean had = false;

    // Check extended registered components.
    if (clearComponentData(checkType, playerName)) had = true;

    // Collect factories.
    final Set<CheckDataFactory> factories = new HashSet<CheckDataFactory>();
    for (CheckType otherType : APIUtils.getWithChildren(checkType)) {
      final CheckDataFactory otherFactory = otherType.getDataFactory();
      if (otherFactory != null) factories.add(otherFactory);
    }
    // Remove data.
    for (final CheckDataFactory otherFactory : factories) {
      if (otherFactory.removeData(playerName) != null) had = true;
    }

    return had;
  }
 /**
  * Match for CheckType, some smart method, to also match after first "_" for convenience of input.
  *
  * @param input
  * @return
  */
 public static List<String> getCheckTypeTabMatches(final String input) {
   final String ref = input.toUpperCase().replace('-', '_').replace('.', '_');
   final List<String> res = new ArrayList<String>();
   for (final CheckType checkType : CheckType.values()) {
     final String name = checkType.name();
     if (name.startsWith(ref)) {
       res.add(name);
     }
   }
   if (ref.indexOf('_') == -1) {
     for (final CheckType checkType : CheckType.values()) {
       final String name = checkType.name();
       final String[] split = name.split("_", 2);
       if (split.length > 1 && split[1].startsWith(ref)) {
         res.add(name);
       }
     }
   }
   if (!res.isEmpty()) {
     Collections.sort(res);
     return res;
   }
   return null;
 }