use of com.palmergames.bukkit.towny.object.Resident 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.object.Resident in project Towny by ElgarL.
the class TownyFlatFileSource method loadTownBlocks.
@Override
public boolean loadTownBlocks() {
String line = "";
String path;
for (TownBlock townBlock : getAllTownBlocks()) {
path = getTownBlockFilename(townBlock);
//boolean set = false;
File fileTownBlock = new File(path);
if (fileTownBlock.exists() && fileTownBlock.isFile()) {
try {
KeyValueFile kvFile = new KeyValueFile(path);
line = kvFile.get("name");
if (line != null)
try {
townBlock.setName(line.trim());
} catch (Exception e) {
}
line = kvFile.getString("price");
if (line != null)
try {
townBlock.setPlotPrice(Double.parseDouble(line.trim()));
} catch (Exception e) {
}
line = kvFile.getString("town");
if (line != null)
try {
Town town = getTown(line.trim());
townBlock.setTown(town);
} catch (Exception e) {
}
line = kvFile.getString("resident");
if (line != null && !line.isEmpty())
try {
Resident res = getResident(line.trim());
townBlock.setResident(res);
} catch (Exception e) {
}
line = kvFile.getString("type");
if (line != null)
try {
townBlock.setType(Integer.parseInt(line));
} catch (Exception e) {
}
line = kvFile.getString("outpost");
if (line != null)
try {
townBlock.setOutpost(Boolean.parseBoolean(line));
} catch (Exception e) {
}
line = kvFile.get("permissions");
if ((line != null) && !line.isEmpty())
try {
townBlock.setPermissions(line.trim());
//set = true;
} catch (Exception e) {
}
line = kvFile.get("changed");
if (line != null)
try {
townBlock.setChanged(Boolean.parseBoolean(line.trim()));
} catch (Exception e) {
}
line = kvFile.get("locked");
if (line != null)
try {
townBlock.setLocked(Boolean.parseBoolean(line.trim()));
} catch (Exception e) {
}
} catch (Exception e) {
TownyMessaging.sendErrorMsg("Loading Error: Exception while reading TownBlock file " + path);
return false;
}
// if (!set) {
// // no permissions found so set in relation to it's owners perms.
// try {
// if (townBlock.hasResident()) {
// townBlock.setPermissions(townBlock.getResident().getPermissions().toString());
// } else {
// townBlock.setPermissions(townBlock.getTown().getPermissions().toString());
// }
// } catch (NotRegisteredException e) {
// // Will never reach here
// }
// }
}
}
return true;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownyFlatFileSource method saveResidentList.
@Override
public boolean saveResidentList() {
List<String> list = new ArrayList<String>();
for (Resident resident : getResidents()) {
try {
list.add(NameValidation.checkAndFilterPlayerName(resident.getName()));
} catch (InvalidNameException e) {
TownyMessaging.sendErrorMsg("Saving Error: Exception while saving town list file:" + resident.getName());
}
}
/*
* Make sure we only save in async
*/
this.queryQueue.add(new FlatFile_Task(list, rootFolder + dataFolder + FileMgmt.fileSeparator() + "residents.txt"));
return true;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class WarTimerTask method run.
@Override
public void run() {
//TODO: check if war has ended and end gracefully
if (!warEvent.isWarTime()) {
warEvent.end();
universe.clearWarEvent();
plugin.resetCache();
TownyMessaging.sendDebugMsg("War ended.");
return;
}
int numPlayers = 0;
for (Player player : BukkitTools.getOnlinePlayers()) {
if (player != null) {
numPlayers += 1;
TownyMessaging.sendDebugMsg("[War] " + player.getName() + ": ");
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
if (resident.hasNation()) {
Nation nation = resident.getTown().getNation();
TownyMessaging.sendDebugMsg("[War] hasNation");
if (nation.isNeutral()) {
if (warEvent.isWarringNation(nation))
warEvent.nationLeave(nation);
continue;
}
TownyMessaging.sendDebugMsg("[War] notNeutral");
if (!warEvent.isWarringNation(nation))
continue;
TownyMessaging.sendDebugMsg("[War] warringNation");
//TODO: Cache player coord & townblock
WorldCoord worldCoord = new WorldCoord(player.getWorld().getName(), Coord.parseCoord(player));
if (!warEvent.isWarZone(worldCoord))
continue;
TownyMessaging.sendDebugMsg("[War] warZone");
if (player.getLocation().getBlockY() < TownySettings.getMinWarHeight())
continue;
TownyMessaging.sendDebugMsg("[War] aboveMinHeight");
//universe.getWorld(player.getWorld().getName()).getTownBlock(worldCoord);
TownBlock townBlock = worldCoord.getTownBlock();
if (nation == townBlock.getTown().getNation() || townBlock.getTown().getNation().hasAlly(nation))
continue;
TownyMessaging.sendDebugMsg("[War] notAlly");
//Enemy nation
warEvent.damage(resident.getTown(), townBlock);
TownyMessaging.sendDebugMsg("[War] damaged");
}
} catch (NotRegisteredException e) {
continue;
}
}
}
TownyMessaging.sendDebugMsg("[War] # Players: " + numPlayers);
}
Aggregations