The Bukkit Metadata API base implementation is thread-safe.
(Checking can be turned off.)
This commit is contained in:
parent
4a7efdc3a4
commit
806e3c2ef8
|
@ -195,7 +195,7 @@ public class BlockBreakListener extends CheckListener {
|
|||
// Destroying liquid blocks.
|
||||
if (!cancelled && BlockProperties.isLiquid(block.getType())
|
||||
&& !pData.hasPermission(Permissions.BLOCKBREAK_BREAK_LIQUID, player)
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.BLOCKBREAK_BREAK, true)){
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.BLOCKBREAK_BREAK)){
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -666,7 +666,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
data.adjustWalkSpeed(player.getWalkSpeed(), tick, cc.speedGrace);
|
||||
}
|
||||
else if (cc.creativeFlyCheck
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY, true)
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY)
|
||||
&& !pData.hasPermission(Permissions.MOVING_CREATIVEFLY, player)) {
|
||||
checkCf = true;
|
||||
checkSf = false;
|
||||
|
@ -780,7 +780,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
// TODO: Redesign to set set backs later (queue + invalidate).
|
||||
boolean mightSkipNoFall = false; // If to skip nofall check (mainly on violation of other checks).
|
||||
if (newTo == null && cc.passableCheck && player.getGameMode() != BridgeMisc.GAME_MODE_SPECTATOR
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_PASSABLE, true)
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_PASSABLE)
|
||||
&& !pData.hasPermission(Permissions.MOVING_PASSABLE, player)) {
|
||||
// Passable is checked first to get the original set back locations from the other checks, if needed.
|
||||
newTo = passable.check(player, pFrom, pTo, data, cc, tick, useBlockChangeTracker);
|
||||
|
@ -867,7 +867,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
|
||||
// Morepackets.
|
||||
if (cc.morePacketsCheck && (newTo == null || data.isMorePacketsSetBackOldest())
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_MOREPACKETS, true)
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_MOREPACKETS)
|
||||
&& !pData.hasPermission(Permissions.MOVING_MOREPACKETS, player)) {
|
||||
/* (Always check morepackets, if there is a chance that setting/overriding newTo is appropriate,
|
||||
to avoid packet speeding using micro-violations.) */
|
||||
|
|
|
@ -401,7 +401,7 @@ public class NoFall extends Check {
|
|||
* @return
|
||||
*/
|
||||
public boolean isEnabled(final Player player , final MovingConfig cc, final PlayerData pData) {
|
||||
return cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL, true)
|
||||
return cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL)
|
||||
&& !pData.hasPermission(Permissions.MOVING_NOFALL, player);
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public class MovingUtil {
|
|||
return cc.survivalFlyCheck && gameMode != BridgeMisc.GAME_MODE_SPECTATOR
|
||||
&& (cc.ignoreCreative || gameMode != GameMode.CREATIVE) && !player.isFlying()
|
||||
&& (cc.ignoreAllowFlight || !player.getAllowFlight())
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY, true)
|
||||
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY)
|
||||
&& (
|
||||
!Bridge1_9.isGlidingWithElytra(player)
|
||||
|| !isGlidingWithElytraValid(player, fromLocation, data, cc)
|
||||
|
|
|
@ -19,7 +19,6 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.NPC;
|
||||
|
||||
|
@ -157,17 +156,6 @@ public class ExemptionSettings {
|
|||
this.npcMetaData = npcMetaData == null ? new MetaDataListCheck(null) : npcMetaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Top level check for exemption by meta data, including NPCs. Meta data is
|
||||
* only checked if this is the primary thread (!).
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public boolean isExemptedBySettings(final Entity entity) {
|
||||
return isExemptedBySettings(entity, Bukkit.isPrimaryThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if according to this instance of settings, the player is regarded as
|
||||
* an NPC. Meta data is only checked if this is the primary thread (!).
|
||||
|
@ -176,20 +164,14 @@ public class ExemptionSettings {
|
|||
* @param isPrimaryThread
|
||||
* @return
|
||||
*/
|
||||
public boolean isExemptedBySettings(final Entity entity, final boolean isPrimaryThread) {
|
||||
return isPrimaryThread && defaultMetaData.hasAnyMetaDataKey(entity)
|
||||
|| npcWildCardExempt && isRegardedAsNpc(entity, isPrimaryThread);
|
||||
public boolean isExemptedBySettings(final Entity entity) {
|
||||
return defaultMetaData.hasAnyMetaDataKey(entity)
|
||||
|| npcWildCardExempt && isRegardedAsNpc(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if according to this instance of settings, the player is regarded as
|
||||
* an NPC.Meta data is only checked if this is the primary thread (!).
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public boolean isRegardedAsNpc(final Entity entity) {
|
||||
return isRegardedAsNpc(entity, Bukkit.isPrimaryThread());
|
||||
@Deprecated
|
||||
public boolean isExemptedBySettings(final Entity entity, final boolean isPrimaryThread) {
|
||||
return isExemptedBySettings(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,8 +182,13 @@ public class ExemptionSettings {
|
|||
* @param isPrimaryThread
|
||||
* @return
|
||||
*/
|
||||
public boolean isRegardedAsNpc(final Entity entity) {
|
||||
return npcBukkitInterface && (entity instanceof NPC) || npcMetaData.hasAnyMetaDataKey(entity);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isRegardedAsNpc(final Entity entity, final boolean isPrimaryThread) {
|
||||
return npcBukkitInterface && (entity instanceof NPC) || isPrimaryThread && npcMetaData.hasAnyMetaDataKey(entity);
|
||||
return isRegardedAsNpc(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package fr.neatmonster.nocheatplus.hooks;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NCPAPIProvider;
|
||||
|
@ -145,19 +144,6 @@ public class NCPExemptionManager {
|
|||
return data != null && data.isExempted(checkType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for exemption, including meta data. Convenience method, testing for
|
||||
* primary thread.
|
||||
*
|
||||
* @see #isExempted(Player, CheckType, boolean)
|
||||
* @param player
|
||||
* @param checkType
|
||||
* @return
|
||||
*/
|
||||
public static final boolean isExempted(final Player player, final CheckType checkType) {
|
||||
return isExempted(player, checkType, Bukkit.isPrimaryThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player is exempted from a check right now. This also checks
|
||||
* for exemption by meta data, iff it's called from within execution of the
|
||||
|
@ -174,10 +160,15 @@ public class NCPExemptionManager {
|
|||
* meta data can't be checked!
|
||||
* @return If the player is exempted from the check right now.
|
||||
*/
|
||||
public static final boolean isExempted(final Player player, final CheckType checkType) {
|
||||
return isExempted(player.getUniqueId(), checkType)
|
||||
|| settings.isExemptedBySettings(player);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static final boolean isExempted(final Player player, final CheckType checkType,
|
||||
final boolean isPrimaryThread) {
|
||||
return isExempted(player.getUniqueId(), checkType)
|
||||
|| settings.isExemptedBySettings(player, isPrimaryThread);
|
||||
return isExempted(player, checkType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -191,7 +191,7 @@ public class CheckUtils {
|
|||
improperAPIAccess(checkType);
|
||||
}
|
||||
// Exemption check.
|
||||
if (NCPExemptionManager.isExempted(player, checkType, isPrimaryThread)) {
|
||||
if (NCPExemptionManager.isExempted(player, checkType)) {
|
||||
return true;
|
||||
}
|
||||
// Check permission policy/cache regardless of the thread context.
|
||||
|
|
Loading…
Reference in New Issue