Search in sources :

Example 6 with Inventory

use of net.citizensnpcs.api.trait.trait.Inventory in project Sentinel by mcmonkey4eva.

the class SentinelTrait method swapToRanged.

public void swapToRanged() {
    if (!npc.hasTrait(Inventory.class)) {
        return;
    }
    int i = 0;
    Inventory inv = npc.getTrait(Inventory.class);
    ItemStack[] items = inv.getContents();
    ItemStack held = items[0] == null ? null : items[0].clone();
    boolean edit = false;
    while (!isRanged() && i < items.length - 1) {
        i++;
        if (items[i] != null && items[i].getType() != Material.AIR) {
            items[0] = items[i].clone();
            items[i] = new ItemStack(Material.AIR);
            inv.setContents(items);
            edit = true;
        }
    }
    if (edit) {
        items[i] = held;
        inv.setContents(items);
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Inventory(net.citizensnpcs.api.trait.trait.Inventory) Waypoint(net.citizensnpcs.trait.waypoint.Waypoint)

Aggregations

Inventory (net.citizensnpcs.api.trait.trait.Inventory)6 Waypoint (net.citizensnpcs.trait.waypoint.Waypoint)6 ItemStack (org.bukkit.inventory.ItemStack)6