Test for NPCs with the Inventory.Open check. (+)

(+) Note: If it's fired asynchronously, meta data isn't checked, due to
that not being thread-safe. In future extra checks for (demanded to be)
thread-safe external plugin APIs can be added (reflection only).
(+) Add comments to PlayerData, concerning future treatment of name-uuid
mappings and retaining data.
This commit is contained in:
asofold 2018-01-15 12:36:56 +01:00
parent 7fdd6a586b
commit def7d61bc5
2 changed files with 23 additions and 1 deletions

View File

@ -18,9 +18,12 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.event.IHandle;
import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
import fr.neatmonster.nocheatplus.hooks.ExemptionSettings;
import fr.neatmonster.nocheatplus.utilities.InventoryUtil;
/**
@ -34,6 +37,8 @@ public class Open extends Check implements IDisableListener{
private UUID nestedPlayer = null;
private final IHandle<ExemptionSettings> exeSet = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstanceHandle(ExemptionSettings.class);
// TODO: Add specific contexts (allow different settings for fight / blockbreak etc.).
/**
@ -62,7 +67,9 @@ public class Open extends Check implements IDisableListener{
* @return If cancelling some event is opportune (open inventory and cancel flag set).
*/
public boolean check(final Player player) {
if (!isEnabled(player) || !InventoryUtil.hasInventoryOpen(player)) {
if (exeSet.getHandle().isRegardedAsNpc(player)
|| !isEnabled(player)
|| !InventoryUtil.hasInventoryOpen(player)) {
return false;
}
final InventoryConfig cc = InventoryConfig.getConfig(player);

View File

@ -126,13 +126,28 @@ public class PlayerData implements IData {
/** Not sure this is the future of extra properties. */
private Set<String> tags = null;
/*
* TODO: Consider updating the UUID for stuff like
* "exempt player/name on next login". This also implies the addition of a
* method to force-postpone data removal, as well as configuration for how
* exactly to apply/timeout, plus new syntax for 'ncp exempt' (flags/side
* conditions like +login/...).
*/
/** Unique id of the player. */
final UUID playerId;
// TODO: Names should get updated. (In which case)
/** Exact case name of the player. */
final String playerName;
/** Lower case name of the player. */
final String lcName;
/*
* TODO: Flags/counters for (async-login,) login, join, 'online', kick, quit
* + shouldBeOnline(). 'online' means that some action has been recorded.
* Same/deduce: isFake(), as opposed to ExemptionSettings.isRegardedAsNPC().
*/
private final PlayerTickListener playerTickListener;
private boolean requestUpdateInventory = false;