Search in sources :

Example 21 with TownyUniverse

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;
}
Also used : Resident(com.palmergames.bukkit.towny.object.Resident) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse)

Example 22 with TownyUniverse

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;
}
Also used : Player(org.bukkit.entity.Player) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 23 with TownyUniverse

use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.

the class BaseCommand method getTownyStartingWith.

/**
 * Returns a List&lt;String&gt; 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;
}
Also used : ArrayList(java.util.ArrayList) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse)

Example 24 with TownyUniverse

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;
}
Also used : ArrayList(java.util.ArrayList) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse)

Example 25 with TownyUniverse

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());
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Translator(com.palmergames.bukkit.towny.object.Translator) Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) Siege(com.gmail.goosius.siegewar.objects.Siege)

Aggregations

TownyUniverse (com.palmergames.bukkit.towny.TownyUniverse)27 Resident (com.palmergames.bukkit.towny.object.Resident)19 ArrayList (java.util.ArrayList)8 Player (org.bukkit.entity.Player)8 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)7 Town (com.palmergames.bukkit.towny.object.Town)6 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)4 EventHandler (org.bukkit.event.EventHandler)4 Nation (com.palmergames.bukkit.towny.object.Nation)3 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)3 HashSet (java.util.HashSet)3 Invite (com.palmergames.bukkit.towny.invites.Invite)2 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)2 Translator (com.palmergames.bukkit.towny.object.Translator)2 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)2 InvalidObjectException (java.io.InvalidObjectException)2 List (java.util.List)2 UUID (java.util.UUID)2 SiegeSide (com.gmail.goosius.siegewar.enums.SiegeSide)1 Siege (com.gmail.goosius.siegewar.objects.Siege)1