mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-06-26 06:14:42 +02:00
FastConsume: account for off-hand on cancel.
This commit is contained in:
parent
5a4f93c1ed
commit
241ff08d47
|
@ -13,12 +13,14 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
|||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
|
||||
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
|
||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||
import fr.neatmonster.nocheatplus.logging.StaticLog;
|
||||
import fr.neatmonster.nocheatplus.players.DataManager;
|
||||
import fr.neatmonster.nocheatplus.stats.Counters;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||
|
||||
/**
|
||||
|
@ -122,7 +124,17 @@ public class FastConsume extends Check implements Listener{
|
|||
// Reset interaction.
|
||||
if (cancel) {
|
||||
// Fake interaction to prevent violation loops with false positives.
|
||||
final ItemStack actualStack = player.getItemInHand();
|
||||
ItemStack actualStack = Bridge1_9.getItemInMainHand(player);
|
||||
if (
|
||||
Bridge1_9.hasGetItemInOffHand()
|
||||
&& (actualStack == null || !CheckUtils.isConsumable(actualStack.getType()))
|
||||
) {
|
||||
// Assume this to make sense.
|
||||
actualStack = Bridge1_9.getItemInOffHand(player);
|
||||
if (actualStack == null || !CheckUtils.isConsumable(actualStack.getType())) {
|
||||
actualStack = null;
|
||||
}
|
||||
}
|
||||
data.instantEatFood = actualStack == null ? null : actualStack.getType();
|
||||
// TODO: Allows some abuse: 1. try instantly eat (cancelled) 2. consume item directly when needed.
|
||||
} else {
|
||||
|
|
|
@ -37,6 +37,7 @@ import fr.neatmonster.nocheatplus.checks.combined.Improbable;
|
|||
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
|
||||
import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
|
||||
import fr.neatmonster.nocheatplus.stats.Counters;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
import fr.neatmonster.nocheatplus.utilities.InventoryUtil;
|
||||
|
||||
/**
|
||||
|
@ -316,7 +317,7 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
|||
// It was a bow, the player starts to pull the string, remember this time.
|
||||
data.instantBowInteract = (data.instantBowInteract > 0 && now - data.instantBowInteract < 800) ? Math.min(System.currentTimeMillis(), data.instantBowInteract) : System.currentTimeMillis();
|
||||
}
|
||||
else if (type.isEdible() || type == Material.POTION || type == Material.MILK_BUCKET) {
|
||||
else if (CheckUtils.isConsumable(type)) {
|
||||
final long now = System.currentTimeMillis();
|
||||
// It was food, the player starts to eat some food, remember this time and the type of food.
|
||||
data.instantEatFood = type;
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Random;
|
|||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -265,4 +266,14 @@ public class CheckUtils {
|
|||
return NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Random.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the item is consumable, like food, potions, milk bucket.
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static boolean isConsumable(final Material type) {
|
||||
return type.isEdible() || type == Material.POTION || type == Material.MILK_BUCKET;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user