diff --git a/src/main/java/net/Indyuce/mmocore/api/eco/Withdraw.java b/src/main/java/net/Indyuce/mmocore/api/eco/Withdraw.java index f1669ba0..e143c2b7 100644 --- a/src/main/java/net/Indyuce/mmocore/api/eco/Withdraw.java +++ b/src/main/java/net/Indyuce/mmocore/api/eco/Withdraw.java @@ -17,7 +17,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.util.item.CurrencyItem; +import net.Indyuce.mmocore.util.item.CurrencyItemBuilder; import io.lumine.mythic.lib.api.util.SmartGive; public class Withdraw implements Listener { @@ -101,9 +101,9 @@ public class Withdraw implements Listener { SmartGive smart = new SmartGive(player); if (note > 0) - smart.give(new CurrencyItem("NOTE", note).build()); + smart.give(new CurrencyItemBuilder("NOTE", note).build()); - ItemStack coinsItem = new CurrencyItem("GOLD_COIN", 1).build(); + ItemStack coinsItem = new CurrencyItemBuilder("GOLD_COIN", 1).build(); coinsItem.setAmount(coins); smart.give(coinsItem); } diff --git a/src/main/java/net/Indyuce/mmocore/api/util/item/ConfigItem.java b/src/main/java/net/Indyuce/mmocore/api/util/item/ConfigItem.java deleted file mode 100644 index 42c0962a..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/util/item/ConfigItem.java +++ /dev/null @@ -1,144 +0,0 @@ -package net.Indyuce.mmocore.api.util.item; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.logging.Level; - -import org.apache.commons.lang.Validate; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; - -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; - -import net.Indyuce.mmocore.MMOCore; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.item.ItemTag; -import io.lumine.mythic.lib.api.item.NBTItem; -import io.lumine.mythic.lib.version.VersionMaterial; - -public class ConfigItem { - private final String name, id, texture; - private final ItemStack item; - private final List lore; - private final int damage, modeldata; - - private boolean unbreakable; - private final Map placeholders = new HashMap<>(); - - public ConfigItem(ConfigurationSection config) { - id = config.getName(); - name = config.getString("name"); - lore = config.getStringList("lore"); - item = new ItemStack(Material.valueOf(config.getString("item"))); - - Validate.notNull(name, "Name cannot be null"); - Validate.notNull(lore, "Lore can be empty but not null"); - - /* - * extra options - */ - damage = config.getInt("damage"); - texture = config.getString("texture"); - modeldata = config.getInt("custom-model-data"); - } - - public ConfigItem(String id) { - this(MMOCore.plugin.configItems.get(id)); - } - - public ConfigItem(ConfigItem cache) { - this.id = cache.id; - name = cache.name; - lore = cache.lore; - item = cache.item; - damage = cache.damage; - texture = cache.texture; - modeldata = cache.modeldata; - unbreakable = cache.unbreakable; - } - - public ItemStack getItem(int amount) { - ItemStack item = this.item.clone(); - item.setAmount(amount); - return item; - } - - public List getLore() { - return lore; - } - - public String getName() { - return name; - } - - public int getModelData() { - return modeldata; - } - - public String getId() { - return id; - } - - public ConfigItem setUnbreakable() { - unbreakable = true; - return this; - } - - public ConfigItem addPlaceholders(String... placeholders) { - for (int j = 0; j < placeholders.length - 1; j += 2) - this.placeholders.put(placeholders[j], placeholders[j + 1]); - return this; - } - - public ItemStack build() { - return build(1); - } - - public ItemStack build(int amount) { - ItemStack item = getItem(amount); - ItemMeta meta = item.getItemMeta(); - - if (meta instanceof Damageable) - ((Damageable) meta).setDamage(damage); - - if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13)) - meta.setCustomModelData(modeldata); - - if (item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && texture != null) - try { - Field profileField = meta.getClass().getDeclaredField("profile"); - profileField.setAccessible(true); - GameProfile profile = new GameProfile(UUID.randomUUID(), null); - profile.getProperties().put("textures", new Property("textures", texture)); - profileField.set(meta, profile); - } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) { - MMOCore.log(Level.WARNING, "Could not load config item texture of " + id); - } - - meta.addItemFlags(ItemFlag.values()); - meta.setDisplayName(format(name)); - - List lore = new ArrayList<>(); - getLore().forEach(line -> lore.add(format(line))); - meta.setLore(lore); - - item.setItemMeta(meta); - return unbreakable ? NBTItem.get(item).addTag(new ItemTag("Unbreakable", true)).toItem() : item; - } - - protected String format(String string) { - for (String placeholder : placeholders.keySet()) - if (string.contains("{" + placeholder + "}")) - string = string.replace("{" + placeholder + "}", "" + placeholders.get(placeholder)); - return MythicLib.plugin.parseColors(string); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/util/item/CurrencyItem.java b/src/main/java/net/Indyuce/mmocore/api/util/item/CurrencyItem.java deleted file mode 100644 index ca8366e6..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/util/item/CurrencyItem.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.Indyuce.mmocore.api.util.item; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.item.ItemTag; -import io.lumine.mythic.lib.api.item.NBTItem; - -public class CurrencyItem extends ConfigItem { - private final int worth, amount; - - public CurrencyItem(String key, int worth) { - this(key, worth, 1); - } - - public CurrencyItem(String key, int worth, int amount) { - super(key); - addPlaceholders("worth", "" + (this.worth = worth)); - this.amount = amount; - } - - @Override - public ItemStack build() { - ItemStack item = getItem(amount); - ItemMeta meta = item.getItemMeta(); - - meta.addItemFlags(ItemFlag.values()); - meta.setDisplayName(format(getName())); - - List lore = new ArrayList<>(); - getLore().forEach(line -> lore.add(format(line))); - meta.setLore(lore); - - if(MythicLib.plugin.getVersion().isStrictlyHigher(1, 13)) - meta.setCustomModelData(getModelData()); - - item.setItemMeta(meta); - return NBTItem.get(item).addTag(new ItemTag("RpgWorth", worth)).toItem(); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/util/item/NamedItemStack.java b/src/main/java/net/Indyuce/mmocore/api/util/item/NamedItemStack.java deleted file mode 100644 index 8bdc5608..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/util/item/NamedItemStack.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.Indyuce.mmocore.api.util.item; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import io.lumine.mythic.lib.MythicLib; - -public class NamedItemStack extends ItemStack { - public NamedItemStack(Material material, String name) { - super(material); - - ItemMeta meta = getItemMeta(); - meta.setDisplayName(MythicLib.plugin.parseColors(name)); - setItemMeta(meta); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/CoinsCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/CoinsCommandTreeNode.java index 0e702165..fc185d36 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/CoinsCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/CoinsCommandTreeNode.java @@ -3,7 +3,7 @@ package net.Indyuce.mmocore.command.rpg; import io.lumine.mythic.lib.api.util.SmartGive; import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.Parameter; -import net.Indyuce.mmocore.api.util.item.CurrencyItemBuilder; +import net.Indyuce.mmocore.util.item.CurrencyItemBuilder; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/NoteCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/NoteCommandTreeNode.java index 74c88e3f..b83173c6 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/NoteCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/NoteCommandTreeNode.java @@ -7,7 +7,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.Indyuce.mmocore.api.util.item.CurrencyItemBuilder; +import net.Indyuce.mmocore.util.item.CurrencyItemBuilder; import io.lumine.mythic.lib.api.util.SmartGive; import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.Parameter; diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/CurrencyItemDrop.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/CurrencyItemDrop.java index 5d849a31..37fc4b9f 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/CurrencyItemDrop.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/CurrencyItemDrop.java @@ -9,7 +9,7 @@ import io.lumine.xikage.mythicmobs.drops.IMultiDrop; import io.lumine.xikage.mythicmobs.drops.LootBag; import io.lumine.xikage.mythicmobs.drops.droppables.ItemDrop; import io.lumine.xikage.mythicmobs.io.MythicLineConfig; -import net.Indyuce.mmocore.api.util.item.CurrencyItem; +import net.Indyuce.mmocore.util.item.CurrencyItemBuilder; public class CurrencyItemDrop extends Drop implements IMultiDrop { private final String key; @@ -30,7 +30,7 @@ public class CurrencyItemDrop extends Drop implements IMultiDrop { @Override public LootBag get(DropMetadata metadata) { LootBag loot = new LootBag(metadata); - loot.add(new ItemDrop(this.getLine(), (MythicLineConfig) this.getConfig(), new BukkitItemStack(new CurrencyItem(key, random(minw, maxw)).build()))); + loot.add(new ItemDrop(this.getLine(), (MythicLineConfig) this.getConfig(), new BukkitItemStack(new CurrencyItemBuilder(key, random(minw, maxw)).build()))); return loot; } diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/GoldPouchDrop.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/GoldPouchDrop.java index 57f8c2ac..f168d904 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/GoldPouchDrop.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/GoldPouchDrop.java @@ -2,6 +2,7 @@ package net.Indyuce.mmocore.comp.mythicmobs.load; import java.util.Random; +import net.Indyuce.mmocore.util.item.SimpleItemBuilder; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -13,8 +14,7 @@ import io.lumine.xikage.mythicmobs.drops.LootBag; import io.lumine.xikage.mythicmobs.drops.droppables.ItemDrop; import io.lumine.xikage.mythicmobs.io.MythicLineConfig; import net.Indyuce.mmocore.api.util.MMOCoreUtils; -import net.Indyuce.mmocore.api.util.item.ConfigItem; -import net.Indyuce.mmocore.api.util.item.CurrencyItem; +import net.Indyuce.mmocore.util.item.CurrencyItemBuilder; import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.NBTItem; @@ -35,7 +35,7 @@ public class GoldPouchDrop extends Drop implements IMultiDrop { @Override public LootBag get(DropMetadata metadata) { LootBag loot = new LootBag(metadata); - NBTItem nbt = NBTItem.get(new ConfigItem("MOB_GOLD_POUCH").build()); + NBTItem nbt = NBTItem.get(new SimpleItemBuilder("MOB_GOLD_POUCH").build()); ItemStack[] content = new ItemStack[18]; int money = random.nextInt(max - min + 1) + min; @@ -45,11 +45,11 @@ public class GoldPouchDrop extends Drop implements IMultiDrop { money -= a; if (a < 30 && random.nextDouble() < .3) { - content[getAvailableSlot(content)] = new CurrencyItem("GOLD_COIN", 1, a).build(); + content[getAvailableSlot(content)] = setAmount(new CurrencyItemBuilder("GOLD_COIN", 1).build(), a); continue; } - content[getAvailableSlot(content)] = new CurrencyItem("NOTE", a, 1).build(); + content[getAvailableSlot(content)] = new CurrencyItemBuilder("NOTE", a).build(); } nbt.addTag(new ItemTag("RpgPouchSize", 18), new ItemTag("RpgPouchMob", true), new ItemTag("RpgPouchInventory", MMOCoreUtils.toBase64(content))); @@ -57,6 +57,11 @@ public class GoldPouchDrop extends Drop implements IMultiDrop { return loot; } + private ItemStack setAmount(ItemStack item, int amount) { + item.setAmount(amount); + return item; + } + private int getAvailableSlot(ItemStack[] content) { int slot; while (content[slot = random.nextInt(content.length)] != null) diff --git a/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java b/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java index 8c943eeb..3260490c 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java +++ b/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.gui.eco; +import net.Indyuce.mmocore.util.item.SimpleItemBuilder; import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -13,7 +14,6 @@ import org.bukkit.scheduler.BukkitRunnable; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.util.MMOCoreUtils; -import net.Indyuce.mmocore.api.util.item.ConfigItem; import net.Indyuce.mmocore.gui.api.PluginInventory; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.SmartGive; @@ -30,7 +30,7 @@ public class DepositMenu extends PluginInventory { public Inventory getInventory() { Inventory inv = Bukkit.createInventory(this, 27, "Deposit"); - inv.setItem(26, depositItem = new ConfigItem("DEPOSIT_ITEM").addPlaceholders("worth", "0").build()); + inv.setItem(26, depositItem = new SimpleItemBuilder("DEPOSIT_ITEM").addPlaceholders("worth", "0").build()); new BukkitRunnable() { @@ -115,6 +115,6 @@ public class DepositMenu extends PluginInventory { private void updateDeposit(Inventory inv) { deposit = MMOCoreUtils.getWorth(inv.getContents()); - inv.setItem(26, depositItem = new ConfigItem("DEPOSIT_ITEM").addPlaceholders("worth", "" + deposit).build()); + inv.setItem(26, depositItem = new SimpleItemBuilder("DEPOSIT_ITEM").addPlaceholders("worth", "" + deposit).build()); } } diff --git a/src/main/java/net/Indyuce/mmocore/loot/chest/TierEffect.java b/src/main/java/net/Indyuce/mmocore/loot/chest/TierEffect.java index fb26bd86..cf80f6d5 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/chest/TierEffect.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/TierEffect.java @@ -7,7 +7,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.scheduler.BukkitRunnable; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.util.math.particle.ChestParticleEffect; +import net.Indyuce.mmocore.loot.chest.particle.ChestParticleEffect; public class TierEffect { private final ChestParticleEffect type; diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/GoldDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/GoldDropItem.java index 6f79c112..b19296fb 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/GoldDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/GoldDropItem.java @@ -1,16 +1,19 @@ package net.Indyuce.mmocore.loot.droptable.dropitem; -import net.Indyuce.mmocore.loot.LootBuilder; -import net.Indyuce.mmocore.api.util.item.CurrencyItem; import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.util.item.CurrencyItemBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; +import org.bukkit.inventory.ItemStack; public class GoldDropItem extends DropItem { - public GoldDropItem(MMOLineConfig config) { - super(config); - } + public GoldDropItem(MMOLineConfig config) { + super(config); + } - @Override - public void collect(LootBuilder builder) { - builder.addLoot(new CurrencyItem("GOLD_COIN", 1, rollAmount()).build()); - } + @Override + public void collect(LootBuilder builder) { + ItemStack item = new CurrencyItemBuilder("GOLD_COIN", 1).build(); + item.setAmount(rollAmount()); + builder.addLoot(item); + } } diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/NoteDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/NoteDropItem.java index 41f45c21..f9afeffa 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/NoteDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/NoteDropItem.java @@ -1,23 +1,26 @@ package net.Indyuce.mmocore.loot.droptable.dropitem; -import net.Indyuce.mmocore.loot.LootBuilder; -import net.Indyuce.mmocore.api.util.item.CurrencyItem; import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.util.item.CurrencyItemBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; +import org.bukkit.inventory.ItemStack; public class NoteDropItem extends DropItem { - private final int min, max; + private final int min, max; - public NoteDropItem(MMOLineConfig config) { - super(config); + public NoteDropItem(MMOLineConfig config) { + super(config); - config.validate("max", "min"); + config.validate("max", "min"); - min = (int) config.getDouble("min"); - max = (int) config.getDouble("max"); - } + min = (int) config.getDouble("min"); + max = (int) config.getDouble("max"); + } - @Override - public void collect(LootBuilder builder) { - builder.addLoot(new CurrencyItem("NOTE", random.nextInt(max - min + 1) + min, rollAmount()).build()); - } + @Override + public void collect(LootBuilder builder) { + ItemStack item = new CurrencyItemBuilder("NOTE", random.nextInt(max - min + 1) + min).build(); + item.setAmount(rollAmount()); + builder.addLoot(item); + } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigItemManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigItemManager.java index 6d69fbda..3714e5fb 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigItemManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigItemManager.java @@ -7,7 +7,7 @@ import java.util.logging.Level; import org.bukkit.configuration.file.FileConfiguration; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.util.item.ConfigItem; +import net.Indyuce.mmocore.util.item.ConfigItem; public class ConfigItemManager { private final Map map = new HashMap<>(); diff --git a/src/main/java/net/Indyuce/mmocore/util/item/AbstractItemBuilder.java b/src/main/java/net/Indyuce/mmocore/util/item/AbstractItemBuilder.java new file mode 100644 index 00000000..18aad29f --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/util/item/AbstractItemBuilder.java @@ -0,0 +1,88 @@ +package net.Indyuce.mmocore.util.item; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import io.lumine.mythic.lib.MythicLib; +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.mmocore.MMOCore; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Field; +import java.util.*; +import java.util.logging.Level; + +public abstract class AbstractItemBuilder { + private final ConfigItem configItem; + private final Map placeholders = new HashMap<>(); + + public AbstractItemBuilder(@NotNull ConfigItem configItem) { + this.configItem = Objects.requireNonNull(configItem, "Config item cannot be null"); + } + + public AbstractItemBuilder(String key) { + this(MMOCore.plugin.configItems.get(key)); + } + + public ConfigItem getItem() { + return configItem; + } + + public AbstractItemBuilder addPlaceholders(String... placeholders) { + for (int j = 0; j < placeholders.length - 1; j += 2) + this.placeholders.put(placeholders[j], placeholders[j + 1]); + return this; + } + + public ItemStack build() { + ItemStack item = new ItemStack(configItem.getMaterial()); + ItemMeta meta = item.getItemMeta(); + + if (item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && configItem.getTexture() != null) + try { + Field profileField = meta.getClass().getDeclaredField("profile"); + profileField.setAccessible(true); + GameProfile profile = new GameProfile(UUID.randomUUID(), null); + profile.getProperties().put("textures", new Property("textures", configItem.getTexture())); + profileField.set(meta, profile); + } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) { + MMOCore.log(Level.WARNING, "Could not load texture of config item called '" + configItem.getId() + "'"); + } + + meta.addItemFlags(ItemFlag.values()); + meta.setDisplayName(applyPlaceholders(configItem.getName())); + if (configItem.isUnbreakable()) + meta.setUnbreakable(true); + if (meta instanceof Damageable) + ((Damageable) meta).setDamage(configItem.getDamage()); + meta.setCustomModelData(configItem.getModelData()); + + List lore = new ArrayList<>(); + configItem.getLore().forEach(line -> lore.add(applyPlaceholders(line))); + meta.setLore(lore); + + whenBuildingMeta(item, meta); + item.setItemMeta(meta); + + NBTItem nbtItem = NBTItem.get(item); + nbtItem.addTag(new ItemTag("MMOCoreItemId", configItem.getId())); + whenBuildingNBT(nbtItem); + return nbtItem.toItem(); + } + + public abstract void whenBuildingMeta(ItemStack item, ItemMeta meta); + + public abstract void whenBuildingNBT(NBTItem nbtItem); + + public String applyPlaceholders(String string) { + for (String placeholder : placeholders.keySet()) + if (string.contains("{" + placeholder + "}")) + string = string.replace("{" + placeholder + "}", "" + placeholders.get(placeholder)); + return MythicLib.plugin.parseColors(string); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/util/item/ConfigItem.java b/src/main/java/net/Indyuce/mmocore/util/item/ConfigItem.java new file mode 100644 index 00000000..f778f7b6 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/util/item/ConfigItem.java @@ -0,0 +1,65 @@ +package net.Indyuce.mmocore.util.item; + +import org.apache.commons.lang.Validate; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; + +import javax.annotation.Nullable; +import java.util.List; + +public class ConfigItem { + private final String name, id, texture; + private final Material material; + private final List lore; + private final int damage, modeldata; + private final boolean unbreakable; + + public ConfigItem(ConfigurationSection config) { + id = config.getName(); + name = config.getString("name"); + lore = config.getStringList("lore"); + material = Material.valueOf(config.getString("item")); + + Validate.notNull(name, "Name cannot be null"); + Validate.notNull(lore, "Lore can be empty but not null"); + + // Extra options + damage = config.getInt("damage"); + texture = config.getString("texture"); + modeldata = config.getInt("custom-model-data"); + unbreakable = config.getBoolean("unbreakable"); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public Material getMaterial() { + return material; + } + + public int getDamage() { + return damage; + } + + @Nullable + public String getTexture() { + return texture; + } + + public boolean isUnbreakable() { + return unbreakable; + } + + public List getLore() { + return lore; + } + + public int getModelData() { + return modeldata; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/util/item/CurrencyItemBuilder.java b/src/main/java/net/Indyuce/mmocore/util/item/CurrencyItemBuilder.java new file mode 100644 index 00000000..63be6b29 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/util/item/CurrencyItemBuilder.java @@ -0,0 +1,26 @@ +package net.Indyuce.mmocore.util.item; + +import io.lumine.mythic.lib.api.item.ItemTag; +import io.lumine.mythic.lib.api.item.NBTItem; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class CurrencyItemBuilder extends AbstractItemBuilder { + private final int worth; + + public CurrencyItemBuilder(String key, int worth) { + super(key); + + addPlaceholders("worth", String.valueOf(this.worth = worth)); + } + + @Override + public void whenBuildingMeta(ItemStack item, ItemMeta meta) { + // Nothing + } + + @Override + public void whenBuildingNBT(NBTItem nbtItem) { + nbtItem.addTag(new ItemTag("RpgWorth", worth)); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/util/item/SimpleItemBuilder.java b/src/main/java/net/Indyuce/mmocore/util/item/SimpleItemBuilder.java new file mode 100644 index 00000000..a9b67f0f --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/util/item/SimpleItemBuilder.java @@ -0,0 +1,26 @@ +package net.Indyuce.mmocore.util.item; + +import io.lumine.mythic.lib.api.item.NBTItem; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; + +public class SimpleItemBuilder extends AbstractItemBuilder { + public SimpleItemBuilder(@NotNull ConfigItem configItem) { + super(configItem); + } + + public SimpleItemBuilder(@NotNull String key) { + super(key); + } + + @Override + public void whenBuildingMeta(ItemStack item, ItemMeta meta) { + // Nothing + } + + @Override + public void whenBuildingNBT(NBTItem nbtItem) { + // Nothing + } +}