Removed unneeded getInstance calls

This commit is contained in:
Auxilor
2021-01-18 18:28:22 +00:00
parent 15d5afd74b
commit cd33d28b32
6 changed files with 61 additions and 48 deletions

View File

@@ -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.

View File

@@ -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"));
}
}

View File

@@ -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<SortParameters> params = new HashSet<>();
if (byType) {
params.add(SortParameters.TYPE);

View File

@@ -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.
* <p>
@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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;