Update to Minecraft 1.20.5

By: md_5 <git@md-5.net>
This commit is contained in:
Bukkit/Spigot
2024-04-24 01:15:00 +10:00
parent 899f2acb84
commit f3502f6dac
54 changed files with 1814 additions and 741 deletions

View File

@@ -1,11 +1,35 @@
package org.bukkit.inventory;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public enum EquipmentSlot {
HAND,
OFF_HAND,
FEET,
LEGS,
CHEST,
HEAD
HAND(EquipmentSlotGroup.MAINHAND),
OFF_HAND(EquipmentSlotGroup.OFFHAND),
FEET(EquipmentSlotGroup.FEET),
LEGS(EquipmentSlotGroup.LEGS),
CHEST(EquipmentSlotGroup.CHEST),
HEAD(EquipmentSlotGroup.HEAD),
/**
* Only for certain entities such as horses and wolves.
*/
BODY(EquipmentSlotGroup.ARMOR);
private final EquipmentSlotGroup group;
private EquipmentSlot(/*@NotNull*/ EquipmentSlotGroup group) {
this.group = group;
}
/**
* Gets the {@link EquipmentSlotGroup} corresponding to this slot.
*
* @return corresponding {@link EquipmentSlotGroup}
*/
@NotNull
@ApiStatus.Internal
public EquipmentSlotGroup getGroup() {
return group;
}
}

View File

@@ -0,0 +1,86 @@
package org.bukkit.inventory;
import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a group of {@link EquipmentSlot}.
*/
@ApiStatus.Experimental
public final class EquipmentSlotGroup implements Predicate<EquipmentSlot> {
private static final Map<String, EquipmentSlotGroup> BY_NAME = new HashMap<>();
//
public static final EquipmentSlotGroup ANY = get("any", (test) -> true, EquipmentSlot.HAND);
public static final EquipmentSlotGroup MAINHAND = get("mainhand", EquipmentSlot.HAND);
public static final EquipmentSlotGroup OFFHAND = get("offhand", EquipmentSlot.OFF_HAND);
public static final EquipmentSlotGroup HAND = get("hand", (test) -> test == EquipmentSlot.HAND || test == EquipmentSlot.OFF_HAND, EquipmentSlot.HAND);
public static final EquipmentSlotGroup FEET = get("feet", EquipmentSlot.FEET);
public static final EquipmentSlotGroup LEGS = get("legs", EquipmentSlot.LEGS);
public static final EquipmentSlotGroup CHEST = get("chest", EquipmentSlot.CHEST);
public static final EquipmentSlotGroup HEAD = get("head", EquipmentSlot.HEAD);
public static final EquipmentSlotGroup ARMOR = get("armor", (test) -> test == EquipmentSlot.FEET || test == EquipmentSlot.LEGS || test == EquipmentSlot.CHEST || test == EquipmentSlot.HEAD, EquipmentSlot.CHEST);
//
private final String key;
private final Predicate<EquipmentSlot> predicate;
private final EquipmentSlot example;
private EquipmentSlotGroup(@NotNull String key, @NotNull Predicate<EquipmentSlot> predicate, @NotNull EquipmentSlot example) {
this.key = key;
this.predicate = predicate;
this.example = example;
BY_NAME.put(key, this);
}
@Override
public boolean test(@NotNull EquipmentSlot test) {
return this.predicate.test(test);
}
@Override
public String toString() {
return this.key;
}
/**
* Gets an {@link EquipmentSlot} which is an example of a slot in this
* group.
*
* @return an example slot
* @deprecated for internal compatibility use only
*/
@NotNull
@Deprecated
@ApiStatus.Internal
public EquipmentSlot getExample() {
return example;
}
/**
* Gets the {@link EquipmentSlotGroup} corresponding to the given string.
*
* @param name group name
* @return associated group or null
*/
@Nullable
@ApiStatus.Internal
public static EquipmentSlotGroup getByName(@NotNull String name) {
Preconditions.checkArgument(name != null, "Name cannot be null");
return BY_NAME.get(name.toLowerCase(java.util.Locale.ENGLISH));
}
private static EquipmentSlotGroup get(@NotNull String key, @NotNull EquipmentSlot slot) {
return get(key, (test) -> test == slot, slot);
}
private static EquipmentSlotGroup get(@NotNull String key, @NotNull Predicate<EquipmentSlot> predicate, @NotNull EquipmentSlot example) {
return new EquipmentSlotGroup(key, predicate, example);
}
}

