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;
}
}
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());
}
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);
}
}
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);
}
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);
}
}
}
Aggregations