use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownyPlayerListener method onPlayerBedEnter.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (!TownySettings.getBedUse())
return;
boolean isOwner = false;
boolean isInnPlot = false;
try {
Resident resident = TownyUniverse.getDataSource().getResident(event.getPlayer().getName());
WorldCoord worldCoord = new WorldCoord(event.getPlayer().getWorld().getName(), Coord.parseCoord(event.getBed().getLocation()));
TownBlock townblock = worldCoord.getTownBlock();
isOwner = townblock.isOwner(resident);
isInnPlot = townblock.getType() == TownBlockType.INN;
if (resident.hasNation() && townblock.getTown().hasNation()) {
Nation residentNation = resident.getTown().getNation();
Nation townblockNation = townblock.getTown().getNation();
if (townblockNation.hasEnemy(residentNation)) {
event.setCancelled(true);
TownyMessaging.sendErrorMsg(event.getPlayer(), "You cannot sleep in an enemy's Inn.");
return;
}
}
} catch (NotRegisteredException e) {
// Wilderness as it error'd getting a townblock.
}
if (!isOwner && !isInnPlot) {
event.setCancelled(true);
TownyMessaging.sendErrorMsg(event.getPlayer(), "You do not own the land this bed occupies and it is not an Inn plot.");
}
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class NationCommand method nationInviteTown.
private static void nationInviteTown(Player player, Nation nation, Town town) throws AlreadyRegisteredException {
Plugin test = plugin.getServer().getPluginManager().getPlugin("Questioner");
Resident townMayor = town.getMayor();
if (TownySettings.isUsingQuestioner() && test != null && test instanceof Questioner && test.isEnabled()) {
Questioner questioner = (Questioner) test;
questioner.loadClasses();
List<Option> options = new ArrayList<Option>();
options.add(new Option(TownySettings.questionerAccept(), new JoinNationTask(townMayor, nation)));
options.add(new Option(TownySettings.questionerDeny(), new ResidentNationQuestionTask(townMayor, nation) {
@Override
public void run() {
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_deny_invite"), getResident().getName()));
}
}));
Question question = new Question(townMayor.getName(), String.format(TownySettings.getLangString("msg_invited"), nation.getName()), options);
try {
plugin.appendQuestion(questioner, question);
} catch (Exception e) {
System.out.println(e.getMessage());
}
} else {
nation.addTown(town);
plugin.resetCache();
TownyUniverse.getDataSource().saveTown(town);
}
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class NationCommand method nationSet.
public void nationSet(Player player, String[] split) throws TownyException, InvalidNameException {
if (split.length == 0) {
player.sendMessage(ChatTools.formatTitle("/nation set"));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "king " + TownySettings.getLangString("res_2"), ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "capital [town]", ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "taxes [$]", ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "name [name]", ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "title/surname [resident] [text]", ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "tag [upto 4 letters] or clear", ""));
} else {
Resident resident;
Nation nation;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
// TODO: Let admin's call a subfunction of this.
if (split[0].equalsIgnoreCase("king")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_KING.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set king Dumbo");
else
try {
Resident newKing = TownyUniverse.getDataSource().getResident(split[1]);
String oldKingsName = nation.getCapital().getMayor().getName();
nation.setKing(newKing);
plugin.deleteCache(oldKingsName);
plugin.deleteCache(newKing.getName());
TownyMessaging.sendNationMessage(nation, TownySettings.getNewKingMsg(newKing.getName(), nation.getName()));
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
} else if (split[0].equalsIgnoreCase("capital")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_CAPITOL.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set capital {town name}");
else
try {
Town newCapital = TownyUniverse.getDataSource().getTown(split[1]);
nation.setCapital(newCapital);
plugin.resetCache();
TownyMessaging.sendNationMessage(nation, TownySettings.getNewKingMsg(newCapital.getMayor().getName(), nation.getName()));
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
} else if (split[0].equalsIgnoreCase("taxes")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TAXES.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set taxes 70");
else {
Integer amount = Integer.parseInt(split[1].trim());
if (amount < 0) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
return;
}
try {
nation.setTaxes(amount);
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_town_set_nation_tax"), player.getName(), split[1]));
} catch (NumberFormatException e) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
}
}
} else if (split[0].equalsIgnoreCase("name")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_NAME.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set name Plutoria");
else {
if (!NameValidation.isBlacklistName(split[1]))
nationRename(player, nation, split[1]);
else
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
}
} else if (split[0].equalsIgnoreCase("tag")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TAG.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set tag PLT");
else if (split[1].equalsIgnoreCase("clear")) {
try {
nation.setTag(" ");
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_reset_nation_tag"), player.getName()));
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
} else
nation.setTag(NameValidation.checkAndFilterName(split[1]));
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_nation_tag"), player.getName(), nation.getTag()));
} else if (split[0].equalsIgnoreCase("title")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TITLE.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
// Give the resident a title
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set title bilbo Jester ");
else
resident = TownyUniverse.getDataSource().getResident(split[1]);
if (resident.hasNation()) {
if (resident.getTown().getNation() != TownyUniverse.getDataSource().getResident(player.getName()).getTown().getNation()) {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
return;
}
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
return;
}
split = StringMgmt.remArgs(split, 2);
if (StringMgmt.join(split).length() > TownySettings.getMaxTitleLength()) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_input_too_long"));
return;
}
String title = StringMgmt.join(NameValidation.checkAndFilterArray(split));
resident.setTitle(title + " ");
TownyUniverse.getDataSource().saveResident(resident);
if (resident.hasTitle())
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_title"), resident.getName(), resident.getTitle()));
else
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_clear_title_surname"), "Title", resident.getName()));
} else if (split[0].equalsIgnoreCase("surname")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_SURNAME.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
// Give the resident a title
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set surname bilbo the dwarf ");
else
resident = TownyUniverse.getDataSource().getResident(split[1]);
if (resident.hasNation()) {
if (resident.getTown().getNation() != TownyUniverse.getDataSource().getResident(player.getName()).getTown().getNation()) {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
return;
}
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
return;
}
split = StringMgmt.remArgs(split, 2);
if (StringMgmt.join(split).length() > TownySettings.getMaxTitleLength()) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_input_too_long"));
return;
}
String surname = StringMgmt.join(NameValidation.checkAndFilterArray(split));
resident.setSurname(" " + surname);
TownyUniverse.getDataSource().saveResident(resident);
if (resident.hasSurname())
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_surname"), resident.getName(), resident.getSurname()));
else
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_clear_title_surname"), "Surname", resident.getName()));
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), split[0]));
return;
}
TownyUniverse.getDataSource().saveNation(nation);
TownyUniverse.getDataSource().saveNationList();
}
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class NationCommand method nationKick.
public void nationKick(Player player, String[] names) {
if (names.length < 1) {
TownyMessaging.sendErrorMsg(player, "Eg: /nation kick [names]");
return;
}
Resident resident;
Nation nation;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
nationKick(player, resident, nation, TownyUniverse.getDataSource().getTowns(names));
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownyFormatter method getStatus.
/**
*
* @param town
* @return a string list containing the results.
*/
public static List<String> getStatus(Town town) {
List<String> out = new ArrayList<String>();
TownyWorld world = town.getWorld();
// ___[ Raccoon City (PvP) (Open) ]___
String title = getFormattedName(town);
title += ((!town.isAdminDisabledPVP()) && ((town.isPVP() || town.getWorld().isForcePVP())) ? Colors.Red + " (PvP)" : "");
title += (town.isOpen() ? Colors.LightBlue + " (Open)" : "");
out.add(ChatTools.formatTitle(title));
// Board: Get your fried chicken
try {
out.add(Colors.Green + "Board: " + Colors.LightGreen + town.getTownBoard());
} catch (NullPointerException e) {
}
// Town Size: 0 / 16 [Bought: 0/48] [Bonus: 0] [Home: 33,44]
try {
out.add(Colors.Green + "Town Size: " + Colors.LightGreen + town.getTownBlocks().size() + " / " + TownySettings.getMaxTownBlocks(town) + (TownySettings.isSellingBonusBlocks() ? Colors.LightBlue + " [Bought: " + town.getPurchasedBlocks() + "/" + TownySettings.getMaxPurchedBlocks() + "]" : "") + (town.getBonusBlocks() > 0 ? Colors.LightBlue + " [Bonus: " + town.getBonusBlocks() + "]" : "") + ((TownySettings.getNationBonusBlocks(town) > 0) ? Colors.LightBlue + " [NationBonus: " + TownySettings.getNationBonusBlocks(town) + "]" : "") + (town.isPublic() ? Colors.LightGray + " [Home: " + (town.hasHomeBlock() ? town.getHomeBlock().getCoord().toString() : "None") + "]" : ""));
} catch (TownyException e) {
}
if (town.hasOutpostSpawn())
out.add(Colors.Green + "Outposts: " + Colors.LightGreen + town.getMaxOutpostSpawn());
// Permissions: B=rao D=--- S=ra-
out.add(Colors.Green + "Permissions: " + town.getPermissions().getColourString().replace("f", "r"));
out.add(Colors.Green + "Explosions: " + ((town.isBANG() || world.isForceExpl()) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Firespread: " + ((town.isFire() || world.isForceFire()) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Mob Spawns: " + ((town.hasMobs() || world.isForceTownMobs()) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
// | Bank: 534 coins
String bankString = "";
if (TownySettings.isUsingEconomy()) {
if (TownyEconomyHandler.isActive()) {
bankString = Colors.Green + "Bank: " + Colors.LightGreen + town.getHoldingFormattedBalance();
if (town.hasUpkeep())
bankString += Colors.Gray + " | " + Colors.Green + "Daily upkeep: " + Colors.Red + TownySettings.getTownUpkeepCost(town);
bankString += Colors.Gray + " | " + Colors.Green + "Tax: " + Colors.Red + town.getTaxes() + (town.isTaxPercentage() ? "%" : "");
}
out.add(bankString);
}
// Mayor: MrSand | Bank: 534 coins
out.add(Colors.Green + "Mayor: " + Colors.LightGreen + getFormattedName(town.getMayor()));
// Assistants [2]: Sammy, Ginger
// if (town.getAssistants().size() > 0)
// out.addAll(getFormattedResidents("Assistants",
// town.getAssistants()));
List<String> ranklist = new ArrayList<String>();
List<Resident> residentss = town.getResidents();
List<String> townranks = TownyPerms.getTownRanks();
List<Resident> residentwithrank = new ArrayList<Resident>();
for (String rank : townranks) {
for (Resident r : residentss) {
if ((r.getTownRanks() != null) && (r.getTownRanks().contains(rank))) {
residentwithrank.add(r);
}
}
ranklist.addAll(getFormattedResidents(rank, residentwithrank));
residentwithrank.clear();
}
out.addAll(ranklist);
// Nation: Azur Empire
try {
out.add(Colors.Green + "Nation: " + Colors.LightGreen + getFormattedName(town.getNation()));
} catch (TownyException e) {
}
// Residents [12]: James, Carry, Mason
String[] residents = getFormattedNames(town.getResidents().toArray(new Resident[0]));
if (residents.length > 34) {
String[] entire = residents;
residents = new String[36];
System.arraycopy(entire, 0, residents, 0, 35);
residents[35] = "and more...";
}
out.addAll(ChatTools.listArr(residents, Colors.Green + "Residents " + Colors.LightGreen + "[" + town.getNumResidents() + "]" + Colors.Green + ":" + Colors.White + " "));
return out;
}
Aggregations