From 676a7174faf145501c72ebb0ec7d106a06a8e563 Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Sat, 1 Aug 2020 09:20:26 +0200 Subject: [PATCH] Fixed CrossbowMeta & PotionMeta --- .../server/item/metadata/CrossbowMeta.java | 18 ++++++++ .../server/item/metadata/PotionMeta.java | 45 +++++++------------ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/minestom/server/item/metadata/CrossbowMeta.java b/src/main/java/net/minestom/server/item/metadata/CrossbowMeta.java index 0f496c68b..69843f476 100644 --- a/src/main/java/net/minestom/server/item/metadata/CrossbowMeta.java +++ b/src/main/java/net/minestom/server/item/metadata/CrossbowMeta.java @@ -82,6 +82,24 @@ public class CrossbowMeta implements ItemMeta { return projectile3; } + /** + * Get if the crossbow is currently charged + * + * @return true if the crossbow is charged, false otherwise + */ + public boolean isCharged() { + return charged; + } + + /** + * Make the bow charged or uncharged + * + * @param charged true to make the crossbow charged, false otherwise + */ + public void setCharged(boolean charged) { + this.charged = charged; + } + @Override public boolean hasNbt() { return ItemStackUtils.isVisible(projectile1); diff --git a/src/main/java/net/minestom/server/item/metadata/PotionMeta.java b/src/main/java/net/minestom/server/item/metadata/PotionMeta.java index f48a278ab..a3b23c1fd 100644 --- a/src/main/java/net/minestom/server/item/metadata/PotionMeta.java +++ b/src/main/java/net/minestom/server/item/metadata/PotionMeta.java @@ -4,71 +4,56 @@ import net.minestom.server.potion.PotionType; import net.minestom.server.registry.Registries; import org.jglrxavpok.hephaistos.nbt.NBTCompound; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - public class PotionMeta implements ItemMeta { - private Set potionTypes = new HashSet<>(); + private PotionType potionType; /** - * Get the item potion types + * Get the potion type * - * @return an unmodifiable {@link Set} containing the item potion types + * @return the potion type */ - public Set getPotionTypes() { - return Collections.unmodifiableSet(potionTypes); + public PotionType getPotionType() { + return potionType; } /** - * Add a potion type to the item + * Change the potion type * - * @param potionType the potion type to add + * @param potionType the new potion type */ - public void addPotionType(PotionType potionType) { - this.potionTypes.add(potionType); - } - - /** - * Remove a potion type to the item - * - * @param potionType the potion type to remove - */ - public void removePotionType(PotionType potionType) { - this.potionTypes.remove(potionType); + public void setPotionType(PotionType potionType) { + this.potionType = potionType; } @Override public boolean hasNbt() { - return !potionTypes.isEmpty(); + return potionType != null; } @Override public boolean isSimilar(ItemMeta itemMeta) { - return itemMeta instanceof PotionMeta && ((PotionMeta) itemMeta).potionTypes.equals(potionTypes); + return itemMeta instanceof PotionMeta && ((PotionMeta) itemMeta).potionType == potionType; } @Override public void read(NBTCompound compound) { if (compound.containsKey("Potion")) { - addPotionType(Registries.getPotionType(compound.getString("Potion"))); + this.potionType = Registries.getPotionType(compound.getString("Potion")); } } @Override public void write(NBTCompound compound) { - if (!potionTypes.isEmpty()) { - for (PotionType potionType : potionTypes) { - compound.setString("Potion", potionType.getNamespaceID()); - } + if (potionType != null) { + compound.setString("Potion", potionType.getNamespaceID()); } } @Override public ItemMeta clone() { PotionMeta potionMeta = new PotionMeta(); - potionMeta.potionTypes.addAll(potionTypes); + potionMeta.potionType = potionType; return potionMeta; }