Search in sources :

Example 46 with Chunk

use of org.bukkit.Chunk in project LandLord by SpatiumPrinceps.

the class SetHome method onSetHome.

// requires permission landlord.player.home
public void onSetHome(Player player) {
    if (!Options.enabled_homes()) {
        player.sendMessage(lm.getString("Commands.SetHome.disabled"));
        return;
    }
    if (this.worldDisabled(player)) {
        player.sendMessage(lm.getString("Disabled-World"));
        return;
    }
    Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
    OwnedLand land = plugin.getWgHandler().getRegion(chunk);
    if (land == null) {
        player.sendMessage(lm.getString("Commands.SetHome.nullLand"));
        return;
    }
    if (!land.isOwner(player.getUniqueId())) {
        player.sendMessage(lm.getString("Commands.SetHome.notOwn").replace("%owner%", land.printOwners()));
        return;
    }
    plugin.getPlayerManager().get(player.getUniqueId()).setHome(player.getLocation());
    player.sendMessage(lm.getString("Commands.SetHome.success"));
}
Also used : OwnedLand(biz.princeps.landlord.util.OwnedLand) Chunk(org.bukkit.Chunk)

Example 47 with Chunk

use of org.bukkit.Chunk in project LandLord by SpatiumPrinceps.

the class Info method onInfo.

public void onInfo(Player player) {
    if (plugin.getConfig().getStringList("disabled-worlds").contains(player.getWorld().getName())) {
        player.sendMessage(lm.getString("Disabled-World"));
        return;
    }
    Chunk chunk = player.getLocation().getChunk();
    OwnedLand land = plugin.getWgHandler().getRegion(chunk);
    new BukkitRunnable() {

        @Override
        public void run() {
            // claimed
            if (land != null) {
                String lastseen;
                LocalDateTime lastSeenDate = null;
                OfflinePlayer op = Bukkit.getOfflinePlayer(land.getOwner());
                if (op.isOnline()) {
                    lastseen = lm.getRawString("Commands.Info.online");
                } else {
                    List<Object> list = plugin.getDatabaseAPI().retrieveObjects(LPlayer.class, new Conditions.Builder().addCondition("uuid", op.getUniqueId().toString()).create());
                    if (list.size() > 0) {
                        lastseen = ((LPlayer) list.get(0)).getLastSeenAsString();
                        lastSeenDate = ((LPlayer) list.get(0)).getLastSeen();
                    } else {
                        lastseen = lm.getRawString("Commands.Info.noLastSeen");
                    }
                }
                if (Util.isInactive(lastSeenDate)) {
                    player.sendMessage(replaceInMessage(inactive, land.getName(), land.printOwners(), land.printMembers(), lastseen, Util.formatCash(plugin.getCostManager().calculateCost(player.getUniqueId()))));
                    OwnedLand.highlightLand(player, CParticle.DRIPLAVA);
                    return;
                }
                Offers offer = plugin.getPlayerManager().getOffer(land.getName());
                if (offer != null) {
                    // advertised land
                    player.sendMessage(replaceInMessage(advertised, land.getName(), land.printOwners(), land.printMembers(), lastseen, Util.formatCash(offer.getPrice())));
                } else {
                    // normal owned land
                    player.sendMessage(replaceInMessage(owned, land.getName(), land.printOwners(), land.printMembers(), lastseen, ""));
                }
                OwnedLand.highlightLand(player, CParticle.DRIPWATER);
            } else {
                // unclaimed
                player.sendMessage(replaceInMessage(free, OwnedLand.getName(chunk), "", "", "", Util.formatCash(plugin.getCostManager().calculateCost(player.getUniqueId()))));
                OwnedLand.highlightLand(player, CParticle.DRIPLAVA);
            }
        }
    }.runTaskAsynchronously(plugin);
}
Also used : LocalDateTime(java.time.LocalDateTime) LPlayer(biz.princeps.landlord.persistent.LPlayer) OwnedLand(biz.princeps.landlord.util.OwnedLand) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) OfflinePlayer(org.bukkit.OfflinePlayer) List(java.util.List) Offers(biz.princeps.landlord.persistent.Offers) Chunk(org.bukkit.Chunk)

Example 48 with Chunk

use of org.bukkit.Chunk in project Towny by ElgarL.

the class TeleportWarmupTimerTask method run.

@Override
public void run() {
    long currentTime = System.currentTimeMillis();
    while (true) {
        Resident resident = teleportQueue.peek();
        if (resident == null)
            break;
        if (currentTime > resident.getTeleportRequestTime() + (TownySettings.getTeleportWarmupTime() * 1000)) {
            resident.clearTeleportRequest();
            try {
                // Make sure the chunk we teleport to is loaded.
                Chunk chunk = resident.getTeleportDestination().getWorld().getChunkAt(resident.getTeleportDestination().getBlock());
                if (!chunk.isLoaded())
                    chunk.load();
                TownyUniverse.getPlayer(resident).teleport(resident.getTeleportDestination());
            } catch (TownyException ignore) {
            }
            teleportQueue.poll();
        } else {
            break;
        }
    }
}
Also used : Resident(com.palmergames.bukkit.towny.object.Resident) Chunk(org.bukkit.Chunk) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 49 with Chunk

use of org.bukkit.Chunk in project Towny by ElgarL.

the class TownyRegenAPI method regenChunk.

/**
 * Regenerate the chunk the player is stood in and store the block data so it can be undone later.
 *
 * @param player
 */
