Search in sources :

Example 61 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException 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 62 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class TownClaim method run.

@Override
public void run() {
    List<TownyWorld> worlds = new ArrayList<TownyWorld>();
    List<Town> towns = new ArrayList<Town>();
    TownyWorld world;
    if (player != null)
        TownyMessaging.sendMsg(player, "Processing " + ((claim) ? "Town Claim..." : "Town unclaim..."));
    if (selection != null) {
        for (WorldCoord worldCoord : selection) {
            try {
                world = worldCoord.getTownyWorld();
                if (!worlds.contains(world))
                    worlds.add(world);
                if (claim) {
                    // Claim
                    townClaim(town, worldCoord, outpost);
                    // Reset so we only flag the first plot as an outpost.
                    outpost = false;
                } else {
                    // Unclaim
                    this.town = worldCoord.getTownBlock().getTown();
                    townUnclaim(town, worldCoord, forced);
                }
                // Mark this town as modified for saving.
                if (!towns.contains(town))
                    towns.add(town);
            } catch (NotRegisteredException e) {
                // Invalid world
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_err_not_configured"));
            } catch (TownyException x) {
                TownyMessaging.sendErrorMsg(player, x.getMessage());
            }
        }
    } else if (!claim) {
        if (town == null) {
            TownyMessaging.sendMsg(player, "Nothing to unclaim!");
            return;
        }
        townUnclaimAll(town);
    }
    if (!towns.isEmpty())
        for (Town test : towns) TownyUniverse.getDataSource().saveTown(test);
    if (!worlds.isEmpty())
        for (TownyWorld test : worlds) TownyUniverse.getDataSource().saveWorld(test);
    plugin.resetCache();
    if (player != null) {
        if (claim) {
            TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_annexed_area"), (selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
            if (town.getWorld().isUsingPlotManagementRevert())
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_wait_locked"));
        } else if (forced) {
            TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_admin_unclaim_area"), (selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
            if ((town != null) && (town.getWorld().isUsingPlotManagementRevert()))
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_wait_locked"));
        }
    }
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 63 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class TownClaim method townUnclaim.

private void townUnclaim(final Town town, final WorldCoord worldCoord, boolean force) throws TownyException {
    try {
        final TownBlock townBlock = worldCoord.getTownBlock();
        if (town != townBlock.getTown() && !force)
            throw new TownyException(TownySettings.getLangString("msg_area_not_own"));
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            @Override
            public void run() {
                TownyUniverse.getDataSource().removeTownBlock(townBlock);
                // Raise an event to signal the unclaim
                BukkitTools.getPluginManager().callEvent(new TownUnclaimEvent(town, worldCoord));
            }
        }, 1);
    } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_not_claimed_1"));
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownUnclaimEvent(com.palmergames.bukkit.towny.event.TownUnclaimEvent) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 64 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class TownyBlockListener method onBurn.

private boolean onBurn(Block block) {
    Location loc = block.getLocation();
    Coord coord = Coord.parseCoord(loc);
    TownyWorld townyWorld;
    try {
        townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
        if (!townyWorld.isUsingTowny())
            return false;
        try {
            if (townyWorld.isWarZone(coord)) {
                if (TownyWarConfig.isAllowingFireInWarZone()) {
                    return false;
                } else {
                    TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " from igniting within " + coord.toString() + ".");
                    return true;
                }
            }
            TownBlock townBlock = townyWorld.getTownBlock(coord);
            if ((block.getRelative(BlockFace.DOWN).getType() != Material.OBSIDIAN) && ((!townBlock.getTown().isFire() && !townyWorld.isForceFire() && !townBlock.getPermissions().fire) || (TownyUniverse.isWarTime() && TownySettings.isAllowWarBlockGriefing() && !townBlock.getTown().hasNation()))) {
                TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " from igniting within " + coord.toString() + ".");
                return true;
            }
        } catch (TownyException x) {
            // Not a town so check the world setting for fire
            if (!townyWorld.isFire()) {
                TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " from igniting within " + coord.toString() + ".");
                return true;
            }
        }
    } catch (NotRegisteredException e) {
    // Failed to fetch the world
    }
    return false;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Coord(com.palmergames.bukkit.towny.object.Coord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) Location(org.bukkit.Location) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 65 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class TownBlock method setType.

public void setType(String typeName) throws TownyException {
    if (typeName.equalsIgnoreCase("reset"))
        typeName = "default";
    TownBlockType type = TownBlockType.lookup(typeName);
    if (type == null)
        throw new TownyException(TownySettings.getLangString("msg_err_not_block_type"));
    setType(type);
}
Also used : TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)70 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)37 Resident (com.palmergames.bukkit.towny.object.Resident)29 Town (com.palmergames.bukkit.towny.object.Town)17 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)16 Nation (com.palmergames.bukkit.towny.object.Nation)16 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)15 ArrayList (java.util.ArrayList)12 Player (org.bukkit.entity.Player)12 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)11 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)11 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)7 Location (org.bukkit.Location)7 IOException (java.io.IOException)6 EventHandler (org.bukkit.event.EventHandler)6 Coord (com.palmergames.bukkit.towny.object.Coord)5 InvalidNameException (javax.naming.InvalidNameException)5 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)4 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)3 EmptyTownException (com.palmergames.bukkit.towny.exceptions.EmptyTownException)3