use of com.palmergames.bukkit.towny.invites.Invite in project Towny by TownyAdvanced.
the class InviteCommand method sendInviteList.
public static void sendInviteList(Player player, List<Invite> list, int page, boolean fromSender) {
if (page < 0) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_negative"));
return;
} else if (page == 0) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_error_must_be_int"));
return;
}
int total = (int) Math.ceil(((double) list.size()) / ((double) 10));
if (page > total) {
return;
}
List<String> invitesFormatted = new ArrayList<>();
int iMax = page * 10;
if ((page * 10) > list.size()) {
iMax = list.size();
}
Translatable object = null;
for (int i = (page - 1) * 10; i < iMax; i++) {
Invite invite = list.get(i);
String name = invite.getDirectSender().getName();
// If it's from the sender, do it differently
String output = null;
if (fromSender) {
output = Colors.Blue + invite.getReceiver().getName() + Colors.Gray + " - " + Colors.Green + name;
if (invite.getSender() instanceof Town) {
// If it's sent by a town to a resident
object = Translatable.of("player_sing");
}
if (invite.getSender() instanceof Nation) {
if (invite.getReceiver() instanceof Town) {
object = Translatable.of("town_sing");
}
if (invite.getReceiver() instanceof Nation) {
object = Translatable.of("nation_sing");
}
}
} else {
// So it's not from the sender, then it's from the receiver so
output = Colors.Blue + invite.getSender().getName() + Colors.Gray + " - " + Colors.Green + name;
if (invite.getReceiver() instanceof Resident) {
object = Translatable.of("town_sing");
}
if (invite.getReceiver() instanceof Town || invite.getReceiver() instanceof Nation) {
object = Translatable.of("nation_sing");
}
}
invitesFormatted.add(output);
}
TownyMessaging.sendMessage(player, ChatTools.formatList(Translatable.of("invite_plu").forLocale(player), Colors.Blue + object.forLocale(player) + Colors.Gray + " - " + Colors.LightBlue + Translatable.of("invite_sent_by").forLocale(player), invitesFormatted, Translatable.of("LIST_PAGE", page, total).forLocale(player)));
}
use of com.palmergames.bukkit.towny.invites.Invite in project Towny by TownyAdvanced.
the class InviteCommand method parseDeny.
public static void parseDeny(Player player, String[] args) {
TownyUniverse townyUniverse = TownyUniverse.getInstance();
Optional<Resident> resOpt = townyUniverse.getResidentOpt(player.getUniqueId());
if (!resOpt.isPresent()) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_not_registered"));
return;
}
Resident resident = resOpt.get();
List<Invite> invites = resident.getReceivedInvites();
if (invites.size() == 0) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_player_no_invites"));
return;
}
Town town;
if (args.length >= 1) {
// We cut the first argument out of it so /invite *accept* args[1]
// SO now args[0] is always the Town, we should check if the argument length is >= 1
town = townyUniverse.getTown(args[0]);
if (town == null) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_invalid_name"));
return;
}
} else {
if (invites.size() == 1) {
// Only 1 Invite.
town = (Town) invites.get(0).getSender();
} else {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_player_has_multiple_invites"));
parseInviteList(player, null);
return;
}
}
Invite toDecline = null;
for (Invite invite : InviteHandler.getActiveInvites()) {
if (invite.getSender().equals(town) && invite.getReceiver().equals(resident)) {
toDecline = invite;
break;
}
}
if (toDecline != null) {
try {
InviteHandler.declineInvite(toDecline, false);
} catch (InvalidObjectException e) {
e.printStackTrace();
}
} else
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_specify_name"));
}
use of com.palmergames.bukkit.towny.invites.Invite in project Towny by TownyAdvanced.
the class TownyDatabaseHandler method removeNation.
@Override
public void removeNation(Nation nation) {
PreDeleteNationEvent preEvent = new PreDeleteNationEvent(nation);
BukkitTools.getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled())
return;
Resident king = null;
if (nation.hasKing())
king = nation.getKing();
// Remove the Nation's spawn particle.
if (nation.hasSpawn()) {
try {
universe.removeSpawnPoint(nation.getSpawn());
} catch (TownyException ignored) {
}
}
// search and remove from all ally/enemy lists
List<Nation> toSaveNation = new ArrayList<>();
for (Nation toCheck : new ArrayList<>(universe.getNations())) if (toCheck.hasAlly(nation) || toCheck.hasEnemy(nation)) {
try {
if (toCheck.hasAlly(nation))
toCheck.removeAlly(nation);
else
toCheck.removeEnemy(nation);
toSaveNation.add(toCheck);
} catch (NotRegisteredException e) {
e.printStackTrace();
}
}
for (Nation toCheck : toSaveNation) saveNation(toCheck);
// Search and remove any ally invites sent to this nation.
for (Nation toCheck : new ArrayList<>(universe.getNations())) for (Invite invite : new ArrayList<>(toCheck.getSentAllyInvites())) if (invite.getReceiver().getName().equalsIgnoreCase(nation.getName())) {
toCheck.deleteSentAllyInvite(invite);
InviteHandler.removeInvite(invite);
}
// Search and remove any sent ally invites sent by this nation.
for (Invite invite : new ArrayList<>(nation.getSentAllyInvites())) {
nation.deleteSentAllyInvite(invite);
InviteHandler.removeInvite(invite);
}
// Transfer any money to the warchest.
if (TownyEconomyHandler.isActive())
nation.getAccount().removeAccount();
// Delete nation and save towns
deleteNation(nation);
List<Town> toSave = new ArrayList<>(nation.getTowns());
nation.clear();
try {
universe.unregisterNation(nation);
} catch (NotRegisteredException e) {
// Just print out the exception. Very unlikely to happen.
e.printStackTrace();
}
for (Town town : toSave) {
for (Resident res : town.getResidents()) {
if (res.hasTitle() || res.hasSurname()) {
res.setTitle("");
res.setSurname("");
}
res.updatePermsForNationRemoval();
res.save();
}
try {
town.setNation(null);
} catch (AlreadyRegisteredException ignored) {
// Cannot reach AlreadyRegisteredException
}
town.save();
BukkitTools.getPluginManager().callEvent(new NationRemoveTownEvent(town, nation));
}
plugin.resetCache();
UUID kingUUID = null;
if (king != null)
kingUUID = king.getUUID();
BukkitTools.getPluginManager().callEvent(new DeleteNationEvent(nation, kingUUID));
}
use of com.palmergames.bukkit.towny.invites.Invite in project Towny by TownyAdvanced.
the class InviteCommand method parseAccept.
public static void parseAccept(Player player, String[] args) {
TownyUniverse townyUniverse = TownyUniverse.getInstance();
Optional<Resident> resOpt = townyUniverse.getResidentOpt(player.getUniqueId());
if (!resOpt.isPresent()) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_not_registered"));
return;
}
Resident resident = resOpt.get();
List<Invite> invites = resident.getReceivedInvites();
if (invites.size() == 0) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_player_no_invites"));
return;
}
Town town;
if (args.length >= 1) {
town = townyUniverse.getTown(args[0]);
if (town == null) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_invalid_name"));
return;
}
} else {
if (invites.size() == 1) {
town = (Town) invites.get(0).getSender();
} else {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_player_has_multiple_invites"));
parseInviteList(player, null);
return;
}
}
// At this point I consider having a valid Town & a valid Player so a final check is ran:
Invite toAccept = null;
for (Invite invite : InviteHandler.getActiveInvites()) {
if (invite.getSender().equals(town) && invite.getReceiver().equals(resident)) {
toAccept = invite;
break;
}
}
if (toAccept != null) {
try {
if (TownySettings.getMaxResidentsPerTown() > 0 && town.getResidents().size() >= TownySettings.getMaxResidentsForTown(town)) {
TownyMessaging.sendMsg(player, Translatable.of("msg_err_max_residents_per_town_reached", TownySettings.getMaxResidentsForTown(town)));
return;
} else
InviteHandler.acceptInvite(toAccept);
} catch (TownyException | InvalidObjectException e) {
e.printStackTrace();
}
} else
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_specify_name"));
}
Aggregations