View File

@@ -0,0 +1,25 @@
package org.bukkit.inventory;
/**
* A item's rarity determines the default color of its name. This enum is
* ordered from least rare to most rare.
*/
public enum ItemRarity {
/**
* White item name.
*/
COMMON,
/**
* Yellow item name.
*/
UNCOMMON,
/**
* Aqua item name.
*/
RARE,
/**
* Light purple item name.
*/
EPIC;
}

View File

@@ -1,32 +1,11 @@
package org.bukkit.inventory.meta;
import java.util.List;
import org.bukkit.DyeColor;
import org.bukkit.block.banner.Pattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface BannerMeta extends ItemMeta {
/**
* Returns the base color for this banner
*
* @return the base color
* @deprecated banner color is now stored as the data value, not meta.
*/
@Deprecated
@Nullable
DyeColor getBaseColor();
/**
* Sets the base color for this banner
*
* @param color the base color
* @deprecated banner color is now stored as the data value, not meta.
*/
@Deprecated
void setBaseColor(@Nullable DyeColor color);
/**
* Returns a list of patterns on this banner
*

View File

@@ -1,15 +1,14 @@
package org.bukkit.inventory.meta;
import java.util.List;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a book ({@link Material#WRITABLE_BOOK} or {@link
* Material#WRITTEN_BOOK}) that can have a title, an author, and pages.
* Represents a {@link Material#WRITTEN_BOOK}) that can have a title, an author,
* and pages.
*/
public interface BookMeta extends ItemMeta {
public interface BookMeta extends WritableBookMeta {
/**
* Represents the generation (or level of copying) of a written book
@@ -111,77 +110,6 @@ public interface BookMeta extends ItemMeta {
*/
void setGeneration(@Nullable Generation generation);
/**
* Checks for the existence of pages in the book.
*
* @return true if the book has pages
*/
boolean hasPages();
/**
* Gets the specified page in the book. The given page must exist.
* <p>
* Pages are 1-indexed.
*
* @param page the page number to get, in range [1, getPageCount()]
* @return the page from the book
*/
@NotNull
String getPage(int page);
/**
* Sets the specified page in the book. Pages of the book must be
* contiguous.
* <p>
* The data can be up to 1024 characters in length, additional characters
* are truncated.
* <p>
* Pages are 1-indexed.
*
* @param page the page number to set, in range [1, getPageCount()]
* @param data the data to set for that page
*/
void setPage(int page, @NotNull String data);
/**
* Gets all the pages in the book.
*
* @return list of all the pages in the book
*/
@NotNull
List<String> getPages();
/**
* Clears the existing book pages, and sets the book to use the provided
* pages. Maximum 100 pages with 1024 characters per page.
*
* @param pages A list of pages to set the book to use
*/
void setPages(@NotNull List<String> pages);
/**
* Clears the existing book pages, and sets the book to use the provided
* pages. Maximum 100 pages with 1024 characters per page.
*
* @param pages A list of strings, each being a page
*/
void setPages(@NotNull String... pages);
/**
* Adds new pages to the end of the book. Up to a maximum of 100 pages with
* 1024 characters per page.
*
* @param pages A list of strings, each being a page
*/
void addPage(@NotNull String... pages);
/**
* Gets the number of pages in the book.
*
* @return the number of pages in the book
*/
int getPageCount();
@Override
@NotNull
BookMeta clone();

View File

@@ -1,6 +1,7 @@
package org.bukkit.inventory.meta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents an item that has durability and can take damage.
@@ -28,6 +29,29 @@ public interface Damageable extends ItemMeta {
*/
void setDamage(int damage);
/**
* Checks to see if this item has a maximum amount of damage.
*
* @return true if this has maximum amount of damage
*/
boolean hasMaxDamage();
/**
* Gets the maximum amount of damage.
*
* Plugins should check {@link #hasMaxDamage()} before calling this method.
*
* @return the maximum amount of damage
*/
int getMaxDamage();
/**
* Sets the maximum amount of damage.
*
* @param maxDamage maximum amount of damage
*/
void setMaxDamage(@Nullable Integer maxDamage);
@NotNull
@Override
Damageable clone();

View File

@@ -11,6 +11,8 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemRarity;
import org.bukkit.inventory.meta.components.FoodComponent;
import org.bukkit.inventory.meta.tags.CustomItemTagContainer;
import org.bukkit.persistence.PersistentDataHolder;
import org.jetbrains.annotations.ApiStatus;
@@ -50,11 +52,47 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*/
void setDisplayName(@Nullable String name);
/**
* Checks for existence of an item name.
* <br>
* Item name differs from display name in that it is cannot be edited by an
* anvil, is not styled with italics, and does not show labels.
*
* @return true if this has an item name
*/
boolean hasItemName();
/**
* Gets the item name that is set.
* <br>
* Item name differs from display name in that it is cannot be edited by an
* anvil, is not styled with italics, and does not show labels.
* <p>
* Plugins should check that hasItemName() returns <code>true</code> before
* calling this method.
*
* @return the item name that is set
*/
@NotNull
String getItemName();
/**
* Sets the item name.
* <br>
* Item name differs from display name in that it is cannot be edited by an
* anvil, is not styled with italics, and does not show labels.
*
* @param name the name to set
*/
void setItemName(@Nullable String name);
/**
* Checks for existence of a localized name.
*
* @return true if this has a localized name
* @deprecated meta no longer exists
*/
@Deprecated(forRemoval = true)
boolean hasLocalizedName();
/**
@@ -64,15 +102,19 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* before calling this method.
*
* @return the localized name that is set
* @deprecated meta no longer exists
*/
@NotNull
@Deprecated(forRemoval = true)
String getLocalizedName();
/**
* Sets the localized name.
*
* @param name the name to set
* @deprecated meta no longer exists
*/
@Deprecated(forRemoval = true)
void setLocalizedName(@Nullable String name);
/**
@@ -231,6 +273,22 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*/
boolean hasItemFlag(@NotNull ItemFlag flag);
/**
* Gets if this item has hide_tooltip set. An item with this set will not
* show any tooltip whatsoever.
*
* @return hide_tooltip
*/
boolean isHideTooltip();
/**
* Sets if this item has hide_tooltip set. An item with this set will not
* show any tooltip whatsoever.
*
* @param hideTooltip new hide_tooltip
*/
void setHideTooltip(boolean hideTooltip);
/**
* Return if the unbreakable tag is true. An unbreakable item will not lose
* durability.
@@ -246,6 +304,120 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*/
void setUnbreakable(boolean unbreakable);
/**
* Gets if an enchantment_glint_override is set.
*
* @return if an enchantment_glint_override is set
*/
boolean hasEnchantmentGlintOverride();
/**
* Sets the enchantment_glint_override. If true, the item will glint, even
* without enchantments; if false, the item will not glint, even with
* enchantments.
*
* Plugins should check {@link #hasEnchantmentGlintOverride()} before
* calling this method.
*
* @return enchantment_glint_override
*/
@NotNull
Boolean getEnchantmentGlintOverride();
/**
* Sets the enchantment_glint_override. If true, the item will glint, even
* without enchantments; if false, the item will not glint, even with
* enchantments. If null, the override will be cleared.
*
* @param override new enchantment_glint_override
*/
void setEnchantmentGlintOverride(@Nullable Boolean override);
/**
* Checks if this item is fire_resistant. If true, it will not burn in fire
* or lava.
*
* @return fire_resistant
*/
boolean isFireResistant();
/**
* Sets if this item is fire_resistant. If true, it will not burn in fire
* or lava.
*
* @param fireResistant fire_resistant
*/
void setFireResistant(boolean fireResistant);
/**
* Gets if the max_stack_size is set.
*
* @return if a max_stack_size is set.
*/
boolean hasMaxStackSize();
/**
* Gets the max_stack_size. This is the maximum amount which an item will
* stack.
*
* @return max_stack_size
*/
int getMaxStackSize();
/**
* Sets the max_stack_size. This is the maximum amount which an item will
* stack.
*
* @param max max_stack_size, between 1 and 99 (inclusive)
*/
void setMaxStackSize(@Nullable Integer max);
/**
* Gets if the rarity is set.
*
* @return rarity
*/
boolean hasRarity();
/**
* Gets the item rarity.
*
* Plugins should check {@link #hasRarity()} before calling this method.
*
* @return rarity
*/
@NotNull
ItemRarity getRarity();
/**
* Sets the item rarity.
*
* @param rarity new rarity
*/
void setRarity(@Nullable ItemRarity rarity);
/**
* Checks if the food is set.
*
* @return if a food is set
*/
boolean hasFood();
/**
* Gets the food set on this item, or creates an empty food instance.
*
* @return food
*/
@NotNull
FoodComponent getFood();
/**
* Sets the item food.
*
* @param food new food
*/
void setFood(@Nullable FoodComponent food);
/**
* Checks for the existence of any AttributeModifiers.
*

View File

@@ -0,0 +1,37 @@
package org.bukkit.inventory.meta;
import org.jetbrains.annotations.NotNull;
/**
* Represents a map that can be scalable.
*/
public interface OminousBottleMeta extends ItemMeta {
/**
* Checks for the presence of an amplifier.
*
* @return true if a customer amplifier is applied
*/
boolean hasAmplifier();
/**
* Gets the amplifier amount for an Ominous Bottle's bad omen effect.
* <p>
* Plugins should check that hasAmplifier() returns true before calling this
* method.
*
* @return amplifier
*/
int getAmplifier();
/**
* Sets the amplifier amount for an Ominous Bottle's bad omen effect.
*
* @param amplifier between 0 and 4
*/
void setAmplifier(int amplifier);
@Override
@NotNull
OminousBottleMeta clone();
}

View File

@@ -2,7 +2,6 @@ package org.bukkit.inventory.meta;
import java.util.List;
import org.bukkit.Color;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
@@ -14,40 +13,28 @@ import org.jetbrains.annotations.Nullable;
*/
public interface PotionMeta extends ItemMeta {
/**
* Sets the underlying potion data
*
* @param data PotionData to set the base potion state to
* @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link #setBasePotionType} instead.
*/
@Deprecated
void setBasePotionData(@NotNull PotionData data);
/**
* Returns the potion data about the base potion
*
* @return a PotionData object
* @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link #getBasePotionType()} instead.
*/
@NotNull
@Deprecated
PotionData getBasePotionData();
/**
* Sets the underlying potion type
*
* @param type PotionType to set the base potion state to
*/
void setBasePotionType(@NotNull PotionType type);
void setBasePotionType(@Nullable PotionType type);
/**
* Returns the potion type about the base potion
*
* @return a PotionType object
*/
@NotNull
@Nullable
PotionType getBasePotionType();
/**
* Checks for the presence of a base potion type
*
* @return true if a base potion type is present
*/
boolean hasBasePotionType();
/**
* Checks for the presence of custom potion effects.
*

View File

@@ -0,0 +1,87 @@
package org.bukkit.inventory.meta;
import java.util.List;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
/**
* Represents a book ({@link Material#WRITABLE_BOOK} or {@link
* Material#WRITTEN_BOOK}) that can have pages.
*/
public interface WritableBookMeta extends ItemMeta {
/**
* Checks for the existence of pages in the book.
*
* @return true if the book has pages
*/
boolean hasPages();
/**
* Gets the specified page in the book. The given page must exist.
* <p>
* Pages are 1-indexed.
*
* @param page the page number to get, in range [1, getPageCount()]
* @return the page from the book
*/
@NotNull
String getPage(int page);
/**
* Sets the specified page in the book. Pages of the book must be
* contiguous.
* <p>
* The data can be up to 1024 characters in length, additional characters
* are truncated.
* <p>
* Pages are 1-indexed.
*
* @param page the page number to set, in range [1, getPageCount()]
* @param data the data to set for that page
*/
void setPage(int page, @NotNull String data);
/**
* Gets all the pages in the book.
*
* @return list of all the pages in the book
*/
@NotNull
List<String> getPages();
/**
* Clears the existing book pages, and sets the book to use the provided
* pages. Maximum 100 pages with 1024 characters per page.
*
* @param pages A list of pages to set the book to use
*/
void setPages(@NotNull List<String> pages);
/**
* Clears the existing book pages, and sets the book to use the provided
* pages. Maximum 100 pages with 1024 characters per page.
*
* @param pages A list of strings, each being a page
*/
void setPages(@NotNull String... pages);
/**
* Adds new pages to the end of the book. Up to a maximum of 100 pages with
* 1024 characters per page.
*
* @param pages A list of strings, each being a page
*/
void addPage(@NotNull String... pages);
/**
* Gets the number of pages in the book.
*
* @return the number of pages in the book
*/
int getPageCount();
@Override
@NotNull
WritableBookMeta clone();
}

View File

@@ -0,0 +1,130 @@
package org.bukkit.inventory.meta.components;
import java.util.List;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Represents a component which can turn any item into food.
*/
@ApiStatus.Experimental
public interface FoodComponent extends ConfigurationSerializable {
/**
* Gets the food restored by this item when eaten.
*
* @return nutrition value
*/
int getNutrition();
/**
* Sets the food restored by this item when eaten.
*
* @param nutrition new nutrition value, must be non-negative
*/
void setNutrition(int nutrition);
/**
* Gets the saturation restored by this item when eaten.
*
* @return saturation value
*/
float getSaturationModifier();
/**
* Sets the saturation restored by this item when eaten.
*
* @param saturationModifier new saturation value
*/
void setSaturationModifier(float saturationModifier);
/**
* Gets if this item can be eaten even when not hungry.
*
* @return true if always edible
*/
boolean canAlwaysEat();
/**
* Sets if this item can be eaten even when not hungry.
*
* @param canAlwaysEat whether always edible
*/
void setCanAlwaysEat(boolean canAlwaysEat);
/**
* Gets the time in seconds it will take for this item to be eaten.
*
* @return eat time
*/
float getEatSeconds();
/**
* Sets the time in seconds it will take for this item to be eaten.
*
* @param eatSeconds new eat time
*/
void setEatSeconds(float eatSeconds);
/**
* Gets the effects which may be applied by this item when eaten.
*
* @return food effects
*/
@NotNull
List<FoodEffect> getEffects();
/**
* Sets the effects which may be applied by this item when eaten.
*
* @param effects new effects
*/
void setEffects(@NotNull List<FoodEffect> effects);
/**
* Adds an effect which may be applied by this item when eaten.
*
* @param effect the effect
* @param probability the probability of the effect being applied
* @return the added effect
*/
@NotNull
FoodEffect addEffect(@NotNull PotionEffect effect, float probability);
/**
* An effect which may be applied by this item when eaten.
*/
public interface FoodEffect extends ConfigurationSerializable {
/**
* Gets the effect which may be applied.
*
* @return the effect
*/
@NotNull
PotionEffect getEffect();
/**
* Sets the effect which may be applied.
*
* @param effect the new effect
*/
void setEffect(@NotNull PotionEffect effect);
/**
* Gets the probability of this effect being applied.
*
* @return probability
*/
float getProbability();
/**
* Sets the probability of this effect being applied.
*
* @param probability between 0 and 1 inclusive.
*/
void setProbability(float probability);
}
}

View File

@@ -0,0 +1,5 @@
/**
* Isolated components which may form part of item meta.
*/
@org.jetbrains.annotations.ApiStatus.Experimental
package org.bukkit.inventory.meta.components;

View File

@@ -75,4 +75,12 @@ public interface TrimPattern extends Keyed, Translatable {
* {@link Material#HOST_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern HOST = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("host"));
/**
* {@link Material#FLOW_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern FLOW = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("flow"));
/**
* {@link Material#BOLT_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern BOLT = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("bolt"));
}