Search in sources :

Example 36 with DurationTag

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

the class BurnCommand method parseArgs.

// <--[command]
// @Name Burn
// @Syntax burn [<entity>|...] (duration:<value>)
// @Required 1
// @Maximum 2
// @Short Sets a list of entities on fire.
// @Synonyms Ignite,Fire,Torch
// @Group entity
// 
// @Description
// Burn will set a list of entities on fire.
// Just specify a list of entities (or a single entity) and optionally, a duration.
// Normal mobs and players will see damage afflicted, but NPCs will block damage from a burn unless 'vulnerable'.
// Since this command sets the total time of fire, it can also be used to cancel fire on a burning entity by specifying a duration of 0.
// Specifying no duration will result in a 5 second burn.
// 
// @Tags
// <EntityTag.fire_time>
// <EntityTag.on_fire>
// 
// @Usage
// Use to set an entity on fire.
// - burn <player> duration:10s
// 
// @Usage
// Use to cancel fire on entities.
// - burn <player.location.find.living_entities.within[10]> duration:0
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, true));
    scriptEntry.defaultObject("duration", new DurationTag(5));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) EntityTag(com.denizenscript.denizen.objects.EntityTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 37 with DurationTag

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

the class ItemPotion method parseEffect.

public static PotionEffect parseEffect(MapTag effectMap, TagContext context) {
    PotionEffectType type;
    DurationTag duration = new DurationTag(0);
    int amplifier = 0;
    boolean ambient = true;
    boolean particles = true;
    boolean icon = false;
    if (effectMap.getObject("type") != null) {
        String typeString = effectMap.getObject("type").toString();
        type = PotionEffectType.getByName(typeString);
        if (type == null) {
            if (context.showErrors()) {
                Debug.echoError("Invalid potion effect type '" + typeString + "': effect type is required.");
            }
            return null;
        }
    } else {
        if (context.showErrors()) {
            Debug.echoError("Invalid potion effect type: effect type is required.");
        }
        return null;
    }
    if (effectMap.getObject("amplifier") != null) {
        ElementTag amplifierElement = effectMap.getObject("amplifier").asElement();
        if (amplifierElement.isInt()) {
            amplifier = amplifierElement.asInt();
        } else if (context.showErrors()) {
            Debug.echoError("Invalid amplifier '" + amplifierElement + "': must be an integer.");
        }
    }
    if (effectMap.getObject("duration") != null) {
        ObjectTag durationObj = effectMap.getObject("duration");
        if (durationObj.canBeType(DurationTag.class)) {
            duration = durationObj.asType(DurationTag.class, context);
        } else if (context.showErrors()) {
            Debug.echoError("Invalid duration '" + durationObj + "': must be a valid DurationTag");
        }
    }
    if (effectMap.getObject("ambient") != null) {
        ElementTag ambientElement = effectMap.getObject("ambient").asElement();
        if (ambientElement.isBoolean()) {
            ambient = ambientElement.asBoolean();
        } else if (context.showErrors()) {
            Debug.echoError("Invalid ambient state '" + ambientElement + "': must be a boolean.");
        }
    }
    if (effectMap.getObject("particles") != null) {
        ElementTag particlesElement = effectMap.getObject("particles").asElement();
        if (particlesElement.isBoolean()) {
            particles = particlesElement.asBoolean();
        } else if (context.showErrors()) {
            Debug.echoError("Invalid particles state '" + particlesElement + "': must be a boolean.");
        }
    }
    if (effectMap.getObject("icon") != null) {
        ElementTag iconElement = effectMap.getObject("icon").asElement();
        if (iconElement.isBoolean()) {
            icon = iconElement.asBoolean();
        } else if (context.showErrors()) {
            Debug.echoError("Invalid icon state '" + iconElement + "': must be a boolean.");
        }
    }
    return new PotionEffect(type, duration.getTicksAsInt(), amplifier, ambient, particles, icon);
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 38 with DurationTag

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

the class LookCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    final LocationTag loc = scriptEntry.getObjectTag("location");
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    final DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag yaw = scriptEntry.getElement("yaw");
    ElementTag pitch = scriptEntry.getElement("pitch");
    ElementTag cancel = scriptEntry.getElement("cancel");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), cancel, loc, duration, yaw, pitch, db("entities", entities));
    }
    for (EntityTag entity : entities) {
        if (entity.isSpawned()) {
            BukkitTask task = lookTasks.remove(entity.getUUID());
            if (task != null) {
                task.cancel();
            }
        }
    }
    if (cancel != null && cancel.asBoolean()) {
        return;
    }
    final float yawRaw = yaw == null ? 0 : yaw.asFloat();
    final float pitchRaw = pitch == null ? 0 : pitch.asFloat();
    for (EntityTag entity : entities) {
        if (entity.isSpawned()) {
            if (loc != null) {
                NMSHandler.getEntityHelper().faceLocation(entity.getBukkitEntity(), loc);
            } else {
                NMSHandler.getEntityHelper().rotate(entity.getBukkitEntity(), yawRaw, pitchRaw);
            }
        }
    }
    if (duration != null && duration.getTicks() > 2) {
        for (EntityTag entity : entities) {
            BukkitRunnable task = new BukkitRunnable() {

                long bounces = 0;

                public void run() {
                    bounces += 2;
                    if (bounces > duration.getTicks()) {
                        this.cancel();
                        lookTasks.remove(entity.getUUID());
                        return;
                    }
                    if (entity.isSpawned()) {
                        if (loc != null) {
                            NMSHandler.getEntityHelper().faceLocation(entity.getBukkitEntity(), loc);
                        } else {
                            NMSHandler.getEntityHelper().rotate(entity.getBukkitEntity(), yawRaw, pitchRaw);
                        }
                    }
                }
            };
            BukkitTask newTask = task.runTaskTimer(Denizen.getInstance(), 0, 2);
            lookTasks.put(entity.getUUID(), newTask);
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 39 with DurationTag

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

the class CooldownCommand method getCooldownDuration.

public static DurationTag getCooldownDuration(PlayerTag player, String scriptName) {
    TimeTag expires = DenizenCore.serverFlagMap.getFlagExpirationTime("__interact_cooldown." + scriptName);
    if (expires != null) {
        return new DurationTag((expires.millis() - TimeTag.now().millis()) / 1000.0);
    }
    if (player == null) {
        return new DurationTag(0);
    }
    expires = player.getFlagTracker().getFlagExpirationTime("__interact_cooldown." + scriptName);
    if (expires != null) {
        return new DurationTag((expires.millis() - TimeTag.now().millis()) / 1000.0);
    }
    return new DurationTag(0);
}
Also used : TimeTag(com.denizenscript.denizencore.objects.core.TimeTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 40 with DurationTag

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

the class PacketHelperImpl method showSignEditor.

@Override
public boolean showSignEditor(Player player, Location location) {
    if (location == null) {
        LocationTag fakeSign = new LocationTag(player.getLocation());
        fakeSign.setY(0);
        FakeBlock.showFakeBlockTo(Collections.singletonList(new PlayerTag(player)), fakeSign, new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN), new DurationTag(1), true);
        BlockPos pos = new BlockPos(fakeSign.getX(), 0, fakeSign.getZ());
        ((DenizenNetworkManagerImpl) ((CraftPlayer) player).getHandle().connection.connection).packetListener.fakeSignExpected = pos;
        send(player, new ClientboundOpenSignEditorPacket(pos));
        return true;
    }
    BlockEntity tileEntity = ((CraftWorld) location.getWorld()).getHandle().getBlockEntity(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), true);
    if (tileEntity instanceof SignBlockEntity) {
        SignBlockEntity sign = (SignBlockEntity) tileEntity;
        // Prevent client crashing by sending current state of the sign
        send(player, sign.getUpdatePacket());
        sign.isEditable = true;
        sign.setAllowedPlayerEditor(player.getUniqueId());
        send(player, new ClientboundOpenSignEditorPacket(sign.getBlockPos()));
        return true;
    } else {
        return false;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BlockPos(net.minecraft.core.BlockPos) DenizenNetworkManagerImpl(com.denizenscript.denizen.nms.v1_18.impl.network.handlers.DenizenNetworkManagerImpl) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity)

Aggregations

DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)54 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)39 LocationTag (com.denizenscript.denizen.objects.LocationTag)19 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)16 ListTag (com.denizenscript.denizencore.objects.core.ListTag)16 EntityTag (com.denizenscript.denizen.objects.EntityTag)15 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)13 List (java.util.List)11 Player (org.bukkit.entity.Player)7 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)6 ColorTag (com.denizenscript.denizen.objects.ColorTag)5 PotionEffect (org.bukkit.potion.PotionEffect)5 PotionEffectType (org.bukkit.potion.PotionEffectType)5 ItemTag (com.denizenscript.denizen.objects.ItemTag)4 NPCTag (com.denizenscript.denizen.objects.NPCTag)4 WorldTag (com.denizenscript.denizen.objects.WorldTag)4 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)4 LivingEntity (org.bukkit.entity.LivingEntity)4 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3