Search in sources :

Example 11 with DurationTag

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

the class RotateCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    final List<EntityTag> entities = new ArrayList<>((List<EntityTag>) scriptEntry.getObject("entities"));
    final DurationTag duration = scriptEntry.getObjectTag("duration");
    final DurationTag frequency = scriptEntry.getObjectTag("frequency");
    final ElementTag yaw = scriptEntry.getElement("yaw");
    final ElementTag pitch = scriptEntry.getElement("pitch");
    boolean cancel = scriptEntry.hasObject("cancel");
    final boolean infinite = scriptEntry.hasObject("infinite");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), db("entities", entities), (infinite ? db("duration", "infinite") : duration), frequency, yaw, pitch);
    }
    for (EntityTag entity : entities) {
        if (cancel) {
            rotatingEntities.remove(entity.getUUID());
        } else {
            rotatingEntities.add(entity.getUUID());
        }
    }
    if (cancel) {
        return;
    }
    BukkitRunnable task = new BukkitRunnable() {

        int ticks = 0;

        int maxTicks = duration.getTicksAsInt();

        ArrayList<EntityTag> unusedEntities = new ArrayList<>();

        @Override
        public void run() {
            if (entities.isEmpty()) {
                scriptEntry.setFinished(true);
                this.cancel();
            } else if (infinite || ticks < maxTicks) {
                for (EntityTag entity : entities) {
                    if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
                        NMSHandler.getEntityHelper().rotate(entity.getBukkitEntity(), EntityHelper.normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()), entity.getLocation().getPitch() + pitch.asFloat());
                    } else {
                        rotatingEntities.remove(entity.getUUID());
                        unusedEntities.add(entity);
                    }
                }
                if (!unusedEntities.isEmpty()) {
                    for (EntityTag unusedEntity : unusedEntities) {
                        entities.remove(unusedEntity);
                    }
                    unusedEntities.clear();
                }
                ticks = (int) (ticks + frequency.getTicks());
            } else {
                scriptEntry.setFinished(true);
                this.cancel();
            }
        }
    };
    task.runTaskTimer(Denizen.getInstance(), 0, frequency.getTicks());
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 12 with DurationTag

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

the class CooldownCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ScriptTag script = scriptEntry.getObjectTag("script");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    Type type = (scriptEntry.hasObject("type") ? (Type) scriptEntry.getObject("type") : Type.PLAYER);
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("Type", type.name()), script, (type.name().equalsIgnoreCase("player") ? Utilities.getEntryPlayer(scriptEntry) : null), duration);
    }
    switch(type) {
        case PLAYER:
            setCooldown(Utilities.getEntryPlayer(scriptEntry), duration, script.getName(), false);
            break;
        case GLOBAL:
            setCooldown(null, duration, script.getName(), true);
            break;
    }
}
Also used : ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 13 with DurationTag

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

the class TriggerCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag toggle = scriptEntry.getElement("toggle");
    ElementTag trigger = scriptEntry.getElement("trigger");
    ElementTag radius = scriptEntry.getElement("radius");
    DurationTag cooldown = scriptEntry.getObjectTag("cooldown");
    NPCTag npc = scriptEntry.hasObject("npc") ? (NPCTag) scriptEntry.getObject("npc") : Utilities.getEntryNPC(scriptEntry);
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), trigger, toggle, radius, cooldown, npc);
    }
    // Add trigger trait
    if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
        npc.getCitizen().addTrait(TriggerTrait.class);
    }
    TriggerTrait trait = npc.getCitizen().getOrAddTrait(TriggerTrait.class);
    switch(Toggle.valueOf(toggle.asString().toUpperCase())) {
        case TOGGLE:
            trait.toggleTrigger(trigger.asString());
            break;
        case TRUE:
            trait.toggleTrigger(trigger.asString(), true);
            break;
        case FALSE:
            trait.toggleTrigger(trigger.asString(), false);
            break;
    }
    if (radius != null) {
        trait.setLocalRadius(trigger.asString(), radius.asInt());
    }
    if (cooldown != null) {
        trait.setLocalCooldown(trigger.asString(), cooldown.getSeconds());
    }
}
Also used : TriggerTrait(com.denizenscript.denizen.npc.traits.TriggerTrait) NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 14 with DurationTag

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

the class ItemCooldownCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ArrayList<MaterialTag> materials = (ArrayList<MaterialTag>) scriptEntry.getObject("materials");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
    if (player == null) {
        Debug.echoError("Invalid linked player.");
        return;
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("materials", materials), duration);
    }
    for (MaterialTag mat : materials) {
        player.getPlayerEntity().setCooldown(mat.getMaterial(), duration.getTicksAsInt());
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ArrayList(java.util.ArrayList) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 15 with DurationTag

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

the class ShowFakeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    NetworkInterceptHelper.enable();
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag cancel = scriptEntry.getElement("cancel");
    List<MaterialTag> materials = (List<MaterialTag>) scriptEntry.getObject("materials");
    List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), duration, cancel, db("materials", materials), db("locations", locations), db("players", players));
    }
    boolean shouldCancel = cancel.asBoolean();
    int i = 0;
    for (LocationTag loc : locations) {
        if (!shouldCancel) {
            FakeBlock.showFakeBlockTo(players, loc.getBlockLocation(), materials.get(i % materials.size()), duration, locations.size() < 5);
        } else {
            FakeBlock.stopShowingTo(players, loc.getBlockLocation());
        }
        i++;
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

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