Add DamageType RegistryEvent (#11783)
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
package io.papermc.paper;
|
||||
|
||||
import net.kyori.adventure.util.Services;
|
||||
import org.bukkit.damage.DamageEffect;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Static bridge to the server internals.
|
||||
* <p>
|
||||
* Any and all methods in here are *not* to be called by plugin developers, may change at any time and may generally
|
||||
* cause issues when called under unexpected circumstances.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
@NullMarked
|
||||
public interface InternalAPIBridge {
|
||||
|
||||
/**
|
||||
* Yields the instance of this API bridge by lazily requesting it from the java service loader API.
|
||||
*
|
||||
* @return the instance.
|
||||
*/
|
||||
static InternalAPIBridge get() {
|
||||
class Holder {
|
||||
public static final InternalAPIBridge INSTANCE = Services.service(InternalAPIBridge.class).orElseThrow();
|
||||
}
|
||||
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a damage effect instance for the passed key.
|
||||
*
|
||||
* @param key the string key.
|
||||
* @return the damage effect.
|
||||
*/
|
||||
DamageEffect getDamageEffect(String key);
|
||||
}
|
||||
|
||||
@ -0,0 +1,120 @@
|
||||
package io.papermc.paper.registry.data;
|
||||
|
||||
import io.papermc.paper.registry.RegistryBuilder;
|
||||
import org.bukkit.damage.DamageEffect;
|
||||
import org.bukkit.damage.DamageScaling;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.damage.DeathMessageType;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
/**
|
||||
* A data-centric version-specific registry entry for the {@link DamageType} type.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
public interface DamageTypeRegistryEntry {
|
||||
|
||||
/**
|
||||
* Provides part of the death message translation key. (death.attack.<message_id>)
|
||||
* <p>
|
||||
* <strong>Note</strong> The translation key is only used if
|
||||
* {@link #deathMessageType()} is {@link DeathMessageType#DEFAULT}
|
||||
*
|
||||
* @return part of the translation key
|
||||
*/
|
||||
String messageId();
|
||||
|
||||
/**
|
||||
* Provides the amount of hunger exhaustion caused by this damage type.
|
||||
*
|
||||
* @return the exhaustion
|
||||
*/
|
||||
float exhaustion();
|
||||
|
||||
/**
|
||||
* Provides the {@link DamageScaling} for this damage type.
|
||||
*
|
||||
* @return the damage scaling
|
||||
*/
|
||||
DamageScaling damageScaling();
|
||||
|
||||
/**
|
||||
* Provides the {@link DamageEffect} for this damage type.
|
||||
*
|
||||
* @return the damage effect
|
||||
*/
|
||||
DamageEffect damageEffect();
|
||||
|
||||
/**
|
||||
* Provides the {@link DeathMessageType} for this damage type.
|
||||
*
|
||||
* @return the death message type
|
||||
*/
|
||||
DeathMessageType deathMessageType();
|
||||
|
||||
/**
|
||||
* A mutable builder for the {@link DamageTypeRegistryEntry} plugins may change in applicable registry events.
|
||||
* <p>
|
||||
* The following values are required for each builder:
|
||||
* <ul>
|
||||
* <li>{@link #messageId(String)}</li>
|
||||
* <li>{@link #exhaustion(float)}</li>
|
||||
* <li>{@link #damageScaling(DamageScaling)}</li>
|
||||
* </ul>
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
interface Builder extends DamageTypeRegistryEntry, RegistryBuilder<DamageType> {
|
||||
|
||||
/**
|
||||
* Sets part of the death message translation key.
|
||||
*
|
||||
* @return this builder instance.
|
||||
* @see DamageTypeRegistryEntry#messageId()
|
||||
* @see DamageType#getTranslationKey()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder messageId(String messageId);
|
||||
|
||||
/**
|
||||
* Sets the amount of hunger exhaustion caused by this damage type.
|
||||
*
|
||||
* @return this builder instance.
|
||||
* @see DamageTypeRegistryEntry#exhaustion()
|
||||
* @see DamageType#getExhaustion()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder exhaustion(float exhaustion);
|
||||
|
||||
/**
|
||||
* Sets the {@link DamageScaling} for this damage type.
|
||||
*
|
||||
* @return this builder instance.
|
||||
* @see DamageTypeRegistryEntry#damageScaling()
|
||||
* @see DamageType#getDamageScaling()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder damageScaling(DamageScaling scaling);
|
||||
|
||||
/**
|
||||
* Sets the {@link DamageEffect} for this damage type.
|
||||
*
|
||||
* @return this builder instance.
|
||||
* @see DamageTypeRegistryEntry#damageEffect()
|
||||
* @see DamageType#getDamageEffect()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder damageEffect(DamageEffect effect);
|
||||
|
||||
/**
|
||||
* Sets the {@link DeathMessageType} for this damage type.
|
||||
*
|
||||
* @return this builder instance.
|
||||
* @see DamageTypeRegistryEntry#deathMessageType()
|
||||
* @see DamageType#getDeathMessageType()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder deathMessageType(DeathMessageType deathMessageType);
|
||||
}
|
||||
}
|
||||
@ -2,12 +2,14 @@ package io.papermc.paper.registry.event;
|
||||
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.data.BannerPatternRegistryEntry;
|
||||
import io.papermc.paper.registry.data.DamageTypeRegistryEntry;
|
||||
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
|
||||
import io.papermc.paper.registry.data.GameEventRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@ -26,6 +28,7 @@ public final class RegistryEvents {
|
||||
public static final RegistryEventProvider<Enchantment, EnchantmentRegistryEntry.Builder> ENCHANTMENT = create(RegistryKey.ENCHANTMENT);
|
||||
public static final RegistryEventProvider<Art, PaintingVariantRegistryEntry.Builder> PAINTING_VARIANT = create(RegistryKey.PAINTING_VARIANT);
|
||||
public static final RegistryEventProvider<PatternType, BannerPatternRegistryEntry.Builder> BANNER_PATTERN = create(RegistryKey.BANNER_PATTERN);
|
||||
public static final RegistryEventProvider<DamageType, DamageTypeRegistryEntry.Builder> DAMAGE_TYPE = create(RegistryKey.DAMAGE_TYPE);
|
||||
|
||||
private RegistryEvents() {
|
||||
}
|
||||
|
||||
@ -126,10 +126,6 @@ public interface UnsafeValues {
|
||||
@Deprecated(since = "1.20.2", forRemoval = true)
|
||||
PotionType.InternalPotionData getInternalPotionData(NamespacedKey key);
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Nullable
|
||||
DamageEffect getDamageEffect(@NotNull String key);
|
||||
|
||||
/**
|
||||
* Create a new {@link DamageSource.Builder}.
|
||||
*
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package org.bukkit.damage;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.Bukkit;
|
||||
import io.papermc.paper.InternalAPIBridge;
|
||||
import org.bukkit.Sound;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -40,7 +40,7 @@ public interface DamageEffect {
|
||||
|
||||
@NotNull
|
||||
private static DamageEffect getDamageEffect(@NotNull String key) {
|
||||
return Preconditions.checkNotNull(Bukkit.getUnsafe().getDamageEffect(key), "No DamageEffect found for %s. This is a bug.", key);
|
||||
return Preconditions.checkNotNull(InternalAPIBridge.get().getDamageEffect(key), "No DamageEffect found for %s. This is a bug.", key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user