diff --git a/build.gradle b/build.gradle index 3e85c1d3..46a0a383 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ allprojects { maven { url "https://oss.sonatype.org/content/repositories/snapshots" } maven { url 'https://oss.sonatype.org/content/groups/public/' } maven { url 'https://maven.enginehub.org/repo/' } + maven { url 'https://repo.essentialsx.net/releases/' } maven { url 'https://ci.ender.zone/plugin/repository/project/' } maven { url 'https://ci.ender.zone/plugin/repository/everything/' } maven { url 'https://repo.md-5.net/content/repositories/snapshots/' } @@ -48,7 +49,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/build.gradle b/eco-core/core-plugin/build.gradle index 9432f089..be5052be 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -3,10 +3,10 @@ version rootProject.version dependencies { compileOnly project(":eco-core:core-proxy") - compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT' compileOnly 'commons-io:commons-io:2.8.0' compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT' - compileOnly 'net.ess3:EssentialsX:2.18.1' - compileOnly 'com.destroystokyo.paper:paper-api:1.16.3-R0.1-SNAPSHOT' + compileOnly 'net.essentialsx:EssentialsX:2.19.0' + compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT' compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT' } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandDebug.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandDebug.java index 2f784d5b..de56b3f3 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandDebug.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandDebug.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -@SuppressWarnings("unchecked") +@SuppressWarnings({"unchecked", "deprecation"}) public class CommandDebug extends Subcommand { /** * Instantiate a new /ecoenchants debug command handler. @@ -102,7 +102,7 @@ public class CommandDebug extends Subcommand { Set withIssues = new HashSet<>(); EcoEnchants.values().forEach(enchant -> { - if (enchant.getRarity() == null) { + if (enchant.getEnchantmentRarity() == null) { withIssues.add(enchant); } if (enchant.getTargets().isEmpty()) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEnchantinfo.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEnchantinfo.java index 79e1e92d..ea5941e6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEnchantinfo.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEnchantinfo.java @@ -140,7 +140,7 @@ public class CommandEnchantinfo extends PluginCommand { final String finalName = EnchantmentCache.getEntry(enchantment).getName(); final String finalDescription = EnchantmentCache.getEntry(enchantment).getStringDescription(1); - final EnchantmentRarity finalRarity = enchantment.getRarity(); + final EnchantmentRarity finalRarity = enchantment.getEnchantmentRarity(); final String finalTargets = allTargets; final String finalConflicts = allConflicts; final String finalMaxLevel = maxLevel; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandGiverandombook.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandGiverandombook.java index 3a980e1d..c93e3806 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandGiverandombook.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandGiverandombook.java @@ -73,7 +73,7 @@ public class CommandGiverandombook extends Subcommand { if (!(enchantment instanceof EcoEnchant)) { return false; } - return ((EcoEnchant) enchantment).getRarity().equals(rarity); + return ((EcoEnchant) enchantment).getEnchantmentRarity().equals(rarity); } return true; }).collect(Collectors.toList()); 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 32c26043..aeaa7ef8 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 @@ -12,7 +12,6 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.util.ItemConversionOptions; import lombok.Getter; -import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -79,7 +78,7 @@ public class EnchantDisplay extends DisplayModule { } @Override - protected void display(@NotNull final ItemStack itemStack, + public void display(@NotNull final ItemStack itemStack, @Nullable final Player player, @NotNull final Object... args) { if (options.isRequireTarget()) { @@ -184,7 +183,7 @@ public class EnchantDisplay extends DisplayModule { } @Override - protected void revert(@NotNull final ItemStack itemStack) { + public void revert(@NotNull final ItemStack itemStack) { if (!EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) { return; } @@ -211,7 +210,7 @@ public class EnchantDisplay extends DisplayModule { } @Override - protected Object[] generateVarArgs(@NotNull final ItemStack itemStack) { + public Object[] generateVarArgs(@NotNull final ItemStack itemStack) { ItemMeta meta = itemStack.getItemMeta(); if (meta == null) { return new Object[]{false}; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java index f2addb96..60e77ca5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java @@ -109,7 +109,7 @@ public class EnchantmentCache { description = StringUtils.formatList(ecoEnchant.getWrappedDescription()); name = ecoEnchant.getDisplayName(); type = ecoEnchant.getType(); - rarity = ecoEnchant.getRarity(); + rarity = ecoEnchant.getEnchantmentRarity(); } else { description = Arrays.asList( WordUtils.wrap( 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..b2edfd4c 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,17 +1,20 @@ 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.display.EnchantmentCache; 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.PaperHelper; import com.willfp.ecoenchants.enchantments.util.Watcher; import lombok.AccessLevel; import lombok.Getter; +import net.kyori.adventure.text.Component; import org.apache.commons.lang.Validate; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; @@ -19,9 +22,11 @@ import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityCategory; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Listener; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; @@ -140,7 +145,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche * The rarity of the enchantment. */ @Getter - private EnchantmentRarity rarity; + private EnchantmentRarity enchantmentRarity; /** * If the enchantment is enabled. @@ -156,7 +161,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. @@ -220,8 +225,8 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche */ public void update() { config.loadFromLang(); - rarity = config.getRarity(); - Validate.notNull(rarity, "Rarity specified in " + this.permissionName + " is invalid!"); + enchantmentRarity = config.getRarity(); + Validate.notNull(enchantmentRarity, "Rarity specified in " + this.permissionName + " is invalid!"); conflicts = config.getEnchantments(EcoEnchants.GENERAL_LOCATION + "conflicts"); grindstoneable = config.getBool(EcoEnchants.GENERAL_LOCATION + "grindstoneable"); availableFromTable = config.getBool(EcoEnchants.OBTAINING_LOCATION + "table"); @@ -233,7 +238,10 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche disabledWorldNames.clear(); disabledWorldNames.addAll(config.getStrings(EcoEnchants.GENERAL_LOCATION + "disabled-in-worlds")); disabledWorlds.clear(); - List worldNames = Bukkit.getWorlds().stream().map(World::getName).map(String::toLowerCase).collect(Collectors.toList()); + List worldNames = new ArrayList<>(); + for (World world : Bukkit.getWorlds()) { + worldNames.add(world.getName().toLowerCase()); + } List disabledExistingWorldNames = disabledWorldNames.stream().filter(s -> worldNames.contains(s.toLowerCase())).collect(Collectors.toList()); disabledWorlds.addAll(Bukkit.getWorlds().stream().filter(world -> disabledExistingWorldNames.contains(world.getName().toLowerCase())).collect(Collectors.toList())); targets.clear(); @@ -250,11 +258,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 +314,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; @@ -443,4 +447,110 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche public boolean canEnchantItem(@NotNull final ItemStack itemStack) { return targetMaterials.contains(itemStack.getType()) || itemStack.getType().equals(Material.BOOK) || itemStack.getType().equals(Material.ENCHANTED_BOOK); } + + /** + * Paper parity. + *

+ * You should use EnchantmentCache instead. + * + * @param level The level. + * @return The display name. + * @deprecated Use {@link EnchantmentCache#getEntry(Enchantment)} instead. + */ + @Deprecated + @Override + public @NotNull Component displayName(final int level) { + return PaperHelper.toComponent(EnchantmentCache.getEntry(this).getNameWithLevel(level)); + } + + /** + * Paper parity. + *

+ * You should use {@link EcoEnchant#isAvailableFromVillager()} instead. + * + * @return If tradeable. + * @deprecated Use {@link EcoEnchant#isAvailableFromVillager()} instead. + */ + @Deprecated + @Override + public boolean isTradeable() { + return this.isAvailableFromVillager(); + } + + /** + * Paper parity. + *

+ * You should use {@link EcoEnchant#isAvailableFromLoot()} instead. + * + * @return If discoverable. + * @deprecated Use {@link EcoEnchant#isAvailableFromLoot()} instead. + */ + @Deprecated + @Override + public boolean isDiscoverable() { + return this.isAvailableFromLoot(); + } + + /** + * Paper parity. + *

+ * EcoEnchants has its own systems for everything like this. Will always return 0. + * + * @param level The level. + * @param entityCategory The category. + * @return 0 + * @deprecated EcoEnchants has its own systems for this. + */ + @Deprecated + @Override + public float getDamageIncrease(final int level, + @NotNull final EntityCategory entityCategory) { + return 0; + } + + /** + * Paper parity. + *

+ * EcoEnchants has its own systems for targets. + *

+ * Use {@link EcoEnchant#getTargets()} instead. + * + * @return An empty set. + * @deprecated Use {@link EcoEnchant#getTargets()}. + */ + @Deprecated + @Override + public @NotNull Set getActiveSlots() { + return new HashSet<>(); + } + + /** + * Paper parity. + *

+ * eco / EcoEnchants recodes display entirely. + * + * @return A translation key. + * @deprecated Useless method, all items will be display differently using eco. + */ + @Deprecated + @Override + public @NotNull String translationKey() { + return "ecoenchants:enchantment." + this.getKey().getKey(); + } + + /** + * Paper parity. + *

+ * EcoEnchants has its own systems for rarity. + *

+ * Use {@link EcoEnchant#getEnchantmentRarity()} instead. + * + * @return {@link io.papermc.paper.enchantments.EnchantmentRarity#COMMON}. + * @deprecated Use {@link EcoEnchant#getEnchantmentRarity()}. + */ + @Deprecated + @Override + public @NotNull io.papermc.paper.enchantments.EnchantmentRarity getRarity() { + return io.papermc.paper.enchantments.EnchantmentRarity.COMMON; + } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java index 5d528498..b0e40957 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java @@ -108,18 +108,20 @@ public abstract class Artifact extends EcoEnchant { return; } - Vector point1 = player.getLocation().getDirection().clone(); - point1.rotateAroundY(Math.toRadians(90)); - point1.multiply(1.2); - Location location1 = player.getLocation().clone().add(point1); + this.getPlugin().getScheduler().runAsync(() -> { + Vector point1 = player.getLocation().getDirection().clone(); + point1.rotateAroundY(Math.toRadians(90)); + point1.multiply(1.2); + Location location1 = player.getLocation().clone().add(point1); - Vector point2 = player.getLocation().getDirection().clone(); - point2.rotateAroundY(Math.toRadians(-90)); - point2.multiply(1.2); - Location location2 = player.getLocation().clone().add(point2); + Vector point2 = player.getLocation().getDirection().clone(); + point2.rotateAroundY(Math.toRadians(-90)); + point2.multiply(1.2); + Location location2 = player.getLocation().clone().add(point2); - player.getWorld().spawnParticle(particle, location1, 1, 0, 0, 0, 0, extra, true); - player.getWorld().spawnParticle(particle, location2, 1, 0, 0, 0, 0, extra, true); + player.getWorld().spawnParticle(particle, location1, 1, 0, 0, 0, 0, extra, true); + player.getWorld().spawnParticle(particle, location2, 1, 0, 0, 0, 0, extra, true); + }); } @Override @@ -178,6 +180,6 @@ public abstract class Artifact extends EcoEnchant { bukkitRunnable.cancel(); } projectile.getLocation().getWorld().spawnParticle(particle, projectile.getLocation(), 1, 0, 0, 0, finalColor, extra, true); - }).runTaskTimer(4, ticks); + }).runTaskTimerAsynchronously(4, ticks); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java index 21e440a1..79e670ea 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java @@ -37,6 +37,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +@SuppressWarnings("deprecation") public abstract class Spell extends EcoEnchant { /** * Items that must be left-clicked to activate spells for. 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; - } - } -} 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 bd0ef1ba..040518ee 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 @@ -22,6 +22,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +@SuppressWarnings("deprecation") @UtilityClass public class AnvilMerge { /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java index 4ff77892..be25e8b6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java @@ -125,10 +125,10 @@ public class EnchantingListeners extends PluginDependent implements L if (!enchantment.canEnchantItem(item)) { continue; } - if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getTableProbability() * multiplier) { + if (NumberUtils.randFloat(0, 1) > enchantment.getEnchantmentRarity().getTableProbability() * multiplier) { continue; } - if (enchantment.getRarity().getMinimumLevel() > cost) { + if (enchantment.getEnchantmentRarity().getMinimumLevel() > cost) { continue; } if (!enchantment.isEnabled()) { @@ -172,7 +172,7 @@ public class EnchantingListeners extends PluginDependent implements L level = (int) Math.ceil(enchantlevel2 / enchantlevel3); } else { int maxLevel = this.getPlugin().getConfigYml().getInt("enchanting-table.maximum-obtainable-level"); - double enchantlevel1 = (cost / (double) enchantment.getRarity().getMinimumLevel()) / (maxLevel / (double) enchantment.getRarity().getMinimumLevel()); + double enchantlevel1 = (cost / (double) enchantment.getEnchantmentRarity().getMinimumLevel()) / (maxLevel / (double) enchantment.getEnchantmentRarity().getMinimumLevel()); double enchantlevel2 = NumberUtils.triangularDistribution(0, 1, enchantlevel1); double enchantlevel3 = 1 / maxLevelDouble; level = (int) Math.ceil(enchantlevel2 / enchantlevel3); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java index 400b741a..a9ec9b0f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; +@SuppressWarnings("deprecation") public class LootPopulator extends BlockPopulator { /** * Instance of ecoenchants. @@ -92,11 +93,11 @@ public class LootPopulator extends BlockPopulator { int cap = 0; for (EcoEnchant enchantment : enchantments) { - if (enchantment == null || enchantment.getRarity() == null) { + if (enchantment == null || enchantment.getEnchantmentRarity() == null) { continue; } - if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getLootProbability() * multiplier) { + if (NumberUtils.randFloat(0, 1) > enchantment.getEnchantmentRarity().getLootProbability() * multiplier) { continue; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java index 9e0bf8e8..a57264ef 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java @@ -73,7 +73,7 @@ public class VillagerListeners extends PluginDependent implements Lis EcoEnchant applied = null; for (EcoEnchant enchantment : enchantments) { - if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) { + if (NumberUtils.randFloat(0, 1) > enchantment.getEnchantmentRarity().getVillagerProbability() * multiplier) { continue; } @@ -167,7 +167,7 @@ public class VillagerListeners extends PluginDependent implements Lis double multiplier = 0.01; for (EcoEnchant enchantment : enchantments) { - if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) { + if (NumberUtils.randFloat(0, 1) > enchantment.getEnchantmentRarity().getVillagerProbability() * multiplier) { continue; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java index c27a4b36..7ae02f0f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java @@ -32,6 +32,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +@SuppressWarnings("deprecation") public class ItemConversions extends PluginDependent implements Listener { /** * Pass an {@link EcoPlugin} in order to interface with it. diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/PaperHelper.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/PaperHelper.java new file mode 100644 index 00000000..2048ecba --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/PaperHelper.java @@ -0,0 +1,25 @@ +package com.willfp.ecoenchants.enchantments.util; + +import lombok.experimental.UtilityClass; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.jetbrains.annotations.NotNull; + +@UtilityClass +public class PaperHelper { + private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() + .hexColors() + .useUnusualXRepeatedCharacterHexFormat() + .character('ยง') + .build(); + + /** + * Convert string to a component. + * + * @param string The string. + * @return The component. + */ + public static Component toComponent(@NotNull final String string) { + return SERIALIZER.deserialize(string); + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/registration/plugins/IntegrationEssentials.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/registration/plugins/IntegrationEssentials.java index 70927125..14398661 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/registration/plugins/IntegrationEssentials.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/registration/plugins/IntegrationEssentials.java @@ -9,17 +9,12 @@ import org.bukkit.enchantments.Enchantment; import java.util.Map; -@SuppressWarnings("unchecked") public class IntegrationEssentials implements RegistrationWrapper { @Override public void registerAllEnchantments() { - try { - for (EcoEnchant enchantment : EcoEnchants.values()) { - ((Map) FieldUtils.readDeclaredStaticField(Enchantments.class, "ENCHANTMENTS", true)).put(enchantment.getKey().getKey(), enchantment); - ((Map) FieldUtils.readDeclaredStaticField(Enchantments.class, "ENCHANTMENTS", true)).put(enchantment.getPermissionName(), enchantment); - } - } catch (IllegalAccessException ignored) { - // Ignore reflective errors that won't happen. + for (EcoEnchant enchantment : EcoEnchants.values()) { + Enchantments.registerEnchantment(enchantment.getKey().getKey(), enchantment); + Enchantments.registerAlias(enchantment.getPermissionName(), enchantment); } } diff --git a/gradle.properties b/gradle.properties index 765d8e82..2fee8c1a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 8.10.13 +version = 8.11.0 plugin-name = EcoEnchants \ No newline at end of file