Search in sources :

Example 16 with ElementTag

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

the class PlayerKickedScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    if (determinationObj instanceof ElementTag) {
        String lower = CoreUtilities.toLowerCase(determinationObj.toString());
        if (lower.startsWith("message:")) {
            event.setLeaveMessage(lower.substring("message:".length()));
            return true;
        } else if (lower.startsWith("reason:")) {
            event.setReason(lower.substring("reason:".length()));
            return true;
        } else if (lower.startsWith("fly_cooldown:")) {
            DurationTag duration = DurationTag.valueOf(lower.substring("fly_cooldown:".length()), getTagContext(path));
            if (duration != null) {
                NMSHandler.getPlayerHelper().setFlyKickCooldown(player.getPlayerEntity(), (int) duration.getTicks());
                cancelled = true;
                return true;
            }
        }
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 17 with ElementTag

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

the class PlayerPlacesBlockScriptEvent method onPlayerPlacesBlock.

@EventHandler
public void onPlayerPlacesBlock(BlockPlaceEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    hand = new ElementTag(event.getHand().name());
    material = new MaterialTag(event.getBlock());
    location = new LocationTag(event.getBlock().getLocation());
    item_in_hand = new ItemTag(event.getItemInHand());
    this.event = event;
    fire(event);
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 18 with ElementTag

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

the class PlayerPreLoginScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    String determination = determinationObj.toString();
    if (determinationObj instanceof ElementTag) {
        if (CoreUtilities.toLowerCase(determination).startsWith("kicked")) {
            String message = determination.length() > 7 ? determination.substring(7) : determination;
            event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, message);
            return true;
        }
    }
    if (QueueTag.matches(determination)) {
        QueueTag newQueue = QueueTag.valueOf(determination, getTagContext(path));
        if (newQueue != null && newQueue.getQueue() != null) {
            waitForQueues.add(newQueue);
        }
        return true;
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : QueueTag(com.denizenscript.denizencore.objects.core.QueueTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 19 with ElementTag

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

the class PlayerPreparesEnchantScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    if (determinationObj instanceof ElementTag) {
        String determineLow = CoreUtilities.toLowerCase(determinationObj.toString());
        if (determineLow.startsWith("offers:")) {
            ListTag offers = ListTag.valueOf(determineLow.substring("offers:".length()), getTagContext(path));
            if (offers.size() != event.getOffers().length) {
                Debug.echoError("Offer list size incorrect.");
                return false;
            }
            for (int i = 0; i < offers.size(); i++) {
                MapTag map = MapTag.getMapFor(offers.getObject(i), getTagContext(path));
                event.getOffers()[i].setCost(map.getObject("cost").asElement().asInt());
                ObjectTag enchantment = map.getObject("enchantment_type");
                if (enchantment == null) {
                    enchantment = map.getObject("enchantment");
                }
                event.getOffers()[i].setEnchantment(enchantment.asType(EnchantmentTag.class, getTagContext(path)).enchantment);
                event.getOffers()[i].setEnchantmentLevel(map.getObject("level").asElement().asInt());
            }
            return true;
        }
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 20 with ElementTag

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

the class PlayerPreparesEnchantScriptEvent method getContext.

@Override
public ObjectTag getContext(String name) {
    switch(name) {
        case "item":
            return new ItemTag(event.getItem());
        case "location":
            return new LocationTag(event.getEnchantBlock().getLocation());
        case "bonus":
            return new ElementTag(event.getEnchantmentBonus());
        case "offers":
            ListTag output = new ListTag();
            for (EnchantmentOffer offer : event.getOffers()) {
                MapTag map = new MapTag();
                map.putObject("cost", new ElementTag(offer.getCost()));
                map.putObject("enchantment", new ElementTag(offer.getEnchantment().getKey().getKey()));
                map.putObject("enchantment_type", new EnchantmentTag(offer.getEnchantment()));
                map.putObject("level", new ElementTag(offer.getEnchantmentLevel()));
                output.addObject(map);
            }
            return output;
    }
    return super.getContext(name);
}
Also used : EnchantmentOffer(org.bukkit.enchantments.EnchantmentOffer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

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