Search in sources :

Example 56 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class StrikeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    LocationTag location = scriptEntry.getObjectTag("location");
    boolean noDamage = scriptEntry.argAsBoolean("no_damage");
    boolean silent = scriptEntry.argAsBoolean("silent");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), location, db("no_damage", noDamage), db("silent", silent));
    }
    if (noDamage) {
        location.getWorld().spigot().strikeLightningEffect(location, silent);
    } else {
        location.getWorld().spigot().strikeLightning(location, silent);
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag)

Example 57 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class WorldBorderCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    WorldTag world = scriptEntry.getObjectTag("world");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    LocationTag center = scriptEntry.getObjectTag("center");
    ElementTag size = scriptEntry.getElement("size");
    ElementTag currSize = scriptEntry.getElement("current_size");
    ElementTag damage = scriptEntry.getElement("damage");
    ElementTag damagebuffer = scriptEntry.getElement("damagebuffer");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag warningdistance = scriptEntry.getElement("warningdistance");
    DurationTag warningtime = scriptEntry.getObjectTag("warningtime");
    ElementTag reset = scriptEntry.getObjectTag("reset");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), world, db("players", players), center, size, currSize, damage, damagebuffer, warningdistance, warningtime, duration, reset);
    }
    if (players != null) {
        if (reset.asBoolean()) {
            for (PlayerTag player : players) {
                NMSHandler.getPacketHelper().resetWorldBorder(player.getPlayerEntity());
            }
            return;
        }
        WorldBorder wb;
        for (PlayerTag player : players) {
            wb = player.getWorld().getWorldBorder();
            NMSHandler.getPacketHelper().setWorldBorder(player.getPlayerEntity(), (center != null ? center : wb.getCenter()), (size != null ? size.asDouble() : wb.getSize()), (currSize != null ? currSize.asDouble() : wb.getSize()), duration.getMillis(), (warningdistance != null ? warningdistance.asInt() : wb.getWarningDistance()), (warningtime != null ? warningtime.getSecondsAsInt() : wb.getWarningTime()));
        }
        return;
    }
    WorldBorder worldborder = world.getWorld().getWorldBorder();
    if (reset.asBoolean()) {
        worldborder.reset();
        return;
    }
    if (center != null) {
        worldborder.setCenter(center);
    }
    if (size != null) {
        if (currSize != null) {
            worldborder.setSize(currSize.asDouble());
        }
        worldborder.setSize(size.asDouble(), duration.getSecondsAsInt());
    }
    if (damage != null) {
        worldborder.setDamageAmount(damage.asDouble());
    }
    if (damagebuffer != null) {
        worldborder.setDamageBuffer(damagebuffer.asDouble());
    }
    if (warningdistance != null) {
        worldborder.setWarningDistance(warningdistance.asInt());
    }
    if (warningtime != null) {
        worldborder.setWarningTime(warningtime.getSecondsAsInt());
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) WorldBorder(org.bukkit.WorldBorder) List(java.util.List) WorldTag(com.denizenscript.denizen.objects.WorldTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 58 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class SwitchCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    final ListTag interactLocations = scriptEntry.getObjectTag("locations");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    final SwitchState switchState = SwitchState.valueOf(scriptEntry.getElement("switchstate").asString());
    ElementTag noPhysics = scriptEntry.getElement("no_physics");
    // Switch the Block
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), interactLocations, duration, noPhysics, db("switchstate", switchState.name()));
    }
    final boolean physics = noPhysics == null || !noPhysics.asBoolean();
    for (final LocationTag interactLocation : interactLocations.filter(LocationTag.class, scriptEntry)) {
        switchBlock(scriptEntry, interactLocation, switchState, physics);
        // If duration set, schedule a delayed task.
        if (duration.getTicks() > 0) {
            // If this block already had a delayed task, cancel it.
            if (taskMap.containsKey(interactLocation)) {
                try {
                    Bukkit.getScheduler().cancelTask(taskMap.get(interactLocation));
                } catch (Exception e) {
                }
            }
            Debug.echoDebug(scriptEntry, "Setting delayed task 'SWITCH' for " + interactLocation.identify());
            // Store new delayed task ID, for checking against, then schedule new delayed task.
            taskMap.put(interactLocation, Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> switchBlock(scriptEntry, interactLocation, SwitchState.TOGGLE, physics), duration.getTicks()));
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 59 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class PathFinder method getPath.

public static List<LocationTag> getPath(Location start, Location dest) {
    VectorGoal goal = new VectorGoal(dest, 1);
    Path plan = (Path) ASTAR.runFully(goal, new VectorNode(goal, start, new ChunkBlockSource(start, 100), new MinecraftBlockExaminer()), 50000);
    if (plan == null || plan.isComplete()) {
        return new ArrayList<>();
    } else {
        List<LocationTag> path = new ArrayList<>();
        while (!plan.isComplete()) {
            Vector v = plan.getCurrentVector();
            path.add(new LocationTag(start.getWorld(), v.getX(), v.getY(), v.getZ()));
            plan.update(null);
        }
        return path;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ArrayList(java.util.ArrayList) Vector(org.bukkit.util.Vector)

Example 60 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method processShowFakeForPacket.

public boolean processShowFakeForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (FakeBlock.blocks.isEmpty()) {
        return false;
    }
    try {
        if (packet instanceof PacketPlayOutMapChunk) {
            FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUniqueID());
            if (map == null) {
                return false;
            }
            int chunkX = CHUNKX_MAPCHUNK.getInt(packet);
            int chunkZ = CHUNKZ_MAPCHUNK.getInt(packet);
            ChunkCoordinate chunkCoord = new ChunkCoordinate(chunkX, chunkZ, player.getWorld().getWorld().getName());
            List<FakeBlock> blocks = FakeBlock.getFakeBlocksFor(player.getUniqueID(), chunkCoord);
            if (blocks == null || blocks.isEmpty()) {
                return false;
            }
            PacketPlayOutMapChunk newPacket = FakeBlockHelper.handleMapChunkPacket((PacketPlayOutMapChunk) packet, blocks);
            oldManager.sendPacket(newPacket, genericfuturelistener);
            return true;
        } else if (packet instanceof PacketPlayOutMultiBlockChange) {
            FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUniqueID());
            if (map == null) {
                return false;
            }
            SectionPosition coord = (SectionPosition) SECTIONPOS_MULTIBLOCKCHANGE.get(packet);
            ChunkCoordinate coordinateDenizen = new ChunkCoordinate(coord.getX(), coord.getZ(), player.getWorld().getWorld().getName());
            if (!map.byChunk.containsKey(coordinateDenizen)) {
                return false;
            }
            PacketPlayOutMultiBlockChange newPacket = new PacketPlayOutMultiBlockChange();
            copyPacket(packet, newPacket);
            LocationTag location = new LocationTag(player.getWorld().getWorld(), 0, 0, 0);
            short[] originalOffsetArray = (short[]) OFFSETARRAY_MULTIBLOCKCHANGE.get(newPacket);
            IBlockData[] originalDataArray = (IBlockData[]) BLOCKARRAY_MULTIBLOCKCHANGE.get(newPacket);
            short[] offsetArray = Arrays.copyOf(originalOffsetArray, originalOffsetArray.length);
            IBlockData[] dataArray = Arrays.copyOf(originalDataArray, originalDataArray.length);
            OFFSETARRAY_MULTIBLOCKCHANGE.set(newPacket, offsetArray);
            BLOCKARRAY_MULTIBLOCKCHANGE.set(newPacket, dataArray);
            for (int i = 0; i < offsetArray.length; i++) {
                short offset = offsetArray[i];
                BlockPosition pos = coord.g(offset);
                location.setX(pos.getX());
                location.setY(pos.getY());
                location.setZ(pos.getZ());
                FakeBlock block = map.byLocation.get(location);
                if (block != null) {
                    dataArray[i] = FakeBlockHelper.getNMSState(block);
                }
            }
            oldManager.sendPacket(newPacket, genericfuturelistener);
            return true;
        } else if (packet instanceof PacketPlayOutBlockChange) {
            BlockPosition pos = (BlockPosition) BLOCKPOS_BLOCKCHANGE.get(packet);
            LocationTag loc = new LocationTag(player.getWorld().getWorld(), pos.getX(), pos.getY(), pos.getZ());
            FakeBlock block = FakeBlock.getFakeBlockFor(player.getUniqueID(), loc);
            if (block != null) {
                PacketPlayOutBlockChange newPacket = new PacketPlayOutBlockChange();
                copyPacket(packet, newPacket);
                newPacket.block = FakeBlockHelper.getNMSState(block);
                oldManager.sendPacket(newPacket, genericfuturelistener);
                return true;
            }
        } else if (packet instanceof PacketPlayOutBlockBreak) {
            BlockPosition pos = (BlockPosition) BLOCKPOS_BLOCKBREAK.get(packet);
            LocationTag loc = new LocationTag(player.getWorld().getWorld(), pos.getX(), pos.getY(), pos.getZ());
            FakeBlock block = FakeBlock.getFakeBlockFor(player.getUniqueID(), loc);
            if (block != null) {
                PacketPlayOutBlockBreak newPacket = new PacketPlayOutBlockBreak();
                copyPacket(packet, newPacket);
                BLOCKDATA_BLOCKBREAK.set(newPacket, FakeBlockHelper.getNMSState(block));
                oldManager.sendPacket(newPacket, genericfuturelistener);
                return true;
            }
        }
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
    return false;
}
Also used : ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) IOException(java.io.IOException) LocationTag(com.denizenscript.denizen.objects.LocationTag)

Aggregations

LocationTag (com.denizenscript.denizen.objects.LocationTag)133 EventHandler (org.bukkit.event.EventHandler)69 EntityTag (com.denizenscript.denizen.objects.EntityTag)45 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)40 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)33 List (java.util.List)21 ItemTag (com.denizenscript.denizen.objects.ItemTag)18 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)15 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)14 ListTag (com.denizenscript.denizencore.objects.core.ListTag)13 NPCTag (com.denizenscript.denizen.objects.NPCTag)12 Location (org.bukkit.Location)11 ArrayList (java.util.ArrayList)8 Entity (org.bukkit.entity.Entity)8 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)6 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)6 Player (org.bukkit.entity.Player)6 Vector (org.bukkit.util.Vector)6 UUID (java.util.UUID)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5