From df7b262d14e4d3d54e09c2050f97285f619f9b31 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 1 May 2021 00:09:38 +0200 Subject: [PATCH] Fixed #3007 --- CHANGELOG.md | 1 + .../slimefun4/api/items/ItemSetting.java | 30 ++++++++++++++- .../magical/talismans/MagicianTalisman.java | 37 +++++++++++-------- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf0c9fd3..eb17f3978 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ * Fixed #2999 * Fixed #2593 * Fixed #2937 +* Fixed #3007 ## Release Candidate 22 (18 Apr 2021) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#22 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java index b753f9c1e..417199e91 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java @@ -1,5 +1,8 @@ package io.github.thebusybiscuit.slimefun4.api.items; +import java.util.List; +import java.util.Objects; + import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; @@ -9,8 +12,6 @@ import io.github.thebusybiscuit.cscorelib2.config.Config; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import java.util.List; - /** * This class represents a Setting for a {@link SlimefunItem} that can be modified via * the {@code Items.yml} {@link Config} file. @@ -91,6 +92,16 @@ public class ItemSetting { return key; } + /** + * This returns the associated {@link SlimefunItem} for this {@link ItemSetting}. + * + * @return The associated {@link SlimefunItem} + */ + @Nonnull + protected SlimefunItem getItem() { + return item; + } + /** * This returns the current value of this {@link ItemSetting}. * @@ -188,4 +199,19 @@ public class ItemSetting { return getClass().getSimpleName() + " {" + getKey() + " = " + currentValue + " (default: " + getDefaultValue() + ")"; } + @Override + public final int hashCode() { + return Objects.hash(item, key); + } + + @Override + public final boolean equals(Object obj) { + if (obj instanceof ItemSetting) { + ItemSetting setting = (ItemSetting) obj; + return Objects.equals(getKey(), setting.getKey()) && Objects.equals(getItem(), setting.getItem()); + } else { + return false; + } + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java index ea305bf32..446cb0b8c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java @@ -1,18 +1,5 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans; -import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.settings.TalismanEnchantment; -import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import org.apache.commons.lang.Validate; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.annotation.ParametersAreNonnullByDefault; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -20,6 +7,21 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.logging.Level; import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.apache.commons.lang.Validate; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import io.github.thebusybiscuit.slimefun4.implementation.settings.TalismanEnchantment; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + /** * The {@link MagicianTalisman} is a special kind of {@link Talisman} which awards a {@link Player} * with an extra {@link Enchantment} when they enchant their {@link ItemStack}. @@ -48,8 +50,13 @@ public class MagicianTalisman extends Talisman { } } - if (!enchantments.isEmpty()) { - addItemSetting(enchantments.toArray(new ItemSetting[0])); + try { + if (!enchantments.isEmpty()) { + // Fixes #3007 - This is a Set, so every Enchantment should only be contained in here once. + addItemSetting(enchantments.toArray(new ItemSetting[0])); + } + } catch (Exception x) { + SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "The following Exception was thrown when initializing the settings for " + toString()); } }