Expand cooldown API (#12435)

This commit is contained in:
Jakub Zacek
2025-04-22 11:30:00 +02:00
committed by GitHub
parent def0532ffc
commit d22644aada
2 changed files with 50 additions and 5 deletions

View File

@@ -8,6 +8,8 @@ import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import io.papermc.paper.adventure.PaperAdventure;
import net.kyori.adventure.key.Key;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
@@ -651,14 +653,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
@Override
public boolean hasCooldown(ItemStack item) {
Preconditions.checkArgument(item != null, "Material cannot be null");
Preconditions.checkArgument(item != null, "Item cannot be null");
return this.getHandle().getCooldowns().isOnCooldown(CraftItemStack.asNMSCopy(item));
}
@Override
public int getCooldown(ItemStack item) {
Preconditions.checkArgument(item != null, "Material cannot be null");
Preconditions.checkArgument(item != null, "Item cannot be null");
ResourceLocation group = this.getHandle().getCooldowns().getCooldownGroup(CraftItemStack.asNMSCopy(item));
if (group == null) {
@@ -671,12 +673,28 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
@Override
public void setCooldown(ItemStack item, int ticks) {
Preconditions.checkArgument(item != null, "Material cannot be null");
Preconditions.checkArgument(item != null, "Item cannot be null");
Preconditions.checkArgument(ticks >= 0, "Cannot have negative cooldown");
this.getHandle().getCooldowns().addCooldown(CraftItemStack.asNMSCopy(item), ticks);
}
@Override
public int getCooldown(Key key) {
Preconditions.checkArgument(key != null, "Key cannot be null");
ItemCooldowns.CooldownInstance cooldown = this.getHandle().getCooldowns().cooldowns.get(PaperAdventure.asVanilla(key));
return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime() - this.getHandle().getCooldowns().tickCount);
}
@Override
public void setCooldown(Key key, int ticks) {
Preconditions.checkArgument(key != null, "Key cannot be null");
Preconditions.checkArgument(ticks >= 0, "Cannot have negative cooldown");
this.getHandle().getCooldowns().addCooldown(PaperAdventure.asVanilla(key), ticks);
}
@Override
public org.bukkit.entity.Entity releaseLeftShoulderEntity() {
if (!getHandle().getShoulderEntityLeft().isEmpty()) {