Search in sources :

Example 21 with ItemTag

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

the class PlayerMendsItemScriptEvent method onPlayerItemMend.

@EventHandler
public void onPlayerItemMend(PlayerItemMendEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    item = new ItemTag(event.getItem());
    location = new LocationTag(event.getPlayer().getLocation());
    this.event = event;
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 22 with ItemTag

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

the class PlayerTakesFromLecternScriptEvent method onPlayerTakesFromLectern.

@EventHandler
public void onPlayerTakesFromLectern(PlayerTakeLecternBookEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    item = new ItemTag(event.getBook());
    location = new LocationTag(event.getLectern().getLocation());
    this.event = event;
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 23 with ItemTag

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

the class PlayerFishesScriptEvent method matches.

@Override
public boolean matches(ScriptPath path) {
    String fish = path.eventArgLowerAt(2);
    if (!fish.isEmpty() && !fish.equals("in") && !fish.equals("while")) {
        if (entity == null) {
            return false;
        }
        if (!tryEntity(entity, fish)) {
            if (item == null) {
                return false;
            }
            if (!tryItem(item, fish)) {
                return false;
            }
        }
    }
    String[] data = path.eventArgsLower;
    for (int index = 2; index < data.length; index++) {
        if (data[index].equals("while") && !data[index + 1].equalsIgnoreCase(state.asString())) {
            return false;
        }
    }
    if (!runInCheck(path, hook.getLocation())) {
        return false;
    }
    if (path.switches.containsKey("with")) {
        if (!EntityTag.isPlayer(event.getPlayer())) {
            return false;
        }
        ItemStack held = event.getPlayer().getEquipment().getItemInMainHand();
        if (held.getType() != Material.FISHING_ROD) {
            held = event.getPlayer().getEquipment().getItemInOffHand();
        }
        if (!runWithCheck(path, new ItemTag(held))) {
            return false;
        }
    }
    return super.matches(path);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 24 with ItemTag

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

the class PlayerFishesScriptEvent method onPlayerFishes.

@EventHandler
public void onPlayerFishes(PlayerFishEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    Entity hookEntity = NMSHandler.getEntityHelper().getFishHook(event);
    EntityTag.rememberEntity(hookEntity);
    hook = new EntityTag(hookEntity);
    state = new ElementTag(event.getState().toString());
    item = null;
    entity = null;
    Entity caughtEntity = event.getCaught();
    if (caughtEntity != null) {
        EntityTag.rememberEntity(caughtEntity);
        entity = new EntityTag(caughtEntity);
        if (caughtEntity instanceof Item) {
            item = new ItemTag(((Item) caughtEntity).getItemStack());
        }
    }
    this.event = event;
    fire(event);
    EntityTag.forgetEntity(hookEntity);
    EntityTag.forgetEntity(caughtEntity);
}
Also used : Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 25 with ItemTag

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

the class LootGenerateScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    if (determinationObj instanceof ElementTag) {
        String determination = determinationObj.toString();
        String determinationLower = CoreUtilities.toLowerCase(determination);
        if (determinationLower.startsWith("loot:")) {
            ListTag list = ListTag.valueOf(determination.substring("loot:".length()), getTagContext(path));
            ArrayList<ItemStack> newLoot = new ArrayList<>(list.size());
            for (ItemTag item : list.filter(ItemTag.class, getTagContext(path))) {
                newLoot.add(item.getItemStack());
            }
            event.setLoot(newLoot);
            return true;
        }
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : ArrayList(java.util.ArrayList) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

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