use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.
the class MayorCheck method runCheck.
@Override
public boolean runCheck(Player player, String checkString) {
TownyUniverse townyUniverse = TownyUniverse.getInstance();
Resident resident = townyUniverse.getResident(player.getUniqueId());
if (resident != null && resident.hasTown())
return resident.getTownOrNull().isMayor(resident);
return false;
}
use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.
the class NationType method getRecipients.
@Override
public Collection<Player> getRecipients(Collection<Player> recipients, Player player) {
TownyUniverse townyUniverse = TownyUniverse.getInstance();
Resident resident = townyUniverse.getResident(player.getUniqueId());
// Shouldn't happen
if (resident == null)
return recipients;
try {
final UUID nation = resident.getTown().getNation().getUUID();
Collection<Player> newRecipients = new HashSet<>();
for (Player p : recipients) {
Resident playerRes = townyUniverse.getResident(p.getUniqueId());
if (playerRes != null && playerRes.getTown().getNation().getUUID().equals(nation)) {
newRecipients.add(p);
}
}
return newRecipients;
} catch (NotRegisteredException e) {
e.printStackTrace();
}
return recipients;
}
use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.
the class BaseCommand method getTownyStartingWith.
/**
* Returns a List<String> containing strings of resident, town, and/or nation names that match with arg.
* Can check for multiple types, for example "rt" would check for residents and towns but not nations or worlds.
*
* @param arg the string to match with the chosen type
* @param type the type of Towny object to check for, can be r(esident), t(own), n(ation), w(orld), or any combination of those to check
* @return Matches for the arg with the chosen type
*/
public static List<String> getTownyStartingWith(String arg, String type) {
List<String> matches = new ArrayList<>();
TownyUniverse townyUniverse = TownyUniverse.getInstance();
if (type.contains("r")) {
matches.addAll(townyUniverse.getResidentsTrie().getStringsFromKey(arg));
}
if (type.contains("t")) {
matches.addAll(townyUniverse.getTownsTrie().getStringsFromKey(arg));
}
if (type.contains("n")) {
matches.addAll(townyUniverse.getNationsTrie().getStringsFromKey(arg));
}
if (type.contains("w")) {
// There aren't many worlds so check even if arg is empty
matches.addAll(NameUtil.filterByStart(NameUtil.getNames(townyUniverse.getTownyWorlds()), arg));
}
return matches;
}
use of com.palmergames.bukkit.towny.TownyUniverse in project SiegeWar by TownyAdvanced.
the class SiegeWarAdminCommand method getTownyStartingWith.
/**
* Returns a List<String> containing strings of resident, town, and/or nation names that match with arg.
* Can check for multiple types, for example "rt" would check for residents and towns but not nations or worlds.
*
* @param arg the string to match with the chosen type
* @param type the type of Towny object to check for, can be r(esident), t(own), n(ation), w(orld), or any combination of those to check
* @return Matches for the arg with the chosen type
*/
static List<String> getTownyStartingWith(String arg, String type) {
List<String> matches = new ArrayList<>();
TownyUniverse townyUniverse = TownyUniverse.getInstance();
if (type.contains("r")) {
matches.addAll(townyUniverse.getResidentsTrie().getStringsFromKey(arg));
}
if (type.contains("t")) {
matches.addAll(townyUniverse.getTownsTrie().getStringsFromKey(arg));
}
if (type.contains("n")) {
matches.addAll(townyUniverse.getNationsTrie().getStringsFromKey(arg));
}
if (type.contains("w")) {
// There aren't many worlds so check even if arg is empty
matches.addAll(NameUtil.filterByStart(NameUtil.getNames(townyUniverse.getWorldMap().values()), arg));
}
return matches;
}
use of com.palmergames.bukkit.towny.TownyUniverse in project SiegeWar by TownyAdvanced.
the class PlunderTown method processPlunderTownRequest.
/**
* Process a plunder town request
*
* This method does some final checks and if they pass, the plunder is executed.
*
* @param player the player who placed the plunder chest
* @param townToBePlundered the town to be plundered
* @throws TownyException when a plunder is not allowed.
*/
public static void processPlunderTownRequest(Player player, Town townToBePlundered) throws TownyException {
TownyUniverse townyUniverse = TownyUniverse.getInstance();
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!townyUniverse.getPermissionSource().testPermission(player, SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_PLUNDER.getNode()))
throw new TownyException(translator.of("msg_err_command_disable"));
Resident resident = townyUniverse.getResident(player.getUniqueId());
if (resident == null)
throw new TownyException(translator.of("msg_err_not_registered_1", player.getName()));
if (!resident.hasTown())
throw new TownyException(translator.of("msg_err_siege_war_action_not_a_town_member"));
Town townOfPlunderingResident = resident.getTown();
if (!townOfPlunderingResident.hasNation())
throw new TownyException(translator.of("msg_err_siege_war_action_not_a_nation_member"));
Siege siege = SiegeController.getSiege(townToBePlundered);
if (siege.isTownPlundered())
throw new TownyException(String.format(translator.of("msg_err_siege_war_town_already_plundered"), townToBePlundered.getName()));
Nation nationOfPlunderingResident = townOfPlunderingResident.getNation();
if (siege.getSiegeType() == SiegeType.REVOLT) {
if (siege.getStatus() == SiegeStatus.ATTACKER_WIN || siege.getStatus() == SiegeStatus.DEFENDER_SURRENDER) {
throw new TownyException(translator.of("msg_err_siege_war_plunder_not_possible_rebels_won"));
}
if (siege.getStatus() != SiegeStatus.DEFENDER_WIN && siege.getStatus() != SiegeStatus.ATTACKER_ABANDON) {
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_victory"));
}
if (nationOfPlunderingResident != siege.getDefender())
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_victory"));
plunderTown(siege, townToBePlundered, (Nation) siege.getDefender());
} else {
if (siege.getStatus() != SiegeStatus.ATTACKER_WIN && siege.getStatus() != SiegeStatus.DEFENDER_SURRENDER) {
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_victory"));
}
if (nationOfPlunderingResident != siege.getAttacker())
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_victory"));
plunderTown(siege, townToBePlundered, (Nation) siege.getAttacker());
}
}
Aggregations