mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-22 09:31:20 +01:00
Skins now apply damage values if set to unbreakable
This commit is contained in:
parent
5732bd6fdc
commit
b296b02dcc
@ -6,12 +6,14 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.stat.data.BooleanData;
|
||||
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
|
||||
import net.Indyuce.mmoitems.stat.data.StringListData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
@ -25,61 +27,73 @@ public class ItemSkin extends UseItem {
|
||||
}
|
||||
|
||||
public ApplyResult applyOntoItem(NBTItem target, Type targetType) {
|
||||
if(targetType == Type.SKIN)
|
||||
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") && target.getBoolean("MMOITEMS_HAS_SKIN")) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
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);
|
||||
}
|
||||
|
||||
boolean compatible = false;
|
||||
if(getMMOItem().hasData(ItemStat.COMPATIBLE_TYPES)) {
|
||||
for(String type : ((StringListData) getMMOItem().getData(ItemStat.COMPATIBLE_TYPES)).getList()) {
|
||||
if(type.equalsIgnoreCase(targetType.getId())) {
|
||||
if (getMMOItem().hasData(ItemStat.COMPATIBLE_TYPES)) {
|
||||
for (String type : ((StringListData) getMMOItem().getData(ItemStat.COMPATIBLE_TYPES)).getList()) {
|
||||
if (type.equalsIgnoreCase(targetType.getId())) {
|
||||
compatible = true;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!compatible){
|
||||
|
||||
if (!compatible) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
|
||||
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
||||
.send(player);
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check for success rate
|
||||
double successRate = getNBTItem().getStat(ItemStat.SUCCESS_RATE);
|
||||
if (successRate != 0)
|
||||
if (random.nextDouble() < 1 - successRate / 100) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||
Message.SKIN_BROKE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
|
||||
Message.SKIN_BROKE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
||||
.send(player);
|
||||
return new ApplyResult(ResultType.FAILURE);
|
||||
}
|
||||
|
||||
|
||||
// Apply skin
|
||||
target.addTag(new ItemTag("MMOITEMS_HAS_SKIN", true));
|
||||
if(getNBTItem().getInteger("CustomModelData") != 0) target.addTag(new ItemTag("CustomModelData", getNBTItem().getInteger("CustomModelData")));
|
||||
if(!getNBTItem().getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", getNBTItem().getString("MMOITEMS_ITEM_PARTICLES")));
|
||||
if (getNBTItem().getInteger("CustomModelData") != 0)
|
||||
target.addTag(new ItemTag("CustomModelData", getNBTItem().getInteger("CustomModelData")));
|
||||
if (!getNBTItem().getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
|
||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", getNBTItem().getString("MMOITEMS_ITEM_PARTICLES")));
|
||||
|
||||
ItemStack item = target.toItem();
|
||||
if(item.getType() != getNBTItem().getItem().getType())
|
||||
if (item.getType() != getNBTItem().getItem().getType())
|
||||
item.setType(getNBTItem().getItem().getType());
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (getMMOItem().hasData(ItemStat.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() &&
|
||||
getNBTItem().getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||
if (((BooleanData) getMMOItem().getData(ItemStat.UNBREAKABLE)).isEnabled()) {
|
||||
meta.setUnbreakable(true);
|
||||
if (meta instanceof Damageable && getNBTItem().getItem().getItemMeta() instanceof Damageable)
|
||||
((Damageable) meta).setDamage(((Damageable) getNBTItem().getItem().getItemMeta()).getDamage());
|
||||
}
|
||||
if (getMMOItem().hasData(ItemStat.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
|
||||
&& getNBTItem().getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||
try {
|
||||
Field profileField = meta.getClass().getDeclaredField("profile"); profileField.setAccessible(true);
|
||||
profileField.set(meta, ((SkullTextureData) getMMOItem().getData(ItemStat.SKULL_TEXTURE)).getGameProfile());
|
||||
Field profileField = meta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta,
|
||||
((SkullTextureData) getMMOItem().getData(ItemStat.SKULL_TEXTURE)).getGameProfile());
|
||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||
MMOItems.plugin.getLogger().warning("Could not read skull texture");
|
||||
}
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
|
||||
|
||||
@ -113,8 +127,6 @@ public class ItemSkin extends UseItem {
|
||||
}
|
||||
|
||||
public enum ResultType {
|
||||
FAILURE,
|
||||
NONE,
|
||||
SUCCESS;
|
||||
FAILURE, NONE, SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ public class SuccessRate extends DoubleStat implements ProperStat {
|
||||
* in a different class because Success Rate is meant to be a proper stat
|
||||
*/
|
||||
public SuccessRate() {
|
||||
super("SUCCESS_RATE", new ItemStack(Material.EMERALD), "Success Rate", new String[] { "The chance of your gem to successfully",
|
||||
"apply onto an item. This value is 100%", "by default. If it is not successfully", "applied, the gem stone will be lost." },
|
||||
super("SUCCESS_RATE", new ItemStack(Material.EMERALD), "Success Rate", new String[] { "The chance of your gem/skin to successfully",
|
||||
"apply onto an item. This value is 100%", "by default. If it is not successfully", "applied, the gem/skin will be lost." },
|
||||
new String[] { "gem_stone", "skin" });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user