Fixed compatibility with recent MythicEnchants builds

This commit is contained in:
Jules 2024-07-25 20:27:52 -07:00
parent 47327657c9
commit 41702be00d
6 changed files with 67 additions and 53 deletions

View File

@ -133,8 +133,8 @@
<!-- MythicEnchants -->
<dependency>
<groupId>io.lumine</groupId>
<artifactId>MythicEnchants</artifactId>
<version>0.0.1-REUPLOAD</version>
<artifactId>MythicEnchants-Dist</artifactId>
<version>0.1.0-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

View File

@ -73,7 +73,7 @@ public class MMOItems extends MMOPlugin {
private final TypeManager typeManager = new TypeManager();
private final ItemManager itemManager = new ItemManager();
private final PlayerInventoryHandler inventory = new PlayerInventoryHandler();
private final List<EnchantPlugin<? extends Enchantment>> enchantPlugins = new ArrayList<>();
private final List<EnchantPlugin<?>> enchantPlugins = new ArrayList<>();
private final StatManager statManager = new StatManager();
private PlayerDataManager playerDataManager;
@ -124,11 +124,11 @@ public class MMOItems extends MMOPlugin {
PluginUtils.isDependencyPresent("MMOCore", u -> new MMOCoreMMOLoader());
PluginUtils.isDependencyPresent("mcMMO", u -> statManager.register(McMMOHook.disableMcMMORepair));
PluginUtils.isDependencyPresent("AdvancedEnchantments", u -> {
PluginUtils.hookDependencyIfPresent("AdvancedEnchantments", u -> {
statManager.register(AdvancedEnchantmentsHook.ADVANCED_ENCHANTMENTS);
statManager.register(AdvancedEnchantmentsHook.DISABLE_ADVANCED_ENCHANTMENTS);
});
PluginUtils.isDependencyPresent("MythicEnchants", u -> enchantPlugins.add(new MythicEnchantsSupport()));
PluginUtils.hookDependencyIfPresent("MythicEnchants", u -> enchantPlugins.add(new MythicEnchantsSupport()));
PluginUtils.isDependencyPresent("Heroes", u -> statManager.register(HeroesHook.MAX_STAMINA));
}
@ -410,10 +410,10 @@ public class MMOItems extends MMOPlugin {
*
* @param value The player inventory subclass
* @deprecated Rather than setting this to the only inventory MMOItems will
* search equipment within, you must add your inventory to the
* handler with <code>getInventory().register()</code>. This method
* will clear all other PlayerInventories for now, as to keep
* backwards compatibility.
* search equipment within, you must add your inventory to the
* handler with <code>getInventory().register()</code>. This method
* will clear all other PlayerInventories for now, as to keep
* backwards compatibility.
*/
@Deprecated
public void setPlayerInventory(PlayerInventory value) {
@ -507,7 +507,7 @@ public class MMOItems extends MMOPlugin {
return vaultSupport != null && vaultSupport.getPermissions() != null;
}
public List<EnchantPlugin<? extends Enchantment>> getEnchantPlugins() {
public List<EnchantPlugin<?>> getEnchantPlugins() {
return enchantPlugins;
}
@ -523,9 +523,9 @@ public class MMOItems extends MMOPlugin {
/**
* @return Generates an item given an item template. The item level will
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
*/
@Nullable
public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, @Nullable PlayerData player) {
@ -543,9 +543,9 @@ public class MMOItems extends MMOPlugin {
/**
* @return Generates an item given an item template. The item level will
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
*/
@Nullable
public ItemStack getItem(@Nullable Type type, @Nullable String id, @NotNull PlayerData player) {
@ -562,7 +562,7 @@ public class MMOItems extends MMOPlugin {
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a
* specific item level and item tier
* specific item level and item tier
*/
@Nullable
public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) {
@ -582,7 +582,7 @@ public class MMOItems extends MMOPlugin {
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a
* specific item level and item tier
* specific item level and item tier
*/
@Nullable
public ItemStack getItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) {
@ -597,10 +597,10 @@ public class MMOItems extends MMOPlugin {
/**
* @return Generates an item given an item template. The item level will be
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
*/
@Nullable
public MMOItem getMMOItem(@Nullable Type type, @Nullable String id) {
@ -609,10 +609,10 @@ public class MMOItems extends MMOPlugin {
/**
* @return Generates an item given an item template. The item level will be
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
*/
@Nullable
@ -625,10 +625,10 @@ public class MMOItems extends MMOPlugin {
/**
* @return Generates an item given an item template. The item level will be
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
*/
@Nullable
public ItemStack getItem(@Nullable Type type, @Nullable String id) {

View File

@ -3,6 +3,8 @@ package net.Indyuce.mmoitems.comp.enchants;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* There are three types of enchant plugins.
@ -13,16 +15,19 @@ import org.bukkit.enchantments.Enchantment;
* Interface used to support plugins which use the Bukkit Enchantment
* interface to register their enchantments. This makes enchant storage
* so much easier for MMOItems.
*
* @param <T> The plugin class implementing Enchantment
*/
public interface EnchantPlugin<T extends Enchantment> {
public interface EnchantPlugin<T> {
/**
* @param enchant Enchant being checked
* @return If this enchant plugin handles a given enchant
* Used to determine if an enchantment comes from that enchant plugin
*
* @return The namespace of keys used for registering Bukkit enchantments
*/
boolean isCustomEnchant(Enchantment enchant);
@NotNull
String getNamespace();
@Nullable
T transfer(@NotNull Enchantment enchant);
/**
* Called when an item is built. This should be used to add the enchantment
@ -32,7 +37,10 @@ public interface EnchantPlugin<T extends Enchantment> {
* @param enchant Enchantment being applied
* @param level Enchant level
*/
void handleEnchant(ItemStackBuilder builder, T enchant, int level);
void handleEnchant(@NotNull ItemStackBuilder builder, @NotNull T enchant, int level);
NamespacedKey getNamespacedKey(String key);
@NotNull
default NamespacedKey getNamespacedKey(@NotNull String key) {
return new NamespacedKey(getNamespace(), key);
}
}

View File

@ -4,28 +4,30 @@ import io.lumine.mythicenchants.MythicEnchants;
import io.lumine.mythicenchants.enchants.MythicEnchant;
import io.lumine.mythicenchants.util.LoreParser;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import org.apache.commons.lang.Validate;
import org.bukkit.NamespacedKey;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class MythicEnchantsSupport implements EnchantPlugin<MythicEnchant> {
private final MythicEnchants manager = (MythicEnchants) Bukkit.getPluginManager().getPlugin("MythicEnchants");
@NotNull
@Override
public boolean isCustomEnchant(Enchantment enchant) {
return enchant instanceof MythicEnchant;
public String getNamespace() {
return "mythicenchants";
}
@Nullable
@Override
public NamespacedKey getNamespacedKey(String key) {
return new NamespacedKey(MythicEnchants.inst(), key);
public MythicEnchant transfer(@NotNull Enchantment enchantment) {
return manager.getEnchantManager().toMythicEnchantment(enchantment).orElse(null);
}
public void handleEnchant(ItemStackBuilder builder, MythicEnchant enchant, int level) {
Validate.isTrue(level > 0, "Level must be strictly positive");
public void handleEnchant(@NotNull ItemStackBuilder builder, @NotNull MythicEnchant enchant, int level) {
// Type cannot be changed. Must make sure that item is an enchanted book
if (!builder.getMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS))
builder.getLore().insert(0, LoreParser.formatEnchantment(enchant, level));
}

View File

@ -283,9 +283,13 @@ public class Enchants extends ItemStat<RandomEnchantListData, EnchantListData> i
}
// Handle custom enchant
for (EnchantPlugin enchantPlugin : MMOItems.plugin.getEnchantPlugins())
if (enchantPlugin.isCustomEnchant(enchant))
enchantPlugin.handleEnchant(item, enchant, lvl);
for (EnchantPlugin enchantPlugin : MMOItems.plugin.getEnchantPlugins()) {
final Object custom = enchantPlugin.transfer(enchant);
if (custom != null) {
enchantPlugin.handleEnchant(item, custom, lvl);
break;
}
}
}
// Apply tags
@ -509,8 +513,8 @@ public class Enchants extends ItemStat<RandomEnchantListData, EnchantListData> i
// Check for custom enchants
for (EnchantPlugin enchPlugin : MMOItems.plugin.getEnchantPlugins()) {
Enchantment checked = Enchantment.getByKey(enchPlugin.getNamespacedKey(key));
if (checked != null) return checked;
enchant = Enchantment.getByKey(enchPlugin.getNamespacedKey(key));
if (enchant != null) return enchant;
}
// Last try, vanilla enchant with name

View File

@ -4,7 +4,7 @@ main: net.Indyuce.mmoitems.MMOItems
author: Indyuce
description: ${project.description}
depend: [MythicLib]
softdepend: [WorldGuard,Residence,BossShopPro,Fabled,SkillsPro,MMOCore,MMOProfiles,MythicMobs,MMOInventory,PlaceholderAPI,Vault,Denizen,AureliumSkills,AuraSkills]
softdepend: [WorldGuard,Residence,BossShopPro,Fabled,SkillsPro,MMOCore,MMOProfiles,MythicMobs,MMOInventory,PlaceholderAPI,Vault,Denizen,AureliumSkills,AuraSkills,MythicEnchants]
api-version: 1.14
website: www.phoenixdevt.fr
commands: