Search in sources :

Example 31 with Town

use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.

the class TownyCommand method parseTownyCommand.

private void parseTownyCommand(Player player, String[] split) {
    if (split.length == 0) {
        for (String line : towny_general_help) player.sendMessage(line);
        return;
    } else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help")) {
        for (String line : towny_help) player.sendMessage(Colors.strip(line));
        return;
    }
    try {
        if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY.getNode(split[0].toLowerCase())))
            throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
        if (split[0].equalsIgnoreCase("map"))
            if (split.length > 1 && split[1].equalsIgnoreCase("big"))
                TownyAsciiMap.generateAndSend(plugin, player, 18);
            else
                showMap(player);
        else if (split[0].equalsIgnoreCase("prices")) {
            Town town = null;
            if (split.length > 1) {
                try {
                    town = TownyUniverse.getDataSource().getTown(split[1]);
                } catch (NotRegisteredException x) {
                    sendErrorMsg(player, x.getMessage());
                    return;
                }
            } else if (split.length == 1)
                try {
                    Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                    town = resident.getTown();
                } catch (NotRegisteredException x) {
                }
            for (String line : getTownyPrices(town)) player.sendMessage(line);
        } else if (split[0].equalsIgnoreCase("top")) {
            TopCommand(player, StringMgmt.remFirstArg(split));
        } else if (split[0].equalsIgnoreCase("tree")) {
            consoleUseOnly(player);
        } else if (split[0].equalsIgnoreCase("time")) {
            TownyMessaging.sendMsg(player, "Time until a New Day: " + TimeMgmt.formatCountdownTime(TownyTimerHandler.townyTime()));
        } else if (split[0].equalsIgnoreCase("universe")) {
            for (String line : getUniverseStats()) player.sendMessage(line);
        } else if (split[0].equalsIgnoreCase("version") || split[0].equalsIgnoreCase("v")) {
            player.sendMessage(towny_version);
        } else if (split[0].equalsIgnoreCase("war")) {
            boolean war = TownyWar(StringMgmt.remFirstArg(split));
            for (String line : towny_war) player.sendMessage(Colors.strip(line));
            if (!war)
                sendErrorMsg(player, "The world isn't currently at war.");
            towny_war.clear();
        } else if (split[0].equalsIgnoreCase("spy")) {
            if (plugin.isPermissions() && TownyUniverse.getPermissionSource().has(player, PermissionNodes.TOWNY_CHAT_SPY.getNode())) {
                if (plugin.hasPlayerMode(player, "spy"))
                    plugin.removePlayerMode(player);
                else
                    plugin.setPlayerMode(player, split, true);
            } else
                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_command_disable"));
        } else
            sendErrorMsg(player, "Invalid sub command.");
    } catch (TownyException e) {
        TownyMessaging.sendErrorMsg(player, e.getMessage());
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 32 with Town

use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.

the class DailyTimerTask method collectNationTaxes.

/**
	 * Collect taxes due to the nation from it's member towns.
	 * 
	 * @param nation
	 * @throws EconomyException
	 */
protected void collectNationTaxes(Nation nation) throws EconomyException {
    if (nation.getTaxes() > 0) {
        List<Town> towns = new ArrayList<Town>(nation.getTowns());
        ListIterator<Town> townItr = towns.listIterator();
        Town town = null;
        while (townItr.hasNext()) {
            town = townItr.next();
            /*
				 * Only collect nation tax from this town if it really still
				 * exists.
				 * We are running in an Async thread so MUST verify all objects.
				 */
            if (TownyUniverse.getDataSource().hasTown(town.getName())) {
                if (town.isCapital() || !town.hasUpkeep())
                    continue;
                if (!town.payTo(nation.getTaxes(), nation, "Nation Tax")) {
                    try {
                        TownyMessaging.sendNationMessage(nation, TownySettings.getCouldntPayTaxesMsg(town, "nation"));
                        nation.removeTown(town);
                    } catch (EmptyNationException e) {
                    // Always has 1 town (capital) so ignore
                    } catch (NotRegisteredException e) {
                    }
                    TownyUniverse.getDataSource().saveTown(town);
                    TownyUniverse.getDataSource().saveNation(nation);
                }
            } else
                TownyMessaging.sendTownMessage(town, TownySettings.getPayedTownTaxMsg() + nation.getTaxes());
        }
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) EmptyNationException(com.palmergames.bukkit.towny.exceptions.EmptyNationException)

Example 33 with Town

use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.

the class OnPlayerLogin method run.

@Override
public void run() {
    Resident resident = null;
    if (!TownyUniverse.getDataSource().hasResident(player.getName())) {
        /*
			 * No record of this resident exists
			 * So create a fresh set of data.
			 */
        try {
            TownyUniverse.getDataSource().newResident(player.getName());
            resident = TownyUniverse.getDataSource().getResident(player.getName());
            TownyMessaging.sendMessage(player, TownySettings.getRegistrationMsg(player.getName()));
            resident.setRegistered(System.currentTimeMillis());
            if (!TownySettings.getDefaultTownName().equals(""))
                try {
                    Town town = TownyUniverse.getDataSource().getTown(TownySettings.getDefaultTownName());
                    town.addResident(resident);
                    TownyUniverse.getDataSource().saveTown(town);
                } catch (NotRegisteredException ex) {
                } catch (AlreadyRegisteredException ex) {
                }
            TownyUniverse.getDataSource().saveResident(resident);
            TownyUniverse.getDataSource().saveResidentList();
        } catch (AlreadyRegisteredException ex) {
        // Should never happen
        } catch (NotRegisteredException ex) {
        // Should never happen
        }
    } else {
        /*
			 * This resident is known so fetch the data and update it.
			 */
        try {
            resident = TownyUniverse.getDataSource().getResident(player.getName());
            resident.setLastOnline(System.currentTimeMillis());
            TownyUniverse.getDataSource().saveResident(resident);
        } catch (NotRegisteredException ex) {
        // Should never happen
        }
    }
    if (resident != null)
        TownyPerms.assignPermissions(resident, player);
    try {
        TownyMessaging.sendTownBoard(player, resident.getTown());
    } catch (NotRegisteredException ex) {
    }
    if (TownyUniverse.isWarTime())
        universe.getWarEvent().sendScores(player, 3);
    //Schedule to setup default modes when the player has finished loading
    if (BukkitTools.scheduleSyncDelayedTask(new SetDefaultModes(player.getName(), false), 1) == -1)
        TownyMessaging.sendErrorMsg("Could not set default modes for " + player.getName() + ".");
    // Send any warning messages at login.
    warningMessage(resident);
    universe.setChangedNotify(PLAYER_LOGIN);
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident)

Example 34 with Town

use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.

the class OnPlayerLogin method warningMessage.

/**
	 * Send a warning message if the town or nation is due to be deleted.
	 * 
	 * @param resident
	 */
private void warningMessage(Resident resident) {
    if (TownyEconomyHandler.isActive() && TownySettings.isTaxingDaily()) {
        if (resident.hasTown()) {
            try {
                Town town = resident.getTown();
                if (town.hasUpkeep()) {
                    double upkeep = TownySettings.getTownUpkeepCost(town);
                    try {
                        if ((upkeep > 0) && (!town.canPayFromHoldings(upkeep))) {
                            /*
								 *  Warn that the town is due to be deleted.
								 */
                            TownyMessaging.sendMessage(resident, String.format(TownySettings.getLangString("msg_warning_delete"), town.getName()));
                        }
                    } catch (EconomyException ex) {
                    // Economy error, so ignore it and try to continue.
                    }
                }
                if (town.hasNation()) {
                    Nation nation = town.getNation();
                    double upkeep = TownySettings.getNationUpkeepCost(nation);
                    try {
                        if ((upkeep > 0) && (!nation.canPayFromHoldings(upkeep))) {
                            /*
								 *  Warn that the nation is due to be deleted.
								 */
                            TownyMessaging.sendMessage(resident, String.format(TownySettings.getLangString("msg_warning_delete"), nation.getName()));
                        }
                    } catch (EconomyException ex) {
                    // Economy error, so ignore it and try to continue.
                    }
                }
            } catch (NotRegisteredException ex) {
            // Should never reach here as we tested it beforehand.
            }
        }
    }
}
Also used : EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) Nation(com.palmergames.bukkit.towny.object.Nation) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town)

Example 35 with Town

use of com.palmergames.bukkit.towny.object.Town 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;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Aggregations

Town (com.palmergames.bukkit.towny.object.Town)41 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)24 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)23 Resident (com.palmergames.bukkit.towny.object.Resident)17 ArrayList (java.util.ArrayList)15 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)14 Nation (com.palmergames.bukkit.towny.object.Nation)10 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)8 IOException (java.io.IOException)8 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)7 InvalidNameException (javax.naming.InvalidNameException)5 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)4 KeyValueFile (com.palmergames.util.KeyValueFile)4 File (java.io.File)4 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)3 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)3 EOFException (java.io.EOFException)3 FileNotFoundException (java.io.FileNotFoundException)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3