Search in sources :

Example 1 with DurationTag

use of com.denizenscript.denizencore.objects.core.DurationTag 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 2 with DurationTag

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

the class ChunkTag method registerTags.

public static void registerTags() {
    AbstractFlagTracker.registerFlagHandlers(tagProcessor);
    // <--[tag]
    // @attribute <ChunkTag.add[<#>,<#>]>
    // @returns ChunkTag
    // @description
    // Returns the chunk with the specified coordinates added to it.
    // -->
    tagProcessor.registerTag(ChunkTag.class, "add", (attribute, object) -> {
        if (!attribute.hasParam()) {
            attribute.echoError("The tag ChunkTag.add[<#>,<#>] must have a value.");
            return null;
        }
        List<String> coords = CoreUtilities.split(attribute.getParam(), ',');
        if (coords.size() < 2) {
            attribute.echoError("The tag ChunkTag.add[<#>,<#>] requires two values!");
            return null;
        }
        if (!ArgumentHelper.matchesInteger(coords.get(0)) || !ArgumentHelper.matchesInteger(coords.get(1))) {
            attribute.echoError("Input to ChunkTag.add[x,z] is not a valid integer pair!");
            return null;
        }
        int x = Integer.parseInt(coords.get(0));
        int z = Integer.parseInt(coords.get(1));
        return new ChunkTag(object.world, object.chunkX + x, object.chunkZ + z);
    });
    // <--[tag]
    // @attribute <ChunkTag.sub[<#>,<#>]>
    // @returns ChunkTag
    // @description
    // Returns the chunk with the specified coordinates subtracted from it.
    // -->
    tagProcessor.registerTag(ChunkTag.class, "sub", (attribute, object) -> {
        if (!attribute.hasParam()) {
            attribute.echoError("The tag ChunkTag.add[<#>,<#>] must have a value.");
            return null;
        }
        List<String> coords = CoreUtilities.split(attribute.getParam(), ',');
        if (coords.size() < 2) {
            attribute.echoError("The tag ChunkTag.sub[<#>,<#>] requires two values!");
            return null;
        }
        if (!ArgumentHelper.matchesInteger(coords.get(0)) || !ArgumentHelper.matchesInteger(coords.get(1))) {
            attribute.echoError("Input to ChunkTag.sub[x,z] is not a valid integer pair!");
            return null;
        }
        int x = Integer.parseInt(coords.get(0));
        int z = Integer.parseInt(coords.get(1));
        return new ChunkTag(object.world, object.chunkX - x, object.chunkZ - z);
    });
    // <--[tag]
    // @attribute <ChunkTag.is_generated>
    // @returns ElementTag(Boolean)
    // @description
    // Returns true if the chunk has already been generated.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_generated", (attribute, object) -> {
        return new ElementTag(object.getBukkitWorld().isChunkGenerated(object.chunkX, object.chunkZ));
    });
    // <--[tag]
    // @attribute <ChunkTag.is_loaded>
    // @returns ElementTag(Boolean)
    // @description
    // Returns true if the chunk is currently loaded into memory.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_loaded", (attribute, object) -> {
        return new ElementTag(object.isLoadedSafe());
    });
    // <--[tag]
    // @attribute <ChunkTag.force_loaded>
    // @returns ElementTag(Boolean)
    // @mechanism ChunkTag.force_loaded
    // @description
    // Returns whether the chunk is forced to stay loaded at all times.
    // -->
    tagProcessor.registerTag(ElementTag.class, "force_loaded", (attribute, object) -> {
        if (!object.isLoadedSafe()) {
            return new ElementTag(false);
        }
        Chunk chunk = object.getChunkForTag(attribute);
        return new ElementTag(chunk != null && chunk.isForceLoaded());
    });
    // <--[tag]
    // @attribute <ChunkTag.plugin_tickets>
    // @returns ListTag(PluginTag)
    // @mechanism ChunkTag.clear_plugin_tickets
    // @description
    // Returns a list of plugins that are keeping this chunk loaded.
    // This is related to the <@link command chunkload> command.
    // -->
    tagProcessor.registerTag(ListTag.class, "plugin_tickets", (attribute, object) -> {
        if (!object.isLoadedSafe()) {
            return new ListTag();
        }
        Chunk chunk = object.getChunkForTag(attribute);
        ListTag result = new ListTag();
        for (Plugin plugin : chunk.getPluginChunkTickets()) {
            result.addObject(new PluginTag(plugin));
        }
        return result;
    });
    // <--[tag]
    // @attribute <ChunkTag.x>
    // @returns ElementTag(Number)
    // @description
    // Returns the x coordinate of the chunk.
    // -->
    tagProcessor.registerTag(ElementTag.class, "x", (attribute, object) -> {
        return new ElementTag(object.chunkX);
    });
    // <--[tag]
    // @attribute <ChunkTag.z>
    // @returns ElementTag(Number)
    // @description
    // Returns the z coordinate of the chunk.
    // -->
    tagProcessor.registerTag(ElementTag.class, "z", (attribute, object) -> {
        return new ElementTag(object.chunkZ);
    });
    // <--[tag]
    // @attribute <ChunkTag.world>
    // @returns WorldTag
    // @description
    // Returns the world associated with the chunk.
    // -->
    tagProcessor.registerTag(WorldTag.class, "world", (attribute, object) -> {
        return object.world;
    });
    // <--[tag]
    // @attribute <ChunkTag.cuboid>
    // @returns CuboidTag
    // @description
    // Returns a cuboid of this chunk.
    // -->
    tagProcessor.registerTag(CuboidTag.class, "cuboid", (attribute, object) -> {
        int yMin = 0, yMax = 255;
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17)) {
            World world = object.getBukkitWorld();
            if (world != null) {
                yMin = world.getMinHeight();
                yMax = world.getMaxHeight();
            }
        }
        return new CuboidTag(new LocationTag(object.getWorldName(), object.getX() * 16, yMin, object.getZ() * 16, 0, 0), new LocationTag(object.getWorldName(), object.getX() * 16 + 15, yMax, object.getZ() * 16 + 15, 0, 0));
    });
    // <--[tag]
    // @attribute <ChunkTag.tile_entities>
    // @returns ListTag(LocationTag)
    // @description
    // Returns a list of tile entity locations in the chunk.
    // -->
    tagProcessor.registerTag(ListTag.class, "tile_entities", (attribute, object) -> {
        ListTag tiles = new ListTag();
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        try {
            NMSHandler.getChunkHelper().changeChunkServerThread(object.getBukkitWorld());
            for (BlockState block : chunk.getTileEntities()) {
                tiles.addObject(new LocationTag(block.getLocation()));
            }
        } finally {
            NMSHandler.getChunkHelper().restoreServerThread(object.getBukkitWorld());
        }
        return tiles;
    });
    // <--[tag]
    // @attribute <ChunkTag.entities[(<entity>|...)]>
    // @returns ListTag(EntityTag)
    // @description
    // Returns a list of entities in the chunk.
    // Optionally specify entity types to filter down to.
    // -->
    tagProcessor.registerTag(ListTag.class, "entities", (attribute, object) -> {
        ListTag entities = new ListTag();
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        ListTag typeFilter = attribute.hasParam() ? attribute.paramAsType(ListTag.class) : null;
        try {
            NMSHandler.getChunkHelper().changeChunkServerThread(object.getBukkitWorld());
            for (Entity entity : chunk.getEntities()) {
                EntityTag current = new EntityTag(entity);
                if (typeFilter != null) {
                    for (String type : typeFilter) {
                        if (current.comparedTo(type)) {
                            entities.addObject(current.getDenizenObject());
                            break;
                        }
                    }
                } else {
                    entities.addObject(current.getDenizenObject());
                }
            }
        } finally {
            NMSHandler.getChunkHelper().restoreServerThread(object.getBukkitWorld());
        }
        return entities;
    });
    // <--[tag]
    // @attribute <ChunkTag.living_entities>
    // @returns ListTag(EntityTag)
    // @description
    // Returns a list of living entities in the chunk.
    // This includes Players, mobs, NPCs, etc., but excludes dropped items, experience orbs, etc.
    // -->
    tagProcessor.registerTag(ListTag.class, "living_entities", (attribute, object) -> {
        ListTag entities = new ListTag();
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        try {
            NMSHandler.getChunkHelper().changeChunkServerThread(object.getBukkitWorld());
            for (Entity ent : chunk.getEntities()) {
                if (ent instanceof LivingEntity) {
                    entities.addObject(new EntityTag(ent).getDenizenObject());
                }
            }
        } finally {
            NMSHandler.getChunkHelper().restoreServerThread(object.getBukkitWorld());
        }
        return entities;
    });
    // <--[tag]
    // @attribute <ChunkTag.players>
    // @returns ListTag(PlayerTag)
    // @description
    // Returns a list of players in the chunk.
    // -->
    tagProcessor.registerTag(ListTag.class, "players", (attribute, object) -> {
        ListTag entities = new ListTag();
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        for (Entity ent : chunk.getEntities()) {
            if (EntityTag.isPlayer(ent)) {
                entities.addObject(new PlayerTag((Player) ent));
            }
        }
        return entities;
    });
    // <--[tag]
    // @attribute <ChunkTag.height_map>
    // @returns ListTag
    // @description
    // Returns a list of the height of each block in the chunk.
    // -->
    tagProcessor.registerTag(ListTag.class, "height_map", (attribute, object) -> {
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        int[] heightMap = NMSHandler.getChunkHelper().getHeightMap(chunk);
        List<String> height_map = new ArrayList<>(heightMap.length);
        for (int i : heightMap) {
            height_map.add(String.valueOf(i));
        }
        return new ListTag(height_map);
    });
    // <--[tag]
    // @attribute <ChunkTag.average_height>
    // @returns ElementTag(Decimal)
    // @description
    // Returns the average height of the blocks in the chunk.
    // -->
    tagProcessor.registerTag(ElementTag.class, "average_height", (attribute, object) -> {
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        int[] heightMap = NMSHandler.getChunkHelper().getHeightMap(chunk);
        int sum = 0;
        for (int i : heightMap) {
            sum += i;
        }
        return new ElementTag(((double) sum) / heightMap.length);
    });
    // <--[tag]
    // @attribute <ChunkTag.is_flat[(<#>)]>
    // @returns ElementTag(Boolean)
    // @description
    // Scans the heights of the blocks to check variance between them.
    // If no number is supplied, is_flat will return true if all the blocks are less than 2 blocks apart in height.
    // Specifying a number will modify the number criteria for determining if it is flat.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_flat", (attribute, object) -> {
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        int[] heightMap = NMSHandler.getChunkHelper().getHeightMap(chunk);
        int tolerance = 2;
        if (attribute.hasParam() && ArgumentHelper.matchesInteger(attribute.getParam())) {
            tolerance = attribute.getIntParam();
        }
        int x = heightMap[0];
        for (int i : heightMap) {
            if (Math.abs(x - i) > tolerance) {
                return new ElementTag(false);
            }
        }
        return new ElementTag(true);
    });
    // <--[tag]
    // @attribute <ChunkTag.surface_blocks>
    // @returns ListTag(LocationTag)
    // @description
    // Returns a list of the highest non-air surface blocks in the chunk.
    // -->
    tagProcessor.registerTag(ListTag.class, "surface_blocks", (attribute, object) -> {
        ListTag surface_blocks = new ListTag();
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        ChunkSnapshot snapshot = chunk.getChunkSnapshot();
        for (int x = 0; x < 16; x++) {
            for (int z = 0; z < 16; z++) {
                surface_blocks.addObject(new LocationTag(chunk.getWorld(), chunk.getX() << 4 | x, snapshot.getHighestBlockYAt(x, z) - 1, chunk.getZ() << 4 | z));
            }
        }
        return surface_blocks;
    });
    // <--[tag]
    // @attribute <ChunkTag.blocks_flagged[<flag_name>]>
    // @returns ListTag(LocationTag)
    // @description
    // Gets a list of all block locations with a specified flag within the CuboidTag.
    // Searches the internal flag lists, rather than through all possible blocks.
    // -->
    tagProcessor.registerTag(ListTag.class, "blocks_flagged", (attribute, object) -> {
        if (!attribute.hasParam()) {
            attribute.echoError("ChunkTag.blocks_flagged[...] must have an input value.");
            return null;
        }
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        String flagName = CoreUtilities.toLowerCase(attribute.getParam());
        ListTag blocks = new ListTag();
        LocationFlagSearchHelper.getFlaggedLocations(chunk, flagName, (loc) -> {
            blocks.addObject(new LocationTag(loc));
        });
        return blocks;
    });
    // <--[tag]
    // @attribute <ChunkTag.spawn_slimes>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the chunk is a specially located 'slime spawner' chunk.
    // -->
    tagProcessor.registerTag(ElementTag.class, "spawn_slimes", (attribute, object) -> {
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        return new ElementTag(chunk.isSlimeChunk());
    });
    // <--[tag]
    // @attribute <ChunkTag.inhabited_time>
    // @returns DurationTag
    // @mechanism ChunkTag.inhabited_time
    // @description
    // Returns the total time the chunk has been inhabited for.
    // This is a primary deciding factor in the "local difficulty" setting.
    // -->
    tagProcessor.registerTag(DurationTag.class, "inhabited_time", (attribute, object) -> {
        Chunk chunk = object.getChunkForTag(attribute);
        if (chunk == null) {
            return null;
        }
        return new DurationTag(chunk.getInhabitedTime());
    });
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ChunkSnapshot(org.bukkit.ChunkSnapshot) Chunk(org.bukkit.Chunk) World(org.bukkit.World) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) LivingEntity(org.bukkit.entity.LivingEntity) BlockState(org.bukkit.block.BlockState) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Plugin(org.bukkit.plugin.Plugin)

