Search in sources :

Example 51 with Resident

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;
        }
    }
}
Also used : Resident(com.palmergames.bukkit.towny.object.Resident) Chunk(org.bukkit.Chunk) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 52 with Resident

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;
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) KeyValueFile(com.palmergames.util.KeyValueFile) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) InvalidNameException(javax.naming.InvalidNameException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 53 with Resident

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;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident)

Example 54 with Resident

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);
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Player(org.bukkit.entity.Player) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Aggregations

Resident (com.palmergames.bukkit.towny.object.Resident)54 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)35 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)32 ArrayList (java.util.ArrayList)18 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)17 Town (com.palmergames.bukkit.towny.object.Town)17 Nation (com.palmergames.bukkit.towny.object.Nation)16 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)11 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)9 IOException (java.io.IOException)8 InvalidNameException (javax.naming.InvalidNameException)7 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)5 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)5 KeyValueFile (com.palmergames.util.KeyValueFile)5 File (java.io.File)5 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)4 LinkedList (java.util.LinkedList)4 Player (org.bukkit.entity.Player)4 EOFException (java.io.EOFException)3 FileNotFoundException (java.io.FileNotFoundException)3