Search in sources :

Example 46 with DurationTag

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

the class SwitchCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("no_physics") && arg.matches("no_physics")) {
            scriptEntry.addObject("no_physics", new ElementTag(true));
        } else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
            scriptEntry.addObject("locations", arg.asType(ListTag.class));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.class)) {
            scriptEntry.addObject("switchstate", new ElementTag(arg.getValue().toUpperCase()));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("locations")) {
        throw new InvalidArgumentsException("Must specify a location!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(0));
    scriptEntry.defaultObject("switchstate", new ElementTag("TOGGLE"));
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 47 with DurationTag

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

the class FakeItemCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<ItemTag> items = (List<ItemTag>) scriptEntry.getObject("item");
    final ElementTag elSlot = scriptEntry.getElement("slot");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    final List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    final ElementTag player_only = scriptEntry.getElement("player_only");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("items", items), elSlot, duration, db("players", players), player_only);
    }
    if (players.size() == 0) {
        return;
    }
    int slot = SlotHelper.nameToIndex(elSlot.asString(), players.get(0).getPlayerEntity());
    if (slot == -1) {
        Debug.echoError(scriptEntry, "The input '" + elSlot.asString() + "' is not a valid slot!");
        return;
    }
    final boolean playerOnly = player_only.asBoolean();
    final PacketHelper packetHelper = NMSHandler.getPacketHelper();
    for (ItemTag item : items) {
        if (item == null) {
            slot++;
            continue;
        }
        for (PlayerTag player : players) {
            Player ent = player.getPlayerEntity();
            packetHelper.setSlot(ent, translateSlot(ent, slot, playerOnly), item.getItemStack(), playerOnly);
        }
        final int slotSnapshot = slot;
        slot++;
        if (duration.getSeconds() > 0) {
            DenizenCore.schedule(new OneTimeSchedulable(() -> {
                for (PlayerTag player : players) {
                    Player ent = player.getPlayerEntity();
                    int translated = translateSlot(ent, slotSnapshot, playerOnly);
                    ItemStack original = ent.getOpenInventory().getItem(translated);
                    packetHelper.setSlot(ent, translated, original, playerOnly);
                }
            }, (float) duration.getSeconds()));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PacketHelper(com.denizenscript.denizen.nms.interfaces.PacketHelper) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) ItemStack(org.bukkit.inventory.ItemStack) OneTimeSchedulable(com.denizenscript.denizencore.utilities.scheduling.OneTimeSchedulable)

Example 48 with DurationTag

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

the class CastCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    PotionEffectType effect = (PotionEffectType) scriptEntry.getObject("effect");
    int amplifier = scriptEntry.getElement("amplifier").asInt();
    DurationTag duration = scriptEntry.getObjectTag("duration");
    boolean remove = scriptEntry.getElement("remove").asBoolean();
    ElementTag showParticles = scriptEntry.getElement("show_particles");
    ElementTag ambient = scriptEntry.getElement("ambient");
    ElementTag showIcon = scriptEntry.getElement("show_icon");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("Target(s)", entities.toString()), db("Effect", effect.getName()), db("Amplifier", amplifier), duration, ambient, showParticles, showIcon);
    }
    boolean amb = ambient.asBoolean();
    boolean showP = showParticles.asBoolean();
    boolean icon = showIcon.asBoolean();
    for (EntityTag entity : entities) {
        if (entity.getLivingEntity().hasPotionEffect(effect)) {
            entity.getLivingEntity().removePotionEffect(effect);
        }
        if (remove) {
            continue;
        }
        PotionEffect potion = new PotionEffect(effect, duration.getTicksAsInt(), amplifier, amb, showP, icon);
        if (!potion.apply(entity.getLivingEntity())) {
            Debug.echoError(scriptEntry, "Bukkit was unable to apply '" + potion.getType().getName() + "' to '" + entity.toString() + "'.");
        }
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) 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 49 with DurationTag

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

the class PauseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag pauseTypeElement = scriptEntry.getElement("pause_type");
    PauseType pauseType = PauseType.valueOf(pauseTypeElement.asString().toUpperCase());
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), duration, pauseTypeElement);
    }
    NPCTag npc = null;
    if (Utilities.getEntryNPC(scriptEntry) != null) {
        npc = Utilities.getEntryNPC(scriptEntry);
    }
    pause(npc, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));
    if (duration != null) {
        if (durations.containsKey(npc.getCitizen().getId() + pauseType.name())) {
            try {
                Denizen.getInstance().getServer().getScheduler().cancelTask(durations.get(npc.getCitizen().getId() + pauseType.name()));
            } catch (Exception e) {
                Debug.echoError(scriptEntry, "There was an error pausing that!");
                Debug.echoError(scriptEntry, e);
            }
        }
        Debug.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());
        final NPCTag theNpc = npc;
        final ScriptEntry se = scriptEntry;
        durations.put(npc.getId() + pauseType.name(), Denizen.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
            Debug.echoDebug(se, "Running delayed task: Pausing " + pauseType.toString());
            pause(theNpc, pauseType, false);
        }, duration.getTicks()));
    }
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 50 with DurationTag

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

the class DisplayItemCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ItemTag item = scriptEntry.getObjectTag("item");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    LocationTag location = scriptEntry.getObjectTag("location");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), item, duration, location);
    }
    // Drop the item
    final Item dropped = location.getWorld().dropItem(location.getBlockLocation().clone().add(0.5, 1.5, 0.5), item.getItemStack());
    dropped.setVelocity(new Vector(0, 0, 0));
    dropped.setGravity(false);
    dropped.setPickupDelay(32767);
    int ticks = duration.getTicksAsInt();
    NMSHandler.getEntityHelper().setTicksLived(dropped, ticks <= 0 ? -32768 : -ticks);
    if (!dropped.isValid()) {
        Debug.echoDebug(scriptEntry, "Item failed to spawned (likely blocked by some plugin).");
        return;
    }
    final UUID itemUUID = dropped.getUniqueId();
    protectedEntities.add(itemUUID);
    scriptEntry.addObject("dropped", new EntityTag(dropped));
    if (ticks > 0) {
        Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
            protectedEntities.remove(itemUUID);
            if (dropped.isValid() && !dropped.isDead()) {
                dropped.remove();
            }
        }, ticks);
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Item(org.bukkit.entity.Item) EntityTag(com.denizenscript.denizen.objects.EntityTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) UUID(java.util.UUID) Vector(org.bukkit.util.Vector)

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