Search in sources :

Example 26 with Resident

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

the class ResidentCommand method onTabComplete.

/**
	 * Overridden method custom for this command set.
	 * 
	 */
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
    LinkedList<String> output = new LinkedList<String>();
    String lastArg = "";
    // Get the last argument
    if (args.length > 0) {
        lastArg = args[args.length - 1].toLowerCase();
    }
    if (!lastArg.equalsIgnoreCase("")) {
        // Match residents
        for (Resident resident : TownyUniverse.getDataSource().getResidents()) {
            if (resident.getName().toLowerCase().startsWith(lastArg)) {
                output.add(resident.getName());
            }
        }
    }
    return output;
}
Also used : Resident(com.palmergames.bukkit.towny.object.Resident) LinkedList(java.util.LinkedList)

Example 27 with Resident

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

the class ResidentCommand method residentToggle.

/**
	 * Toggle modes for this player.
	 * 
	 * @param player
	 * @param newSplit
	 * @throws TownyException
	 */
private void residentToggle(Player player, String[] newSplit) throws TownyException {
    Resident resident;
    try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
    } catch (NotRegisteredException e) {
        // unknown resident
        throw new TownyException(String.format(TownySettings.getLangString("msg_err_not_registered"), player.getName()));
    }
    if (newSplit.length == 0) {
        player.sendMessage(ChatTools.formatTitle("/res toggle"));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "pvp", ""));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "fire", ""));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "mobs", ""));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "plotborder", ""));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "spy", ""));
        TownyMessaging.sendMsg(resident, ("Modes set: " + StringMgmt.join(resident.getModes(), ",")));
        return;
    }
    if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_TOGGLE.getNode(newSplit[0].toLowerCase())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
    TownyPermission perm = resident.getPermissions();
    // Special case chat spy
    if (newSplit[0].equalsIgnoreCase("spy")) {
        if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_CHAT_SPY.getNode(newSplit[0].toLowerCase())))
            throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
        resident.toggleMode(newSplit, true);
        return;
    } else if (newSplit[0].equalsIgnoreCase("pvp")) {
        perm.pvp = !perm.pvp;
    } else if (newSplit[0].equalsIgnoreCase("fire")) {
        perm.fire = !perm.fire;
    } else if (newSplit[0].equalsIgnoreCase("explosion")) {
        perm.explosion = !perm.explosion;
    } else if (newSplit[0].equalsIgnoreCase("mobs")) {
        perm.mobs = !perm.mobs;
    } else {
        resident.toggleMode(newSplit, true);
        return;
    }
    notifyPerms(player, perm);
    TownyUniverse.getDataSource().saveResident(resident);
}
Also used : TownyPermission(com.palmergames.bukkit.towny.object.TownyPermission) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 28 with Resident

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

the class ResidentCommand method residentFriendAdd.

public void residentFriendAdd(Player player, Resident resident, List<Resident> invited) {
    ArrayList<Resident> remove = new ArrayList<Resident>();
    for (Resident newFriend : invited) try {
        resident.addFriend(newFriend);
        plugin.deleteCache(newFriend.getName());
    } catch (AlreadyRegisteredException e) {
        remove.add(newFriend);
    }
    /*
		 *  Remove any names from the list who were already listed as friends
		 */
    for (Resident newFriend : remove) {
        invited.remove(newFriend);
    }
    /*
		 * If we added any friends format the confirmation message.
		 */
    if (invited.size() > 0) {
        String msg = "Added ";
        for (Resident newFriend : invited) {
            msg += newFriend.getName() + ", ";
            Player p = BukkitTools.getPlayer(newFriend.getName());
            if (p != null) {
                TownyMessaging.sendMsg(p, String.format(TownySettings.getLangString("msg_friend_add"), player.getName()));
            }
        }
        msg = msg.substring(0, msg.length() - 2);
        msg += TownySettings.getLangString("msg_to_list");
        TownyMessaging.sendMsg(player, msg);
        TownyUniverse.getDataSource().saveResident(resident);
    } else {
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
    }
}
Also used : Player(org.bukkit.entity.Player) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident)

Example 29 with Resident

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

the class ResidentCommand method listResidents.

public void listResidents(Player player) {
    player.sendMessage(ChatTools.formatTitle(TownySettings.getLangString("res_list")));
    String colour;
    ArrayList<String> formatedList = new ArrayList<String>();
    for (Resident resident : plugin.getTownyUniverse().getActiveResidents()) {
        if (player.canSee(BukkitTools.getPlayerExact(resident.getName()))) {
            if (resident.isKing())
                colour = Colors.Gold;
            else if (resident.isMayor())
                colour = Colors.LightBlue;
            else
                colour = Colors.White;
            formatedList.add(colour + resident.getName() + Colors.White);
        }
    }
    for (String line : ChatTools.list(formatedList)) player.sendMessage(line);
}
Also used : ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident)

Example 30 with Resident

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

the class TownyFormatter method getRanks.

/**
	 * Returns a Chat Formatted List of all town residents who hold a rank.
	 * 
	 * @param town
	 * @return a list containing formatted rank data.
	 */
public static List<String> getRanks(Town town) {
    List<String> ranklist = new ArrayList<String>();
    String towntitle = getFormattedName(town);
    towntitle += Colors.Blue + " Rank List";
    ranklist.add(ChatTools.formatTitle(towntitle));
    ranklist.add(Colors.Green + "Mayor: " + Colors.LightGreen + getFormattedName(town.getMayor()));
    List<Resident> residents = town.getResidents();
    List<String> townranks = TownyPerms.getTownRanks();
    List<Resident> residentwithrank = new ArrayList<Resident>();
    for (String rank : townranks) {
        for (Resident r : residents) {
            if ((r.getTownRanks() != null) && (r.getTownRanks().contains(rank))) {
                residentwithrank.add(r);
            }
        }
        ranklist.addAll(getFormattedResidents(rank, residentwithrank));
        residentwithrank.clear();
    }
    return ranklist;
}
Also used : ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident)

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