Search in sources :

Example 11 with ItemTag

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

the class ItemRecipeFormedScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    if (determinationObj.canBeType(ItemTag.class)) {
        ItemTag result = determinationObj.asType(ItemTag.class, getTagContext(path));
        event.getInventory().setResult(result.getItemStack());
        return true;
    } else {
        return super.applyDetermination(path, determinationObj);
    }
}
Also used : ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 12 with ItemTag

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

the class EntityDeathScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    String determination = determinationObj.toString();
    String lower = CoreUtilities.toLowerCase(determination);
    if (lower.startsWith("drops ")) {
        // legacy drops determination format
        lower = lower.substring(6);
        determination = determination.substring(6);
    }
    if (lower.startsWith("no_drops")) {
        event.getDrops().clear();
        if (lower.endsWith("_or_xp")) {
            event.setDroppedExp(0);
        }
        return true;
    } else if (lower.equals("no_xp")) {
        event.setDroppedExp(0);
        return true;
    } else if (lower.equals("keep_inv") && event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setKeepInventory(true);
        return true;
    } else if (lower.equals("keep_level") && event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setKeepLevel(true);
        return true;
    } else if (lower.equals("no_message") && event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setDeathMessage(null);
        return true;
    } else if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
        event.setDroppedExp(((ElementTag) determinationObj).asInt());
        return true;
    } else if (Argument.valueOf(lower).matchesArgumentList(ItemTag.class)) {
        List<ItemStack> drops = event.getDrops();
        drops.clear();
        for (ItemTag item : ListTag.getListFor(determinationObj, getTagContext(path)).filter(ItemTag.class, getTagContext(path), true)) {
            if (item != null) {
                drops.add(item.getItemStack());
            }
        }
        return true;
    } else if (event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setDeathMessage(determination);
        return true;
    } else {
        return super.applyDetermination(path, determinationObj);
    }
}
Also used : PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 13 with ItemTag

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

the class EntityDropsItemScriptEvent method onPlayerDropsItem.

@EventHandler
public void onPlayerDropsItem(PlayerDropItemEvent event) {
    dropper = new EntityTag(event.getPlayer());
    location = dropper.getLocation();
    itemEntity = new EntityTag(event.getItemDrop());
    EntityTag.rememberEntity(itemEntity.getBukkitEntity());
    item = new ItemTag(((Item) itemEntity.getBukkitEntity()).getItemStack());
    fire(event);
}
Also used : Item(org.bukkit.entity.Item) EntityTag(com.denizenscript.denizen.objects.EntityTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 14 with ItemTag

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

the class EntityDropsItemScriptEvent method onEntityDropsItem.

@EventHandler
public void onEntityDropsItem(EntityDropItemEvent event) {
    dropper = new EntityTag(event.getEntity());
    location = dropper.getLocation();
    itemEntity = new EntityTag(event.getItemDrop());
    EntityTag.rememberEntity(itemEntity.getBukkitEntity());
    item = new ItemTag(((Item) itemEntity.getBukkitEntity()).getItemStack());
    fire(event);
}
Also used : Item(org.bukkit.entity.Item) EntityTag(com.denizenscript.denizen.objects.EntityTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 15 with ItemTag

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

the class PlayerConsumesScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    String determination = determinationObj.toString();
    if (ItemTag.matches(determination)) {
        BukkitTagContext context = new BukkitTagContext(EntityTag.getPlayerFrom(event.getPlayer()), null, new ScriptTag(path.container));
        ItemTag newitem = ItemTag.valueOf(determination, context);
        if (newitem != null) {
            event.setItem(newitem.getItemStack());
            return true;
        } else {
            Debug.echoError("Invalid event 'item' check [" + getName() + "] ('determine item ????'): '" + determination + "' for " + path.container.getName());
        }
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Aggregations

ItemTag (com.denizenscript.denizen.objects.ItemTag)77 EventHandler (org.bukkit.event.EventHandler)35 ItemStack (org.bukkit.inventory.ItemStack)20 LocationTag (com.denizenscript.denizen.objects.LocationTag)19 EntityTag (com.denizenscript.denizen.objects.EntityTag)14 ListTag (com.denizenscript.denizencore.objects.core.ListTag)14 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)13 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)9 Item (org.bukkit.entity.Item)7 Argument (com.denizenscript.denizencore.objects.Argument)6 List (java.util.List)6 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)5 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)5 HumanEntity (org.bukkit.entity.HumanEntity)5 Player (org.bukkit.entity.Player)5 InventoryTag (com.denizenscript.denizen.objects.InventoryTag)4 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)4 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)4 ArrayList (java.util.ArrayList)4 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)3