#999: Prevent non-item cooldowns

By: Doc <nachito94@msn.com>
This commit is contained in:
CraftBukkit/Spigot 2022-01-23 11:37:48 -03:00
parent b80113b447
commit 2007d3c69f

View file

@ -473,14 +473,16 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
@Override
public boolean hasCooldown(Material material) {
Preconditions.checkArgument(material != null, "material");
Preconditions.checkArgument(material != null, "Material cannot be null");
Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material);
return getHandle().getCooldowns().isOnCooldown(CraftMagicNumbers.getItem(material));
}
@Override
public int getCooldown(Material material) {
Preconditions.checkArgument(material != null, "material");
Preconditions.checkArgument(material != null, "Material cannot be null");
Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material);
ItemCooldown.Info cooldown = getHandle().getCooldowns().cooldowns.get(CraftMagicNumbers.getItem(material));
return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime - getHandle().getCooldowns().tickCount);
@ -488,7 +490,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
@Override
public void setCooldown(Material material, int ticks) {
Preconditions.checkArgument(material != null, "material");
Preconditions.checkArgument(material != null, "Material cannot be null");
Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material);
Preconditions.checkArgument(ticks >= 0, "Cannot have negative cooldown");
getHandle().getCooldowns().addCooldown(CraftMagicNumbers.getItem(material), ticks);