Search in sources :

Example 1 with IItemStack

use of io.github.wysohn.triggerreactor.core.bridge.IItemStack in project TriggerReactor by wysohn.

the class InventoryTriggerManager method setData.

@Override
public void setData(File file, String key, Object value) throws IOException {
    if (key.equals(ITEMS)) {
        Utf8YamlConfiguration conf = new Utf8YamlConfiguration();
        try {
            conf.load(file);
        } catch (InvalidConfigurationException e) {
            e.printStackTrace();
        }
        IItemStack[] items = (IItemStack[]) value;
        writeItemList(conf, items);
        conf.save(file);
    } else {
        BukkitTriggerManager.super.setData(file, key, value);
    }
}
Also used : Utf8YamlConfiguration(io.github.wysohn.triggerreactor.misc.Utf8YamlConfiguration) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 2 with IItemStack

use of io.github.wysohn.triggerreactor.core.bridge.IItemStack in project TriggerReactor by wysohn.

the class InventoryTriggerManager method parseItemsList.

@SuppressWarnings("unchecked")
private void parseItemsList(ConfigurationSection itemSection, Map<Integer, IItemStack> items, int size) {
    for (int i = 0; i < size; i++) {
        ConfigurationSection section = itemSection.getConfigurationSection(String.valueOf(i));
        if (section == null)
            continue;
        Material type = Material.valueOf((String) section.get("Type", Material.DIRT.name()));
        int amount = section.getInt("Amount", 1);
        short data = (short) section.getInt("Data", 0);
        ItemMeta IM = (ItemMeta) section.get("Meta");
        ItemStack IS = new ItemStack(type, amount, data);
        if (IM == null)
            IM = IS.getItemMeta();
        if (IM != null) {
            // leave these for backward compatibility
            String title = section.getString("Title", null);
            Object lore = section.get("Lore", null);
            if (title != null)
                IM.setDisplayName(title);
            if (lore != null && lore instanceof List)
                IM.setLore((List<String>) lore);
            IS.setItemMeta(IM);
        }
        items.put(i, new BukkitItemStack(IS));
    }
}
Also used : BukkitItemStack(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitItemStack) Material(org.bukkit.Material) ArrayList(java.util.ArrayList) List(java.util.List) BukkitItemStack(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitItemStack) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 3 with IItemStack

use of io.github.wysohn.triggerreactor.core.bridge.IItemStack in project TriggerReactor by wysohn.

the class JavaPluginBridge method setLore.

@Override
protected boolean setLore(IItemStack iS, int index, String lore) {
    ItemStack IS = iS.get();
    ItemMeta IM = IS.getItemMeta();
    List<String> lores = IM.hasLore() ? IM.getLore() : new ArrayList<>();
    if (lore == null || index < 0 || index > lores.size() - 1)
        return false;
    lores.set(index, lore);
    IM.setLore(lores);
    IS.setItemMeta(IM);
    return true;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 4 with IItemStack

use of io.github.wysohn.triggerreactor.core.bridge.IItemStack in project TriggerReactor by wysohn.

the class JavaPluginBridge method setItemTitle.

@Override
protected void setItemTitle(IItemStack iS, String title) {
    ItemStack IS = iS.get();
    ItemMeta IM = IS.getItemMeta();
    IM.setDisplayName(title);
    IS.setItemMeta(IM);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 5 with IItemStack

use of io.github.wysohn.triggerreactor.core.bridge.IItemStack in project TriggerReactor by wysohn.

the class JavaPluginBridge method addItemLore.

@Override
protected void addItemLore(IItemStack iS, String lore) {
    ItemStack IS = iS.get();
    ItemMeta IM = IS.getItemMeta();
    List<String> lores = IM.hasLore() ? IM.getLore() : new ArrayList<>();
    lores.add(lore);
    IM.setLore(lores);
    IS.setItemMeta(IM);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

IItemStack (io.github.wysohn.triggerreactor.core.bridge.IItemStack)10 ItemStack (org.bukkit.inventory.ItemStack)6 ItemMeta (org.bukkit.inventory.meta.ItemMeta)5 BukkitItemStack (io.github.wysohn.triggerreactor.bukkit.bridge.BukkitItemStack)2 Utf8YamlConfiguration (io.github.wysohn.triggerreactor.misc.Utf8YamlConfiguration)2 HashMap (java.util.HashMap)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)2 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)1 ILocation (io.github.wysohn.triggerreactor.core.bridge.ILocation)1 IPlayer (io.github.wysohn.triggerreactor.core.bridge.player.IPlayer)1 AbstractAreaSelectionManager (io.github.wysohn.triggerreactor.core.manager.AbstractAreaSelectionManager)1 AbstractExecutorManager (io.github.wysohn.triggerreactor.core.manager.AbstractExecutorManager)1 AbstractPermissionManager (io.github.wysohn.triggerreactor.core.manager.AbstractPermissionManager)1 AbstractPlaceholderManager (io.github.wysohn.triggerreactor.core.manager.AbstractPlaceholderManager)1 AbstractPlayerLocationManager (io.github.wysohn.triggerreactor.core.manager.AbstractPlayerLocationManager)1 AbstractScriptEditManager (io.github.wysohn.triggerreactor.core.manager.AbstractScriptEditManager)1 AbstractVariableManager (io.github.wysohn.triggerreactor.core.manager.AbstractVariableManager)1 Manager (io.github.wysohn.triggerreactor.core.manager.Manager)1 Area (io.github.wysohn.triggerreactor.core.manager.location.Area)1