use of com.palmergames.bukkit.towny.object.TownyWorld in project Towny by ElgarL.
the class HealthRegenTimerTask method run.
@Override
public void run() {
if (TownyUniverse.isWarTime())
return;
for (Player player : server.getOnlinePlayers()) {
if (player.getHealth() <= 0)
continue;
Coord coord = Coord.parseCoord(player);
try {
TownyWorld world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
TownBlock townBlock = world.getTownBlock(coord);
if (CombatUtil.isAlly(townBlock.getTown(), TownyUniverse.getDataSource().getResident(player.getName()).getTown()))
if (// only regen if not in an arena
!townBlock.getType().equals(TownBlockType.ARENA))
incHealth(player);
} catch (TownyException x) {
}
}
//if (TownySettings.getDebug())
// System.out.println("[Towny] Debug: Health Regen");
}
use of com.palmergames.bukkit.towny.object.TownyWorld in project Towny by ElgarL.
the class TownyHModFlatFileSource method loadWorlds.
@Override
public boolean loadWorlds() {
System.out.println("[Towny] [hMod Conversion] Town Blocks");
String line;
String[] tokens;
//Default world is the first one loaded
TownyWorld world = getWorlds().toArray(new TownyWorld[0])[0];
try {
BufferedReader fin = new BufferedReader(new FileReader(rootFolder + dataFolder + "/townblocks.csv"));
while ((line = fin.readLine()) != null) {
tokens = line.split(",");
if (tokens.length >= 4)
try {
Town town = getTown(tokens[2]);
int x = Integer.parseInt(tokens[0]);
int z = Integer.parseInt(tokens[1]);
try {
world.newTownBlock(x, z);
} catch (AlreadyRegisteredException e) {
}
TownBlock townblock = world.getTownBlock(x, z);
if (town != null)
townblock.setTown(town);
try {
townblock.setResident(getResident(tokens[3]));
} catch (NotRegisteredException e) {
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (NotRegisteredException e) {
e.printStackTrace();
}
}
fin.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
use of com.palmergames.bukkit.towny.object.TownyWorld in project Towny by ElgarL.
the class TownySQLSource method loadTownBlockList.
/*
* Load keys
*/
@Override
public boolean loadTownBlockList() {
TownyMessaging.sendDebugMsg("Loading TownBlock List");
if (!getContext())
return false;
try {
Statement s = cntx.createStatement();
ResultSet rs = s.executeQuery("SELECT world,x,z FROM " + tb_prefix + "TOWNBLOCKS");
while (rs.next()) {
TownyWorld world = getWorld(rs.getString("world"));
int x = Integer.parseInt(rs.getString("x"));
int z = Integer.parseInt(rs.getString("z"));
try {
world.newTownBlock(x, z);
} catch (AlreadyRegisteredException e) {
}
}
s.close();
return true;
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of com.palmergames.bukkit.towny.object.TownyWorld 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.object.TownyWorld 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;
}
Aggregations