Search in sources :

Example 6 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerClicksBlockScriptEvent method playerClicksBlock.

@EventHandler
public void playerClicksBlock(PlayerInteractEvent event) {
    if (event.getAction() == Action.PHYSICAL) {
        return;
    }
    blockMaterial = event.hasBlock() ? new MaterialTag(event.getClickedBlock()) : new MaterialTag(Material.AIR);
    hand = new ElementTag(event.getHand().name());
    item = new ItemTag(event.getItem());
    location = event.hasBlock() ? new LocationTag(event.getClickedBlock().getLocation()) : null;
    click_type = new ElementTag(event.getAction().name());
    // Spigot is dumb!
    cancelled = event.isCancelled() && event.useItemInHand() == Event.Result.DENY;
    this.event = event;
    // Explicitly don't use `fire(event)` due to spigot bork
    fire();
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 7 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemEnchantedScriptEvent method onItemEnchanted.

@EventHandler
public void onItemEnchanted(EnchantItemEvent event) {
    entity = new EntityTag(event.getEnchanter());
    location = new LocationTag(event.getEnchantBlock().getLocation());
    inventory = InventoryTag.mirrorBukkitInventory(event.getInventory());
    item = new ItemTag(event.getItem());
    button = new ElementTag(event.whichButton());
    cost = event.getExpLevelCost();
    this.event = event;
    fire(event);
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 8 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerBreaksBlockScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    String determination = determinationObj.toString();
    Block block = event.getBlock();
    if (determinationObj instanceof ElementTag) {
        String lower = CoreUtilities.toLowerCase(determination);
        if (lower.equals("nothing")) {
            event.setExpToDrop(0);
            event.setDropItems(false);
            return true;
        } else if (((ElementTag) determinationObj).isInt()) {
            event.setExpToDrop(((ElementTag) determinationObj).asInt());
            return true;
        }
    }
    if (Argument.valueOf(determination).matchesArgumentList(ItemTag.class)) {
        event.setDropItems(false);
        for (ItemTag newItem : ListTag.valueOf(determination, getTagContext(path)).filter(ItemTag.class, path.container, true)) {
            // Drop each item
            block.getWorld().dropItemNaturally(block.getLocation(), newItem.getItemStack());
        }
        return true;
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : Block(org.bukkit.block.Block) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 9 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerChangesGamemodeScriptEvent method onPlayerChangesGamemode.

@EventHandler
public void onPlayerChangesGamemode(PlayerGameModeChangeEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    gamemode = new ElementTag(event.getNewGameMode().name());
    this.event = event;
    fire(event);
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 10 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class EntityShootsBowEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    String determination = determinationObj.toString();
    if (determinationObj instanceof ElementTag) {
        String lower = CoreUtilities.toLowerCase(determination);
        if (lower.equals("keep_item")) {
            event.setConsumeItem(false);
            if (entity.isPlayer()) {
                final Player p = entity.getPlayer();
                Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), p::updateInventory, 1);
            }
            return true;
        }
    }
    if (Argument.valueOf(determination).matchesArgumentList(EntityTag.class)) {
        cancelled = true;
        cancellationChanged();
        // Get the list of entities
        List<EntityTag> newProjectiles = ListTag.getListFor(determinationObj, getTagContext(path)).filter(EntityTag.class, path.container, true);
        // Go through all the entities, spawning/teleporting them
        for (EntityTag newProjectile : newProjectiles) {
            newProjectile.spawnAt(entity.getEyeLocation().add(entity.getEyeLocation().getDirection()));
            // where applicable
            if (newProjectile.isProjectile()) {
                newProjectile.setShooter(entity);
            }
        }
        // Mount the projectiles on top of each other
        Position.mount(Conversion.convertEntities(newProjectiles));
        // Get the last entity on the list, i.e. the one at the bottom
        // if there are many mounted on top of each other
        Entity lastProjectile = newProjectiles.get(newProjectiles.size() - 1).getBukkitEntity();
        // Give it the same velocity as the arrow that would
        // have been shot by the bow
        // Note: No, I can't explain why this has to be multiplied by three, it just does.
        lastProjectile.setVelocity(event.getEntity().getLocation().getDirection().multiply(event.getForce() * 3));
        return true;
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)237 ListTag (com.denizenscript.denizencore.objects.core.ListTag)86 EntityTag (com.denizenscript.denizen.objects.EntityTag)66 LocationTag (com.denizenscript.denizen.objects.LocationTag)49 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)48 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)43 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)40 List (java.util.List)40 Argument (com.denizenscript.denizencore.objects.Argument)28 Player (org.bukkit.entity.Player)28 MapTag (com.denizenscript.denizencore.objects.core.MapTag)27 EventHandler (org.bukkit.event.EventHandler)26 NPCTag (com.denizenscript.denizen.objects.NPCTag)24 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)19 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)18 ArrayList (java.util.ArrayList)16 Entity (org.bukkit.entity.Entity)16 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)12 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)12