mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-03-11 13:11:50 +01:00
New API for enchant plugins
This commit is contained in:
parent
dd0fb95cd2
commit
78cec9d144
Binary file not shown.
2
pom.xml
2
pom.xml
@ -312,7 +312,7 @@
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost</groupId>
|
||||
<artifactId>HolographicDisplays</artifactId>
|
||||
<version>6.9.1</version>
|
||||
<version>2.4.8</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/HolographicDisplays.jar</systemPath>
|
||||
</dependency>
|
||||
|
@ -17,6 +17,7 @@ import net.Indyuce.mmoitems.api.util.message.FFPMMOItems;
|
||||
import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot;
|
||||
import net.Indyuce.mmoitems.comp.*;
|
||||
import net.Indyuce.mmoitems.comp.eco.VaultSupport;
|
||||
import net.Indyuce.mmoitems.comp.enchants.EnchantPlugin;
|
||||
import net.Indyuce.mmoitems.comp.flags.DefaultFlags;
|
||||
import net.Indyuce.mmoitems.comp.flags.FlagPlugin;
|
||||
import net.Indyuce.mmoitems.comp.flags.ResidenceFlags;
|
||||
@ -27,7 +28,7 @@ import net.Indyuce.mmoitems.comp.itemglow.ItemGlowListener;
|
||||
import net.Indyuce.mmoitems.comp.itemglow.NoGlowListener;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.MMOCoreMMOLoader;
|
||||
import net.Indyuce.mmoitems.comp.mmoinventory.MMOInventorySupport;
|
||||
import net.Indyuce.mmoitems.comp.mythicenchants.MythicEnchantsSupport;
|
||||
import net.Indyuce.mmoitems.comp.enchants.MythicEnchantsSupport;
|
||||
import net.Indyuce.mmoitems.comp.mythicmobs.LootsplosionListener;
|
||||
import net.Indyuce.mmoitems.comp.mythicmobs.MythicMobsLoader;
|
||||
import net.Indyuce.mmoitems.comp.parse.IridescentParser;
|
||||
@ -79,6 +80,7 @@ public class MMOItems extends LuminePlugin {
|
||||
private final ItemManager itemManager = new ItemManager();
|
||||
private final PlayerInventoryHandler inventory = new PlayerInventoryHandler();
|
||||
private final List<StringInputParser> stringInputParsers = new ArrayList<>();
|
||||
private final List<EnchantPlugin> enchantPlugins = new ArrayList<>();
|
||||
|
||||
private DropTableManager dropTableManager;
|
||||
private WorldGenManager worldGenManager;
|
||||
@ -95,7 +97,6 @@ public class MMOItems extends LuminePlugin {
|
||||
private HologramSupport hologramSupport;
|
||||
private VaultSupport vaultSupport;
|
||||
private RPGHandler rpgPlugin;
|
||||
private MythicEnchantsSupport mythicEnchantsSupport;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
@ -136,9 +137,9 @@ public class MMOItems extends LuminePlugin {
|
||||
if (Bukkit.getPluginManager().getPlugin("AdvancedEnchantments") != null) {
|
||||
statManager.register(AdvancedEnchantmentsHook.ADVANCED_ENCHANTMENTS); }
|
||||
if (Bukkit.getPluginManager().getPlugin("MythicEnchants") != null)
|
||||
mythicEnchantsSupport = new MythicEnchantsSupport();
|
||||
|
||||
enchantPlugins.add(new MythicEnchantsSupport());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
|
||||
@ -447,6 +448,19 @@ public class MMOItems extends LuminePlugin {
|
||||
getInventory().register(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugins like MythicEnchants which utilize the Bukkit
|
||||
* class Enchantment by extending it don't use any ItemStat
|
||||
* to store their enchants and therefore need to be called
|
||||
* to update the item lore when any item is built.
|
||||
*
|
||||
* @param enchantPlugin Enchantment plugin
|
||||
*/
|
||||
public void registerEnchantPlugin(EnchantPlugin enchantPlugin) {
|
||||
Validate.notNull(enchantPlugin, "Enchant plugin cannot be null");
|
||||
enchantPlugins.add(enchantPlugin);
|
||||
}
|
||||
|
||||
public StatManager getStats() {
|
||||
return statManager;
|
||||
}
|
||||
@ -498,6 +512,7 @@ public class MMOItems extends LuminePlugin {
|
||||
public HologramSupport getHolograms() {
|
||||
return hologramSupport;
|
||||
}
|
||||
|
||||
public EquipListener getEquipListener(){
|
||||
return equipListener;
|
||||
}
|
||||
@ -522,9 +537,9 @@ public class MMOItems extends LuminePlugin {
|
||||
return vaultSupport != null && vaultSupport.getPermissions() != null;
|
||||
}
|
||||
|
||||
public MythicEnchantsSupport getMythicEnchantsSupport(){
|
||||
return mythicEnchantsSupport;
|
||||
}
|
||||
public List<EnchantPlugin> getEnchantPlugins() {
|
||||
return enchantPlugins;
|
||||
}
|
||||
|
||||
public boolean hasEconomy() {
|
||||
return vaultSupport != null && vaultSupport.getEconomy() != null;
|
||||
|
@ -34,221 +34,253 @@ import java.util.UUID;
|
||||
|
||||
public class GemStone extends UseItem {
|
||||
|
||||
public GemStone(Player player, NBTItem item) {
|
||||
super(player, item);
|
||||
}
|
||||
public GemStone(Player player, NBTItem item) {
|
||||
super(player, item);
|
||||
}
|
||||
|
||||
@NotNull public ApplyResult applyOntoItem(@NotNull NBTItem target, @NotNull Type targetType) {
|
||||
@NotNull
|
||||
public ApplyResult applyOntoItem(@NotNull NBTItem target, @NotNull Type targetType) {
|
||||
|
||||
/*
|
||||
* Entirely loads the MMOItem and checks if it has the required empty
|
||||
* socket for the gem
|
||||
*/
|
||||
MMOItem targetMMO = new LiveMMOItem(target);
|
||||
return applyOntoItem(targetMMO, targetType, MMOUtils.getDisplayName(target.getItem()), true, false);
|
||||
}
|
||||
/*
|
||||
* Entirely loads the MMOItem and checks if it has the required empty
|
||||
* socket for the gem
|
||||
*/
|
||||
MMOItem targetMMO = new LiveMMOItem(target);
|
||||
return applyOntoItem(targetMMO, targetType, MMOUtils.getDisplayName(target.getItem()), true, false);
|
||||
}
|
||||
|
||||
@NotNull public ApplyResult applyOntoItem(@NotNull MMOItem targetMMO, @NotNull Type targetType, @NotNull String itemName, boolean buildStack, boolean silent){
|
||||
@NotNull
|
||||
public ApplyResult applyOntoItem(@NotNull MMOItem targetMMO, @NotNull Type targetType, @NotNull String itemName, boolean buildStack, boolean silent) {
|
||||
|
||||
if (!targetMMO.hasData(ItemStats.GEM_SOCKETS))
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
if (!targetMMO.hasData(ItemStats.GEM_SOCKETS))
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
|
||||
String gemType = getNBTItem().getString(ItemStats.GEM_COLOR.getNBTPath());
|
||||
String gemType = getNBTItem().getString(ItemStats.GEM_COLOR.getNBTPath());
|
||||
|
||||
GemSocketsData sockets = (GemSocketsData) targetMMO.getData(ItemStats.GEM_SOCKETS);
|
||||
String foundSocketColor = sockets.getEmptySocket(gemType);
|
||||
if (foundSocketColor == null)
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
GemSocketsData sockets = (GemSocketsData) targetMMO.getData(ItemStats.GEM_SOCKETS);
|
||||
String foundSocketColor = sockets.getEmptySocket(gemType);
|
||||
if (foundSocketColor == null)
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
|
||||
/*
|
||||
* Checks if the gem supports the item type, or the item set, or a
|
||||
* weapon
|
||||
*/
|
||||
String appliableTypes = getNBTItem().getString(ItemStats.ITEM_TYPE_RESTRICTION.getNBTPath());
|
||||
if (!appliableTypes.equals("") && (!targetType.isWeapon() || !appliableTypes.contains("WEAPON"))
|
||||
&& !appliableTypes.contains(targetType.getItemSet().name()) && !appliableTypes.contains(targetType.getId()))
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
/*
|
||||
* Checks if the gem supports the item type, or the item set, or a
|
||||
* weapon
|
||||
*/
|
||||
String appliableTypes = getNBTItem().getString(ItemStats.ITEM_TYPE_RESTRICTION.getNBTPath());
|
||||
if (!appliableTypes.equals("") && (!targetType.isWeapon() || !appliableTypes.contains("WEAPON"))
|
||||
&& !appliableTypes.contains(targetType.getItemSet().name()) && !appliableTypes.contains(targetType.getId()))
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
|
||||
// check for success rate
|
||||
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
|
||||
if (successRate != 0 && RANDOM.nextDouble() > successRate / 100) {
|
||||
// check for success rate
|
||||
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
|
||||
if (successRate != 0 && RANDOM.nextDouble() > successRate / 100) {
|
||||
|
||||
if (!silent) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||
Message.GEM_STONE_BROKE.format(ChatColor.RED, "#gem#", MMOUtils.getDisplayName(getItem()), "#item#", itemName).send(player); }
|
||||
if (!silent) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||
Message.GEM_STONE_BROKE.format(ChatColor.RED, "#gem#", MMOUtils.getDisplayName(getItem()), "#item#", itemName).send(player);
|
||||
}
|
||||
|
||||
return new ApplyResult(ResultType.FAILURE);
|
||||
}
|
||||
return new ApplyResult(ResultType.FAILURE);
|
||||
}
|
||||
|
||||
ApplyGemStoneEvent called = new ApplyGemStoneEvent(playerData, mmoitem, targetMMO);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
ApplyGemStoneEvent called = new ApplyGemStoneEvent(playerData, mmoitem, targetMMO);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
|
||||
/*
|
||||
* To not clear enchantments put by players
|
||||
*/
|
||||
Enchants.separateEnchantments(targetMMO);
|
||||
/*
|
||||
* To not clear enchantments put by players
|
||||
*/
|
||||
Enchants.separateEnchantments(targetMMO);
|
||||
|
||||
/*
|
||||
* Gem stone can be successfully applied. apply stats then abilities and
|
||||
* permanent effects. also REGISTER gem stone in the item gem stone
|
||||
* list.
|
||||
*/
|
||||
LiveMMOItem gemMMOItem = new LiveMMOItem(getNBTItem());
|
||||
GemstoneData gemData = new GemstoneData(gemMMOItem, foundSocketColor);
|
||||
/*
|
||||
* Gem stone can be successfully applied. apply stats then abilities and
|
||||
* permanent effects. also REGISTER gem stone in the item gem stone
|
||||
* list.
|
||||
*/
|
||||
LiveMMOItem gemMMOItem = new LiveMMOItem(getNBTItem());
|
||||
GemstoneData gemData = new GemstoneData(gemMMOItem, foundSocketColor);
|
||||
|
||||
/*
|
||||
* Now must apply the gem sockets data to the Stat History and then recalculate.
|
||||
*
|
||||
* Gotta, however, find the correct StatData to which apply it to. Damn this can
|
||||
* be pretty complicated!
|
||||
*/
|
||||
StatHistory gemStory = StatHistory.from(targetMMO, ItemStats.GEM_SOCKETS);
|
||||
/*
|
||||
* Now must apply the gem sockets data to the Stat History and then recalculate.
|
||||
*
|
||||
* Gotta, however, find the correct StatData to which apply it to. Damn this can
|
||||
* be pretty complicated!
|
||||
*/
|
||||
StatHistory gemStory = StatHistory.from(targetMMO, ItemStats.GEM_SOCKETS);
|
||||
|
||||
// Original?
|
||||
if (((GemSocketsData) gemStory.getOriginalData()).getEmptySocket(gemType) != null) {
|
||||
//UPGRD//MMOItems.log("\u00a77Applied Gemstone @\u00a76Original\u00a77: \u00a73" + foundSocketColor);
|
||||
// Original?
|
||||
if (((GemSocketsData) gemStory.getOriginalData()).getEmptySocket(gemType) != null) {
|
||||
//UPGRD//MMOItems.log("\u00a77Applied Gemstone @\u00a76Original\u00a77: \u00a73" + foundSocketColor);
|
||||
|
||||
// Charmer
|
||||
((GemSocketsData) gemStory.getOriginalData()).apply(gemType, gemData);
|
||||
// Charmer
|
||||
((GemSocketsData) gemStory.getOriginalData()).apply(gemType, gemData);
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
// Check Gem gems are not supported >:l. Check the modifiers ig
|
||||
boolean success = false;
|
||||
for (UUID uid : gemStory.getAllModifiers()) {
|
||||
// Check Gem gems are not supported >:l. Check the modifiers ig
|
||||
boolean success = false;
|
||||
for (UUID uid : gemStory.getAllModifiers()) {
|
||||
|
||||
// Get that gem
|
||||
GemSocketsData registeredGemData = (GemSocketsData) gemStory.getModifiersBonus(uid);
|
||||
if (registeredGemData != null) {
|
||||
// Get that gem
|
||||
GemSocketsData registeredGemData = (GemSocketsData) gemStory.getModifiersBonus(uid);
|
||||
if (registeredGemData != null) {
|
||||
|
||||
if (registeredGemData.getEmptySocket(gemType) != null) {
|
||||
//UPGRD//MMOItems.log("\u00a77Applied Gemstone @\u00a76Gemstone\u00a77: \u00a73" + foundSocketColor);
|
||||
if (registeredGemData.getEmptySocket(gemType) != null) {
|
||||
//UPGRD//MMOItems.log("\u00a77Applied Gemstone @\u00a76Gemstone\u00a77: \u00a73" + foundSocketColor);
|
||||
|
||||
// Charmer
|
||||
success = true;
|
||||
registeredGemData.apply(gemType, gemData);
|
||||
} } }
|
||||
// Charmer
|
||||
success = true;
|
||||
registeredGemData.apply(gemType, gemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (!success) {
|
||||
|
||||
for (StatData extraneousGem : gemStory.getExternalData()) {
|
||||
for (StatData extraneousGem : gemStory.getExternalData()) {
|
||||
|
||||
// Get that gem
|
||||
GemSocketsData registeredGemData = (GemSocketsData) extraneousGem;
|
||||
if (registeredGemData == null) { continue; }
|
||||
// Get that gem
|
||||
GemSocketsData registeredGemData = (GemSocketsData) extraneousGem;
|
||||
if (registeredGemData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (registeredGemData.getEmptySocket(gemType) != null) {
|
||||
//UPGRD//MMOItems.log("\u00a77Applied Gemstone @\u00a76External\u00a77: \u00a73" + foundSocketColor);
|
||||
if (registeredGemData.getEmptySocket(gemType) != null) {
|
||||
//UPGRD//MMOItems.log("\u00a77Applied Gemstone @\u00a76External\u00a77: \u00a73" + foundSocketColor);
|
||||
|
||||
// Charmer
|
||||
registeredGemData.apply(gemType, gemData); break; } } } }
|
||||
// Charmer
|
||||
registeredGemData.apply(gemType, gemData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recalculate
|
||||
//HSY//MMOItems.log(" \u00a73-\u00a7a- \u00a77Gem Application Recalculation \u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-");
|
||||
targetMMO.setData(ItemStats.GEM_SOCKETS, gemStory.recalculate(targetMMO.getUpgradeLevel()));
|
||||
//UPGRD//MMOItems.log("Applied Gemstone: \u00a73" + foundSocketColor);
|
||||
// Recalculate
|
||||
//HSY//MMOItems.log(" \u00a73-\u00a7a- \u00a77Gem Application Recalculation \u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-");
|
||||
targetMMO.setData(ItemStats.GEM_SOCKETS, gemStory.recalculate(targetMMO.getUpgradeLevel()));
|
||||
//UPGRD//MMOItems.log("Applied Gemstone: \u00a73" + foundSocketColor);
|
||||
|
||||
/*
|
||||
* Get the item's level, important for the GemScalingStat
|
||||
*/
|
||||
Integer levelIdentified = null; String scaling = GemUpgradeScaling.defaultValue;
|
||||
if (gemMMOItem.hasData(ItemStats.GEM_UPGRADE_SCALING)) { scaling = gemMMOItem.getData(ItemStats.GEM_UPGRADE_SCALING).toString(); }
|
||||
//UPGRD//MMOItems.log("Scaling Identified: \u00a73" + scaling);
|
||||
switch (scaling) {
|
||||
case GemUpgradeScaling.HISTORIC:
|
||||
levelIdentified = 0;
|
||||
break;
|
||||
case GemUpgradeScaling.SUBSEQUENT:
|
||||
levelIdentified = targetMMO.getUpgradeLevel();
|
||||
break;
|
||||
case GemUpgradeScaling.NEVER:
|
||||
default: break; }
|
||||
/*
|
||||
* Get the item's level, important for the GemScalingStat
|
||||
*/
|
||||
Integer levelIdentified = null;
|
||||
String scaling = GemUpgradeScaling.defaultValue;
|
||||
if (gemMMOItem.hasData(ItemStats.GEM_UPGRADE_SCALING)) {
|
||||
scaling = gemMMOItem.getData(ItemStats.GEM_UPGRADE_SCALING).toString();
|
||||
}
|
||||
//UPGRD//MMOItems.log("Scaling Identified: \u00a73" + scaling);
|
||||
switch (scaling) {
|
||||
case GemUpgradeScaling.HISTORIC:
|
||||
levelIdentified = 0;
|
||||
break;
|
||||
case GemUpgradeScaling.SUBSEQUENT:
|
||||
levelIdentified = targetMMO.getUpgradeLevel();
|
||||
break;
|
||||
case GemUpgradeScaling.NEVER:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
gemData.setLevel(levelIdentified);
|
||||
//UPGRD//MMOItems.log("Set Level: \u00a7b" + gemData.getLevel());
|
||||
/*
|
||||
* Only applies NON PROPER and MERGEABLE item stats
|
||||
*/
|
||||
for (ItemStat stat : gemMMOItem.getStats()) {
|
||||
gemData.setLevel(levelIdentified);
|
||||
//UPGRD//MMOItems.log("Set Level: \u00a7b" + gemData.getLevel());
|
||||
/*
|
||||
* Only applies NON PROPER and MERGEABLE item stats
|
||||
*/
|
||||
for (ItemStat stat : gemMMOItem.getStats()) {
|
||||
|
||||
// If it is not PROPER
|
||||
if (!(stat instanceof GemStoneStat)) {
|
||||
// If it is not PROPER
|
||||
if (!(stat instanceof GemStoneStat)) {
|
||||
|
||||
// Get the stat data
|
||||
StatData data = gemMMOItem.getData(stat);
|
||||
// Get the stat data
|
||||
StatData data = gemMMOItem.getData(stat);
|
||||
|
||||
// If the data is MERGEABLE
|
||||
if (data instanceof Mergeable) {
|
||||
//UPGRD//MMOItems.log("\u00a79>>> \u00a77Gem-Merging \u00a7c" + stat.getNBTPath());
|
||||
// If the data is MERGEABLE
|
||||
if (data instanceof Mergeable) {
|
||||
//UPGRD//MMOItems.log("\u00a79>>> \u00a77Gem-Merging \u00a7c" + stat.getNBTPath());
|
||||
|
||||
// Merge into it
|
||||
targetMMO.mergeData(stat, data, gemData.getHistoricUUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Merge into it
|
||||
targetMMO.mergeData(stat, data, gemData.getHistoricUUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!silent) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
Message.GEM_STONE_APPLIED.format(ChatColor.YELLOW, "#gem#", MMOUtils.getDisplayName(getItem()), "#item#", itemName).send(player); }
|
||||
if (!silent) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
Message.GEM_STONE_APPLIED.format(ChatColor.YELLOW, "#gem#", MMOUtils.getDisplayName(getItem()), "#item#", itemName).send(player);
|
||||
}
|
||||
|
||||
if (buildStack) {
|
||||
return new ApplyResult(targetMMO.newBuilder().build());
|
||||
if (buildStack) {
|
||||
return new ApplyResult(targetMMO.newBuilder().build());
|
||||
|
||||
} else { return new ApplyResult(targetMMO, ResultType.SUCCESS); }
|
||||
}
|
||||
} else {
|
||||
return new ApplyResult(targetMMO, ResultType.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApplyResult {
|
||||
@NotNull private final ResultType type;
|
||||
@Nullable private final ItemStack result;
|
||||
@Nullable private final MMOItem resultAsMMOItem;
|
||||
public static class ApplyResult {
|
||||
@NotNull
|
||||
private final ResultType type;
|
||||
@Nullable
|
||||
private final ItemStack result;
|
||||
@Nullable
|
||||
private final MMOItem resultAsMMOItem;
|
||||
|
||||
public ApplyResult(@NotNull ResultType type) {
|
||||
this((ItemStack) null, type);
|
||||
}
|
||||
public ApplyResult(@NotNull ResultType type) {
|
||||
this((ItemStack) null, type);
|
||||
}
|
||||
|
||||
public ApplyResult(@Nullable ItemStack result) { this(result, ResultType.SUCCESS); }
|
||||
public ApplyResult(@Nullable ItemStack result) {
|
||||
this(result, ResultType.SUCCESS);
|
||||
}
|
||||
|
||||
public ApplyResult(@Nullable ItemStack result, @NotNull ResultType type) {
|
||||
this.type = type;
|
||||
this.result = result;
|
||||
this.resultAsMMOItem = null;
|
||||
}
|
||||
public ApplyResult(@Nullable MMOItem result, @NotNull ResultType type) {
|
||||
this.type = type;
|
||||
this.result = null;
|
||||
this.resultAsMMOItem = result;
|
||||
}
|
||||
public ApplyResult(@Nullable ItemStack result, @NotNull ResultType type) {
|
||||
this.type = type;
|
||||
this.result = result;
|
||||
this.resultAsMMOItem = null;
|
||||
}
|
||||
|
||||
@NotNull public ResultType getType() {
|
||||
return type;
|
||||
}
|
||||
public ApplyResult(@Nullable MMOItem result, @NotNull ResultType type) {
|
||||
this.type = type;
|
||||
this.result = null;
|
||||
this.resultAsMMOItem = result;
|
||||
}
|
||||
|
||||
@Nullable public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
@Nullable public MMOItem getResultAsMMOItem() { return resultAsMMOItem; }
|
||||
}
|
||||
@NotNull
|
||||
public ResultType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public enum ResultType {
|
||||
/*
|
||||
* when the gem stone is not successfully applied onto the item and when
|
||||
* it needs to be destroyed
|
||||
*/
|
||||
FAILURE,
|
||||
@Nullable
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* when a gem stone, for some reason, cannot be applied onto an item (if
|
||||
* it has no more empty gem socket), but when the gem must not be
|
||||
* destroyed
|
||||
*/
|
||||
NONE,
|
||||
@Nullable
|
||||
public MMOItem getResultAsMMOItem() {
|
||||
return resultAsMMOItem;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* when a gem stone is successfully applied onto an item without any
|
||||
* error
|
||||
*/
|
||||
SUCCESS
|
||||
}
|
||||
public enum ResultType {
|
||||
|
||||
/**
|
||||
* The gem stone is not successfully applied
|
||||
* onto the item and NEEDS to be destroyed
|
||||
*/
|
||||
FAILURE,
|
||||
|
||||
/**
|
||||
* The gem stone cannot be applied onto an item but the gem
|
||||
* MUST NOT be destroyed. Used when there are no available
|
||||
* gem sockets left or when the apply event is canceled.
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* Gem stone is successfully applied and can be consumed
|
||||
*/
|
||||
SUCCESS
|
||||
}
|
||||
}
|
||||
|
@ -223,28 +223,9 @@ public class ItemStackBuilder {
|
||||
lore.insert("lore", parsed);
|
||||
}
|
||||
|
||||
// Calculate item lore
|
||||
// Calculate and apply item lore
|
||||
List<String> builtLore = lore.build();
|
||||
|
||||
// TODO generalize this to all enchants plugins, not only MythicEnchants
|
||||
if (MMOItems.plugin.getMythicEnchantsSupport() != null && mmoitem.hasData(ItemStats.ENCHANTS)) {
|
||||
ItemStack metaItem = item.clone();
|
||||
ItemMeta meta = metaItem.getItemMeta();
|
||||
meta.setLore(builtLore);
|
||||
metaItem.setItemMeta(meta);
|
||||
|
||||
EnchantListData data = (EnchantListData) mmoitem.getData(ItemStats.ENCHANTS);
|
||||
for (Enchantment enchant : data.getEnchants()) {
|
||||
int lvl = data.getLevel(enchant);
|
||||
if (lvl != 0 && enchant instanceof MythicEnchant)
|
||||
MMOItems.plugin.getMythicEnchantsSupport().handleEnchant(metaItem, enchant, lvl);
|
||||
}
|
||||
builtLore = metaItem.getItemMeta().getLore();
|
||||
}
|
||||
|
||||
// Apply item lore
|
||||
meta.setLore(builtLore);
|
||||
|
||||
/*
|
||||
* Save dynamic lore for later calculations. Not used anymore, but
|
||||
* kept in case we need to roll back the lore update change.
|
||||
|
@ -34,6 +34,16 @@ public class LoreBuilder {
|
||||
lore.addAll(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by custom enchantment plugins to add enchant display to item lore.
|
||||
*
|
||||
* @param index Index of insertion
|
||||
* @param element String to insert
|
||||
*/
|
||||
public void insert(int index, String element) {
|
||||
lore.add(index, element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a list of strings in the item lore. The lines are added only if a
|
||||
* line #item-stat-id# can be found in the lore format.
|
||||
|
@ -0,0 +1,26 @@
|
||||
package net.Indyuce.mmoitems.comp.enchants;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public interface EnchantPlugin<T extends Enchantment> {
|
||||
|
||||
/**
|
||||
* @param enchant Enchant being checked
|
||||
* @return If this enchant plugin handles a given enchant
|
||||
*/
|
||||
public boolean isCustomEnchant(Enchantment enchant);
|
||||
|
||||
/**
|
||||
* Called when an item is built. This should be used to add the enchantment
|
||||
* lines to the item lore or add any item tag required by the enchantment.
|
||||
*
|
||||
* @param builder Item being built
|
||||
* @param enchant Enchantment being applied
|
||||
* @param level Enchant level
|
||||
*/
|
||||
public void handleEnchant(ItemStackBuilder builder, T enchant, int level);
|
||||
|
||||
public NamespacedKey getNamespacedKey(String key);
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package net.Indyuce.mmoitems.comp.enchants;
|
||||
|
||||
import io.lumine.mythicenchants.MythicEnchants;
|
||||
import io.lumine.mythicenchants.enchants.MythicEnchant;
|
||||
import io.lumine.mythicenchants.util.LoreParser;
|
||||
import io.lumine.mythicenchants.util.MythicEnchantsHelper;
|
||||
import io.lumine.xikage.mythicmobs.adapters.AbstractPlayer;
|
||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.black_ixx.bossshop.misc.Enchant;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MythicEnchantsSupport implements EnchantPlugin<MythicEnchant> {
|
||||
|
||||
public void reparseWeapon(AbstractPlayer player) {
|
||||
MythicEnchantsHelper.reparseWeapon(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomEnchant(Enchantment enchant) {
|
||||
return enchant instanceof MythicEnchant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getNamespacedKey(String key) {
|
||||
return new NamespacedKey(MythicEnchants.inst(), key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete copy and paste of the class {@link MythicEnchant#applyToItem(ItemStack, int)}
|
||||
* because that method takes as parameter a fully generated item and updates its meta.
|
||||
* Since meta is being generated in parallel to the itemStack in MMOItems, we need
|
||||
* to update its lore manually.
|
||||
*/
|
||||
public void handleEnchant(ItemStackBuilder builder, MythicEnchant enchant, int level) {
|
||||
Validate.isTrue(level > 0, "Level must be strictly positive");
|
||||
|
||||
// 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));
|
||||
|
||||
if (builder.getItemStack().getType() == Material.ENCHANTED_BOOK) {
|
||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) builder.getMeta();
|
||||
|
||||
if (!builder.getMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS))
|
||||
builder.getLore().insert(0, LoreParser.formatEnchantment(enchant, level));
|
||||
|
||||
/* lvl = (Integer)this.getEnchantManager().getMythicEnchants(item).getOrDefault(this, 0);
|
||||
if (lvl > 0) {
|
||||
((List)lore).remove(LoreParser.formatEnchantment(this, lvl));
|
||||
}*/
|
||||
|
||||
// Now handled in the Enchants item stat
|
||||
// meta.addStoredEnchant(this, level, true);
|
||||
} else {
|
||||
/*lvl = (Integer)this.getEnchantManager().getMythicEnchants(item).getOrDefault(this, 0);
|
||||
if (lvl > 0) {
|
||||
((List)lore).remove(LoreParser.formatEnchantment(this, lvl));
|
||||
}*/
|
||||
|
||||
if (!builder.getMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS))
|
||||
builder.getLore().insert(0, LoreParser.formatEnchantment(enchant, level));
|
||||
|
||||
// Now handled in the Enchants stat
|
||||
// item.addUnsafeEnchantment(this, level);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package net.Indyuce.mmoitems.comp.mythicenchants;
|
||||
|
||||
import io.lumine.mythicenchants.enchants.MythicEnchant;
|
||||
import io.lumine.mythicenchants.util.MythicEnchantsHelper;
|
||||
import io.lumine.xikage.mythicmobs.adapters.AbstractPlayer;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class MythicEnchantsSupport {
|
||||
public MythicEnchantsSupport() {}
|
||||
|
||||
public void reparseWeapon(AbstractPlayer player) {
|
||||
MythicEnchantsHelper.reparseWeapon(player);
|
||||
}
|
||||
|
||||
public boolean handleEnchant(ItemStack item, Enchantment enchant, int level) {
|
||||
if(enchant instanceof MythicEnchant) {
|
||||
((MythicEnchant)enchant).applyToItem(item, level);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -28,9 +28,12 @@ public class EnchantListData implements StatData, Mergeable {
|
||||
return enchants.get(enchant);
|
||||
}
|
||||
|
||||
public void addEnchant(Enchantment enchant, int level) {
|
||||
enchants.put(enchant, level);
|
||||
}
|
||||
public void addEnchant(Enchantment enchant, int level) {
|
||||
if (level == 0)
|
||||
enchants.remove(enchant);
|
||||
enchants.put(enchant, level);
|
||||
}
|
||||
|
||||
public void clear() { enchants.clear(); }
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user