From 0312915d336470bf7389b10d2d41b86c211b2edf Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 17 Sep 2021 19:58:52 +0100 Subject: [PATCH] Updated to eco 6.8.0 --- build.gradle | 2 +- config/checkstyle/suppression.xml | 1 - .../ecoenchants/enchantments/EcoEnchant.java | 14 ++-- .../requirements/EnchantmentRequirement.java | 31 --------- .../requirements/EnchantmentRequirements.java | 68 ------------------- .../RequirementHasPermission.java | 23 ------- .../RequirementPlaceholderEquals.java | 26 ------- .../RequirementPlaceholderGreaterThan.java | 30 -------- .../RequirementPlaceholderLessThan.java | 30 -------- 9 files changed, 6 insertions(+), 219 deletions(-) delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/EnchantmentRequirement.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/EnchantmentRequirements.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementHasPermission.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderEquals.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderGreaterThan.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderLessThan.java diff --git a/build.gradle b/build.gradle index 3e85c1d3..bc0e0a3a 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:6.7.5' + compileOnly 'com.willfp:eco:6.8.0' compileOnly 'org.jetbrains:annotations:19.0.0' diff --git a/config/checkstyle/suppression.xml b/config/checkstyle/suppression.xml index 86f19c96..4821bb6e 100644 --- a/config/checkstyle/suppression.xml +++ b/config/checkstyle/suppression.xml @@ -19,7 +19,6 @@ - diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index e1cefe52..e74d4c8a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -1,13 +1,13 @@ package com.willfp.ecoenchants.enchantments; import com.willfp.eco.core.Prerequisite; +import com.willfp.eco.core.requirement.Requirement; +import com.willfp.eco.core.requirement.Requirements; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.config.configs.EnchantmentConfig; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; -import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement; -import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirements; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.enchantments.util.Watcher; import lombok.AccessLevel; @@ -156,7 +156,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche /** * All the requirements needed in order to use the enchantment. */ - private final Map> requirements = new HashMap<>(); + private final Map> requirements = new HashMap<>(); /** * Cached players to see if they meet requirements. @@ -250,11 +250,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche continue; } - EnchantmentRequirement requirement = EnchantmentRequirements.getByID(split.get(0).toLowerCase()); - - if (requirement == null) { - continue; - } + Requirement requirement = Requirements.getByID(split.get(0).toLowerCase()); this.requirements.put(requirement, split.subList(1, split.size())); } @@ -310,7 +306,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche return cachedRequirements.get(player.getUniqueId()); } - for (Map.Entry> entry : requirements.entrySet()) { + for (Map.Entry> entry : requirements.entrySet()) { if (!entry.getKey().doesPlayerMeet(player, entry.getValue())) { cachedRequirements.put(player.getUniqueId(), false); return false; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/EnchantmentRequirement.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/EnchantmentRequirement.java deleted file mode 100644 index 3eef6341..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/EnchantmentRequirement.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.willfp.ecoenchants.enchantments.meta.requirements; - -import lombok.Getter; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public abstract class EnchantmentRequirement { - /** - * The ID of the requirement. - */ - @Getter - private final String id; - - protected EnchantmentRequirement(@NotNull final String id) { - this.id = id; - - EnchantmentRequirements.addNewRequirement(this); - } - - /** - * Test if the player meets the requirement. - * - * @param player The player. - * @param args The arguments. - * @return The requirement. - */ - public abstract boolean doesPlayerMeet(@NotNull Player player, - @NotNull List args); -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/EnchantmentRequirements.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/EnchantmentRequirements.java deleted file mode 100644 index e7907519..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/EnchantmentRequirements.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.willfp.ecoenchants.enchantments.meta.requirements; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.ImmutableList; -import com.willfp.ecoenchants.enchantments.EcoEnchant; -import com.willfp.ecoenchants.enchantments.meta.requirements.requirements.RequirementHasPermission; -import com.willfp.ecoenchants.enchantments.meta.requirements.requirements.RequirementPlaceholderEquals; -import com.willfp.ecoenchants.enchantments.meta.requirements.requirements.RequirementPlaceholderGreaterThan; -import com.willfp.ecoenchants.enchantments.meta.requirements.requirements.RequirementPlaceholderLessThan; -import lombok.experimental.UtilityClass; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -@UtilityClass -@SuppressWarnings({"unused", "checkstyle:JavadocVariable"}) -public class EnchantmentRequirements { - /** - * All registered requirements. - */ - private static final BiMap BY_ID = HashBiMap.create(); - - public static final EnchantmentRequirement HAS_PERMISSION = new RequirementHasPermission(); - public static final EnchantmentRequirement PLACEHOLDER_EQUALS = new RequirementPlaceholderEquals(); - public static final EnchantmentRequirement PLACEHOLDER_GREATER_THAN = new RequirementPlaceholderGreaterThan(); - public static final EnchantmentRequirement PLACEHOLDER_LESS_THAN = new RequirementPlaceholderLessThan(); - - /** - * Get all registered {@link EcoEnchant}s. - * - * @return A list of all {@link EcoEnchant}s. - */ - public static List values() { - return ImmutableList.copyOf(BY_ID.values()); - } - - /** - * Get {@link EnchantmentRequirement} matching ID. - * - * @param name The ID to search for. - * @return The matching {@link EnchantmentRequirement}, or null if not found. - */ - public static EnchantmentRequirement getByID(@NotNull final String name) { - return BY_ID.get(name); - } - - /** - * Add new {@link EnchantmentRequirement} to EcoEnchants. - *

- * Only for internal use, requirements are automatically added in the constructor. - * - * @param req The {@link EnchantmentRequirement} to add. - */ - public static void addNewRequirement(@NotNull final EnchantmentRequirement req) { - BY_ID.inverse().remove(req); - BY_ID.put(req.getId(), req); - } - - /** - * Remove {@link EnchantmentRequirement} from EcoEnchants. - * - * @param req The {@link EnchantmentRequirement} to remove. - */ - public static void removeRequirement(@NotNull final EnchantmentRequirement req) { - BY_ID.inverse().remove(req); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementHasPermission.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementHasPermission.java deleted file mode 100644 index 671833d0..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementHasPermission.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.willfp.ecoenchants.enchantments.meta.requirements.requirements; - -import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class RequirementHasPermission extends EnchantmentRequirement { - /** - * Create new requirement. - */ - public RequirementHasPermission() { - super("has-permission"); - } - - @Override - public boolean doesPlayerMeet(@NotNull final Player player, - @NotNull final List args) { - String permission = args.get(0); - return player.hasPermission(permission); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderEquals.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderEquals.java deleted file mode 100644 index cd76e1be..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderEquals.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.willfp.ecoenchants.enchantments.meta.requirements.requirements; - -import com.willfp.eco.core.integrations.placeholder.PlaceholderManager; -import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class RequirementPlaceholderEquals extends EnchantmentRequirement { - /** - * Create new requirement. - */ - public RequirementPlaceholderEquals() { - super("placeholder-equals"); - } - - @Override - public boolean doesPlayerMeet(@NotNull final Player player, - @NotNull final List args) { - String placeholder = args.get(0); - String equals = args.get(1); - - return PlaceholderManager.translatePlaceholders(placeholder, player).equalsIgnoreCase(equals); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderGreaterThan.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderGreaterThan.java deleted file mode 100644 index 4e9d24ec..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderGreaterThan.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.willfp.ecoenchants.enchantments.meta.requirements.requirements; - -import com.willfp.eco.core.integrations.placeholder.PlaceholderManager; -import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class RequirementPlaceholderGreaterThan extends EnchantmentRequirement { - /** - * Create new requirement. - */ - public RequirementPlaceholderGreaterThan() { - super("placeholder-greater-than"); - } - - @Override - public boolean doesPlayerMeet(@NotNull final Player player, - @NotNull final List args) { - String placeholder = args.get(0); - double equals = Double.parseDouble(args.get(1)); - - try { - return Double.parseDouble(PlaceholderManager.translatePlaceholders(placeholder, player)) >= equals; - } catch (NumberFormatException e) { - return false; - } - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderLessThan.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderLessThan.java deleted file mode 100644 index 41ab9dbb..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/requirements/requirements/RequirementPlaceholderLessThan.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.willfp.ecoenchants.enchantments.meta.requirements.requirements; - -import com.willfp.eco.core.integrations.placeholder.PlaceholderManager; -import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class RequirementPlaceholderLessThan extends EnchantmentRequirement { - /** - * Create new requirement. - */ - public RequirementPlaceholderLessThan() { - super("placeholder-less-than"); - } - - @Override - public boolean doesPlayerMeet(@NotNull final Player player, - @NotNull final List args) { - String placeholder = args.get(0); - double equals = Double.parseDouble(args.get(1)); - - try { - return Double.parseDouble(PlaceholderManager.translatePlaceholders(placeholder, player)) < equals; - } catch (NumberFormatException e) { - return false; - } - } -}