public static void regenChunk(Player player) {
    try {
        Coord coord = Coord.parseCoord(player);
        World world = player.getWorld();
        Chunk chunk = world.getChunkAt(player.getLocation());
        int maxHeight = world.getMaxHeight();
        Object[][][] snapshot = new Object[16][maxHeight][16];
        for (int x = 0; x < 16; x++) {
            for (int z = 0; z < 16; z++) {
                for (int y = 0; y < maxHeight; y++) {
                    // Current block to save
                    BlockState state = chunk.getBlock(x, y, z).getState();
                    if (state instanceof org.bukkit.block.Sign) {
                        BlockSign sign = new BlockSign(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), ((org.bukkit.block.Sign) state).getLines());
                        sign.setLocation(state.getLocation());
                        snapshot[x][y][z] = sign;
                    } else if (state instanceof CreatureSpawner) {
                        BlockMobSpawner spawner = new BlockMobSpawner(((CreatureSpawner) state).getSpawnedType());
                        spawner.setLocation(state.getLocation());
                        spawner.setDelay(((CreatureSpawner) state).getDelay());
                        snapshot[x][y][z] = spawner;
                    } else if ((state instanceof InventoryHolder) && !(state instanceof Player)) {
                        BlockInventoryHolder holder = new BlockInventoryHolder(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), ((InventoryHolder) state).getInventory().getContents());
                        holder.setLocation(state.getLocation());
                        snapshot[x][y][z] = holder;
                    } else {
                        snapshot[x][y][z] = new BlockObject(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), state.getLocation());
                    }
                }
            }
        }
        TownyUniverse.getDataSource().getResident(player.getName()).addUndo(snapshot);
        Bukkit.getWorld(player.getWorld().getName()).regenerateChunk(coord.getX(), coord.getZ());
    } catch (NotRegisteredException e) {
    // Failed to get resident
    }
}
Also used : Player(org.bukkit.entity.Player) BlockInventoryHolder(com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) World(org.bukkit.World) Chunk(org.bukkit.Chunk) CreatureSpawner(org.bukkit.block.CreatureSpawner) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Coord(com.palmergames.bukkit.towny.object.Coord) BlockMobSpawner(com.palmergames.bukkit.towny.regen.block.BlockMobSpawner) BlockState(org.bukkit.block.BlockState) BlockSign(com.palmergames.bukkit.towny.regen.block.BlockSign) BlockObject(com.palmergames.bukkit.towny.regen.block.BlockObject) Sign(org.bukkit.block.Sign) BlockSign(com.palmergames.bukkit.towny.regen.block.BlockSign) InventoryHolder(org.bukkit.inventory.InventoryHolder) BlockInventoryHolder(com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder) BlockObject(com.palmergames.bukkit.towny.regen.block.BlockObject)

Example 50 with Chunk

use of org.bukkit.Chunk in project Towny by ElgarL.

the class TownyRegenAPI method regenUndo.

/**
 * Restore the relevant chunk using the snapshot data stored in the resident
 * object.
 *
 * @param snapshot
 * @param resident
 */
public static void regenUndo(Object[][][] snapshot, Resident resident) {
    BlockObject key = ((BlockObject) snapshot[0][0][0]);
    World world = key.getLocation().getWorld();
    Chunk chunk = key.getLocation().getChunk();
    int maxHeight = world.getMaxHeight();
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            for (int y = 0; y < maxHeight; y++) {
                // Snapshot data we need to update the world.
                Object state = snapshot[x][y][z];
                // The block we will be updating
                Block block = chunk.getBlock(x, y, z);
                if (state instanceof BlockSign) {
                    BlockSign signData = (BlockSign) state;
                    BukkitTools.setTypeIdAndData(block, signData.getTypeId(), signData.getData(), false);
                    Sign sign = (Sign) block.getState();
                    int i = 0;
                    for (String line : signData.getLines()) sign.setLine(i++, line);
                    sign.update(true);
                } else if (state instanceof BlockMobSpawner) {
                    BlockMobSpawner spawnerData = (BlockMobSpawner) state;
                    BukkitTools.setTypeIdAndData(block, spawnerData.getTypeId(), spawnerData.getData(), false);
                    ((CreatureSpawner) block.getState()).setSpawnedType(spawnerData.getSpawnedType());
                    ((CreatureSpawner) block.getState()).setDelay(spawnerData.getDelay());
                } else if ((state instanceof BlockInventoryHolder) && !(state instanceof Player)) {
                    BlockInventoryHolder containerData = (BlockInventoryHolder) state;
                    BukkitTools.setTypeIdAndData(block, containerData.getTypeId(), containerData.getData(), false);
                    // Container to receive the inventory
                    InventoryHolder container = (InventoryHolder) block.getState();
                    // Contents we are respawning.
                    if (containerData.getItems().length > 0)
                        container.getInventory().setContents(containerData.getItems());
                } else {
                    BlockObject blockData = (BlockObject) state;
                    BukkitTools.setTypeIdAndData(block, blockData.getTypeId(), blockData.getData(), false);
                }
            }
        }
    }
    TownyMessaging.sendMessage(BukkitTools.getPlayerExact(resident.getName()), TownySettings.getLangString("msg_undo_complete"));
}
Also used : BlockInventoryHolder(com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder) Player(org.bukkit.entity.Player) World(org.bukkit.World) Chunk(org.bukkit.Chunk) BlockMobSpawner(com.palmergames.bukkit.towny.regen.block.BlockMobSpawner) BlockSign(com.palmergames.bukkit.towny.regen.block.BlockSign) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) BlockObject(com.palmergames.bukkit.towny.regen.block.BlockObject) Sign(org.bukkit.block.Sign) BlockSign(com.palmergames.bukkit.towny.regen.block.BlockSign) InventoryHolder(org.bukkit.inventory.InventoryHolder) BlockInventoryHolder(com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder) BlockObject(com.palmergames.bukkit.towny.regen.block.BlockObject)

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