mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-25 20:17:38 +01:00
Added new CraftEnchantment management system and added vanillaenchants.yml
This commit is contained in:
parent
0784e12496
commit
1076d210f5
@ -13,6 +13,10 @@
|
||||
<suppress files="[\\/]eco-extensions[\\/]" checks="MissingJavadocMethod"/>
|
||||
<suppress files="[\\/]eco-extensions[\\/]" checks="JavadocVariable"/>
|
||||
|
||||
<!-- NMS doesn't need javadoc. -->
|
||||
<suppress files="[\\/]eco-nms[\\/]" checks="MissingJavadocMethod"/>
|
||||
<suppress files="[\\/]eco-nms[\\/]" checks="JavadocVariable"/>
|
||||
|
||||
<!-- Fields don't need javadoc -->
|
||||
<suppress files="EcoEnchants.java" checks="JavadocVariable"/>
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantments;
|
||||
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy;
|
||||
import com.willfp.ecoenchants.proxy.v1_16_R3.vanilla.EcoCraftEnchantment;
|
||||
import net.minecraft.server.v1_16_R3.Enchantment;
|
||||
import net.minecraft.server.v1_16_R3.IRegistry;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class EcoCraftEnchantmentManager implements EcoCraftEnchantmentManagerProxy {
|
||||
@Override
|
||||
public void registerNewCraftEnchantments() {
|
||||
Map<org.bukkit.enchantments.Enchantment, VanillaEnchantmentMetadata> metadataMap = VanillaEnchantments.getMetadataMap();
|
||||
|
||||
for (Enchantment enchantment : IRegistry.ENCHANTMENT) {
|
||||
NamespacedKey key = CraftNamespacedKey.fromMinecraft(IRegistry.ENCHANTMENT.getKey(enchantment));
|
||||
VanillaEnchantmentMetadata metadata = metadataMap.get(org.bukkit.enchantments.Enchantment.getByKey(key));
|
||||
new EcoCraftEnchantment(enchantment, metadata).register();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R3.vanilla;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.EcoCraftEnchantmentWrapper;
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
|
||||
import net.minecraft.server.v1_16_R3.Enchantment;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.enchantments.CraftEnchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EcoCraftEnchantment extends CraftEnchantment implements EcoCraftEnchantmentWrapper {
|
||||
private final VanillaEnchantmentMetadata metadata;
|
||||
|
||||
public EcoCraftEnchantment(@NotNull final Enchantment target,
|
||||
@NotNull final VanillaEnchantmentMetadata metadata) {
|
||||
super(target);
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return metadata.getMaxLevel();
|
||||
}
|
||||
|
||||
public void register() {
|
||||
try {
|
||||
Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey");
|
||||
Field byNameField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byName");
|
||||
byIdField.setAccessible(true);
|
||||
byNameField.setAccessible(true);
|
||||
Map<NamespacedKey, org.bukkit.enchantments.Enchantment> byKey = (Map<NamespacedKey, org.bukkit.enchantments.Enchantment>) byIdField.get(null);
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byName = (Map<String, org.bukkit.enchantments.Enchantment>) byNameField.get(null);
|
||||
byKey.remove(this.getKey());
|
||||
byName.remove(this.getName());
|
||||
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byNameClone = new HashMap<>(byName);
|
||||
for (Map.Entry<String, org.bukkit.enchantments.Enchantment> entry : byNameClone.entrySet()) {
|
||||
if (entry.getValue().getKey().equals(this.getKey())) {
|
||||
byName.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
Field f = org.bukkit.enchantments.Enchantment.class.getDeclaredField("acceptingNew");
|
||||
f.setAccessible(true);
|
||||
f.set(null, true);
|
||||
f.setAccessible(false);
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
@ -241,7 +241,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
|
||||
Map<NamespacedKey, Enchantment> byKey = (Map<NamespacedKey, Enchantment>) byIdField.get(null);
|
||||
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
|
||||
byKey.remove(this.getKey());
|
||||
byName.remove(this.getDisplayName());
|
||||
byName.remove(this.getName());
|
||||
|
||||
Map<String, Enchantment> byNameClone = new HashMap<>(byName);
|
||||
for (Map.Entry<String, Enchantment> entry : byNameClone.entrySet()) {
|
||||
|
@ -236,12 +236,12 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Dynamite;
|
||||
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.itemtypes.VanillaEcoEnchantWrapper;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
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.bukkit.enchantments.EnchantmentWrapper;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -579,6 +579,8 @@ public class EcoEnchants {
|
||||
for (EcoEnchant ecoEnchant : new HashSet<>(values())) {
|
||||
ecoEnchant.update();
|
||||
}
|
||||
|
||||
ProxyUtils.getProxy(EcoCraftEnchantmentManagerProxy.class).registerNewCraftEnchantments();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -604,14 +606,4 @@ public class EcoEnchants {
|
||||
BY_KEY.remove(enchant.getKey());
|
||||
BY_NAME.inverse().remove(enchant);
|
||||
}
|
||||
|
||||
static {
|
||||
for (Enchantment value : Enchantment.values()) {
|
||||
if (value instanceof EcoEnchant || value instanceof EnchantmentWrapper) {
|
||||
continue;
|
||||
}
|
||||
|
||||
new VanillaEcoEnchantWrapper(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.itemtypes;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class VanillaEcoEnchantWrapper extends EcoEnchant {
|
||||
/**
|
||||
* Create a new Vanilla EcoEnchant Wrapper.
|
||||
*
|
||||
* @param enchantment The enchantment to wrap.
|
||||
*/
|
||||
public VanillaEcoEnchantWrapper(@NotNull final Enchantment enchantment) {
|
||||
super(enchantment.getKey().getKey(), enchantment.isCursed() ? EnchantmentType.CURSE : EnchantmentType.NORMAL);
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.willfp.ecoenchants.enchantments.support.vanilla;
|
||||
|
||||
public interface EcoCraftEnchantmentWrapper {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.support.vanilla;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class VanillaEnchantmentMetadata {
|
||||
/**
|
||||
* The maximum level for the enchantment.
|
||||
*/
|
||||
private final int maxLevel;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.willfp.ecoenchants.enchantments.support.vanilla;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class VanillaEnchantments {
|
||||
/**
|
||||
* Get a map of all custom enchantment metadata.
|
||||
*
|
||||
* @return The map.
|
||||
*/
|
||||
public Map<Enchantment, VanillaEnchantmentMetadata> getMetadataMap() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
@ -35,157 +35,4 @@ special-color: "&d"
|
||||
artifact-color: "&e"
|
||||
spell-color: "&9"
|
||||
|
||||
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.
|
||||
description-color: "&8"
|
153
eco-core/core-plugin/src/main/resources/vanillaenchants.yml
Normal file
153
eco-core/core-plugin/src/main/resources/vanillaenchants.yml
Normal file
@ -0,0 +1,153 @@
|
||||
protection:
|
||||
name: "Protection"
|
||||
description: Reduces most types of damage.
|
||||
max-level: 4
|
||||
|
||||
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.
|
@ -0,0 +1,10 @@
|
||||
package com.willfp.ecoenchants.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.core.proxy.AbstractProxy;
|
||||
|
||||
public interface EcoCraftEnchantmentManagerProxy extends AbstractProxy {
|
||||
/**
|
||||
* Re-Register new CraftEnchantments for all vanilla enchantments in order to modify their max level.
|
||||
*/
|
||||
void registerNewCraftEnchantments();
|
||||
}
|
Loading…
Reference in New Issue
Block a user