Search in sources :

Example 1 with Chunk

use of org.bukkit.Chunk in project Denizen-For-Bukkit by DenizenScript.

the class ChunkLoadCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    Element action = scriptEntry.getElement("action");
    dLocation chunkloc = (dLocation) scriptEntry.getObject("location");
    Duration length = (Duration) scriptEntry.getObject("duration");
    dB.report(scriptEntry, getName(), action.debug() + chunkloc.debug() + length.debug());
    Chunk chunk = chunkloc.getChunk();
    String chunkString = chunk.getX() + ", " + chunk.getZ();
    switch(Action.valueOf(action.asString())) {
        case ADD:
            if (length.getSeconds() != 0) {
                chunkDelays.put(chunkString, System.currentTimeMillis() + length.getMillis());
            } else {
                chunkDelays.put(chunkString, (long) 0);
            }
            dB.echoDebug(scriptEntry, "...added chunk " + chunk.getX() + ", " + chunk.getZ() + " with a delay of " + length.getSeconds() + " seconds.");
            if (!chunk.isLoaded()) {
                chunk.load();
            }
            break;
        case REMOVE:
            if (chunkDelays.containsKey(chunkString)) {
                chunkDelays.remove(chunkString);
                dB.echoDebug(scriptEntry, "...allowing unloading of chunk " + chunk.getX() + ", " + chunk.getZ());
            } else {
                dB.echoError("Chunk was not on the load list!");
            }
            break;
        case REMOVEALL:
            dB.echoDebug(scriptEntry, "...allowing unloading of all stored chunks");
            chunkDelays.clear();
            break;
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) net.aufdemrand.denizen.objects.dChunk(net.aufdemrand.denizen.objects.dChunk) Chunk(org.bukkit.Chunk)

Example 2 with Chunk

use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.

the class BlockStateConversion method tileEntityToBlockState.

public static BlockState tileEntityToBlockState(Block block, Object nmsTileEntity) {
    // Store and restore old state in case of recursive calls to this function
    // This could happen if inside BlockState construction a chunk is loaded anyway
    // Would be bad, but its best to assume the worst
    TileState old_state = input_state;
    try {
        input_state = new TileState(block, nmsTileEntity);
        BlockState result = proxy_block.getState();
        // Internal BlockState needs to have all proxy field instances replaced with what it should be
        BlockStateCache cache = BlockStateCache.get(result.getClass());
        for (SafeField<World> worldField : cache.worldFields) {
            worldField.set(result, input_state.block.getWorld());
        }
        for (SafeField<Chunk> chunkField : cache.chunkFields) {
            chunkField.set(result, input_state.block.getChunk());
        }
        // All done!
        return result;
    } catch (Throwable t) {
        Logging.LOGGER_CONVERSION.once(Level.SEVERE, "Failed to convert " + nmsTileEntity.getClass().getName() + " to CraftBlockState", t);
        return CraftBlockStateHandle.createNew(input_state.block);
    } finally {
        input_state = old_state;
    }
}
Also used : BlockState(org.bukkit.block.BlockState) World(org.bukkit.World) Chunk(org.bukkit.Chunk)

Example 3 with Chunk

use of org.bukkit.Chunk in project Essentials by drtshock.

the class Commandremove method removeHandler.

