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;
}
}
}
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"));
}
}
}
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"));
}
}
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;
}
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);
}
Aggregations