[BLEEDING] Partial overhaul for CheckType.
Yes * Remove the UNKNOWN type. * All types except ALL have a parent now. * All types have a type now. * APIUtils: Add getDirectChildren for distinction. No * APIUtils doesn't collect the descendants in a generic way yet.
This commit is contained in:
parent
073220cc01
commit
532eef14a2
|
@ -45,7 +45,7 @@ import fr.neatmonster.nocheatplus.permissions.Permissions;
|
|||
public enum CheckType {
|
||||
ALL(Permissions.CHECKS),
|
||||
|
||||
BLOCKBREAK(BlockBreakConfig.factory, BlockBreakData.factory, Permissions.BLOCKBREAK),
|
||||
BLOCKBREAK(CheckType.ALL, BlockBreakConfig.factory, BlockBreakData.factory, Permissions.BLOCKBREAK),
|
||||
/** This will allow breaking all special blocks, currently only liquid. Later there might be more sub-types. */
|
||||
BLOCKBREAK_BREAK(BLOCKBREAK, Permissions.BLOCKBREAK_BREAK),
|
||||
BLOCKBREAK_DIRECTION(BLOCKBREAK, Permissions.BLOCKBREAK_DIRECTION),
|
||||
|
@ -55,13 +55,13 @@ public enum CheckType {
|
|||
BLOCKBREAK_REACH(BLOCKBREAK, Permissions.BLOCKBREAK_REACH),
|
||||
BLOCKBREAK_WRONGBLOCK(BLOCKBREAK, Permissions.BLOCKBREAK_WRONGBLOCK),
|
||||
|
||||
BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory, Permissions.BLOCKINTERACT),
|
||||
BLOCKINTERACT(CheckType.ALL, BlockInteractConfig.factory, BlockInteractData.factory, Permissions.BLOCKINTERACT),
|
||||
BLOCKINTERACT_DIRECTION(BLOCKINTERACT, Permissions.BLOCKINTERACT_DIRECTION),
|
||||
BLOCKINTERACT_REACH(BLOCKINTERACT, Permissions.BLOCKINTERACT_REACH),
|
||||
BLOCKINTERACT_SPEED(BLOCKINTERACT, Permissions.BLOCKINTERACT_SPEED),
|
||||
BLOCKINTERACT_VISIBLE(BLOCKINTERACT, Permissions.BLOCKINTERACT_VISIBLE),
|
||||
|
||||
BLOCKPLACE(BlockPlaceConfig.factory, BlockPlaceData.factory, Permissions.BLOCKPLACE),
|
||||
BLOCKPLACE(CheckType.ALL, BlockPlaceConfig.factory, BlockPlaceData.factory, Permissions.BLOCKPLACE),
|
||||
BLOCKPLACE_AGAINST(BLOCKPLACE, Permissions.BLOCKPLACE_AGAINST),
|
||||
BLOCKPLACE_AUTOSIGN(BLOCKPLACE, Permissions.BLOCKPLACE_AUTOSIGN),
|
||||
BLOCKPLACE_DIRECTION(BLOCKPLACE, Permissions.BLOCKPLACE_DIRECTION),
|
||||
|
@ -70,7 +70,7 @@ public enum CheckType {
|
|||
BLOCKPLACE_REACH(BLOCKPLACE, Permissions.BLOCKBREAK_REACH),
|
||||
BLOCKPLACE_SPEED(BLOCKPLACE, Permissions.BLOCKPLACE_SPEED),
|
||||
|
||||
CHAT(ChatConfig.factory, ChatData.factory, Permissions.CHAT),
|
||||
CHAT(CheckType.ALL, ChatConfig.factory, ChatData.factory, Permissions.CHAT),
|
||||
CHAT_CAPTCHA(CHAT, Permissions.CHAT_CAPTCHA),
|
||||
CHAT_COLOR(CHAT, Permissions.CHAT_COLOR),
|
||||
CHAT_COMMANDS(CHAT, Permissions.CHAT_COMMANDS),
|
||||
|
@ -79,14 +79,14 @@ public enum CheckType {
|
|||
CHAT_RELOG(CHAT, Permissions.CHAT_RELOG),
|
||||
|
||||
|
||||
COMBINED(CombinedConfig.factory, CombinedData.factory, Permissions.COMBINED),
|
||||
COMBINED(CheckType.ALL, CombinedConfig.factory, CombinedData.factory, Permissions.COMBINED),
|
||||
COMBINED_BEDLEAVE(COMBINED, Permissions.COMBINED_BEDLEAVE),
|
||||
COMBINED_IMPROBABLE(COMBINED, Permissions.COMBINED_IMPROBABLE),
|
||||
COMBINED_MUNCHHAUSEN(COMBINED, Permissions.COMBINED_MUNCHHAUSEN),
|
||||
/** Rather for data removal and exemption. */
|
||||
COMBINED_YAWRATE(COMBINED),
|
||||
|
||||
FIGHT(FightConfig.factory, FightData.factory, Permissions.FIGHT),
|
||||
FIGHT(CheckType.ALL, FightConfig.factory, FightData.factory, Permissions.FIGHT),
|
||||
FIGHT_ANGLE(FIGHT, Permissions.FIGHT_ANGLE),
|
||||
FIGHT_CRITICAL(FIGHT, Permissions.FIGHT_CRITICAL),
|
||||
FIGHT_DIRECTION(FIGHT, Permissions.FIGHT_DIRECTION),
|
||||
|
@ -98,7 +98,7 @@ public enum CheckType {
|
|||
FightConfig.factory, FightData.selfHitDataFactory),
|
||||
FIGHT_SPEED(FIGHT, Permissions.FIGHT_SPEED),
|
||||
|
||||
INVENTORY(InventoryConfig.factory, InventoryData.factory, Permissions.INVENTORY),
|
||||
INVENTORY(CheckType.ALL, InventoryConfig.factory, InventoryData.factory, Permissions.INVENTORY),
|
||||
INVENTORY_DROP(INVENTORY, Permissions.INVENTORY_DROP),
|
||||
INVENTORY_FASTCLICK(INVENTORY, Permissions.INVENTORY_FASTCLICK),
|
||||
INVENTORY_FASTCONSUME(INVENTORY, Permissions.INVENTORY_FASTCONSUME),
|
||||
|
@ -108,7 +108,7 @@ public enum CheckType {
|
|||
INVENTORY_ITEMS(INVENTORY, Permissions.INVENTORY_ITEMS),
|
||||
INVENTORY_OPEN(INVENTORY, Permissions.INVENTORY_OPEN),
|
||||
|
||||
MOVING(MovingConfig.factory, MovingData.factory, Permissions.MOVING),
|
||||
MOVING(CheckType.ALL, MovingConfig.factory, MovingData.factory, Permissions.MOVING),
|
||||
MOVING_CREATIVEFLY(MOVING, Permissions.MOVING_CREATIVEFLY),
|
||||
MOVING_MOREPACKETS(MOVING, Permissions.MOVING_MOREPACKETS),
|
||||
MOVING_NOFALL(MOVING, Permissions.MOVING_NOFALL),
|
||||
|
@ -118,18 +118,21 @@ public enum CheckType {
|
|||
MOVING_VEHICLE_MOREPACKETS(MOVING_VEHICLE, Permissions.MOVING_VEHICLE_MOREPACKETS),
|
||||
MOVING_VEHICLE_ENVELOPE(MOVING_VEHICLE, Permissions.MOVING_VEHICLE_ENVELOPE),
|
||||
|
||||
NET(new NetConfigCache(), new NetDataFactory(), Permissions.NET),
|
||||
NET(CheckType.ALL, new NetConfigCache(), new NetDataFactory(), Permissions.NET),
|
||||
NET_ATTACKFREQUENCY(NET, Permissions.NET_ATTACKFREQUENCY),
|
||||
NET_FLYINGFREQUENCY(NET, Permissions.NET_FLYINGFREQUENCY),
|
||||
NET_KEEPALIVEFREQUENCY(NET, Permissions.NET_KEEPALIVEFREQUENCY),
|
||||
NET_PACKETFREQUENCY(NET, Permissions.NET_PACKETFREQUENCY),
|
||||
NET_SOUNDDISTANCE(NET), // Can not exempt players from this one.
|
||||
|
||||
UNKNOWN;
|
||||
;
|
||||
|
||||
public static enum CheckTypeType {
|
||||
/** Special types, like ALL */
|
||||
SPECIAL,
|
||||
/** Potentially obsolete: A check group that is not a check itself. */
|
||||
GROUP,
|
||||
/** An actual check. Could in future still have sub checks. */
|
||||
CHECK
|
||||
}
|
||||
|
||||
|
@ -148,13 +151,6 @@ public enum CheckType {
|
|||
/** The bypass permission. */
|
||||
private final String permission;
|
||||
|
||||
/**
|
||||
* Special purpose check types (likely not actual checks).
|
||||
*/
|
||||
private CheckType() {
|
||||
this(CheckTypeType.SPECIAL, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special purpose for grouping (ALL).
|
||||
*
|
||||
|
@ -164,10 +160,6 @@ public enum CheckType {
|
|||
this(CheckTypeType.SPECIAL, null, permission, null, null);
|
||||
}
|
||||
|
||||
private CheckType(final CheckType parent) {
|
||||
this(parent, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for root checks or check groups, that are not grouped under
|
||||
* another check type.
|
||||
|
@ -176,9 +168,20 @@ public enum CheckType {
|
|||
* @param dataFactory
|
||||
* @param permission
|
||||
*/
|
||||
private CheckType(final CheckConfigFactory configFactory, final CheckDataFactory dataFactory,
|
||||
private CheckType(final CheckType parent,
|
||||
final CheckConfigFactory configFactory, final CheckDataFactory dataFactory,
|
||||
final String permission) {
|
||||
this(CheckTypeType.GROUP, null, permission, configFactory, dataFactory);
|
||||
this(CheckTypeType.GROUP, parent, permission, configFactory, dataFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for sub-checks grouped under another check type, without
|
||||
* having a permission set.
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
private CheckType(final CheckType parent) {
|
||||
this(parent, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -668,7 +668,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
}
|
||||
else {
|
||||
checkCf = checkSf = false;
|
||||
// (thisMove.flyCheck stays UNKNOWN.)
|
||||
// (thisMove.flyCheck stays null.)
|
||||
}
|
||||
|
||||
// Pre-check checks (hum), either for cf or for sf.
|
||||
|
|
|
@ -95,7 +95,7 @@ public class PlayerMoveData extends MoveData {
|
|||
hAllowedDistanceBase = 0.0;
|
||||
hAllowedDistance = 0.0;
|
||||
// Meta stuff.
|
||||
flyCheck = CheckType.UNKNOWN;
|
||||
flyCheck = null;
|
||||
modelFlying = null;
|
||||
multiMoveCount = 0;
|
||||
verVelUsed = null;
|
||||
|
|
|
@ -17,6 +17,7 @@ package fr.neatmonster.nocheatplus.hooks;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -30,6 +31,9 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
|
|||
*/
|
||||
public class APIUtils {
|
||||
|
||||
/** Direct children only. */
|
||||
private static final Map<CheckType, Set<CheckType>> directChildrenMap = new HashMap<CheckType, Set<CheckType>>();
|
||||
|
||||
/** All descendants recursively. */
|
||||
private static final Map<CheckType, Set<CheckType>> descendantsMap = new HashMap<CheckType, Set<CheckType>>();
|
||||
|
||||
|
@ -41,6 +45,9 @@ public class APIUtils {
|
|||
|
||||
static {
|
||||
// Parent/children relations.
|
||||
|
||||
// Recursive first.
|
||||
// TODO: Really recursive (...). So create direct children first, then others from those.
|
||||
final Map<CheckType, Set<CheckType>> map = new HashMap<CheckType, Set<CheckType>>();
|
||||
for (final CheckType type : CheckType.values()) {
|
||||
map.put(type, new LinkedHashSet<CheckType>());
|
||||
|
@ -63,46 +70,59 @@ public class APIUtils {
|
|||
withDescendantsMap.put(parent,
|
||||
Collections.unmodifiableSet(wpSet));
|
||||
}
|
||||
|
||||
// Direct children only.
|
||||
for (final CheckType parent : map.keySet()) {
|
||||
final Set<CheckType> set = new LinkedHashSet<CheckType>(map.get(parent));
|
||||
final Iterator<CheckType> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().getParent() != parent) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
directChildrenMap.put(parent, Collections.unmodifiableSet(set));
|
||||
}
|
||||
|
||||
// needSync: Note that tests use the same definitions.
|
||||
for (final CheckType checkType : new CheckType[] { CheckType.CHAT,
|
||||
CheckType.NET }) {
|
||||
needSync.add(checkType);
|
||||
}
|
||||
boolean added = true;
|
||||
while (added) { // Just in case.
|
||||
added = false;
|
||||
for (final CheckType checkType : CheckType.values()) {
|
||||
// Fill in needSync.
|
||||
if (checkType.getParent() != null
|
||||
&& !needSync.contains(checkType)
|
||||
&& needSync.contains(checkType.getParent())) {
|
||||
needSync.add(checkType);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
needSync.addAll(getWithDescendants(checkType));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an unmodifiable collection of children for the given check type.
|
||||
* Always returns a collection, does not contain check type itself.
|
||||
* Get an unmodifiable collection of direct children for the given check
|
||||
* type. Always returns a collection, does not contain check type itself.
|
||||
*
|
||||
* @param type
|
||||
* the check type
|
||||
* @return the children
|
||||
*/
|
||||
public static final Set<CheckType> getDirectChildren(
|
||||
final CheckType type) {
|
||||
return directChildrenMap.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an unmodifiable collection of descendants for the given check type.
|
||||
* Always returns a collection, does not contain check type itself.
|
||||
*
|
||||
* @param type
|
||||
* the check type
|
||||
* @return the descendants
|
||||
*/
|
||||
public static final Set<CheckType> getDescendants(
|
||||
final CheckType type) {
|
||||
return descendantsMap.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an unmodifiable collection of the given check type with children.
|
||||
* Get an unmodifiable collection of the given check type with descendants.
|
||||
* Always returns a collection, does contain the check type itself.
|
||||
*
|
||||
* @param type
|
||||
* the check type
|
||||
* @return the children
|
||||
* @return the given check type with descendants
|
||||
*/
|
||||
public static final Set<CheckType> getWithDescendants(
|
||||
final CheckType type) {
|
||||
|
@ -144,7 +164,7 @@ public class APIUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return if the check type requires synchronization. This indicates, if a
|
||||
* Test if the check type requires synchronization. This indicates, if a
|
||||
* check can be called off primary thread at all.
|
||||
* <hr>
|
||||
* That should be CHAT and NET checks, currently.
|
||||
|
|
|
@ -48,16 +48,16 @@ public class TestCheckType {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testChildren() {
|
||||
public void testDirectChildren() {
|
||||
for (CheckType checkType : CheckType.values()) {
|
||||
// checkType is child of parent.
|
||||
if (checkType.getParent() != null) {
|
||||
if (!APIUtils.getDescendants(checkType.getParent()).contains(checkType)) {
|
||||
if (!APIUtils.getDirectChildren(checkType.getParent()).contains(checkType)) {
|
||||
fail("Expect parents children to contain self: " + checkType);
|
||||
}
|
||||
}
|
||||
// checkType is direct parent of all children.
|
||||
for (CheckType child : APIUtils.getDescendants(checkType)) {
|
||||
for (CheckType child : APIUtils.getDirectChildren(checkType)) {
|
||||
if (child.getParent() != checkType) {
|
||||
fail("Expect " + checkType + " to be direct parent of " + child + ", insteat parent is set to: " + child.getParent());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue