mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-23 04:47:34 +01:00
Merge branch 'feat-deskin' into 'master'
feat(mmoitems): add deskin consumable option
This commit is contained in:
commit
17651d6137
@ -1,7 +1,27 @@
|
||||
package net.Indyuce.mmoitems.api.interaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ItemTier;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.event.item.*;
|
||||
import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
||||
import net.Indyuce.mmoitems.api.item.util.DynamicLore;
|
||||
import net.Indyuce.mmoitems.api.item.util.identify.IdentifiedItem;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.comp.flags.FlagPlugin.CustomFlag;
|
||||
import net.Indyuce.mmoitems.stat.data.*;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.api.item.ItemTag;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import net.mmogroup.mmolib.api.util.SmartGive;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -11,33 +31,10 @@ 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 net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ItemTier;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.event.item.ApplySoulboundEvent;
|
||||
import net.Indyuce.mmoitems.api.event.item.BreakSoulboundEvent;
|
||||
import net.Indyuce.mmoitems.api.event.item.DeconstructItemEvent;
|
||||
import net.Indyuce.mmoitems.api.event.item.IdentifyItemEvent;
|
||||
import net.Indyuce.mmoitems.api.event.item.RepairItemEvent;
|
||||
import net.Indyuce.mmoitems.api.event.item.UpgradeItemEvent;
|
||||
import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.util.DynamicLore;
|
||||
import net.Indyuce.mmoitems.api.item.util.identify.IdentifiedItem;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.comp.flags.FlagPlugin.CustomFlag;
|
||||
import net.Indyuce.mmoitems.stat.data.PotionEffectListData;
|
||||
import net.Indyuce.mmoitems.stat.data.SoulboundData;
|
||||
import net.Indyuce.mmoitems.stat.data.UpgradeData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.api.item.ItemTag;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import net.mmogroup.mmolib.api.util.SmartGive;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
public class Consumable extends UseItem {
|
||||
public Consumable(Player player, NBTItem item) {
|
||||
@ -295,6 +292,81 @@ public class Consumable extends UseItem {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Item Deskinning
|
||||
* Sets the target item into its original Custom Model Data
|
||||
* and returning skin item to the player
|
||||
*/
|
||||
String skinId = target.getString("MMOITEMS_SKIN_ID");
|
||||
if(getNBTItem().getBoolean("MMOITEMS_CAN_DESKIN") && !skinId.isEmpty()) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
//Set target item to default skin
|
||||
String targetItemId = target.getString("MMOITEMS_ITEM_ID");
|
||||
target.removeTag("MMOITEMS_HAS_SKIN");
|
||||
target.removeTag("MMOITEMS_SKIN_ID");
|
||||
|
||||
MMOItemTemplate targetTemplate = MMOItems.plugin.getTemplates().getTemplateOrThrow(targetType, targetItemId);
|
||||
MMOItem originalMmoitem = targetTemplate.newBuilder(playerData.get(player).getRPG()).build();
|
||||
ItemStack originalItem = targetTemplate.newBuilder(playerData.get(player).getRPG()).build().newBuilder().build();
|
||||
|
||||
int originalCustomModelData = originalItem.getItemMeta().hasCustomModelData() ? originalItem.getItemMeta().getCustomModelData() : -1;
|
||||
if(originalCustomModelData != -1) {
|
||||
target.addTag(new ItemTag("CustomModelData", originalCustomModelData));
|
||||
} else {
|
||||
target.removeTag("CustomModelData");
|
||||
}
|
||||
|
||||
if(originalMmoitem.hasData(ItemStat.ITEM_PARTICLES)) {
|
||||
JsonObject itemParticles = ((ParticleData) originalMmoitem.getData(ItemStat.ITEM_PARTICLES)).toJson();
|
||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", itemParticles.toString()));
|
||||
} else {
|
||||
target.removeTag("MMOITEMS_ITEM_PARTICLES");
|
||||
}
|
||||
|
||||
ItemStack targetItem = target.toItem();
|
||||
ItemMeta targetItemMeta = targetItem.getItemMeta();
|
||||
ItemMeta originalItemMeta = originalItem.getItemMeta();
|
||||
|
||||
if(targetItemMeta.isUnbreakable()) {
|
||||
targetItemMeta.setUnbreakable(originalItemMeta.isUnbreakable());
|
||||
if(targetItemMeta instanceof Damageable && originalItemMeta instanceof Damageable)
|
||||
((Damageable) targetItemMeta).setDamage(((Damageable) originalItemMeta).getDamage());
|
||||
}
|
||||
|
||||
if(targetItemMeta instanceof LeatherArmorMeta && originalItemMeta instanceof LeatherArmorMeta)
|
||||
((LeatherArmorMeta) targetItemMeta).setColor(((LeatherArmorMeta) originalItemMeta).getColor());
|
||||
|
||||
if (target.hasTag("SkullOwner") && (targetItem.getType() == VersionMaterial.PLAYER_HEAD.toMaterial())
|
||||
&& (originalItem.getType() == VersionMaterial.PLAYER_HEAD.toMaterial())) {
|
||||
try {
|
||||
Field profileField = targetItemMeta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(targetItemMeta,
|
||||
((SkullTextureData) originalMmoitem.getData(ItemStat.SKULL_TEXTURE)).getGameProfile());
|
||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||
MMOItems.plugin.getLogger().warning("Could not read skull texture");
|
||||
}
|
||||
}
|
||||
|
||||
targetItem.setItemMeta(targetItemMeta);
|
||||
targetItem.setType(originalItem.getType());
|
||||
event.getCurrentItem().setAmount(0);
|
||||
new SmartGive(player).give(targetItem);
|
||||
|
||||
|
||||
// Give back skin item
|
||||
MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplateOrThrow(Type.SKIN, skinId);
|
||||
MMOItem mmoitem = template.newBuilder(playerData.get(player).getRPG()).build();
|
||||
ItemStack item = mmoitem.newBuilder().build();
|
||||
|
||||
new SmartGive(player).give(item);
|
||||
Message.SKIN_REMOVED
|
||||
.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(targetItem))
|
||||
.send(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ public class ItemSkin extends UseItem {
|
||||
|
||||
// Apply skin
|
||||
target.addTag(new ItemTag("MMOITEMS_HAS_SKIN", true));
|
||||
target.addTag(new ItemTag("MMOITEMS_SKIN_ID", getNBTItem().getString("MMOITEMS_ITEM_ID")));
|
||||
if (getNBTItem().getInteger("CustomModelData") != 0)
|
||||
target.addTag(new ItemTag("CustomModelData", getNBTItem().getInteger("CustomModelData")));
|
||||
if (!getNBTItem().getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
|
||||
|
@ -41,6 +41,7 @@ public enum Message {
|
||||
GEM_STONE_BROKE("Your gem stone &6#gem#&c broke while trying to apply it onto &6#item#&c."),
|
||||
REPAIRED_ITEM("You successfully repaired &6#item#&e for &6#amount# &euses."),
|
||||
SKIN_APPLIED("You successfully applied the skin onto your &6#item#&e!"),
|
||||
SKIN_REMOVED("You successfully removed the skin from your &6#item#&e!"),
|
||||
SKIN_BROKE("Your skin broke while trying to apply it onto your &6#item#&c."),
|
||||
SKIN_REJECTED("A skin has already been applied onto your &6#item#&c!"),
|
||||
SKIN_INCOMPATIBLE("This skin is not compatible with your &6#item#&c!"),
|
||||
|
@ -155,6 +155,9 @@ public abstract class ItemStat {
|
||||
public static final ItemStat CAN_DECONSTRUCT = new BooleanStat("CAN_DECONSTRUCT", new ItemStack(Material.PAPER), "Can Deconstruct?",
|
||||
new String[] { "Players can deconstruct their item", "using this consumable, creating", "another random item." },
|
||||
new String[] { "consumable" });
|
||||
public static final ItemStat CAN_DESKIN = new BooleanStat("CAN_DESKIN", new ItemStack(Material.LEATHER), "Can Deskin?",
|
||||
new String[] { "Players can deskin their item", "and get their skin back", "from the item." },
|
||||
new String[] { "consumable" });
|
||||
public static final ItemStat EFFECTS = new Effects(), PERM_EFFECTS = new PermanentEffects(), GRANTED_PERMISSIONS = new GrantedPermissions();
|
||||
public static final ItemStat SOULBINDING_CHANCE = new DoubleStat("SOULBINDING_CHANCE", VersionMaterial.ENDER_EYE.toItem(), "Soulbinding Chance",
|
||||
new String[] { "Defines the chance your item has to", "link another item to your soul,", "preventing other players from using it." },
|
||||
|
@ -31,6 +31,7 @@ lore-format:
|
||||
- '{bar}'
|
||||
- '#can-identify#'
|
||||
- '#can-deconstruct#'
|
||||
- '#can-deskin#'
|
||||
- '#attack-damage#'
|
||||
- '#knockback#'
|
||||
- '#recoil#'
|
||||
|
@ -78,6 +78,7 @@ effect: '&7■ Grants &f#e &7for &f#d&7s'
|
||||
repair: '&7■ Repair: &f#'
|
||||
can-identify: '&7■ Can identify items.'
|
||||
can-deconstruct: '&7■ Can deconstruct tiered items.'
|
||||
can-deskin: '&7■ Can de-skin skinned items.'
|
||||
success-rate: '&7■ Success Rate: &a&l#%'
|
||||
max-consume: '&7■ Max Consume: &f# &7uses'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user