Example 3 with DurationTag

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

the class BukkitScriptProperties method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <ScriptTag.cooled_down[<player>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the script is currently cooled down for the player. Any global
    // cooldown present on the script will also be taken into account. Not specifying a player will result in
    // using the attached player available in the script entry. Not having a valid player will result in 'null'.
    // -->
    PropertyParser.<BukkitScriptProperties, ElementTag>registerTag(ElementTag.class, "cooled_down", (attribute, script) -> {
        PlayerTag player = (attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
        if (player != null && player.isValid()) {
            return new ElementTag(CooldownCommand.checkCooldown(player, script.script.getContainer().getName()));
        } else {
            return null;
        }
    });
    // <--[tag]
    // @attribute <ScriptTag.cooldown[<player>]>
    // @returns DurationTag
    // @description
    // Returns the time left for the player to cooldown for the script.
    // -->
    PropertyParser.<BukkitScriptProperties, DurationTag>registerTag(DurationTag.class, "cooldown", (attribute, script) -> {
        PlayerTag player = (attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
        return CooldownCommand.getCooldownDuration(player, script.script.getName());
    });
    // <--[tag]
    // @attribute <ScriptTag.step[(<player>)]>
    // @returns ElementTag
    // @description
    // Returns the name of a script step that the player is currently on.
    // Must be an INTERACT script.
    // -->
    PropertyParser.<BukkitScriptProperties, ElementTag>registerTag(ElementTag.class, "step", (attribute, script) -> {
        PlayerTag player = attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer();
        if (player != null && player.isValid()) {
            return new ElementTag(InteractScriptHelper.getCurrentStep(player, script.script.getContainer().getName()));
        } else {
            return null;
        }
    });
    // <--[tag]
    // @attribute <ScriptTag.step_expiration[(<player>)]>
    // @returns TimeTag
    // @description
    // Returns the time that an interact script step expires at, if applied by <@link command zap> with a duration limit.
    // -->
    PropertyParser.<BukkitScriptProperties, TimeTag>registerTag(TimeTag.class, "step_expiration", (attribute, script) -> {
        PlayerTag player = attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer();
        if (player != null && player.isValid()) {
            return InteractScriptHelper.getStepExpiration(player, script.script.getContainer().getName());
        } else {
            return null;
        }
    });
    // <--[tag]
    // @attribute <ScriptTag.default_step>
    // @returns ElementTag
    // @description
    // Returns the name of the default step of an interact script.
    // -->
    PropertyParser.<BukkitScriptProperties, ElementTag>registerStaticTag(ElementTag.class, "default_step", (attribute, script) -> {
        String step = ((InteractScriptContainer) script.script.getContainer()).getDefaultStepName();
        return new ElementTag(step);
    });
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) TimeTag(com.denizenscript.denizencore.objects.core.TimeTag) InteractScriptContainer(com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 4 with DurationTag

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

the class ItemPotion method effectToMap.

public static MapTag effectToMap(PotionEffect effect) {
    MapTag map = new MapTag();
    map.putObject("type", new ElementTag(effect.getType().getName()));
    map.putObject("amplifier", new ElementTag(effect.getAmplifier()));
    map.putObject("duration", new DurationTag((long) effect.getDuration()));
    map.putObject("ambient", new ElementTag(effect.isAmbient()));
    map.putObject("particles", new ElementTag(effect.hasParticles()));
    map.putObject("icon", new ElementTag(effect.hasIcon()));
    return map;
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 5 with DurationTag

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

the class PushCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    EntityTag originEntity = scriptEntry.getObjectTag("origin_entity");
    LocationTag originLocation = scriptEntry.hasObject("origin_location") ? (LocationTag) scriptEntry.getObject("origin_location") : new LocationTag(originEntity.getEyeLocation().add(originEntity.getEyeLocation().getDirection()).subtract(0, 0.4, 0));
    boolean no_rotate = scriptEntry.hasObject("no_rotate") && scriptEntry.getElement("no_rotate").asBoolean();
    final boolean no_damage = scriptEntry.hasObject("no_damage") && scriptEntry.getElement("no_damage").asBoolean();
    // If there is no destination set, but there is a shooter, get a point in front of the shooter and set it as the destination
    final LocationTag destination = scriptEntry.hasObject("destination") ? (LocationTag) scriptEntry.getObject("destination") : (originEntity != null ? new LocationTag(originEntity.getEyeLocation().add(originEntity.getEyeLocation().getDirection().multiply(30))) : null);
    // TODO: Should this be checked in argument parsing?
    if (destination == null) {
        Debug.echoError("No destination specified!");
        scriptEntry.setFinished(true);
        return;
    }
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    final ScriptTag script = scriptEntry.getObjectTag("script");
    final ListTag definitions = scriptEntry.getObjectTag("definitions");
    ElementTag speedElement = scriptEntry.getElement("speed");
    DurationTag duration = (DurationTag) scriptEntry.getObject("duration");
    ElementTag force_along = scriptEntry.getElement("force_along");
    ElementTag precision = scriptEntry.getElement("precision");
    ElementTag ignore_collision = scriptEntry.getElement("ignore_collision");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("origin", originEntity != null ? originEntity : originLocation), db("entities", entities), destination, speedElement, duration, script, force_along, precision, (no_rotate ? db("no_rotate", "true") : ""), (no_damage ? db("no_damage", "true") : ""), ignore_collision, definitions);
    }
    final boolean ignoreCollision = ignore_collision != null && ignore_collision.asBoolean();
    final double speed = speedElement.asDouble();
    final int maxTicks = duration.getTicksAsInt();
    final boolean forceAlong = force_along.asBoolean();
    // Keep a ListTag of entities that can be called using <entry[name].pushed_entities> later in the script queue
    final ListTag entityList = new ListTag();
    for (EntityTag entity : entities) {
        entity.spawnAt(originLocation);
        entityList.addObject(entity);
        if (!no_rotate) {
            NMSHandler.getEntityHelper().faceLocation(entity.getBukkitEntity(), destination);
        }
        if (entity.isProjectile() && originEntity != null) {
            entity.setShooter(originEntity);
        }
    }
    scriptEntry.addObject("pushed_entities", entityList);
    Position.mount(Conversion.convertEntities(entities));
    final EntityTag lastEntity = entities.get(entities.size() - 1);
    final Vector v2 = destination.toVector();
    final Vector Origin = originLocation.toVector();
    final int prec = precision.asInt();
    BukkitRunnable task = new BukkitRunnable() {

        int runs = 0;

        LocationTag lastLocation;

        @Override
        public void run() {
            if (runs < maxTicks && lastEntity.isValid()) {
                Vector v1 = lastEntity.getLocation().toVector();
                Vector v3 = v2.clone().subtract(v1).normalize();
                if (forceAlong) {
                    Vector newDest = v2.clone().subtract(Origin).normalize().multiply(runs * speed).add(Origin);
                    lastEntity.teleport(new Location(lastEntity.getLocation().getWorld(), newDest.getX(), newDest.getY(), newDest.getZ(), lastEntity.getLocation().getYaw(), lastEntity.getLocation().getPitch()));
                }
                runs += prec;
                // Check if the entity is close to its destination
                if (Math.abs(v2.getX() - v1.getX()) < 1.5f && Math.abs(v2.getY() - v1.getY()) < 1.5f && Math.abs(v2.getZ() - v1.getZ()) < 1.5f) {
                    runs = maxTicks;
                    return;
                }
                Vector newVel = v3.multiply(speed);
                lastEntity.setVelocity(newVel);
                if (!ignoreCollision && lastEntity.isValid()) {
                    BoundingBox box = lastEntity.getBukkitEntity().getBoundingBox().expand(newVel);
                    Location ref = lastEntity.getLocation().clone();
                    for (int x = (int) Math.floor(box.getMinX()); x < Math.ceil(box.getMaxX()); x++) {
                        ref.setX(x);
                        for (int y = (int) Math.floor(box.getMinY()); y < Math.ceil(box.getMaxY()); y++) {
                            ref.setY(y);
                            for (int z = (int) Math.floor(box.getMinZ()); z < Math.ceil(box.getMaxZ()); z++) {
                                ref.setZ(z);
                                if (!isSafeBlock(ref)) {
                                    runs = maxTicks;
                                }
                            }
                        }
                    }
                }
                if (no_damage && lastEntity.isLivingEntity()) {
                    lastEntity.getLivingEntity().setFallDistance(0);
                }
                // Record the location in case the entity gets lost (EG, if a pushed arrow hits a mob)
                lastLocation = lastEntity.getLocation();
            } else {
                this.cancel();
                if (script != null) {
                    Consumer<ScriptQueue> configure = (queue) -> {
                        if (lastEntity.getLocation() != null) {
                            queue.addDefinition("location", lastEntity.getLocation());
                        } else {
                            queue.addDefinition("location", lastLocation);
                        }
                        queue.addDefinition("pushed_entities", entityList);
                        queue.addDefinition("last_entity", lastEntity);
                    };
                    ScriptUtilities.createAndStartQueue(script.getContainer(), null, scriptEntry.entryData, null, configure, null, null, definitions, scriptEntry);
                }
                scriptEntry.setFinished(true);
            }
        }
    };
    task.runTaskTimer(Denizen.getInstance(), 0, prec);
}
Also used : Utilities(com.denizenscript.denizen.utilities.Utilities) BoundingBox(org.bukkit.util.BoundingBox) LocationTag(com.denizenscript.denizen.objects.LocationTag) NMSHandler(com.denizenscript.denizen.nms.NMSHandler) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) Holdable(com.denizenscript.denizencore.scripts.commands.Holdable) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue) Location(org.bukkit.Location) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Position(com.denizenscript.denizen.utilities.entity.Position) Denizen(com.denizenscript.denizen.Denizen) Vector(org.bukkit.util.Vector) Consumer(java.util.function.Consumer) List(java.util.List) ScriptUtilities(com.denizenscript.denizencore.utilities.ScriptUtilities) EntityTag(com.denizenscript.denizen.objects.EntityTag) com.denizenscript.denizencore.objects(com.denizenscript.denizencore.objects) Debug(com.denizenscript.denizen.utilities.debugging.Debug) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) AbstractCommand(com.denizenscript.denizencore.scripts.commands.AbstractCommand) Conversion(com.denizenscript.denizen.utilities.Conversion) TaskScriptContainer(com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) BoundingBox(org.bukkit.util.BoundingBox) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

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