Search in sources :

Example 1 with InventoryTag

use of com.denizenscript.denizen.objects.InventoryTag in project Denizen-For-Bukkit by DenizenScript.

the class GiveCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag unlimit_stack_size = scriptEntry.getElement("unlimit_stack_size");
    InventoryTag inventory = scriptEntry.getObjectTag("inventory");
    ElementTag quantity = scriptEntry.getElement("quantity");
    Type type = (Type) scriptEntry.getObject("type");
    ElementTag slot = scriptEntry.getElement("slot");
    Object items_object = scriptEntry.getObject("items");
    List<ItemTag> items = null;
    if (items_object != null) {
        items = (List<ItemTag>) items_object;
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("Type", type.name()), inventory, quantity, unlimit_stack_size, db("Items", items), slot);
    }
    switch(type) {
        case MONEY:
            if (Depends.economy != null) {
                Depends.economy.depositPlayer(Utilities.getEntryPlayer(scriptEntry).getOfflinePlayer(), quantity.asDouble());
            } else {
                Debug.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
            }
            break;
        case EXP:
            Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().giveExp(quantity.asInt());
            break;
        case ITEM:
            boolean set_quantity = scriptEntry.hasObject("set_quantity");
            boolean limited = !unlimit_stack_size.asBoolean();
            for (ItemTag item : items) {
                ItemStack is = item.getItemStack();
                if (is.getType() == Material.AIR) {
                    Debug.echoError("Cannot give air!");
                    continue;
                }
                if (set_quantity) {
                    is.setAmount(quantity.asInt());
                }
                int slotId = SlotHelper.nameToIndexFor(slot.asString(), inventory.getInventory().getHolder());
                if (slotId == -1) {
                    Debug.echoError(scriptEntry, "The input '" + slot.asString() + "' is not a valid slot!");
                    return;
                }
                List<ItemStack> leftovers = inventory.addWithLeftovers(slotId, limited, is);
                if (!leftovers.isEmpty()) {
                    Debug.echoDebug(scriptEntry, "The inventory didn't have enough space, the rest of the items have been placed on the floor.");
                    for (ItemStack leftoverItem : leftovers) {
                        inventory.getLocation().getWorld().dropItem(inventory.getLocation(), leftoverItem);
                    }
                }
            }
            break;
    }
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) ItemStack(org.bukkit.inventory.ItemStack) InventoryTag(com.denizenscript.denizen.objects.InventoryTag)

Example 2 with InventoryTag

use of com.denizenscript.denizen.objects.InventoryTag in project Denizen-For-Bukkit by DenizenScript.

the class InventoryTrackerSystem method setup.

public static void setup() {
    Bukkit.getScheduler().scheduleSyncRepeatingTask(Denizen.getInstance(), () -> {
        if (idTrackedInventories.size() > 300) {
            idTrackedInventories.clear();
            for (InventoryTag temp : temporaryInventoryLinks.values()) {
                idTrackedInventories.put(temp.uniquifier, temp);
            }
            for (InventoryTag retained : retainedInventoryLinks.values()) {
                idTrackedInventories.put(retained.uniquifier, retained);
                temporaryInventoryLinks.put(retained.getInventory(), retained);
            }
        }
        InventoryTrackerSystem.temporaryInventoryLinks.clear();
    }, 20, 20);
    Bukkit.getPluginManager().registerEvents(new InventoryTrackerSystem(), Denizen.getInstance());
}
Also used : InventoryTag(com.denizenscript.denizen.objects.InventoryTag)

Example 3 with InventoryTag

use of com.denizenscript.denizen.objects.InventoryTag in project Denizen-For-Bukkit by DenizenScript.

the class InventoryTrackerSystem method onPlayerOpensInventory.

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerOpensInventory(InventoryOpenEvent event) {
    if (event.isCancelled()) {
        return;
    }
    InventoryTag tagForm = getTagFormFor(event.getInventory());
    if (isGenericTrackable(tagForm)) {
        trackTemporaryInventory(event.getInventory(), tagForm);
        retainedInventoryLinks.put(event.getInventory(), tagForm);
    }
}
Also used : InventoryTag(com.denizenscript.denizen.objects.InventoryTag) EventHandler(org.bukkit.event.EventHandler)

Example 4 with InventoryTag

use of com.denizenscript.denizen.objects.InventoryTag in project Denizen-For-Bukkit by DenizenScript.

the class InventoryTrackerSystem method onPlayerCloseInventory.

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCloseInventory(InventoryCloseEvent event) {
    Inventory inv = event.getInventory();
    Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
        if (inv.getViewers().isEmpty()) {
            InventoryTag removed = retainedInventoryLinks.remove(inv);
            if (removed != null && removed.uniquifier != null) {
                idTrackedInventories.remove(removed.uniquifier);
                temporaryInventoryLinks.put(inv, removed);
            }
        }
    }, 1);
}
Also used : InventoryTag(com.denizenscript.denizen.objects.InventoryTag) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 5 with InventoryTag

use of com.denizenscript.denizen.objects.InventoryTag in project Denizen-For-Bukkit by DenizenScript.

the class InventoryScriptHelper method onPlayerClicks.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerClicks(InventoryClickEvent event) {
    InventoryTag inventory = InventoryTag.mirrorBukkitInventory(event.getInventory());
    if (event.getRawSlot() >= event.getInventory().getSize() || event.getRawSlot() < 0) {
        if (allowedClicks.contains(event.getClick())) {
            return;
        }
    }
    if (inventory.getIdHolder() instanceof ScriptTag) {
        if (((InventoryScriptContainer) ((ScriptTag) inventory.getIdHolder()).getContainer()).gui) {
            event.setCancelled(true);
            Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
                ((Player) event.getWhoClicked()).updateInventory();
            }, 1);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ImprovedOfflinePlayer(com.denizenscript.denizen.nms.abstracts.ImprovedOfflinePlayer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) InventoryTag(com.denizenscript.denizen.objects.InventoryTag) EventHandler(org.bukkit.event.EventHandler)

Aggregations

InventoryTag (com.denizenscript.denizen.objects.InventoryTag)9 ItemTag (com.denizenscript.denizen.objects.ItemTag)4 ListTag (com.denizenscript.denizencore.objects.core.ListTag)4 ItemStack (org.bukkit.inventory.ItemStack)4 EventHandler (org.bukkit.event.EventHandler)3 Argument (com.denizenscript.denizencore.objects.Argument)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)2 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)2 List (java.util.List)2 Player (org.bukkit.entity.Player)2 Inventory (org.bukkit.inventory.Inventory)2 BukkitScriptEvent (com.denizenscript.denizen.events.BukkitScriptEvent)1 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)1 ImprovedOfflinePlayer (com.denizenscript.denizen.nms.abstracts.ImprovedOfflinePlayer)1 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)1 ItemScriptHelper (com.denizenscript.denizen.scripts.containers.core.ItemScriptHelper)1 Utilities (com.denizenscript.denizen.utilities.Utilities)1 Debug (com.denizenscript.denizen.utilities.debugging.Debug)1 Depends (com.denizenscript.denizen.utilities.depends.Depends)1