mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Fixed an issue with revid & item skins
This commit is contained in:
parent
33ba1828c4
commit
cc403091a7
@ -33,10 +33,9 @@ public class ItemSkin extends UseItem {
|
||||
if (targetType == Type.SKIN)
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
|
||||
if (MMOItems.plugin.getConfig().getBoolean("locked-skins") && target.getBoolean("MMOITEMS_HAS_SKIN")) {
|
||||
if (MMOItems.plugin.getConfig().getBoolean("locked-skins") && MMOUtils.isNonEmpty(target.getString(ItemSkin.SKIN_ID_TAG))) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
|
||||
Message.SKIN_REJECTED.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
||||
.send(player);
|
||||
Message.SKIN_REJECTED.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
}
|
||||
|
||||
@ -102,8 +101,6 @@ public class ItemSkin extends UseItem {
|
||||
return new ApplyResult(item);
|
||||
}
|
||||
|
||||
public static final String HAS_SKIN_TAG = "MMOITEMS_HAS_SKIN";
|
||||
|
||||
/**
|
||||
* When applying a skin to an item, the skin item ID is saved
|
||||
* in the target item so that if deskined, it can be retrieved
|
||||
@ -113,118 +110,67 @@ public class ItemSkin extends UseItem {
|
||||
|
||||
/**
|
||||
* Applies the skin information from a skin consumable onto any item.
|
||||
* <p>
|
||||
* This methods also works if the provided VolatileMMOItem matches an item
|
||||
* that already has a skin information stored inside of it, in which case it
|
||||
* will fetch the value of the {@link #SKIN_ID_TAG} nbttag.
|
||||
*
|
||||
* @param target Target item that the skin has been <b>successfully</b> applied to
|
||||
* @param skinItemMMO Skin consumable
|
||||
* @param target Target item that the skin has been <b>successfully</b> applied to
|
||||
* @param volSkin Skin consumable
|
||||
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
|
||||
* @deprecated Badly implemented. This handles individual stats and should use some SkinStat interface
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull VolatileMMOItem skinItemMMO) {
|
||||
final NBTItem skinItemNBT = skinItemMMO.getNBT();
|
||||
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull VolatileMMOItem volSkin) {
|
||||
final NBTItem nbtSkin = volSkin.getNBT();
|
||||
|
||||
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
|
||||
target.addTag(new ItemTag(SKIN_ID_TAG, skinItemNBT.getString("MMOITEMS_ITEM_ID")));
|
||||
if (skinItemNBT.getInteger("CustomModelData") != 0)
|
||||
target.addTag(new ItemTag("CustomModelData", skinItemNBT.getInteger("CustomModelData")));
|
||||
// Apply skin ID to new item
|
||||
@Nullable String appliedSkinId = volSkin.getNBT().getString(SKIN_ID_TAG);
|
||||
appliedSkinId = MMOUtils.isNonEmpty(appliedSkinId) ? appliedSkinId : nbtSkin.getString("MMOITEMS_ITEM_ID");
|
||||
target.addTag(new ItemTag(SKIN_ID_TAG, appliedSkinId));
|
||||
|
||||
if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
|
||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
|
||||
// Custom model data
|
||||
if (nbtSkin.getInteger("CustomModelData") != 0)
|
||||
target.addTag(new ItemTag("CustomModelData", nbtSkin.getInteger("CustomModelData")));
|
||||
|
||||
ItemStack item = target.toItem();
|
||||
if (item.getType() != skinItemNBT.getItem().getType())
|
||||
item.setType(skinItemNBT.getItem().getType());
|
||||
// Particles
|
||||
if (!nbtSkin.getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
|
||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", nbtSkin.getString("MMOITEMS_ITEM_PARTICLES")));
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta();
|
||||
final ItemStack item = target.toItem();
|
||||
if (item.getType() != nbtSkin.getItem().getType())
|
||||
item.setType(nbtSkin.getItem().getType());
|
||||
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
final ItemMeta skinMeta = nbtSkin.getItem().getItemMeta();
|
||||
if (skinMeta != null && meta != null) {
|
||||
|
||||
// TODO factorize with a ItemSkinStat stat interface
|
||||
// TODO SkinStat interface
|
||||
|
||||
// Unbreakable & durability
|
||||
if (skinMeta.isUnbreakable()) {
|
||||
meta.setUnbreakable(true);
|
||||
if (meta instanceof Damageable && skinMeta instanceof Damageable)
|
||||
((Damageable) meta).setDamage(((Damageable) skinMeta).getDamage());
|
||||
}
|
||||
|
||||
// Leather armor
|
||||
if (skinMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
|
||||
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) skinMeta).getColor());
|
||||
|
||||
if (skinItemMMO.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
|
||||
&& skinItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||
// Skull texture
|
||||
if (volSkin.hasData(ItemStats.SKULL_TEXTURE)
|
||||
&& item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
|
||||
&& nbtSkin.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial())
|
||||
try {
|
||||
Field profileField = meta.getClass().getDeclaredField("profile");
|
||||
final Field profileField = meta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta,
|
||||
((SkullTextureData) skinItemMMO.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
|
||||
((SkullTextureData) volSkin.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
|
||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||
MMOItems.plugin.getLogger().warning("Could not read skull texture");
|
||||
}
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a skin from one item to another
|
||||
*
|
||||
* @param target Target item that you are copying the skin onto
|
||||
* @param originalItemNBT Item with a skin already, as NBT. Operation will fail
|
||||
* if it doesnt have a skin.
|
||||
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
|
||||
* @author Gunging
|
||||
*/
|
||||
@Nullable
|
||||
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem originalItemNBT) {
|
||||
|
||||
// No skin no service
|
||||
if (!originalItemNBT.getBoolean(HAS_SKIN_TAG)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Copy over data
|
||||
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
|
||||
target.addTag(new ItemTag(SKIN_ID_TAG, originalItemNBT.getString("MMOITEMS_ITEM_ID")));
|
||||
if (originalItemNBT.getInteger("CustomModelData") != 0) {
|
||||
target.addTag(new ItemTag("CustomModelData", originalItemNBT.getInteger("CustomModelData")));
|
||||
}
|
||||
if (!originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
|
||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
|
||||
}
|
||||
|
||||
// ItemMeta values copy-over
|
||||
ItemStack item = target.toItem();
|
||||
if (item.getType() != originalItemNBT.getItem().getType()) {
|
||||
item.setType(originalItemNBT.getItem().getType());
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
ItemMeta originalMeta = originalItemNBT.getItem().getItemMeta();
|
||||
if (originalMeta != null && meta != null) {
|
||||
|
||||
if (originalMeta.isUnbreakable()) {
|
||||
meta.setUnbreakable(true);
|
||||
if (meta instanceof Damageable && originalMeta instanceof Damageable)
|
||||
((Damageable) meta).setDamage(((Damageable) originalMeta).getDamage());
|
||||
}
|
||||
|
||||
if (originalMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
|
||||
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) originalMeta).getColor());
|
||||
|
||||
VolatileMMOItem originalVolatile = new VolatileMMOItem(originalItemNBT);
|
||||
if (originalVolatile.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
|
||||
&& originalItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||
|
||||
try {
|
||||
Field profileField = meta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta,
|
||||
((SkullTextureData) originalVolatile.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
|
||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||
MMOItems.plugin.getLogger().warning("Could not read skull texture");
|
||||
}
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class ArrowParticlesEdition extends EditionInventory {
|
||||
|
||||
if (particle != null) {
|
||||
ConfigurationSection section = getEditedSection().getConfigurationSection("arrow-particles");
|
||||
if (ParticleData.isColorable(particle)) {
|
||||
if (MMOUtils.isColorable(particle)) {
|
||||
int red = section.getInt("color.red");
|
||||
int green = section.getInt("color.green");
|
||||
int blue = section.getInt("color.blue");
|
||||
|
@ -6,7 +6,6 @@ import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.edition.StatEdition;
|
||||
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
||||
import net.Indyuce.mmoitems.particle.api.ParticleType;
|
||||
import net.Indyuce.mmoitems.stat.data.ParticleData;
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import io.lumine.mythic.lib.api.util.AltChar;
|
||||
@ -103,7 +102,7 @@ public class ParticlesEdition extends EditionInventory {
|
||||
}
|
||||
}
|
||||
|
||||
if (ParticleData.isColorable(particle)) {
|
||||
if (MMOUtils.isColorable(particle)) {
|
||||
int red = getEditedSection().getInt("item-particles.color.red");
|
||||
int green = getEditedSection().getInt("item-particles.color.green");
|
||||
int blue = getEditedSection().getInt("item-particles.color.blue");
|
||||
|
@ -48,7 +48,7 @@ public class ArrowParticles extends ItemStat<ArrowParticlesData, ArrowParticlesD
|
||||
int amount = config.getInt("amount");
|
||||
double offset = config.getDouble("offset");
|
||||
|
||||
return ParticleData.isColorable(particle)
|
||||
return MMOUtils.isColorable(particle)
|
||||
? new ArrowParticlesData(particle, amount, offset, config.getInt("color.red"), config.getInt("color.green"),
|
||||
config.getInt("color.blue"))
|
||||
: new ArrowParticlesData(particle, amount, offset, config.getDouble("speed"));
|
||||
@ -105,7 +105,7 @@ public class ArrowParticles extends ItemStat<ArrowParticlesData, ArrowParticlesD
|
||||
double offset = json.get("Offset").getAsDouble();
|
||||
|
||||
// Ist it colorable'
|
||||
if (ParticleData.isColorable(particle)) {
|
||||
if (MMOUtils.isColorable(particle)) {
|
||||
|
||||
// Return as colourable
|
||||
return new ArrowParticlesData(particle, amount, offset, json.get("Red").getAsInt(), json.get("Green").getAsInt(), json.get("Blue").getAsInt());
|
||||
@ -187,7 +187,7 @@ public class ArrowParticles extends ItemStat<ArrowParticlesData, ArrowParticlesD
|
||||
lore.add(ChatColor.GRAY + "* Offset: " + ChatColor.WHITE + cast.getOffset());
|
||||
lore.add("");
|
||||
|
||||
if (ParticleData.isColorable(cast.getParticle()))
|
||||
if (MMOUtils.isColorable(cast.getParticle()))
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&',
|
||||
"&7* Color: &c&l" + cast.getRed() + "&7 - &a&l" + cast.getGreen() + "&7 - &9&l" + cast.getBlue()));
|
||||
else
|
||||
|
@ -7,6 +7,7 @@ import io.lumine.mythic.lib.api.util.SmartGive;
|
||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||
import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.interaction.ItemSkin;
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.interaction.Consumable;
|
||||
@ -38,15 +39,14 @@ public class CanDeskin extends BooleanStat implements ConsumableItemInteraction
|
||||
|
||||
@Override
|
||||
public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) {
|
||||
final String skinId = target.getString("MMOITEMS_SKIN_ID");
|
||||
final String skinId = target.getString(ItemSkin.SKIN_ID_TAG);
|
||||
Player player = playerData.getPlayer();
|
||||
|
||||
if (consumable.getNBTItem().getBoolean("MMOITEMS_CAN_DESKIN") && !skinId.isEmpty()) {
|
||||
|
||||
// Set target item to default skin
|
||||
String targetItemId = target.getString("MMOITEMS_ITEM_ID");
|
||||
target.removeTag("MMOITEMS_HAS_SKIN");
|
||||
target.removeTag("MMOITEMS_SKIN_ID");
|
||||
target.removeTag(ItemSkin.SKIN_ID_TAG);
|
||||
|
||||
MMOItemTemplate targetTemplate = MMOItems.plugin.getTemplates().getTemplateOrThrow(targetType, targetItemId);
|
||||
MMOItem originalMmoitem = targetTemplate.newBuilder(playerData.getRPG()).build();
|
||||
|
@ -6,12 +6,12 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
|
||||
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
|
||||
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
||||
import net.Indyuce.mmoitems.stat.data.DoubleData;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.InternalStat;
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -31,23 +31,22 @@ public class ItemLevel extends ItemStat<NumericStatFormula, DoubleData> implemen
|
||||
@Nullable
|
||||
@Override
|
||||
public NumericStatFormula whenInitialized(Object object) {
|
||||
// not supported
|
||||
return null;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
// not supported
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
// not supported
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<NumericStatFormula> statData) {
|
||||
// not supported
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -4,10 +4,8 @@ import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
|
||||
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
||||
import net.Indyuce.mmoitems.stat.data.SoulboundData;
|
||||
import net.Indyuce.mmoitems.stat.data.StoredTagsData;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
|
||||
import net.Indyuce.mmoitems.stat.type.InternalStat;
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
@ -22,6 +20,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* This is another fictive item stat that makes sure that all
|
||||
* the NBT tags from the previous item are transferred towards
|
||||
* the new item.
|
||||
*/
|
||||
public class StoredTags extends ItemStat<RandomStatData<StoredTagsData>, StoredTagsData> implements InternalStat, GemStoneStat {
|
||||
public StoredTags() {
|
||||
super("STORED_TAGS", VersionMaterial.OAK_SIGN.toMaterial(), "Stored Tags",
|
||||
|
@ -25,150 +25,151 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This is not really a stat data since abilities are always
|
||||
* stored as lists inside of items. This is more of a commonly
|
||||
* used utility class which defines the castable implementation
|
||||
* of the {@link Skill} interface for MMOItems.
|
||||
*/
|
||||
public class AbilityData extends Skill {
|
||||
private final RegisteredSkill ability;
|
||||
@NotNull private final Map<String, Double> modifiers = new HashMap<>();
|
||||
private final RegisteredSkill ability;
|
||||
@NotNull
|
||||
private final Map<String, Double> modifiers = new HashMap<>();
|
||||
|
||||
public AbilityData(@NotNull JsonObject object) {
|
||||
super(MMOUtils.backwardsCompatibleTriggerType(object.get("CastMode").getAsString()));
|
||||
public AbilityData(@NotNull JsonObject object) {
|
||||
super(MMOUtils.backwardsCompatibleTriggerType(object.get("CastMode").getAsString()));
|
||||
|
||||
ability = MMOItems.plugin.getSkills().getSkill(object.get("Id").getAsString());
|
||||
ability = MMOItems.plugin.getSkills().getSkill(object.get("Id").getAsString());
|
||||
|
||||
JsonObject modifiers = object.getAsJsonObject("Modifiers");
|
||||
modifiers.entrySet().forEach(entry -> setModifier(entry.getKey(), entry.getValue().getAsDouble()));
|
||||
}
|
||||
JsonObject modifiers = object.getAsJsonObject("Modifiers");
|
||||
modifiers.entrySet().forEach(entry -> setModifier(entry.getKey(), entry.getValue().getAsDouble()));
|
||||
}
|
||||
|
||||
public AbilityData(@NotNull ConfigurationSection config) {
|
||||
public AbilityData(@NotNull ConfigurationSection config) {
|
||||
super(MMOUtils.backwardsCompatibleTriggerType(UtilityMethods.enumName(Objects.requireNonNull(config.getString("mode"), "Ability is missing mode"))));
|
||||
|
||||
Validate.isTrue(config.contains("type"), "Ability is missing type");
|
||||
Validate.isTrue(config.contains("type"), "Ability is missing type");
|
||||
|
||||
String abilityFormat = UtilityMethods.enumName(config.getString("type"));
|
||||
Validate.isTrue(MMOItems.plugin.getSkills().hasSkill(abilityFormat), "Could not find ability called '" + abilityFormat + "'");
|
||||
ability = MMOItems.plugin.getSkills().getSkill(abilityFormat);
|
||||
String abilityFormat = UtilityMethods.enumName(config.getString("type"));
|
||||
Validate.isTrue(MMOItems.plugin.getSkills().hasSkill(abilityFormat), "Could not find ability called '" + abilityFormat + "'");
|
||||
ability = MMOItems.plugin.getSkills().getSkill(abilityFormat);
|
||||
|
||||
for (String key : config.getKeys(false))
|
||||
if (!key.equalsIgnoreCase("mode") && !key.equalsIgnoreCase("type") && ability.getHandler().getModifiers().contains(key))
|
||||
modifiers.put(key, config.getDouble(key));
|
||||
}
|
||||
for (String key : config.getKeys(false))
|
||||
if (!key.equalsIgnoreCase("mode") && !key.equalsIgnoreCase("type") && ability.getHandler().getModifiers().contains(key))
|
||||
modifiers.put(key, config.getDouble(key));
|
||||
}
|
||||
|
||||
public AbilityData(RegisteredSkill ability, TriggerType triggerType) {
|
||||
super(triggerType);
|
||||
public AbilityData(RegisteredSkill ability, TriggerType triggerType) {
|
||||
super(triggerType);
|
||||
|
||||
this.ability = ability;
|
||||
}
|
||||
this.ability = ability;
|
||||
}
|
||||
|
||||
public RegisteredSkill getAbility() {
|
||||
return ability;
|
||||
}
|
||||
public RegisteredSkill getAbility() {
|
||||
return ability;
|
||||
}
|
||||
|
||||
public Set<String> getModifiers() {
|
||||
return modifiers.keySet();
|
||||
}
|
||||
public Set<String> getModifiers() {
|
||||
return modifiers.keySet();
|
||||
}
|
||||
|
||||
public void setModifier(String path, double value) {
|
||||
// Validate.isTrue(getHandler().getModifiers().contains(path), "Could not find modifier called '" + path + "'");
|
||||
modifiers.put(path, value);
|
||||
}
|
||||
public void setModifier(String path, double value) {
|
||||
// Validate.isTrue(getHandler().getModifiers().contains(path), "Could not find modifier called '" + path + "'");
|
||||
modifiers.put(path, value);
|
||||
}
|
||||
|
||||
public boolean hasModifier(String path) {
|
||||
return modifiers.containsKey(path);
|
||||
}
|
||||
public boolean hasModifier(String path) {
|
||||
return modifiers.containsKey(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResult(SkillMetadata meta) {
|
||||
@Override
|
||||
public boolean getResult(SkillMetadata meta) {
|
||||
|
||||
PlayerData playerData = PlayerData.get(meta.getCaster().getData().getUniqueId());
|
||||
RPGPlayer rpgPlayer = playerData.getRPG();
|
||||
Player player = meta.getCaster().getPlayer();
|
||||
PlayerData playerData = PlayerData.get(meta.getCaster().getData().getUniqueId());
|
||||
RPGPlayer rpgPlayer = playerData.getRPG();
|
||||
Player player = meta.getCaster().getPlayer();
|
||||
|
||||
// Check for cooldown
|
||||
if (meta.getCaster().getData().getCooldownMap().isOnCooldown(this)) {
|
||||
CooldownInfo info = playerData.getMMOPlayerData().getCooldownMap().getInfo(this);
|
||||
if (!getTrigger().isSilent()) {
|
||||
StringBuilder progressBar = new StringBuilder(ChatColor.YELLOW + "");
|
||||
double progress = (double) (info.getInitialCooldown() - info.getRemaining()) / info.getInitialCooldown() * 10;
|
||||
String barChar = MMOItems.plugin.getConfig().getString("cooldown-progress-bar-char");
|
||||
for (int j = 0; j < 10; j++)
|
||||
progressBar.append(progress >= j ? ChatColor.GREEN : ChatColor.WHITE).append(barChar);
|
||||
Message.SPELL_ON_COOLDOWN.format(ChatColor.RED, "#left#", MythicLib.plugin.getMMOConfig().decimal.format(info.getRemaining() / 1000d), "#progress#",
|
||||
progressBar.toString(), "#s#", (info.getRemaining() > 1999 ? "s" : "")).send(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Check for cooldown
|
||||
if (meta.getCaster().getData().getCooldownMap().isOnCooldown(this)) {
|
||||
CooldownInfo info = playerData.getMMOPlayerData().getCooldownMap().getInfo(this);
|
||||
if (!getTrigger().isSilent()) {
|
||||
StringBuilder progressBar = new StringBuilder(ChatColor.YELLOW + "");
|
||||
double progress = (double) (info.getInitialCooldown() - info.getRemaining()) / info.getInitialCooldown() * 10;
|
||||
String barChar = MMOItems.plugin.getConfig().getString("cooldown-progress-bar-char");
|
||||
for (int j = 0; j < 10; j++)
|
||||
progressBar.append(progress >= j ? ChatColor.GREEN : ChatColor.WHITE).append(barChar);
|
||||
Message.SPELL_ON_COOLDOWN.format(ChatColor.RED, "#left#", MythicLib.plugin.getMMOConfig().decimal.format(info.getRemaining() / 1000d), "#progress#", progressBar.toString(), "#s#", (info.getRemaining() > 1999 ? "s" : "")).send(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for permission
|
||||
if (MMOItems.plugin.getConfig().getBoolean("permissions.abilities")
|
||||
&& !player.hasPermission("mmoitems.ability." + getHandler().getLowerCaseId())
|
||||
&& !player.hasPermission("mmoitems.bypass.ability"))
|
||||
return false;
|
||||
// Check for permission
|
||||
if (MMOItems.plugin.getConfig().getBoolean("permissions.abilities") && !player.hasPermission("mmoitems.ability." + getHandler().getLowerCaseId()) && !player.hasPermission("mmoitems.bypass.ability"))
|
||||
return false;
|
||||
|
||||
// Check for mana cost
|
||||
if (hasModifier("mana") && rpgPlayer.getMana() < getModifier("mana")) {
|
||||
Message.NOT_ENOUGH_MANA.format(ChatColor.RED).send(player);
|
||||
return false;
|
||||
}
|
||||
// Check for mana cost
|
||||
if (hasModifier("mana") && rpgPlayer.getMana() < getModifier("mana")) {
|
||||
Message.NOT_ENOUGH_MANA.format(ChatColor.RED).send(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for stamina cost
|
||||
if (hasModifier("stamina") && rpgPlayer.getStamina() < getModifier("stamina")) {
|
||||
Message.NOT_ENOUGH_STAMINA.format(ChatColor.RED).send(player);
|
||||
return false;
|
||||
}
|
||||
// Check for stamina cost
|
||||
if (hasModifier("stamina") && rpgPlayer.getStamina() < getModifier("stamina")) {
|
||||
Message.NOT_ENOUGH_STAMINA.format(ChatColor.RED).send(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenCast(SkillMetadata meta) {
|
||||
PlayerData playerData = PlayerData.get(meta.getCaster().getData().getUniqueId());
|
||||
RPGPlayer rpgPlayer = playerData.getRPG();
|
||||
@Override
|
||||
public void whenCast(SkillMetadata meta) {
|
||||
PlayerData playerData = PlayerData.get(meta.getCaster().getData().getUniqueId());
|
||||
RPGPlayer rpgPlayer = playerData.getRPG();
|
||||
|
||||
// Apply mana cost
|
||||
if (hasModifier("mana"))
|
||||
rpgPlayer.giveMana(-meta.getModifier("mana"));
|
||||
// Apply mana cost
|
||||
if (hasModifier("mana")) rpgPlayer.giveMana(-meta.getModifier("mana"));
|
||||
|
||||
// Apply stamina cost
|
||||
if (hasModifier("stamina"))
|
||||
rpgPlayer.giveStamina(-meta.getModifier("stamina"));
|
||||
// Apply stamina cost
|
||||
if (hasModifier("stamina")) rpgPlayer.giveStamina(-meta.getModifier("stamina"));
|
||||
|
||||
// Apply cooldown
|
||||
double cooldown = meta.getModifier("cooldown") * (1 - Math.min(.8, meta.getCaster().getStat("COOLDOWN_REDUCTION") / 100));
|
||||
if (cooldown > 0)
|
||||
meta.getCaster().getData().getCooldownMap().applyCooldown(this, cooldown);
|
||||
}
|
||||
// Apply cooldown
|
||||
double cooldown = meta.getModifier("cooldown") * (1 - Math.min(.8, meta.getCaster().getStat("COOLDOWN_REDUCTION") / 100));
|
||||
if (cooldown > 0) meta.getCaster().getData().getCooldownMap().applyCooldown(this, cooldown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkillHandler getHandler() {
|
||||
return ability.getHandler();
|
||||
}
|
||||
@Override
|
||||
public SkillHandler getHandler() {
|
||||
return ability.getHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getModifier(String path) {
|
||||
return modifiers.getOrDefault(path, ability.getDefaultModifier(path));
|
||||
}
|
||||
@Override
|
||||
public double getModifier(String path) {
|
||||
return modifiers.getOrDefault(path, ability.getDefaultModifier(path));
|
||||
}
|
||||
|
||||
public JsonObject toJson() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("Id", ability.getHandler().getId());
|
||||
object.addProperty("CastMode", getTrigger().name());
|
||||
public JsonObject toJson() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("Id", ability.getHandler().getId());
|
||||
object.addProperty("CastMode", getTrigger().name());
|
||||
|
||||
JsonObject modifiers = new JsonObject();
|
||||
this.modifiers.keySet().forEach(modifier -> modifiers.addProperty(modifier, getModifier(modifier)));
|
||||
object.add("Modifiers", modifiers);
|
||||
JsonObject modifiers = new JsonObject();
|
||||
this.modifiers.keySet().forEach(modifier -> modifiers.addProperty(modifier, getModifier(modifier)));
|
||||
object.add("Modifiers", modifiers);
|
||||
|
||||
return object;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AbilityData that = (AbilityData) o;
|
||||
return ability.equals(that.ability) && getTrigger().equals(that.getTrigger()) && modifiers.equals(that.modifiers);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AbilityData that = (AbilityData) o;
|
||||
return ability.equals(that.ability) && getTrigger().equals(that.getTrigger()) && modifiers.equals(that.modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(ability, modifiers);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(ability, modifiers);
|
||||
}
|
||||
}
|
@ -72,6 +72,11 @@ public class ArrowParticlesData implements StatData, RandomStatData<ArrowParticl
|
||||
return blue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
JsonObject object = new JsonObject();
|
||||
|
@ -45,6 +45,11 @@ public class ColorData implements StatData, RandomStatData<ColorData> {
|
||||
return Color.fromRGB(red, green, blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{Red=" + red + ",Green=" + green + ",Blue=" + blue + "}";
|
||||
|
@ -11,53 +11,55 @@ import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CommandListData implements StatData, Mergeable, RandomStatData<CommandListData> {
|
||||
@NotNull private final List<CommandData> commands;
|
||||
@NotNull
|
||||
private final List<CommandData> commands;
|
||||
|
||||
public CommandListData(@NotNull List<CommandData> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
public CommandListData(@NotNull List<CommandData> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public CommandListData(CommandData... commands) {
|
||||
this(new ArrayList<>());
|
||||
public CommandListData(CommandData... commands) {
|
||||
this(new ArrayList<>());
|
||||
|
||||
add(commands);
|
||||
}
|
||||
add(commands);
|
||||
}
|
||||
|
||||
public void add(CommandData... commands) {
|
||||
for (CommandData data : commands)
|
||||
this.commands.add(data);
|
||||
}
|
||||
public void add(CommandData... commands) {
|
||||
for (CommandData data : commands)
|
||||
this.commands.add(data);
|
||||
}
|
||||
|
||||
@NotNull public List<CommandData> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
@NotNull
|
||||
public List<CommandData> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CommandListData that = (CommandListData) o;
|
||||
return commands.equals(that.commands);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CommandListData that = (CommandListData) o;
|
||||
return commands.equals(that.commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof CommandListData, "Cannot merge two different stat data types");
|
||||
commands.addAll(((CommandListData) data).commands);
|
||||
}
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof CommandListData, "Cannot merge two different stat data types");
|
||||
commands.addAll(((CommandListData) data).commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull StatData cloneData() {
|
||||
return new CommandListData(commands);
|
||||
}
|
||||
@Override
|
||||
public @NotNull StatData cloneData() {
|
||||
return new CommandListData(commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return commands.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return commands.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandListData randomize(MMOItemBuilder builder) {
|
||||
return new CommandListData(new ArrayList<>(commands));
|
||||
}
|
||||
@Override
|
||||
public CommandListData randomize(MMOItemBuilder builder) {
|
||||
return new CommandListData(new ArrayList<>(commands));
|
||||
}
|
||||
}
|
@ -129,8 +129,8 @@ public class GemSocketsData implements StatData, Mergeable<GemSocketsData>, Rand
|
||||
public void merge(GemSocketsData data) {
|
||||
|
||||
// Combine both actual gems, and empty slots
|
||||
emptySlots.addAll(((GemSocketsData) data).emptySlots);
|
||||
gems.addAll(((GemSocketsData) data).getGemstones());
|
||||
emptySlots.addAll(data.emptySlots);
|
||||
gems.addAll(data.gems);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +28,11 @@ public class MaterialData implements StatData, RandomStatData<MaterialData> {
|
||||
return material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialData randomize(MMOItemBuilder builder) {
|
||||
return this;
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
@ -119,7 +120,7 @@ public class ParticleData implements StatData, RandomStatData<ParticleData> {
|
||||
object.addProperty("Particle", getParticle().name());
|
||||
object.addProperty("Type", getType().name());
|
||||
|
||||
if (isColorable(particle)) {
|
||||
if (MMOUtils.isColorable(particle)) {
|
||||
JsonObject color = new JsonObject();
|
||||
color.addProperty("Red", getColor().getRed());
|
||||
color.addProperty("Green", getColor().getGreen());
|
||||
@ -133,11 +134,10 @@ public class ParticleData implements StatData, RandomStatData<ParticleData> {
|
||||
return object;
|
||||
}
|
||||
|
||||
// TODO Allow Note to be colored and allow BLOCK_DUST/ITEM_DUST to pick a block/item.
|
||||
public static boolean isColorable(Particle particle) {
|
||||
// || particle == Particle.NOTE
|
||||
return particle == Particle.REDSTONE || particle == Particle.SPELL_MOB || particle == Particle.SPELL_MOB_AMBIENT;
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleData randomize(MMOItemBuilder builder) {
|
||||
|
@ -2,13 +2,10 @@ package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.api.interaction.ItemSkin;
|
||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -17,50 +14,33 @@ import java.util.List;
|
||||
public class StoredTagsData implements StatData, Mergeable<StoredTagsData> {
|
||||
private final List<ItemTag> tags = new ArrayList<>();
|
||||
|
||||
private static final List<String> ignoreList = Arrays.asList("Unbreakable", "BlockEntityTag", "display", "Enchantments", "HideFlags", "Damage",
|
||||
private static final List<String> IGNORED_TAGS = Arrays.asList(
|
||||
"Unbreakable", "BlockEntityTag", "display", "Enchantments", "HideFlags", "Damage",
|
||||
"AttributeModifiers", "SkullOwner", "CanDestroy", "PickupDelay", "Age");
|
||||
|
||||
@Deprecated
|
||||
private static final List<String> SAVED_MMOITEMS_TAGS = Arrays.asList(
|
||||
"MMOITEMS_SKIN_ID");
|
||||
|
||||
@Deprecated
|
||||
public StoredTagsData(ItemStack stack) {
|
||||
this(NBTItem.get(stack));
|
||||
}
|
||||
|
||||
public StoredTagsData(List<ItemTag> tgs) { tags.addAll(tgs); }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof StoredTagsData)) { return false; }
|
||||
|
||||
if (((StoredTagsData) obj).getTags().size() != getTags().size()) { return false; }
|
||||
|
||||
for (ItemTag tag : ((StoredTagsData) obj).getTags()) {
|
||||
|
||||
if (tag == null) { continue; }
|
||||
|
||||
boolean unmatched = true;
|
||||
for (ItemTag tg : getTags()) {
|
||||
if (tag.equals(tg)) { unmatched = false; break; } }
|
||||
if (unmatched) { return false; } }
|
||||
return true;
|
||||
}
|
||||
|
||||
public StoredTagsData(NBTItem nbt) {
|
||||
for (String tag : nbt.getTags()) {
|
||||
|
||||
// Usually ignore mmoitems
|
||||
if (tag.startsWith("MMOITEMS_")) {
|
||||
if (tag.startsWith("MMOITEMS_") && !SAVED_MMOITEMS_TAGS.contains(tag))
|
||||
|
||||
// Do not delete the skin tags (save them here)
|
||||
if (!ItemSkin.HAS_SKIN_TAG.equals(tag) && !ItemSkin.SKIN_ID_TAG.equals(tag)) {
|
||||
|
||||
// Not either of the skin tags, skip this.
|
||||
// Must be handled by its respective stat.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Must be handled by its respective stat.
|
||||
continue;
|
||||
|
||||
// Any vanilla or MMOItem tag should be ignored as those are
|
||||
// automatically handled. Same for the History stat ones.
|
||||
if (ignoreList.contains(tag) || tag.startsWith(ItemStackBuilder.history_keyword))
|
||||
if (IGNORED_TAGS.contains(tag) || tag.startsWith(ItemStackBuilder.history_keyword))
|
||||
continue;
|
||||
|
||||
// As more methods are added we can add more types here
|
||||
@ -134,4 +114,21 @@ public class StoredTagsData implements StatData, Mergeable<StoredTagsData> {
|
||||
public boolean isEmpty() {
|
||||
return tags.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof StoredTagsData)) { return false; }
|
||||
|
||||
if (((StoredTagsData) obj).getTags().size() != getTags().size()) { return false; }
|
||||
|
||||
for (ItemTag tag : ((StoredTagsData) obj).getTags()) {
|
||||
|
||||
if (tag == null) { continue; }
|
||||
|
||||
boolean unmatched = true;
|
||||
for (ItemTag tg : getTags()) {
|
||||
if (tag.equals(tg)) { unmatched = false; break; } }
|
||||
if (unmatched) { return false; } }
|
||||
return true;
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
@ -13,12 +12,11 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.bouncycastle.util.StringList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class StringListData implements StatData, RandomStatData<StringListData>, Mergeable<StringListData> {
|
||||
@NotNull private List<String> list;
|
||||
@NotNull private final List<String> list;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@ -80,34 +78,12 @@ public class StringListData implements StatData, RandomStatData<StringListData>,
|
||||
|
||||
/**
|
||||
* @param str Entry to remove
|
||||
*
|
||||
* @return If the value was actually removed. If it wasn't there
|
||||
* in the first place, this will return false.
|
||||
*
|
||||
* in the first place, this will return false.
|
||||
* @deprecated Deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean remove(@Nullable String str) {
|
||||
|
||||
if (!list.contains(str)) { return false; }
|
||||
|
||||
if (removeGuarantee) {
|
||||
|
||||
// Remove that sh
|
||||
return list.remove(str);
|
||||
} else {
|
||||
|
||||
// OK
|
||||
try {
|
||||
return list.remove(str);
|
||||
|
||||
} catch (UnsupportedOperationException ignored) {
|
||||
|
||||
list = new ArrayList<>(list);
|
||||
removeGuarantee = true;
|
||||
return list.remove(str);
|
||||
}
|
||||
}
|
||||
return list.remove(str);
|
||||
}
|
||||
boolean removeGuarantee = false;
|
||||
}
|
||||
|
@ -11,10 +11,7 @@ import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -33,11 +30,18 @@ import java.util.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class MMOUtils {
|
||||
|
||||
public MMOUtils() {
|
||||
throw new IllegalArgumentException("This class cannot be instantiated.");
|
||||
}
|
||||
|
||||
public static boolean isColorable(Particle particle) {
|
||||
return particle.getDataType() == Particle.DustOptions.class;
|
||||
}
|
||||
|
||||
public static boolean isNonEmpty(@Nullable String str) {
|
||||
return str != null && !str.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The skull texture URL from a given player head
|
||||
*/
|
||||
|
@ -3,13 +3,15 @@ package net.Indyuce.mmoitems.listener.reforging;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.api.event.MMOItemReforgeFinishEvent;
|
||||
import net.Indyuce.mmoitems.api.interaction.ItemSkin;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Transfers the lore from the old MMOItem to the new one.
|
||||
*
|
||||
* <p>
|
||||
* This operation is intended to allow refreshing the lore,
|
||||
* but keeping external things too.
|
||||
*
|
||||
@ -19,22 +21,15 @@ public class RFFKeepSkins implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onReforge(MMOItemReforgeFinishEvent event) {
|
||||
if (!event.getOptions().shouldKeepSkins()) { return; }
|
||||
if (!event.getOptions().shouldKeepSkins()) return;
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping Skins");
|
||||
|
||||
// Got skin?
|
||||
if (!event.getReforger().getNBTItem().getBoolean(ItemSkin.HAS_SKIN_TAG)) { return; }
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Item has skin");
|
||||
|
||||
// Apply skin to result
|
||||
NBTItem resultAsNBT = NBTItem.get(event.getFinishedItem());
|
||||
|
||||
// Apply skin
|
||||
ItemStack ret = ItemSkin.applySkin(resultAsNBT, event.getReforger().getNBTItem());
|
||||
|
||||
// Success?
|
||||
if (ret != null) {
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Success");
|
||||
event.setFinishedItem(ret); }
|
||||
final @Nullable String tagValue = event.getReforger().getNBTItem().getString(ItemSkin.SKIN_ID_TAG);
|
||||
if (tagValue != null && !tagValue.isEmpty()) {
|
||||
NBTItem resultAsNBT = NBTItem.get(event.getFinishedItem());
|
||||
ItemStack ret = ItemSkin.applySkin(resultAsNBT, new VolatileMMOItem(event.getReforger().getNBTItem()));
|
||||
event.setFinishedItem(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user