Skip to content

Commit 8e1c091

Browse files
committed
feat: enable cooldown group data keys
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
1 parent a0bfac5 commit 8e1c091

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/main/java/org/spongepowered/api/data/Keys.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import org.spongepowered.api.data.value.MapValue;
101101
import org.spongepowered.api.data.value.SetValue;
102102
import org.spongepowered.api.data.value.Value;
103+
import org.spongepowered.api.data.value.ValueContainer;
103104
import org.spongepowered.api.data.value.WeightedCollectionValue;
104105
import org.spongepowered.api.effect.VanishState;
105106
import org.spongepowered.api.effect.particle.ParticleEffect;
@@ -185,6 +186,7 @@
185186
import org.spongepowered.api.entity.living.monster.spider.Spider;
186187
import org.spongepowered.api.entity.living.monster.zombie.ZombieVillager;
187188
import org.spongepowered.api.entity.living.monster.zombie.ZombifiedPiglin;
189+
import org.spongepowered.api.entity.living.player.CooldownTracker;
188190
import org.spongepowered.api.entity.living.player.Player;
189191
import org.spongepowered.api.entity.living.player.User;
190192
import org.spongepowered.api.entity.living.player.chat.ChatVisibility;
@@ -223,6 +225,7 @@
223225
import org.spongepowered.api.item.enchantment.EnchantmentTypes;
224226
import org.spongepowered.api.item.inventory.Inventory;
225227
import org.spongepowered.api.item.inventory.ItemStack;
228+
import org.spongepowered.api.item.inventory.ItemStackLike;
226229
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
227230
import org.spongepowered.api.item.inventory.Slot;
228231
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
@@ -239,6 +242,7 @@
239242
import org.spongepowered.api.projectile.source.ProjectileSource;
240243
import org.spongepowered.api.raid.Raid;
241244
import org.spongepowered.api.raid.RaidWave;
245+
import org.spongepowered.api.registry.DefaultedRegistryType;
242246
import org.spongepowered.api.statistic.Statistic;
243247
import org.spongepowered.api.tag.Tag;
244248
import org.spongepowered.api.util.Axis;
@@ -752,9 +756,24 @@ public final class Keys {
752756
* The amount of ticks a {@link EndGateway} has to wait for the next teleportation.
753757
* or
754758
* The amount of ticks a {@link Crafter} has to wait for the next craft.
759+
* or
760+
* The amount of ticks an {@link ItemStack} has to wait before being used again, primarily in conjunction
761+
* with {@link #COOLDOWN_GROUP} in a joined {@link ValueContainer} to be offered as a custom cooldown. Using
762+
* a {@link DataManipulator#mutableOf( Iterable)} to set this value using {@link Value#mutableOf( Key, Object)}
763+
* to join together a group is ideal.
755764
*/
756765
public static final Key<Value<Ticks>> COOLDOWN = Keys.key(ResourceKey.sponge("cooldown"), Ticks.class);
757766

767+
/**
768+
* The {@link ResourceKey group} of an {@link ItemStackLike ItemStack} that would apply a
769+
* cooldown to the item when used. Note that this affects the {@link CooldownTracker} when
770+
* a {@link Player} uses the item. Can be used in tandem with the {@link #COOLDOWN} key
771+
* to apply a cooldown to said group. A group will differentiate a cooldown from the default
772+
* {@link ItemStackLike ItemStack} cooldown based on the
773+
* {@link ItemType#key(DefaultedRegistryType) ResourceKey}.
774+
*/
775+
public static final Key<Value<ResourceKey>> COOLDOWN_GROUP = Keys.key(ResourceKey.sponge("cooldown_group"), ResourceKey.class);
776+
758777
/**
759778
* The coordinate scale of a {@link WorldType} applied to the coordinates of a {@link ServerPlayer player}
760779
* when traveling in between {@link ServerWorld worlds}.

src/main/java/org/spongepowered/api/entity/living/player/CooldownTracker.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public interface CooldownTracker {
5858
*/
5959
Optional<Ticks> cooldown(ItemStack stack);
6060

61+
/**
62+
* Gets the cooldown for the specified {@link ResourceKey group} in ticks
63+
* for the player, or empty if the group is not on cooldown.
64+
*
65+
* @param group The group to get the cooldown for
66+
* @return The cooldown remaining for this group in ticks, if not on cooldown
67+
*/
6168
Optional<Ticks> cooldown(ResourceKey group);
6269

6370
/**

0 commit comments

Comments
 (0)