Suspicious Effect Entry API

Exposes a new suspicious effect entry type that properly represents
storable effects in the context of suspicious effects as they only
define the potion effect type and duration.

This differentiates them from the existing PotionEffect API found in
bukkit and hence clarifies that storable values in the parts of the API
in which it replaces PotionEffect.

Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
This commit is contained in:
Owen1212055
2024-03-03 19:45:52 +01:00
parent 3073742fd7
commit 1725de0232
4 changed files with 151 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package io.papermc.paper.potion;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NullMarked;
/**
* Represents a {@link PotionEffectType} paired with a duration.
*/
@NullMarked
public sealed interface SuspiciousEffectEntry permits SuspiciousEffectEntryImpl {
/**
* Gets the effect type.
*
* @return effect type
*/
PotionEffectType effect();
/**
* Gets the duration for this effect instance.
*
* @return duration (in ticks) or {@link PotionEffect#INFINITE_DURATION}
*/
int duration();
/**
* Creates a new instance of SuspiciousEffectEntry.
*
* @param effectType effect type
* @param duration duration (in ticks) or {@link PotionEffect#INFINITE_DURATION}
* @return new instance of an entry
*/
@Contract(value = "_, _ -> new", pure = true)
static SuspiciousEffectEntry create(final PotionEffectType effectType, final int duration) {
return new SuspiciousEffectEntryImpl(effectType, duration);
}
}

View File

@@ -0,0 +1,10 @@
package io.papermc.paper.potion;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
@ApiStatus.Internal
@NullMarked
record SuspiciousEffectEntryImpl(PotionEffectType effect, int duration) implements SuspiciousEffectEntry {
}