Search in sources :

Example 46 with Resident

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

the class ResidentCommand method parseResidentCommand.

public void parseResidentCommand(Player player, String[] split) {
    try {
        if (split.length == 0) {
            try {
                Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                TownyMessaging.sendMessage(player, TownyFormatter.getStatus(resident, player));
            } catch (NotRegisteredException x) {
                throw new TownyException(TownySettings.getLangString("msg_err_not_registered"));
            }
        } else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help")) {
            for (String line : output) player.sendMessage(line);
        } else if (split[0].equalsIgnoreCase("list")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_LIST.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            listResidents(player);
        } else if (split[0].equalsIgnoreCase("tax")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_TAX.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            try {
                Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                TownyMessaging.sendMessage(player, TownyFormatter.getTaxStatus(resident));
            } catch (NotRegisteredException x) {
                throw new TownyException(TownySettings.getLangString("msg_err_not_registered"));
            }
        } else if (split[0].equalsIgnoreCase("set")) {
            /*
				 * perms checked in method.
				 */
            String[] newSplit = StringMgmt.remFirstArg(split);
            residentSet(player, newSplit);
        } else if (split[0].equalsIgnoreCase("toggle")) {
            /*
				 * 
				 */
            String[] newSplit = StringMgmt.remFirstArg(split);
            residentToggle(player, newSplit);
        } else if (split[0].equalsIgnoreCase("friend")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_FRIEND.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            String[] newSplit = StringMgmt.remFirstArg(split);
            residentFriend(player, newSplit);
        } else if (split[0].equalsIgnoreCase("spawn")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_SPAWN.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            residentSpawn(player);
        } else {
            try {
                Resident resident = TownyUniverse.getDataSource().getResident(split[0]);
                TownyMessaging.sendMessage(player, TownyFormatter.getStatus(resident, player));
            } catch (NotRegisteredException x) {
                throw new TownyException(String.format(TownySettings.getLangString("msg_err_not_registered_1"), split[0]));
            }
        }
    } catch (Exception x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 47 with Resident

use of com.palmergames.bukkit.towny.object.Resident 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 48 with Resident

use of com.palmergames.bukkit.towny.object.Resident 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 49 with Resident

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

the class TownyHModFlatFileSource method loadTown.

@Override
public boolean loadTown(Town town) {
    System.out.println("[Towny] [hMod Conversion] Town: " + town.getName());
    String line;
    String[] tokens;
    String path = rootFolder + dataFolder + "/towns/" + town.getName() + ".txt";
    File fileResident = new File(path);
    if (fileResident.exists() && fileResident.isFile()) {
        try {
            KeyValueFile kvFile = new KeyValueFile(path);
            line = kvFile.get("residents");
            if (line != null) {
                tokens = line.split(",");
                for (String token : tokens) {
                    Resident resident = getResident(token);
                    if (resident != null)
                        town.addResident(resident);
                }
            }
            line = kvFile.get("mayor");
            if (line != null)
                town.setMayor(getResident(line));
            //				line = kvFile.get("assistants");
            //				if (line != null) {
            //					tokens = line.split(",");
            //					for (String token : tokens) {
            //						Resident assistant = getResident(token);
            //						if (assistant != null)
            //							town.addAssistant(assistant);
            //					}
            //				}
            town.setTownBoard(kvFile.get("townBoard"));
            line = kvFile.get("bonusBlocks");
            if (line != null)
                try {
                    town.setBonusBlocks(Integer.parseInt(line));
                } catch (Exception e) {
                    town.setBonusBlocks(0);
                }
            line = kvFile.get("purchasedBlocks");
            if (line != null)
                try {
                    town.setPurchasedBlocks(Integer.parseInt(line));
                } catch (Exception e) {
                    town.setPurchasedBlocks(0);
                }
            line = kvFile.get("plotPrice");
            if (line != null)
                try {
                    town.setPlotPrice(Integer.parseInt(line));
                } catch (Exception e) {
                    town.setPlotPrice(0);
                }
            line = kvFile.get("taxes");
            if (line != null)
                try {
                    town.setTaxes(Integer.parseInt(line));
                } catch (Exception e) {
                    town.setTaxes(0);
                }
            line = kvFile.get("plotTax");
            if (line != null)
                try {
                    town.setPlotTax(Integer.parseInt(line));
                } catch (Exception e) {
                    town.setPlotTax(0);
                }
            line = kvFile.get("pvp");
            if (line != null)
                try {
                    town.setPVP(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
            line = kvFile.get("explosion");
            if (line != null)
                try {
                    town.setBANG(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
            line = kvFile.get("taxpercent");
            if (line != null)
                try {
                    town.setTaxPercentage(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
            line = kvFile.get("fire");
            if (line != null)
                try {
                    town.setFire(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
        } catch (Exception e) {
            System.out.println("[Towny] Loading Error: Exception while reading town file " + town.getName());
            e.printStackTrace();
            return false;
        }
        return true;
    } else
        return false;
}
Also used : Resident(com.palmergames.bukkit.towny.object.Resident) KeyValueFile(com.palmergames.util.KeyValueFile) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Example 50 with Resident

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

the class PlotClaim method residentClaim.

private boolean residentClaim(WorldCoord worldCoord) throws TownyException, EconomyException {
    //if (resident.hasTown())
    try {
        TownBlock townBlock = worldCoord.getTownBlock();
        Town town = townBlock.getTown();
        if ((resident.hasTown() && (resident.getTown() != town) && (!townBlock.getType().equals(TownBlockType.EMBASSY))) || ((!resident.hasTown()) && (!townBlock.getType().equals(TownBlockType.EMBASSY))))
            throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
        try {
            Resident owner = townBlock.getResident();
            if (townBlock.getPlotPrice() != -1) {
                if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), owner, "Plot - Buy From Seller"))
                    throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
                int maxPlots = TownySettings.getMaxResidentPlots(resident);
                if (maxPlots >= 0 && resident.getTownBlocks().size() + 1 > maxPlots)
                    throw new TownyException(String.format(TownySettings.getLangString("msg_max_plot_own"), maxPlots));
                TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(resident.getName(), owner.getName(), townBlock.getPlotPrice()));
                townBlock.setPlotPrice(-1);
                townBlock.setResident(resident);
                // Set the plot permissions to mirror the new owners.
                townBlock.setType(townBlock.getType());
                TownyUniverse.getDataSource().saveResident(owner);
                TownyUniverse.getDataSource().saveTownBlock(townBlock);
                // Update any caches for this WorldCoord
                plugin.updateCache(worldCoord);
                return true;
            } else if (player.hasPermission(PermissionNodes.TOWNY_COMMAND_PLOT_ASMAYOR.getNode())) {
                if (TownySettings.isUsingEconomy() && !town.payTo(0.0, owner, "Plot - Buy Back"))
                    throw new TownyException(TownySettings.getLangString("msg_town_no_money_purchase_plot"));
                TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(town.getName(), owner.getName(), 0.0));
                townBlock.setResident(null);
                townBlock.setPlotPrice(-1);
                // Set the plot permissions to mirror the towns.
                townBlock.setType(townBlock.getType());
                TownyUniverse.getDataSource().saveResident(owner);
                // Update the townBlock data file so it's no longer using custom settings.
                TownyUniverse.getDataSource().saveTownBlock(townBlock);
                return true;
            } else {
                //Should never reach here.
                throw new AlreadyRegisteredException(String.format(TownySettings.getLangString("msg_already_claimed"), owner.getName()));
            }
        } catch (NotRegisteredException e) {
            if (townBlock.getPlotPrice() == -1)
                throw new TownyException(TownySettings.getLangString("msg_err_plot_nfs"));
            double bankcap = TownySettings.getTownBankCap();
            if (bankcap > 0) {
                if (townBlock.getPlotPrice() + town.getHoldingBalance() > bankcap)
                    throw new TownyException(String.format(TownySettings.getLangString("msg_err_deposit_capped"), bankcap));
            }
            if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), town, "Plot - Buy From Town"))
                throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
            townBlock.setPlotPrice(-1);
            townBlock.setResident(resident);
            // Set the plot permissions to mirror the new owners.
            townBlock.setType(townBlock.getType());
            TownyUniverse.getDataSource().saveTownBlock(townBlock);
            return true;
        }
    } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
    }
//else
//	throw new TownyException(TownySettings.getLangString("msg_err_not_in_town_claim"));
}
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) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

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