diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/vanilla/EcoCraftEnchantment.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/vanilla/EcoCraftEnchantment.java index dbaba3ba..eb3bfbc0 100644 --- a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/vanilla/EcoCraftEnchantment.java +++ b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/vanilla/EcoCraftEnchantment.java @@ -23,7 +23,7 @@ public class EcoCraftEnchantment extends CraftEnchantment implements EcoCraftEnc @Override public int getMaxLevel() { - return metadata.getMaxLevel(); + return metadata.getMaxLevel() == null ? this.getHandle().getMaxLevel() : metadata.getMaxLevel(); } public void register() { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java index 249493be..a6d006e5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java @@ -14,6 +14,7 @@ import com.willfp.ecoenchants.command.commands.CommandRandomenchant; import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo; import com.willfp.ecoenchants.config.RarityYml; import com.willfp.ecoenchants.config.TargetYml; +import com.willfp.ecoenchants.config.VanillaEnchantsYml; import com.willfp.ecoenchants.display.EnchantDisplay; import com.willfp.ecoenchants.display.EnchantmentCache; import com.willfp.ecoenchants.enchantments.EcoEnchants; @@ -63,6 +64,12 @@ public class EcoEnchantsPlugin extends EcoPlugin { @Getter private final TargetYml targetYml; + /** + * VanillaEnchants.yml. + */ + @Getter + private final VanillaEnchantsYml vanillaEnchantsYml; + /** * Internal constructor called by bukkit on plugin load. */ @@ -72,6 +79,7 @@ public class EcoEnchantsPlugin extends EcoPlugin { rarityYml = new RarityYml(this); targetYml = new TargetYml(this); + vanillaEnchantsYml = new VanillaEnchantsYml(this); } /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/VanillaEnchantsYml.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/VanillaEnchantsYml.java new file mode 100644 index 00000000..f14aeb16 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/VanillaEnchantsYml.java @@ -0,0 +1,16 @@ +package com.willfp.ecoenchants.config; + +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.config.BaseConfig; +import org.jetbrains.annotations.NotNull; + +public class VanillaEnchantsYml extends BaseConfig { + /** + * Instantiate target.yml. + * + * @param plugin Instance of EcoEnchants. + */ + public VanillaEnchantsYml(@NotNull final EcoPlugin plugin) { + super("vanillaenchants", true, plugin); + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index 96931814..79a0f819 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -237,6 +237,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Missile; import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Quake; import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Vitalize; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantments; import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy; import com.willfp.ecoenchants.util.ProxyUtils; import lombok.experimental.UtilityClass; @@ -580,7 +581,7 @@ public class EcoEnchants { ecoEnchant.update(); } - ProxyUtils.getProxy(EcoCraftEnchantmentManagerProxy.class).registerNewCraftEnchantments(); + VanillaEnchantments.update(); } /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantmentMetadata.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantmentMetadata.java index 37674853..462fd6de 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantmentMetadata.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantmentMetadata.java @@ -7,5 +7,5 @@ public class VanillaEnchantmentMetadata { /** * The maximum level for the enchantment. */ - private final int maxLevel; + private Integer maxLevel = null; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java index c3e009f2..933f60b9 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java @@ -1,19 +1,67 @@ package com.willfp.ecoenchants.enchantments.support.vanilla; +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 java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @UtilityClass public class VanillaEnchantments { + /** + * Instance of EcoEnchants. + */ + private static final EcoEnchantsPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); + + /** + * Vanilla Enchantment Metadata Map. + */ + private static final Map MAP = new HashMap<>(); + /** * Get a map of all custom enchantment metadata. * * @return The map. */ public Map getMetadataMap() { - return new HashMap<>(); + return MAP; + } + + /** + * Update the map. + */ + public static void update() { + Map map = new HashMap<>(); + + List enchantments = Arrays.stream(Enchantment.values()) + .filter(enchantment -> enchantment.getClass().getName().contains("CraftEnchantment")) + .collect(Collectors.toList()); + + Map 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]) + )); + + for (Enchantment enchantment : enchantments) { + VanillaEnchantmentMetadata metadata = new VanillaEnchantmentMetadata(); + + metadata.setMaxLevel(maxLevels.get(enchantment)); + + map.put(enchantment, metadata); + } + + MAP.clear(); + MAP.putAll(map); + + + ProxyUtils.getProxy(EcoCraftEnchantmentManagerProxy.class).registerNewCraftEnchantments(); } } diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 8d2dd20c..f6a43416 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -35,4 +35,157 @@ special-color: "&d" artifact-color: "&e" spell-color: "&9" -description-color: "&8" \ No newline at end of file +description-color: "&8" + +enchantments: + protection: + name: "Protection" + description: Reduces most types of damage. + + fire_protection: + name: "Fire Protection" + description: Reduces fire damage and burn time. + + feather_falling: + name: "Feather Falling" + description: Reduces fall damage. + + blast_protection: + name: "Blast Protection" + description: Reduces explosion damage and knockback. + + projectile_protection: + name: "Projectile Protection" + description: Reduces projectile damage. + + respiration: + name: "Respiration" + description: Extends underwater breathing time. + + aqua_affinity: + name: "Aqua Affinity" + description: Increases underwater mining speed. + + thorns: + name: "Thorns" + description: Reflects some of the damage taken when hit. + + depth_strider: + name: "Depth Strider" + description: Increases underwater movement speed. + + frost_walker: + name: "Frost Walker" + description: Turns water beneath the player into ice. + + binding_curse: + name: "Curse of Binding" + description: Items cannot be removed from armor slots. + + sharpness: + name: "Sharpness" + description: Increases damage. + + smite: + name: "Smite" + description: Increases damage against undead mobs. + + bane_of_arthropods: + name: "Bane of Arthropods" + description: Increases damage and slows arthropod mobs. + + knockback: + name: "Knockback" + description: Increases knockback. + + fire_aspect: + name: "Fire Aspect" + description: Sets target on fire. + + looting: + name: "Looting" + description: Increases mob loot. + + sweeping: + name: "Sweeping Edge" + description: Increases sweeping attack damage. + + efficiency: + name: "Efficiency" + description: Increases mining speed. + + silk_touch: + name: "Silk Touch" + description: Mined blocks drop themselves exactly. + + unbreaking: + name: "Unbreaking" + description: Increases item durability. + + fortune: + name: "Fortune" + description: Increases certain block drops. + + power: + name: "Power" + description: Increases arrow damage. + + punch: + name: "Punch" + description: Increases arrow knockback. + + flame: + name: "Flame" + description: Arrows set target on fire. + + infinity: + name: "Infinity" + description: Shooting consumes no regular arrows. + + luck_of_the_sea: + name: "Luck of the Sea" + description: Increases rate of good loot. + + lure: + name: "Lure" + description: Decreases fishing wait time. + + loyalty: + name: "Loyalty" + description: Trident returns after being thrown. + + impaling: + name: "Impaling" + description: Trident deals additional damage to ocean mobs. + + riptide: + name: "Riptide" + description: Trident launches player when thrown in water or while raining. + + channeling: + name: "Channeling" + description: Strikes lightning where trident lands during thunderstorms. + + multishot: + name: "Multishot" + description: Shoots 3 arrows. + + quick_charge: + name: "Quick Charge" + description: Decreases crossbow charging time. + + piercing: + name: "Piercing" + description: Arrows pass through multiple entities. + + mending: + name: "Mending" + description: Repair the item while gaining XP orbs. + + vanishing_curse: + name: "Curse of Vanishing" + description: Item destroyed on death. + + soul_speed: + name: "Soul Speed" + description: Increases walking speed on soul sand and soul soil. diff --git a/eco-core/core-plugin/src/main/resources/vanillaenchants.yml b/eco-core/core-plugin/src/main/resources/vanillaenchants.yml index 73d8d95e..2e694459 100644 --- a/eco-core/core-plugin/src/main/resources/vanillaenchants.yml +++ b/eco-core/core-plugin/src/main/resources/vanillaenchants.yml @@ -1,153 +1,16 @@ -protection: - name: "Protection" - description: Reduces most types of damage. - max-level: 4 +# +# Allows for modifying certain aspects of vanilla enchantments +# -fire_protection: - name: "Fire Protection" - description: Reduces fire damage and burn time. - max-level: 4 - -feather_falling: - name: "Feather Falling" - description: Reduces fall damage. - -blast_protection: - name: "Blast Protection" - description: Reduces explosion damage and knockback. - -projectile_protection: - name: "Projectile Protection" - description: Reduces projectile damage. - -respiration: - name: "Respiration" - description: Extends underwater breathing time. - -aqua_affinity: - name: "Aqua Affinity" - description: Increases underwater mining speed. - -thorns: - name: "Thorns" - description: Reflects some of the damage taken when hit. - -depth_strider: - name: "Depth Strider" - description: Increases underwater movement speed. - -frost_walker: - name: "Frost Walker" - description: Turns water beneath the player into ice. - -binding_curse: - name: "Curse of Binding" - description: Items cannot be removed from armor slots. - -sharpness: - name: "Sharpness" - description: Increases damage. - -smite: - name: "Smite" - description: Increases damage against undead mobs. - -bane_of_arthropods: - name: "Bane of Arthropods" - description: Increases damage and slows arthropod mobs. - -knockback: - name: "Knockback" - description: Increases knockback. - -fire_aspect: - name: "Fire Aspect" - description: Sets target on fire. - -looting: - name: "Looting" - description: Increases mob loot. - -sweeping: - name: "Sweeping Edge" - description: Increases sweeping attack damage. - -efficiency: - name: "Efficiency" - description: Increases mining speed. - -silk_touch: - name: "Silk Touch" - description: Mined blocks drop themselves exactly. - -unbreaking: - name: "Unbreaking" - description: Increases item durability. - -fortune: - name: "Fortune" - description: Increases certain block drops. - -power: - name: "Power" - description: Increases arrow damage. - -punch: - name: "Punch" - description: Increases arrow knockback. - -flame: - name: "Flame" - description: Arrows set target on fire. - -infinity: - name: "Infinity" - description: Shooting consumes no regular arrows. - -luck_of_the_sea: - name: "Luck of the Sea" - description: Increases rate of good loot. - -lure: - name: "Lure" - description: Decreases fishing wait time. - -loyalty: - name: "Loyalty" - description: Trident returns after being thrown. - -impaling: - name: "Impaling" - description: Trident deals additional damage to ocean mobs. - -riptide: - name: "Riptide" - description: Trident launches player when thrown in water or while raining. - -channeling: - name: "Channeling" - description: Strikes lightning where trident lands during thunderstorms. - -multishot: - name: "Multishot" - description: Shoots 3 arrows. - -quick_charge: - name: "Quick Charge" - description: Decreases crossbow charging time. - -piercing: - name: "Piercing" - description: Arrows pass through multiple entities. - -mending: - name: "Mending" - description: Repair the item while gaining XP orbs. - -vanishing_curse: - name: "Curse of Vanishing" - description: Item destroyed on death. - -soul_speed: - name: "Soul Speed" - description: Increases walking speed on soul sand and soul soil. +# Set custom max levels for vanilla enchantments. +# To do this, add each enchantment like this: +# - ":4" +# For example, to allow efficiency 5 and protection 6, you would do this: +# max-levels: +# - "efficiency:5" +# - "protection:6" +# +# Currently, it is *not* possible to modify the enchantment levels from enchanting tables. +# It will work with anvils however, but since it is still possible to get enchantments at their vanilla +# max levels, then it isn't recommended to lower the max level of a vanilla enchantment, only to raise it. +max-levels: [] \ No newline at end of file