Code cleanup

This commit is contained in:
Auxilor 2021-06-28 20:17:01 +01:00
parent d46a15881a
commit a4741283dd
4 changed files with 14 additions and 17 deletions

View File

@ -21,7 +21,7 @@ public class EnchantmentRarity {
private static final Set<EnchantmentRarity> REGISTERED = new HashSet<>();
static {
update();
update(EcoEnchantsPlugin.getInstance());
}
/**
@ -94,8 +94,8 @@ public class EnchantmentRarity {
* Update all rarities.
*/
@ConfigUpdater
public static void update() {
RarityYml rarityYml = EcoEnchantsPlugin.getInstance().getRarityYml();
public static void update(@NotNull final EcoEnchantsPlugin plugin) {
RarityYml rarityYml = plugin.getRarityYml();
List<String> raritiesNames = rarityYml.getRarities();
raritiesNames.forEach(rarity -> {
double probability = rarityYml.getDouble("rarities." + rarity + ".table-probability");

View File

@ -25,7 +25,7 @@ public class EnchantmentTarget {
static {
REGISTERED.add(ALL);
update();
update(EcoEnchantsPlugin.getInstance());
}
/**
@ -67,11 +67,11 @@ public class EnchantmentTarget {
* Update all targets.
*/
@ConfigUpdater
public static void update() {
List<String> targetNames = EcoEnchantsPlugin.getInstance().getTargetYml().getTargets();
public static void update(@NotNull final EcoEnchantsPlugin plugin) {
List<String> targetNames = plugin.getTargetYml().getTargets();
ALL.materials.clear();
targetNames.forEach(name -> {
Set<Material> materials = EcoEnchantsPlugin.getInstance().getTargetYml().getTargetMaterials(name);
Set<Material> materials = plugin.getTargetYml().getTargetMaterials(name);
new EnchantmentTarget(name, materials).register();
});
}

View File

@ -1,11 +1,13 @@
package com.willfp.ecoenchants.enchantments.support.vanilla;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy;
import com.willfp.ecoenchants.util.ProxyUtils;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.HashMap;
@ -15,11 +17,6 @@ import java.util.stream.Collectors;
@UtilityClass
public class VanillaEnchantments {
/**
* Instance of EcoEnchants.
*/
private static final EcoEnchantsPlugin PLUGIN = EcoEnchantsPlugin.getInstance();
/**
* Vanilla Enchantment Metadata Map.
*/
@ -37,14 +34,14 @@ public class VanillaEnchantments {
/**
* Update the map.
*/
public static void update() {
public static void update(@NotNull final EcoEnchantsPlugin plugin) {
Map<Enchantment, VanillaEnchantmentMetadata> map = new HashMap<>();
List<Enchantment> enchantments = Arrays.stream(Enchantment.values())
.filter(enchantment -> enchantment.getClass().getName().contains("CraftEnchantment"))
.collect(Collectors.toList());
Map<Enchantment, Integer> maxLevels = PLUGIN.getVanillaEnchantsYml().getStrings("max-levels").stream()
Map<Enchantment, Integer> maxLevels = plugin.getVanillaEnchantsYml().getStrings("max-levels").stream()
.collect(Collectors.toMap(
s -> Enchantment.getByKey(NamespacedKey.minecraft(s.split(":")[0].toLowerCase())),
s1 -> Integer.parseInt(s1.split(":")[1])
@ -59,7 +56,7 @@ public class VanillaEnchantments {
MAP.clear();
MAP.putAll(map);
if (PLUGIN.getVanillaEnchantsYml().getBool("enabled")) {
if (plugin.getVanillaEnchantsYml().getBool("enabled")) {
ProxyUtils.getProxy(EcoCraftEnchantmentManagerProxy.class).registerNewCraftEnchantments();
}
}

View File

@ -53,8 +53,8 @@ public class WatcherTriggers extends PluginDependent implements Listener {
* Update if allowed on npc.
*/
@ConfigUpdater
public static void update() {
allowOnNPC = EcoEnchantsPlugin.getInstance().getConfig().getBoolean("allow-on-npc");
public static void update(@NotNull final EcoEnchantsPlugin plugin) {
allowOnNPC = plugin.getConfig().getBoolean("allow-on-npc");
}
/**