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;
}
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);
}
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"));
}
}
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);
}
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;
}
Aggregations