mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-08 07:27:39 +01:00
Revision ID update. Enchantments, custom names, lores, soulbinding, gemstones AND upgrades
This commit is contained in:
parent
3f1dfc855e
commit
164ec172ce
35
src/main/java/net/Indyuce/mmoitems/api/ReforgeOptions.java
Normal file
35
src/main/java/net/Indyuce/mmoitems/api/ReforgeOptions.java
Normal file
@ -0,0 +1,35 @@
|
||||
package net.Indyuce.mmoitems.api;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class ReforgeOptions {
|
||||
private final boolean keepName, keepLore, keepEnchantments, keepModifications, keepSoulbind;
|
||||
|
||||
public ReforgeOptions(ConfigurationSection config) {
|
||||
this.keepName = config.getBoolean("display-name");
|
||||
this.keepLore = config.getBoolean("lore");
|
||||
this.keepEnchantments = config.getBoolean("enchantments");
|
||||
this.keepModifications = config.getBoolean("modifications");
|
||||
this.keepSoulbind = config.getBoolean("soulbound");
|
||||
}
|
||||
|
||||
public boolean shouldKeepName() {
|
||||
return keepName;
|
||||
}
|
||||
|
||||
public boolean shouldKeepLore() {
|
||||
return keepLore;
|
||||
}
|
||||
|
||||
public boolean shouldKeepEnchantments() {
|
||||
return keepEnchantments;
|
||||
}
|
||||
|
||||
public boolean shouldKeepModifications() {
|
||||
return keepModifications;
|
||||
}
|
||||
|
||||
public boolean shouldKeepSoulbind() {
|
||||
return keepSoulbind;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.api.util;
|
||||
import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ItemTier;
|
||||
import net.Indyuce.mmoitems.api.ReforgeOptions;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||
@ -11,24 +12,38 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||
import net.Indyuce.mmoitems.stat.Soulbound;
|
||||
import net.Indyuce.mmoitems.stat.data.DoubleData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.Indyuce.mmoitems.stat.type.Upgradable;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemModInstance {
|
||||
private final NBTItem nbtItem;
|
||||
private final int amount;
|
||||
private final Map<Enchantment, Integer> enchantments;
|
||||
|
||||
private final Map<ItemStat, StatData> itemData = new HashMap<>();
|
||||
|
||||
// Not initialized at first for performance reasons
|
||||
private MMOItem mmoItem;
|
||||
|
||||
private String cachedName;
|
||||
private List<String> cachedLore;
|
||||
private Map<Enchantment, Integer> cachedEnchants;
|
||||
private StatData cachedSoulbound;
|
||||
|
||||
public ItemModInstance(NBTItem nbt) {
|
||||
this.nbtItem = nbt;
|
||||
this.amount = nbt.getItem().getAmount();
|
||||
this.enchantments = nbt.getItem().getEnchantments();
|
||||
}
|
||||
|
||||
public void applySoulbound(Player p) {
|
||||
@ -40,8 +55,8 @@ public class ItemModInstance {
|
||||
mmoItem.setData(ItemStats.SOULBOUND, ((Soulbound) ItemStats.SOULBOUND).newSoulboundData(p.getUniqueId(), p.getName(), level));
|
||||
}
|
||||
|
||||
public void reforge(Player p) {
|
||||
reforge(p == null ? null : PlayerData.get(p).getRPG());
|
||||
public void reforge(Player p, ReforgeOptions options) {
|
||||
reforge(p == null ? null : PlayerData.get(p).getRPG(), options);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,9 +64,33 @@ public class ItemModInstance {
|
||||
* If empty, it will use the old items level
|
||||
* and tier, or default values if needed.
|
||||
*/
|
||||
public void reforge(RPGPlayer player) {
|
||||
public void reforge(RPGPlayer player, ReforgeOptions options) {
|
||||
loadVolatileMMOItem();
|
||||
MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplate(mmoItem.getType(), mmoItem.getId());
|
||||
|
||||
ItemMeta meta = nbtItem.getItem().getItemMeta();
|
||||
if(options.shouldKeepName() && meta.hasDisplayName()) cachedName = meta.getDisplayName();
|
||||
if(options.shouldKeepLore() && meta.hasLore()) cachedLore = meta.getLore();
|
||||
if(options.shouldKeepEnchantments()) cachedEnchants = nbtItem.getItem().getEnchantments();
|
||||
|
||||
if(options.shouldKeepModifications())
|
||||
for (ItemStat stat : mmoItem.getStats()) {
|
||||
if(stat instanceof Upgradable)
|
||||
itemData.put(stat, mmoItem.getData(stat));
|
||||
|
||||
if (!(stat instanceof GemStoneStat)) {
|
||||
StatData data = mmoItem.getData(stat);
|
||||
if (data instanceof Mergeable) {
|
||||
if(itemData.containsKey(stat))
|
||||
((Mergeable) itemData.get(stat)).merge(data);
|
||||
else itemData.put(stat, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(options.shouldKeepSoulbind() && mmoItem.hasData(ItemStats.SOULBOUND))
|
||||
cachedSoulbound = mmoItem.getData(ItemStats.SOULBOUND);
|
||||
|
||||
if (player == null) {
|
||||
final int iLevel = MMOItems.plugin.getConfig().getInt("item-revision.default-item-level", -1);
|
||||
int level = iLevel == -1 ? (mmoItem.hasData(ItemStats.ITEM_LEVEL) ? (int) ((DoubleData) mmoItem.getData(ItemStats.ITEM_LEVEL)).getValue() : 0) : iLevel;
|
||||
@ -65,9 +104,17 @@ public class ItemModInstance {
|
||||
}
|
||||
|
||||
public ItemStack toStack() {
|
||||
for(Map.Entry<ItemStat, StatData> data : itemData.entrySet())
|
||||
if (mmoItem.hasData(data.getKey())) ((Mergeable) mmoItem.getData(data.getKey())).merge(data.getValue());
|
||||
else mmoItem.setData(data.getKey(), data.getValue());
|
||||
if(cachedSoulbound != null) mmoItem.setData(ItemStats.SOULBOUND, cachedSoulbound);
|
||||
ItemStack stack = mmoItem.newBuilder().build();
|
||||
stack.setAmount(amount);
|
||||
stack.addUnsafeEnchantments(this.enchantments);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
if(cachedName != null) meta.setDisplayName(cachedName);
|
||||
if(cachedLore != null) meta.setLore(cachedLore);
|
||||
stack.setItemMeta(meta);
|
||||
if(cachedEnchants != null) stack.addUnsafeEnchantments(cachedEnchants);
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class ItemListener implements Listener {
|
||||
if (!nbt.hasType()) return null;
|
||||
ItemModInstance mod = new ItemModInstance(nbt);
|
||||
if (shouldUpdate(nbt, type))
|
||||
mod.reforge(MMOItems.plugin.getLanguage().rerollOnItemUpdate ? player : null);
|
||||
mod.reforge(MMOItems.plugin.getLanguage().rerollOnItemUpdate ? player : null, MMOItems.plugin.getLanguage().revisionOptions);
|
||||
if (shouldSoulbind(nbt, type)) mod.applySoulbound(player);
|
||||
return mod.hasChanges() ? mod.toStack() : null;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.manager;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.ReforgeOptions;
|
||||
import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.ability.Ability.CastingMode;
|
||||
import net.Indyuce.mmoitems.api.item.util.ConfigItem;
|
||||
@ -42,6 +43,7 @@ public class ConfigManager implements Reloadable {
|
||||
public DecimalFormat healIndicatorDecimalFormat, damageIndicatorDecimalFormat;
|
||||
public double dodgeKnockbackForce, soulboundBaseDamage, soulboundPerLvlDamage, levelSpread;
|
||||
public NumericStatFormula defaultItemCapacity;
|
||||
public ReforgeOptions revisionOptions;
|
||||
|
||||
/** DE-TAREAS: Implement reward system for good users? */
|
||||
@SuppressWarnings("unused")
|
||||
@ -215,6 +217,8 @@ public class ConfigManager implements Reloadable {
|
||||
rerollOnItemUpdate = MMOItems.plugin.getConfig().getBoolean("item-revision.reroll-when-updated");
|
||||
levelSpread = MMOItems.plugin.getConfig().getDouble("item-level-spread");
|
||||
|
||||
revisionOptions = new ReforgeOptions(MMOItems.plugin.getConfig().getConfigurationSection("item-revision.keep-data"));
|
||||
|
||||
try {
|
||||
defaultItemCapacity = new NumericStatFormula(MMOItems.plugin.getConfig().getConfigurationSection("default-item-capacity"));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
|
@ -264,9 +264,14 @@ item-revision:
|
||||
# Whether or not specific stats should be kept
|
||||
# when an item is updated to latest revision.
|
||||
keep-data:
|
||||
gemstones: true
|
||||
display-name: true
|
||||
lore: false # Warning, this prevents stats in the lore from updating visually!
|
||||
enchantments: true
|
||||
soulbound: true
|
||||
upgrades: true
|
||||
# Modifications are Gemstones and Upgrades
|
||||
# Please note that some stats will be unable to update
|
||||
# to the latest changes if you enable these.
|
||||
modifications: false
|
||||
# Here you can disable individual events for when
|
||||
# Items should update when a higher revision ID is found
|
||||
disable-on:
|
||||
|
Loading…
Reference in New Issue
Block a user