private void removeHandler(CommandSource sender, List<String> types, List<String> customTypes, World world, int radius) {
    int removed = 0;
    if (radius > 0) {
        radius *= radius;
    }
    ArrayList<ToRemove> removeTypes = new ArrayList<>();
    ArrayList<Mob> customRemoveTypes = new ArrayList<>();
    for (String s : types) {
        removeTypes.add(ToRemove.valueOf(s));
    }
    boolean warnUser = false;
    for (String s : customTypes) {
        Mob mobType = Mob.fromName(s);
        if (mobType == null) {
            warnUser = true;
        } else {
            customRemoveTypes.add(mobType);
        }
    }
    if (warnUser) {
        sender.sendMessage(tl("invalidMob"));
    }
    for (Chunk chunk : world.getLoadedChunks()) {
        for (Entity e : chunk.getEntities()) {
            if (radius > 0) {
                if (sender.getPlayer().getLocation().distanceSquared(e.getLocation()) > radius) {
                    continue;
                }
            }
            if (e instanceof HumanEntity) {
                continue;
            }
            for (ToRemove toRemove : removeTypes) {
                // We should skip any TAMED animals unless we are specifially targetting them.
                if (e instanceof Tameable && ((Tameable) e).isTamed() && !removeTypes.contains(ToRemove.TAMED)) {
                    continue;
                }
                // We should skip any NAMED animals unless we are specifially targetting them.
                if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
                    continue;
                }
                switch(toRemove) {
                    case TAMED:
                        if (e instanceof Tameable && ((Tameable) e).isTamed()) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case NAMED:
                        if (e instanceof LivingEntity && e.getCustomName() != null) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case DROPS:
                        if (e instanceof Item) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ARROWS:
                        if (e instanceof Projectile) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case BOATS:
                        if (e instanceof Boat) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case MINECARTS:
                        if (e instanceof Minecart) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case XP:
                        if (e instanceof ExperienceOrb) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case PAINTINGS:
                        if (e instanceof Painting) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ITEMFRAMES:
                        if (e instanceof ItemFrame) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ENDERCRYSTALS:
                        if (e instanceof EnderCrystal) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case AMBIENT:
                        if (e instanceof Flying) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case HOSTILE:
                    case MONSTERS:
                        if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case PASSIVE:
                    case ANIMALS:
                        if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case MOBS:
                        if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ENTITIES:
                    case ALL:
                        if (e instanceof Entity) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case CUSTOM:
                        for (Mob type : customRemoveTypes) {
                            if (e.getType() == type.getType()) {
                                e.remove();
                                removed++;
                            }
                        }
                        break;
                }
            }
        }
    }
    sender.sendMessage(tl("removed", removed));
}
Also used : ArrayList(java.util.ArrayList) Mob(com.earth2me.essentials.Mob) Chunk(org.bukkit.Chunk)

Example 4 with Chunk

use of org.bukkit.Chunk in project MagicPlugin by elBukkit.

the class RegenerateBatch method process.

@Override
public int process(int maxBlocks) {
    int processedBlocks = 0;
    if (state == RegenerateState.SAVING && expand && !spell.isUndoable()) {
        state = RegenerateState.REGENERATING;
    }
    switch(state) {
        case SAVING:
            while (processedBlocks <= maxBlocks && ix < absx) {
                while (processedBlocks <= maxBlocks && blockY < 256) {
                    Chunk chunk = world.getChunkAt(x + ix * dx, z + iz * dz);
                    if (!chunk.isLoaded()) {
                        chunk.load();
                        return processedBlocks;
                    }
                    Block block = chunk.getBlock(blockX, blockY, blockZ);
                    if (!spell.hasBuildPermission(block) || !spell.hasBreakPermission(block)) {
                        spell.sendMessage(spell.getMessage("insufficient_permission"));
                        finish();
                        return processedBlocks;
                    }
                    if (!expand && !bounds.contains(block.getLocation().toVector())) {
                        restoredBlocks.add(block);
                    } else {
                        registerForUndo(block);
                    }
                    processedBlocks++;
                    blockX++;
                    if (blockX > 15) {
                        blockX = 0;
                        blockZ++;
                        if (blockZ > 15) {
                            blockZ = 0;
                            blockY++;
                        }
                    }
                }
                if (blockY >= 256) {
                    blockX = 0;
                    blockZ = 0;
                    blockY = 0;
                    iz++;
                    if (iz >= absz) {
                        iz = 0;
                        ix++;
                    }
                }
            }
            if (ix >= absx) {
                state = RegenerateState.REGENERATING;
                ix = 0;
                iz = 0;
            }
            break;
        case REGENERATING:
            while (processedBlocks <= maxBlocks && ix < absx) {
                Chunk chunk = world.getChunkAt(x + ix * dx, z + iz * dz);
                if (!chunk.isLoaded()) {
                    chunk.load();
                    return processedBlocks;
                }
                // Note that we've already done permissions checks for every block in this chunk.
                processedBlocks += 256 * 16 * 16;
                world.regenerateChunk(chunk.getX(), chunk.getZ());
                iz++;
                if (iz >= absz) {
                    iz = 0;
                    ix++;
                }
            }
            if (ix >= absx) {
                restoreBlocks = restoredBlocks.toArray(template);
                if (expand && !spell.isUndoable()) {
                    finish();
                } else {
                    state = RegenerateState.RESTORING;
                }
            }
            break;
        case RESTORING:
            while (restoreBlocks != null && processedBlocks < maxBlocks && restoringIndex < restoreBlocks.length) {
                restoreBlocks[restoringIndex].restore();
                restoringIndex++;
                processedBlocks++;
            }
            if (restoreBlocks == null || restoringIndex >= restoredBlocks.size()) {
                finish();
            }
            break;
    }
    return processedBlocks;
}
Also used : Block(org.bukkit.block.Block) Chunk(org.bukkit.Chunk)

