BROWN_EGG = getItemType("brown_egg");
/**
* ItemMeta: {@link CompassMeta}
*/
diff --git a/src/main/java/org/bukkit/inventory/SmithingTrimRecipe.java b/src/main/java/org/bukkit/inventory/SmithingTrimRecipe.java
index 4271c54c..740a0c01 100644
--- a/src/main/java/org/bukkit/inventory/SmithingTrimRecipe.java
+++ b/src/main/java/org/bukkit/inventory/SmithingTrimRecipe.java
@@ -2,6 +2,7 @@ package org.bukkit.inventory;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
+import org.bukkit.inventory.meta.trim.TrimPattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -11,6 +12,56 @@ import org.jetbrains.annotations.Nullable;
public class SmithingTrimRecipe extends SmithingRecipe implements ComplexRecipe {
private final RecipeChoice template;
+ private final TrimPattern trimPattern;
+
+ @NotNull
+ @Deprecated(since = "1.21.5")
+ private static TrimPattern getTrimPattern(@Nullable RecipeChoice template) {
+ if (template == null) {
+ return TrimPattern.SENTRY;
+ }
+
+ return switch (template.getItemStack().getType()) {
+ case SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.SENTRY;
+ case DUNE_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.DUNE;
+ case COAST_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.COAST;
+ case WILD_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.WILD;
+ case WARD_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.WARD;
+ case EYE_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.EYE;
+ case VEX_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.VEX;
+ case TIDE_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.TIDE;
+ case SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.SNOUT;
+ case RIB_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.RIB;
+ case SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.SPIRE;
+ case WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.WAYFINDER;
+ case SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.SHAPER;
+ case SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.SILENCE;
+ case RAISER_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.RAISER;
+ case HOST_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.HOST;
+ case FLOW_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.FLOW;
+ case BOLT_ARMOR_TRIM_SMITHING_TEMPLATE ->
+ TrimPattern.BOLT;
+ default ->
+ TrimPattern.SENTRY;
+ };
+ }
/**
* Create a smithing recipe to produce the specified result ItemStack.
@@ -19,10 +70,18 @@ public class SmithingTrimRecipe extends SmithingRecipe implements ComplexRecipe
* @param template The template item.
* @param base The base ingredient
* @param addition The addition ingredient
+ * @see #SmithingTrimRecipe(org.bukkit.NamespacedKey, org.bukkit.inventory.RecipeChoice, org.bukkit.inventory.RecipeChoice, org.bukkit.inventory.RecipeChoice, org.bukkit.inventory.meta.trim.TrimPattern)
+ * @deprecated trimPattern must be specified
*/
+ @Deprecated(since = "1.21.5")
public SmithingTrimRecipe(@NotNull NamespacedKey key, @Nullable RecipeChoice template, @Nullable RecipeChoice base, @Nullable RecipeChoice addition) {
+ this(key, template, base, addition, getTrimPattern(template));
+ }
+
+ public SmithingTrimRecipe(@NotNull NamespacedKey key, @Nullable RecipeChoice template, @Nullable RecipeChoice base, @Nullable RecipeChoice addition, @NotNull TrimPattern trimPattern) {
super(key, new ItemStack(Material.AIR), base, addition);
this.template = template;
+ this.trimPattern = trimPattern;
}
/**
@@ -34,4 +93,9 @@ public class SmithingTrimRecipe extends SmithingRecipe implements ComplexRecipe
public RecipeChoice getTemplate() {
return (template != null) ? template.clone() : null;
}
+
+ @NotNull
+ public TrimPattern getTrimPattern() {
+ return trimPattern;
+ }
}
diff --git a/src/main/java/org/bukkit/inventory/TransmuteRecipe.java b/src/main/java/org/bukkit/inventory/TransmuteRecipe.java
index 5a861679..aab360be 100644
--- a/src/main/java/org/bukkit/inventory/TransmuteRecipe.java
+++ b/src/main/java/org/bukkit/inventory/TransmuteRecipe.java
@@ -16,6 +16,20 @@ public class TransmuteRecipe extends CraftingRecipe implements ComplexRecipe {
private final RecipeChoice input;
private final RecipeChoice material;
+ /**
+ * Create a transmute recipe to produce a result of the specified type.
+ *
+ * @param key the unique recipe key
+ * @param result the transmuted result item
+ * @param input the input ingredient
+ * @param material the additional ingredient
+ */
+ public TransmuteRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result, @NotNull RecipeChoice input, @NotNull RecipeChoice material) {
+ super(key, checkResult(result));
+ this.input = input;
+ this.material = material;
+ }
+
/**
* Create a transmute recipe to produce a result of the specified type.
*
@@ -25,9 +39,7 @@ public class TransmuteRecipe extends CraftingRecipe implements ComplexRecipe {
* @param material the additional ingredient
*/
public TransmuteRecipe(@NotNull NamespacedKey key, @NotNull Material result, @NotNull RecipeChoice input, @NotNull RecipeChoice material) {
- super(key, checkResult(new ItemStack(result)));
- this.input = input;
- this.material = material;
+ this(key, new ItemStack(result), input, material);
}
/**
diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
index 9dc6690a..a16f481d 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.NamespacedKey;
+import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
@@ -17,12 +18,14 @@ import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemRarity;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.components.BlocksAttacksComponent;
import org.bukkit.inventory.meta.components.CustomModelDataComponent;
import org.bukkit.inventory.meta.components.EquippableComponent;
import org.bukkit.inventory.meta.components.FoodComponent;
import org.bukkit.inventory.meta.components.JukeboxPlayableComponent;
import org.bukkit.inventory.meta.components.ToolComponent;
import org.bukkit.inventory.meta.components.UseCooldownComponent;
+import org.bukkit.inventory.meta.components.WeaponComponent;
import org.bukkit.inventory.meta.components.consumable.ConsumableComponent;
import org.bukkit.inventory.meta.tags.CustomItemTagContainer;
import org.bukkit.persistence.PersistentDataHolder;
@@ -680,6 +683,61 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*/
void setTool(@Nullable ToolComponent tool);
+ /**
+ * Checks if the weapon is set.
+ *
+ * @return if a weapon is set
+ */
+ boolean hasWeapon();
+
+ /**
+ * Gets the weapon set on this item, or creates an empty weapon instance.
+ *
+ * The returned component is a snapshot of its current state and does not
+ * reflect a live view of what is on an item. After changing any value on
+ * this component, it must be set with {@link #setWeapon(WeaponComponent)} to
+ * apply the changes.
+ *
+ * @return weapon
+ */
+ @NotNull
+ WeaponComponent getWeapon();
+
+ /**
+ * Sets the item weapon.
+ *
+ * @param weapon new weapon
+ */
+ void setWeapon(@Nullable WeaponComponent weapon);
+
+ /**
+ * Checks if the {@link BlocksAttacksComponent} is set.
+ *
+ * @return if a {@link BlocksAttacksComponent} is set
+ */
+ boolean hasBlocksAttacks();
+
+ /**
+ * Gets the {@link BlocksAttacksComponent} set on this item, or creates an
+ * empty {@link BlocksAttacksComponent} instance.
+ *
+ * The returned component is a snapshot of its current state and does not
+ * reflect a live view of what is on an item. After changing any value on
+ * this component, it must be set with
+ * {@link #setBlocksAttacks(BlocksAttacksComponent)} to apply the changes.
+ *
+ * @return component
+ */
+ @NotNull
+ BlocksAttacksComponent getBlocksAttacks();
+
+ /**
+ * Sets the item {@link BlocksAttacksComponent}.
+ *
+ * @param blocksAttacks new component
+ */
+ void setBlocksAttacks(@Nullable BlocksAttacksComponent blocksAttacks);
+
/**
* Checks if the equippable is set.
*
@@ -736,6 +794,30 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*/
void setJukeboxPlayable(@Nullable JukeboxPlayableComponent jukeboxPlayable);
+ /**
+ * Gets if the break sound is set.
+ *
+ * @return if break sound is set
+ */
+ boolean hasBreakSound();
+
+ /**
+ * Gets the sound to play when the item is broken.
+ *
+ * Plugins should check {@link #hasBreakSound()} before calling this method.
+ *
+ * @return the sound
+ */
+ @Nullable
+ Sound getBreakSound();
+
+ /**
+ * Sets the sound to play when the item is broken.
+ *
+ * @param sound sound
+ */
+ void setBreakSound(@Nullable Sound sound);
+
/**
* Checks for the existence of any AttributeModifiers.
*
diff --git a/src/main/java/org/bukkit/inventory/meta/PotionMeta.java b/src/main/java/org/bukkit/inventory/meta/PotionMeta.java
index b61d2e32..45bfb0a2 100644
--- a/src/main/java/org/bukkit/inventory/meta/PotionMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/PotionMeta.java
@@ -171,6 +171,31 @@ public interface PotionMeta extends ItemMeta {
*/
void setCustomName(@Nullable String name);
+ /**
+ * Checks for existence of a potion duration scale.
+ *
+ * @return true if this has a potion duration scale.
+ */
+ boolean hasDurationScale();
+
+ /**
+ * Gets the potion duration scale that is set.
+ *
+ * Plugins should check that hasDurationScale() returns true
+ * before calling this method.
+ *
+ * @return the scale factor applied to all potion effect durations
+ */
+ @Nullable
+ float getDurationScale();
+
+ /**
+ * Gets the potion duration scale.
+ *
+ * @param scale the scale factor applied to all potion effect durations
+ */
+ void setDurationScale(@Nullable Float scale);
+
@Override
PotionMeta clone();
}
diff --git a/src/main/java/org/bukkit/inventory/meta/components/BlocksAttacksComponent.java b/src/main/java/org/bukkit/inventory/meta/components/BlocksAttacksComponent.java
new file mode 100644
index 00000000..2c7c12d7
--- /dev/null
+++ b/src/main/java/org/bukkit/inventory/meta/components/BlocksAttacksComponent.java
@@ -0,0 +1,291 @@
+package org.bukkit.inventory.meta.components;
+
+import java.util.Collection;
+import java.util.List;
+import org.bukkit.Sound;
+import org.bukkit.Tag;
+import org.bukkit.configuration.serialization.ConfigurationSerializable;
+import org.bukkit.damage.DamageType;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents a component which can turn any item into a shield-like item which
+ * blocks attack damage.
+ */
+@ApiStatus.Experimental
+public interface BlocksAttacksComponent extends ConfigurationSerializable {
+
+ /**
+ * Gets the delay on equip before this item will block attacks.
+ *
+ * @return the delay in seconds
+ */
+ float getBlockDelaySeconds();
+
+ /**
+ * Sets the delay on equip before this item will block attacks.
+ *
+ * @param seconds the delay in seconds to set
+ */
+ void setBlockDelaySeconds(float seconds);
+
+ /**
+ * Gets the multiplier applied to the item cooldown when attacked by a
+ * disabling attack.
+ *
+ * @return the scale
+ */
+ float getDisableCooldownScale();
+
+ /**
+ * Sets the multiplier applied to the item cooldown when attacked by a
+ * disabling attack.
+ *
+ * @param scale the scale to set. Must be 0 or a positive integer
+ */
+ void setDisableCooldownScale(float scale);
+
+ /**
+ * Get the list of {@link DamageReduction DamageReductions} that apply to
+ * this item.
+ *
+ * @return all damage reductions. The mutability of the returned list cannot
+ * be guaranteed, but its contents are mutable and can have their values
+ * changed
+ */
+ @NotNull
+ List getDamageReductions();
+
+ /**
+ * Set the list of {@link DamageReduction DamageReductions} to apply to this
+ * item. This will remove any existing damage reductions.
+ *
+ * @param reductions the reductions to set
+ */
+ void setDamageReductions(@NotNull List reductions);
+
+ /**
+ * Add a new damage reduction to this component, which blocks specific types
+ * of attacks.
+ *
+ * @param type the type of attack
+ * @param base the constant amount of damage to be blocked
+ * @param factor the proportion of damage to be blocked
+ * @param horizontalBlockingAngle the maximum angle at which attacks will be
+ * blocked
+ * @return the {@link DamageReduction} instance that was added to this item
+ */
+ @NotNull
+ DamageReduction addDamageReduction(@NotNull DamageType type, float base, float factor, float horizontalBlockingAngle);
+
+ /**
+ * Add a new damage reduction to this component, which blocks specific types
+ * of attacks.
+ *
+ * @param types the types of attack
+ * @param base the constant amount of damage to be blocked
+ * @param factor the proportion of damage to be blocked
+ * @param horizontalBlockingAngle the maximum angle at which attacks will be
+ * blocked
+ * @return the {@link DamageReduction} instance that was added to this item
+ */
+ @NotNull
+ DamageReduction addDamageReduction(@NotNull Collection types, float base, float factor, float horizontalBlockingAngle);
+
+ /**
+ * Add a new damage reduction to this component, which blocks specific types
+ * of attacks.
+ *
+ * @param tag the type of attacks
+ * @param base the constant amount of damage to be blocked
+ * @param factor the proportion of damage to be blocked
+ * @param horizontalBlockingAngle the maximum angle at which attacks will be
+ * blocked
+ * @return the {@link DamageReduction} instance that was added to this item
+ */
+ @NotNull
+ DamageReduction addDamageReduction(@NotNull Tag tag, float base, float factor, float horizontalBlockingAngle);
+
+ /**
+ * Remove the given {@link DamageReduction} from this item.
+ *
+ * @param reduction the reduction to remove
+ * @return true if the reduction was removed, false if this component did
+ * not contain a matching reduction
+ */
+ boolean removeDamageReduction(@NotNull DamageReduction reduction);
+
+ /**
+ * Gets the amount of damage required to be dealt before damage is also
+ * applied to the item.
+ *
+ * @return threshold damage amount
+ */
+ float getItemDamageThreshold();
+
+ /**
+ * Sets the amount of damage required to be dealt before damage is also
+ * applied to the item.
+ *
+ * @param threshold new threshold damage amount
+ */
+ void setItemDamageThreshold(float threshold);
+
+ /**
+ * Gets the constant amount of damage applied to the item if the threshold
+ * is reached.
+ *
+ * @return base item damage
+ */
+ float getItemDamageBase();
+
+ /**
+ * Sets the constant amount of damage applied to the item if the threshold
+ * is reached.
+ *
+ * @param base new base item damage
+ */
+ void setItemDamageBase(float base);
+
+ /**
+ * Gets the proportion of damage applied to the item if the threshold is
+ * reached.
+ *
+ * @return item damage factor
+ */
+ float getItemDamageFactor();
+
+ /**
+ * Sets the proportion of damage applied to the item if the threshold is
+ * reached.
+ *
+ * @param factor new item damage factor
+ */
+ void setItemDamageFactor(float factor);
+
+ /**
+ * Gets the sound to play when the item blocks an attack.
+ *
+ * @return the sound
+ */
+ @Nullable
+ Sound getBlockSound();
+
+ /**
+ * Sets the sound to play when the item blocks an attack.
+ *
+ * @param sound sound or null for current default
+ */
+ void setBlockSound(@Nullable Sound sound);
+
+ /**
+ * Gets the sound to play when the item is disabled.
+ *
+ * @return the sound
+ */
+ @Nullable
+ Sound getDisableSound();
+
+ /**
+ * Sets the sound to play when the item is disabled.
+ *
+ * @param sound sound or null for current default
+ */
+ void setDisableSound(@Nullable Sound sound);
+
+ /**
+ * Gets the type of damage that will bypass blocking by this item.
+ *
+ * @return damage type
+ */
+ @Nullable
+ Tag getBypassedBy();
+
+ /**
+ * Sets the type of damage that will bypass blocking by this item.
+ *
+ * @param tag the tag, or null to clear
+ */
+ void setBypassedBy(@Nullable Tag tag);
+
+ /**
+ * A damage reduction for a specific set of damage types.
+ */
+ public interface DamageReduction extends ConfigurationSerializable {
+
+ /**
+ * Gets the types to which this reduction applies.
+ *
+ * @return the damage types
+ */
+ @Nullable
+ Collection getTypes();
+
+ /**
+ * Sets the types to which this reduction applies.
+ *
+ * @param type the damage types
+ */
+ void setTypes(@Nullable DamageType type);
+
+ /**
+ * Sets the types to which this reduction applies.
+ *
+ * @param types the damage types
+ */
+ void setTypes(@Nullable Collection types);
+
+ /**
+ * Sets the types to which this reduction applies.
+ *
+ * @param tag the damage tag
+ */
+ void setTypes(@Nullable Tag tag);
+
+ /**
+ * Gets the constant amount of damage to be blocked.
+ *
+ * @return base block amount
+ */
+ float getBase();
+
+ /**
+ * Sets the constant amount of damage to be blocked.
+ *
+ * @param base new base amount
+ */
+ void setBase(float base);
+
+ /**
+ * Gets the proportion of damage to be blocked.
+ *
+ * @return base blocking factor
+ */
+ float getFactor();
+
+ /**
+ * Sets the proportion of damage to be blocked.
+ *
+ * @param factor new blocking factor
+ */
+ void setFactor(float factor);
+
+ /**
+ * Gets the maximum angle at which attacks will be blocked (defaults to
+ * 90).
+ *
+ * @return maximum blocking angle
+ */
+ float getHorizontalBlockingAngle();
+
+ /**
+ * Sets the maximum angle at which attacks will be blocked (defaults to
+ * 90).
+ *
+ * @param horizontalBlockingAngle new blocking angle
+ */
+ void setHorizontalBlockingAngle(float horizontalBlockingAngle);
+ }
+}
diff --git a/src/main/java/org/bukkit/inventory/meta/components/EquippableComponent.java b/src/main/java/org/bukkit/inventory/meta/components/EquippableComponent.java
index c56e81eb..60eefa4b 100644
--- a/src/main/java/org/bukkit/inventory/meta/components/EquippableComponent.java
+++ b/src/main/java/org/bukkit/inventory/meta/components/EquippableComponent.java
@@ -150,4 +150,18 @@ public interface EquippableComponent extends ConfigurationSerializable {
* @param damage whether the item will be damaged
*/
void setDamageOnHurt(boolean damage);
+
+ /**
+ * Gets if the item will be equipped on interact.
+ *
+ * @return whether the item will be equipped
+ */
+ boolean isEquipOnInteract();
+
+ /**
+ * Sets if the item will be equipped on interact.
+ *
+ * @param equip whether the item will be equipped
+ */
+ void setEquipOnInteract(boolean equip);
}
diff --git a/src/main/java/org/bukkit/inventory/meta/components/JukeboxPlayableComponent.java b/src/main/java/org/bukkit/inventory/meta/components/JukeboxPlayableComponent.java
index 785c6b27..9f61aa8e 100644
--- a/src/main/java/org/bukkit/inventory/meta/components/JukeboxPlayableComponent.java
+++ b/src/main/java/org/bukkit/inventory/meta/components/JukeboxPlayableComponent.java
@@ -26,7 +26,7 @@ public interface JukeboxPlayableComponent extends ConfigurationSerializable {
*
* @return the song key
*/
- @NotNull
+ @Nullable
NamespacedKey getSongKey();
/**
@@ -42,18 +42,4 @@ public interface JukeboxPlayableComponent extends ConfigurationSerializable {
* @param song the song key
*/
void setSongKey(@NotNull NamespacedKey song);
-
- /**
- * Gets if the song will show in the item tooltip.
- *
- * @return if the song will show in the tooltip
- */
- boolean isShowInTooltip();
-
- /**
- * Sets if the song will show in the item tooltip.
- *
- * @param show true if the song will show in the tooltip
- */
- void setShowInTooltip(boolean show);
}
diff --git a/src/main/java/org/bukkit/inventory/meta/components/ToolComponent.java b/src/main/java/org/bukkit/inventory/meta/components/ToolComponent.java
index 83de6c9d..edc35288 100644
--- a/src/main/java/org/bukkit/inventory/meta/components/ToolComponent.java
+++ b/src/main/java/org/bukkit/inventory/meta/components/ToolComponent.java
@@ -48,6 +48,20 @@ public interface ToolComponent extends ConfigurationSerializable {
*/
void setDamagePerBlock(int damage);
+ /**
+ * Get whether this tool can destroy blocks in creative.
+ *
+ * @return whether can destroy
+ */
+ boolean canDestroyBlocksInCreative();
+
+ /**
+ * Set whether this tool can destroy blocks in creative.
+ *
+ * @param destroy whether can destroy
+ */
+ void setCanDestroyBlocksInCreative(boolean destroy);
+
/**
* Get the list of {@link ToolRule ToolRules} that apply to this tool.
*
diff --git a/src/main/java/org/bukkit/inventory/meta/components/WeaponComponent.java b/src/main/java/org/bukkit/inventory/meta/components/WeaponComponent.java
new file mode 100644
index 00000000..239c3d68
--- /dev/null
+++ b/src/main/java/org/bukkit/inventory/meta/components/WeaponComponent.java
@@ -0,0 +1,39 @@
+package org.bukkit.inventory.meta.components;
+
+import org.bukkit.configuration.serialization.ConfigurationSerializable;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * Represents a component which can turn any item into a weapon.
+ */
+@ApiStatus.Experimental
+public interface WeaponComponent extends ConfigurationSerializable {
+
+ /**
+ * Get the weapon damage per attack.
+ *
+ * @return the damage per attack
+ */
+ int getItemDamagePerAttack();
+
+ /**
+ * Set the weapon damage per attack.
+ *
+ * @param damage the damage to set. Must be 0 or a positive integer
+ */
+ void setItemDamagePerAttack(int damage);
+
+ /**
+ * Get the time in seconds which this weapon disabled blocking for.
+ *
+ * @return the blocking disable time in seconds
+ */
+ float getDisableBlockingForSeconds();
+
+ /**
+ * Set the time in seconds which this weapon disabled blocking for.
+ *
+ * @param time the blocking disable time in seconds
+ */
+ void setDisableBlockingForSeconds(float time);
+}