From cd33d28b32cd1e2768ea4f44e96c7ca11f69fa8d Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 18 Jan 2021 18:28:22 +0000 Subject: [PATCH] Removed unneeded getInstance calls --- .../ecoenchants/display/EnchantDisplay.java | 2 +- .../display/options/DescriptionOptions.java | 25 ++++++++------ .../display/options/DisplayOptions.java | 33 +++++++++---------- .../display/options/NumbersOptions.java | 23 ++++++++----- .../display/options/ShrinkOptions.java | 25 ++++++++------ .../support/merging/anvil/AnvilMerge.java | 1 - 6 files changed, 61 insertions(+), 48 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index abaf2b96..f8c9a9c8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -56,7 +56,7 @@ public class EnchantDisplay { /** * The configurable options for displaying enchantments. */ - public static final DisplayOptions OPTIONS = new DisplayOptions(); + public static final DisplayOptions OPTIONS = new DisplayOptions(PLUGIN); /** * Update config values. diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java index 2394138f..f53b843c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java @@ -1,16 +1,12 @@ package com.willfp.ecoenchants.display.options; import com.willfp.eco.util.StringUtils; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; +import org.jetbrains.annotations.NotNull; -public class DescriptionOptions { - /** - * Instance of EcoEnchants. - */ - public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); - +public class DescriptionOptions extends PluginDependent { /** * The threshold below which to describe enchantments. */ @@ -29,12 +25,21 @@ public class DescriptionOptions { @Getter private String color; + /** + * Create new description options. + * + * @param plugin EcoEnchants. + */ + public DescriptionOptions(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + /** * Update the options. */ public void update() { - threshold = PLUGIN.getConfigYml().getInt("lore.describe.before-lines"); - enabled = PLUGIN.getConfigYml().getBool("lore.describe.enabled"); - color = StringUtils.translate(PLUGIN.getLangYml().getString("description-color")); + threshold = this.getPlugin().getConfigYml().getInt("lore.describe.before-lines"); + enabled = this.getPlugin().getConfigYml().getBool("lore.describe.enabled"); + color = StringUtils.translate(this.getPlugin().getLangYml().getString("description-color")); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java index d7ba80dd..ef4a5d20 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java @@ -1,7 +1,7 @@ package com.willfp.ecoenchants.display.options; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter; import com.willfp.ecoenchants.display.options.sorting.SortParameters; import com.willfp.ecoenchants.display.options.sorting.SorterManager; @@ -9,6 +9,7 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import lombok.Getter; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashSet; @@ -17,12 +18,7 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -public class DisplayOptions { - /** - * Instance of EcoEnchants. - */ - public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); - +public class DisplayOptions extends PluginDependent { /** * The enchantment sorter being used. */ @@ -33,19 +29,19 @@ public class DisplayOptions { * The description options being used. */ @Getter - private final DescriptionOptions descriptionOptions = new DescriptionOptions(); + private final DescriptionOptions descriptionOptions = new DescriptionOptions(this.getPlugin()); /** * The enchantment level options being used. */ @Getter - private final NumbersOptions numbersOptions = new NumbersOptions(); + private final NumbersOptions numbersOptions = new NumbersOptions(this.getPlugin()); /** * The shrink options being used. */ @Getter - private final ShrinkOptions shrinkOptions = new ShrinkOptions(); + private final ShrinkOptions shrinkOptions = new ShrinkOptions(this.getPlugin()); /** * The enchantment types, sorted according to config. @@ -67,9 +63,12 @@ public class DisplayOptions { /** * Instantiate new display options. + * + * @param plugin EcoEnchants. */ @ApiStatus.Internal - public DisplayOptions() { + public DisplayOptions(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); update(); } @@ -82,24 +81,24 @@ public class DisplayOptions { shrinkOptions.update(); sortedTypes.clear(); - sortedTypes.addAll(PLUGIN.getConfigYml().getStrings("lore.type-ordering").stream() + sortedTypes.addAll(this.getPlugin().getConfigYml().getStrings("lore.type-ordering").stream() .map(typeName -> EnchantmentType.values().stream().filter(type -> type.getName().equalsIgnoreCase(typeName)).findFirst().orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toList())); sortedTypes.addAll(EnchantmentType.values().stream().filter(enchantmentType -> !sortedTypes.contains(enchantmentType)).collect(Collectors.toList())); sortedRarities.clear(); - sortedRarities.addAll(PLUGIN.getConfigYml().getStrings("lore.rarity-ordering").stream() + sortedRarities.addAll(this.getPlugin().getConfigYml().getStrings("lore.rarity-ordering").stream() .map(rarityName -> EnchantmentRarity.values().stream().filter(rarity -> rarity.getName().equalsIgnoreCase(rarityName)).findFirst().orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toList())); sortedRarities.addAll(EnchantmentRarity.values().stream().filter(enchantmentRarity -> !sortedRarities.contains(enchantmentRarity)).collect(Collectors.toList())); - useLoreGetter = PLUGIN.getConfigYml().getBool("advanced.lore-getter"); + useLoreGetter = this.getPlugin().getConfigYml().getBool("advanced.lore-getter"); - boolean byType = PLUGIN.getConfigYml().getBool("lore.sort-by-type"); - boolean byLength = PLUGIN.getConfigYml().getBool("lore.sort-by-length"); - boolean byRarity = PLUGIN.getConfigYml().getBool("lore.sort-by-rarity"); + boolean byType = this.getPlugin().getConfigYml().getBool("lore.sort-by-type"); + boolean byLength = this.getPlugin().getConfigYml().getBool("lore.sort-by-length"); + boolean byRarity = this.getPlugin().getConfigYml().getBool("lore.sort-by-rarity"); Set params = new HashSet<>(); if (byType) { params.add(SortParameters.TYPE); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java index 24625af0..0661faf9 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java @@ -1,15 +1,11 @@ package com.willfp.ecoenchants.display.options; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; +import org.jetbrains.annotations.NotNull; -public class NumbersOptions { - /** - * Instance of EcoEnchants. - */ - public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); - +public class NumbersOptions extends PluginDependent { /** * If numerals should be used. *

@@ -24,11 +20,20 @@ public class NumbersOptions { @Getter private int threshold; + /** + * Create new numbers options. + * + * @param plugin EcoEnchants. + */ + public NumbersOptions(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + /** * Update the options. */ public void update() { - useNumerals = PLUGIN.getConfigYml().getBool("lore.use-numerals"); - threshold = PLUGIN.getConfigYml().getInt("lore.use-numbers-above-threshold"); + useNumerals = this.getPlugin().getConfigYml().getBool("lore.use-numerals"); + threshold = this.getPlugin().getConfigYml().getInt("lore.use-numbers-above-threshold"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java index b9fb6194..4611e534 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java @@ -1,15 +1,11 @@ package com.willfp.ecoenchants.display.options; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; +import org.jetbrains.annotations.NotNull; -public class ShrinkOptions { - /** - * Instance of EcoEnchants. - */ - public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); - +public class ShrinkOptions extends PluginDependent { /** * The threshold above which enchantments will be shrunk. */ @@ -28,12 +24,21 @@ public class ShrinkOptions { @Getter private int shrinkPerLine; + /** + * Create new shrink options. + * + * @param plugin EcoEnchants. + */ + public ShrinkOptions(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + /** * Update the options. */ public void update() { - threshold = PLUGIN.getConfigYml().getInt("lore.shrink.after-lines"); - enabled = PLUGIN.getConfigYml().getBool("lore.shrink.enabled"); - shrinkPerLine = PLUGIN.getConfigYml().getInt("lore.shrink.maximum-per-line"); + threshold = this.getPlugin().getConfigYml().getInt("lore.shrink.after-lines"); + enabled = this.getPlugin().getConfigYml().getBool("lore.shrink.enabled"); + shrinkPerLine = this.getPlugin().getConfigYml().getInt("lore.shrink.maximum-per-line"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java index 0fd6b51c..937dd51e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java @@ -1,6 +1,5 @@ package com.willfp.ecoenchants.enchantments.support.merging.anvil; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.tuplets.Pair; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant;