mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Fixed item deskin
This commit is contained in:
parent
ab7c40d41a
commit
c63a107cf3
@ -1,17 +1,16 @@
|
|||||||
package net.Indyuce.mmoitems.api.interaction;
|
package net.Indyuce.mmoitems.api.interaction;
|
||||||
|
|
||||||
|
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||||
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import net.Indyuce.mmoitems.ItemStats;
|
import net.Indyuce.mmoitems.ItemStats;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.MMOUtils;
|
import net.Indyuce.mmoitems.MMOUtils;
|
||||||
import net.Indyuce.mmoitems.api.Type;
|
import net.Indyuce.mmoitems.api.Type;
|
||||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
|
||||||
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||||
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
|
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
|
||||||
import net.Indyuce.mmoitems.stat.data.StringListData;
|
import net.Indyuce.mmoitems.stat.data.StringListData;
|
||||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -102,7 +101,7 @@ public class ItemSkin extends UseItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply skin
|
// Apply skin
|
||||||
ItemStack item = applySkin(target, getNBTItem(), getMMOItem());
|
ItemStack item = applySkin(target, getMMOItem());
|
||||||
|
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||||
Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
|
Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
|
||||||
@ -110,35 +109,45 @@ public class ItemSkin extends UseItem {
|
|||||||
return new ApplyResult(item);
|
return new ApplyResult(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String tagHasSkin = "MMOITEMS_HAS_SKIN";
|
public static final String HAS_SKIN_TAG = "MMOITEMS_HAS_SKIN";
|
||||||
public static final String tagSkinID = "MMOITEMS_SKIN_ID";
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* and given back to the player.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String SKIN_ID_TAG = "MMOITEMS_SKIN_ID";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the skin information from a skin consumable onto any item.
|
* Applies the skin information from a skin consumable onto any item.
|
||||||
*
|
*
|
||||||
* @param target Target item that the skin has been <b>successfully</b> applied to
|
* @param target Target item that the skin has been <b>successfully</b> applied to
|
||||||
*
|
* @param skinItemMMO Skin consumable
|
||||||
* @param skinItemNBT Skin consumable, as NBT
|
|
||||||
* @param skinItemMMO Skin consumable, as MMOItem
|
|
||||||
*
|
|
||||||
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
|
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
|
||||||
*/
|
*/
|
||||||
@NotNull public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem skinItemNBT, @NotNull MMOItem skinItemMMO) {
|
@NotNull
|
||||||
|
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull VolatileMMOItem skinItemMMO) {
|
||||||
|
final NBTItem skinItemNBT = skinItemMMO.getNBT();
|
||||||
|
|
||||||
target.addTag(new ItemTag(tagHasSkin, true));
|
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
|
||||||
target.addTag(new ItemTag(tagSkinID, skinItemNBT.getString(tagSkinID)));
|
target.addTag(new ItemTag(SKIN_ID_TAG, skinItemNBT.getString("MMOITEMS_ITEM_ID")));
|
||||||
if (skinItemNBT.getInteger("CustomModelData") != 0) {
|
if (skinItemNBT.getInteger("CustomModelData") != 0)
|
||||||
target.addTag(new ItemTag("CustomModelData", skinItemNBT.getInteger("CustomModelData"))); }
|
target.addTag(new ItemTag("CustomModelData", skinItemNBT.getInteger("CustomModelData")));
|
||||||
if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
|
|
||||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES"))); }
|
if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
|
||||||
|
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
|
||||||
|
|
||||||
ItemStack item = target.toItem();
|
ItemStack item = target.toItem();
|
||||||
if (item.getType() != skinItemNBT.getItem().getType()) { item.setType(skinItemNBT.getItem().getType()); }
|
if (item.getType() != skinItemNBT.getItem().getType())
|
||||||
|
item.setType(skinItemNBT.getItem().getType());
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta();
|
ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta();
|
||||||
if (skinMeta != null && meta != null) {
|
if (skinMeta != null && meta != null) {
|
||||||
|
|
||||||
|
// TODO factorize with a ItemSkinStat stat interface
|
||||||
if (skinMeta.isUnbreakable()) {
|
if (skinMeta.isUnbreakable()) {
|
||||||
meta.setUnbreakable(true);
|
meta.setUnbreakable(true);
|
||||||
if (meta instanceof Damageable && skinMeta instanceof Damageable)
|
if (meta instanceof Damageable && skinMeta instanceof Damageable)
|
||||||
@ -181,11 +190,11 @@ public class ItemSkin extends UseItem {
|
|||||||
@Nullable public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem originalItemNBT) {
|
@Nullable public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem originalItemNBT) {
|
||||||
|
|
||||||
// No skin no service
|
// No skin no service
|
||||||
if (!originalItemNBT.getBoolean("MMOITEMS_HAS_SKIN")) { return null; }
|
if (!originalItemNBT.getBoolean(HAS_SKIN_TAG)) { return null; }
|
||||||
|
|
||||||
// Copy over data
|
// Copy over data
|
||||||
target.addTag(new ItemTag("MMOITEMS_HAS_SKIN", true));
|
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
|
||||||
target.addTag(new ItemTag("MMOITEMS_SKIN_ID", originalItemNBT.getString("MMOITEMS_ITEM_ID")));
|
target.addTag(new ItemTag(SKIN_ID_TAG, originalItemNBT.getString("MMOITEMS_ITEM_ID")));
|
||||||
if (originalItemNBT.getInteger("CustomModelData") != 0) {
|
if (originalItemNBT.getInteger("CustomModelData") != 0) {
|
||||||
target.addTag(new ItemTag("CustomModelData", originalItemNBT.getInteger("CustomModelData"))); }
|
target.addTag(new ItemTag("CustomModelData", originalItemNBT.getInteger("CustomModelData"))); }
|
||||||
if (!originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
|
if (!originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.Indyuce.mmoitems.listener.reforging;
|
package net.Indyuce.mmoitems.listener.reforging;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
|
||||||
import net.Indyuce.mmoitems.api.event.MMOItemReforgeFinishEvent;
|
import net.Indyuce.mmoitems.api.event.MMOItemReforgeFinishEvent;
|
||||||
import net.Indyuce.mmoitems.api.interaction.ItemSkin;
|
import net.Indyuce.mmoitems.api.interaction.ItemSkin;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -24,7 +23,7 @@ public class RFFKeepSkins implements Listener {
|
|||||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping Skins");
|
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping Skins");
|
||||||
|
|
||||||
// Got skin?
|
// Got skin?
|
||||||
if (!event.getReforger().getNBTItem().getBoolean(ItemSkin.tagHasSkin)) { return; }
|
if (!event.getReforger().getNBTItem().getBoolean(ItemSkin.HAS_SKIN_TAG)) { return; }
|
||||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Item has skin");
|
//RFG// MMOItems.log("§8Reforge §4EFG§7 Item has skin");
|
||||||
|
|
||||||
// Apply skin to result
|
// Apply skin to result
|
||||||
|
@ -1,18 +1,10 @@
|
|||||||
package net.Indyuce.mmoitems.stat;
|
package net.Indyuce.mmoitems.stat;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.Damageable;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||||
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
|
import io.lumine.mythic.lib.api.util.SmartGive;
|
||||||
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import net.Indyuce.mmoitems.ItemStats;
|
import net.Indyuce.mmoitems.ItemStats;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.MMOUtils;
|
import net.Indyuce.mmoitems.MMOUtils;
|
||||||
@ -26,22 +18,27 @@ import net.Indyuce.mmoitems.stat.data.ParticleData;
|
|||||||
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
|
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
|
||||||
import net.Indyuce.mmoitems.stat.type.BooleanStat;
|
import net.Indyuce.mmoitems.stat.type.BooleanStat;
|
||||||
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
|
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
|
||||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
import org.bukkit.ChatColor;
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import org.bukkit.Material;
|
||||||
import io.lumine.mythic.lib.api.util.SmartGive;
|
import org.bukkit.entity.Player;
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class CanDeskin extends BooleanStat implements ConsumableItemInteraction {
|
public class CanDeskin extends BooleanStat implements ConsumableItemInteraction {
|
||||||
public CanDeskin() {
|
public CanDeskin() {
|
||||||
super("CAN_DESKIN", Material.LEATHER, "Can Deskin?",
|
super("CAN_DESKIN", Material.LEATHER, "Can Deskin?",
|
||||||
new String[] { "Players can deskin their item", "and get their skin back", "from the item." }, new String[] { "consumable" });
|
new String[] { "Players can deskin their item", "and get their skin back", "from the item." }, new String[] { "consumable" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO needs some cleanup
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) {
|
public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) {
|
||||||
String skinId = target.getString("MMOITEMS_SKIN_ID");
|
final String skinId = target.getString("MMOITEMS_SKIN_ID");
|
||||||
Player player = playerData.getPlayer();
|
Player player = playerData.getPlayer();
|
||||||
|
|
||||||
if (consumable.getNBTItem().getBoolean("MMOITEMS_CAN_DESKIN") && !skinId.isEmpty()) {
|
if (consumable.getNBTItem().getBoolean("MMOITEMS_CAN_DESKIN") && !skinId.isEmpty()) {
|
||||||
@ -91,17 +88,16 @@ public class CanDeskin extends BooleanStat implements ConsumableItemInteraction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
targetItem.setItemMeta(targetItemMeta);
|
// Update deskined item
|
||||||
targetItem.setType(originalItem.getType());
|
final ItemStack updated = target.getItem();
|
||||||
target.getItem().setAmount(0);
|
updated.setItemMeta(targetItemMeta);
|
||||||
new SmartGive(player).give(targetItem);
|
updated.setType(originalItem.getType());
|
||||||
|
|
||||||
// Give back skin item
|
// Give back skin item
|
||||||
MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplateOrThrow(Type.SKIN, skinId);
|
MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplateOrThrow(Type.SKIN, skinId);
|
||||||
MMOItem mmoitem = template.newBuilder(playerData.getRPG()).build();
|
MMOItem mmoitem = template.newBuilder(playerData.getRPG()).build();
|
||||||
ItemStack item = mmoitem.newBuilder().build();
|
new SmartGive(player).give(mmoitem.newBuilder().build());
|
||||||
|
|
||||||
new SmartGive(player).give(item);
|
|
||||||
Message.SKIN_REMOVED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(targetItem)).send(player);
|
Message.SKIN_REMOVED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(targetItem)).send(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class StoredTagsData implements StatData, Mergeable {
|
|||||||
if (tag.startsWith("MMOITEMS_")) {
|
if (tag.startsWith("MMOITEMS_")) {
|
||||||
|
|
||||||
// Do not delete the skin tags (save them here)
|
// Do not delete the skin tags (save them here)
|
||||||
if (!ItemSkin.tagHasSkin.equals(tag) && !ItemSkin.tagSkinID.equals(tag)) {
|
if (!ItemSkin.HAS_SKIN_TAG.equals(tag) && !ItemSkin.SKIN_ID_TAG.equals(tag)) {
|
||||||
|
|
||||||
// Not either of the skin tags, skip this.
|
// Not either of the skin tags, skip this.
|
||||||
// Must be handled by its respective stat.
|
// Must be handled by its respective stat.
|
||||||
|
Loading…
Reference in New Issue
Block a user