Added loading for vanilla enchantment metadata

This commit is contained in:
Auxilor 2021-04-27 12:59:18 +01:00
parent 1076d210f5
commit 48a400a30e
8 changed files with 246 additions and 157 deletions

View File

@ -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() {

View File

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

View File

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

View File

@ -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();
}
/**

View File

@ -7,5 +7,5 @@ public class VanillaEnchantmentMetadata {
/**
* The maximum level for the enchantment.
*/
private final int maxLevel;
private Integer maxLevel = null;
}

View File

@ -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<Enchantment, VanillaEnchantmentMetadata> MAP = new HashMap<>();
/**
* Get a map of all custom enchantment metadata.
*
* @return The map.
*/
public Map<Enchantment, VanillaEnchantmentMetadata> getMetadataMap() {
return new HashMap<>();
return MAP;
}
/**
* Update the map.
*/
public static void update() {
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()
.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();
}
}

View File

@ -35,4 +35,157 @@ special-color: "&d"
artifact-color: "&e"
spell-color: "&9"
description-color: "&8"
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.

View File

@ -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:
# - "<key>: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: []