Example 5 with Chunk

use of org.bukkit.Chunk in project MagicPlugin by elBukkit.

the class WandCleanupRunnable method run.

@Override
public void run() {
    if (lostWands.isEmpty()) {
        finish();
        return;
    }
    LostWand lostWand = lostWands.getFirst();
    Location location = lostWand.getLocation();
    if (world != null && !location.getWorld().getName().equals(world.getName())) {
        lostWands.removeFirst();
        return;
    }
    String lostWandOwner = lostWand.getOwner();
    lostWandOwner = lostWandOwner == null ? "" : lostWandOwner;
    if (!removeAll) {
        // If no owner was specified, skip wands that have any owner
        if (owner.length() == 0 && lostWandOwner.length() > 0) {
            lostWands.removeFirst();
            return;
        }
        // Skip wands that don't match the specified owner
        if (owner.length() > 0 && !lostWandOwner.equals(owner)) {
            lostWands.removeFirst();
            return;
        }
    }
    Chunk chunk = location.getChunk();
    if (!chunk.isLoaded()) {
        chunk.load();
        return;
    }
    Entity[] entities = chunk.getEntities();
    for (Entity entity : entities) {
        if (!(entity instanceof Item))
            continue;
        Item item = (Item) entity;
        ItemStack itemStack = item.getItemStack();
        if (api.isWand(itemStack)) {
            String lostId = Wand.getWandId(itemStack);
            if (lostId != null && lostWand.getId().equals(lostId)) {
                String description = check ? "Found" : "Removed";
                logger.info(description + " lost wand " + lostWand.getName() + " (" + lostWand.getOwner() + "), id " + lostWand.getId() + " in " + location.getWorld().getName() + " at " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
                if (check) {
                    if (lostWand instanceof com.elmakers.mine.bukkit.wand.LostWand) {
                        ((com.elmakers.mine.bukkit.wand.LostWand) lostWand).setLocation(entity.getLocation());
                    }
                } else {
                    api.removeLostWand(lostWand.getId());
                    item.remove();
                }
                lostWands.removeFirst();
                return;
            }
        }
    }
    lostWands.removeFirst();
    api.removeLostWand(lostWand.getId());
    logger.info("Could not find wand " + lostWand.getName() + " (" + lostWand.getOwner() + "), id " + lostWand.getId() + ", removing from list");
}
Also used : LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) Chunk(org.bukkit.Chunk) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Aggregations

Chunk (org.bukkit.Chunk)52 Location (org.bukkit.Location)16 World (org.bukkit.World)10 OwnedLand (biz.princeps.landlord.util.OwnedLand)9 Entity (org.bukkit.entity.Entity)9 ArrayList (java.util.ArrayList)6 IntVector2 (com.bergerkiller.bukkit.common.bases.IntVector2)5 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)5 Block (org.bukkit.block.Block)5 BlockState (org.bukkit.block.BlockState)5 Player (org.bukkit.entity.Player)5 Offers (biz.princeps.landlord.persistent.Offers)4 HashSet (java.util.HashSet)4 EventHandler (org.bukkit.event.EventHandler)3 Plugin (org.bukkit.plugin.Plugin)3 LPlayer (biz.princeps.landlord.persistent.LPlayer)2 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 ListTag (com.denizenscript.denizencore.objects.core.ListTag)2 Mob (com.earth2me.essentials.Mob)2