Search in sources :

Example 16 with Resident

use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.

the class TownyFormatter method getStatus.

/**
	 * 
	 * @param townBlock
	 * @return a string list containing the results.
	 */
public static List<String> getStatus(TownBlock townBlock) {
    List<String> out = new ArrayList<String>();
    try {
        TownBlockOwner owner;
        Town town = townBlock.getTown();
        TownyWorld world = townBlock.getWorld();
        if (townBlock.hasResident()) {
            owner = townBlock.getResident();
        } else {
            owner = townBlock.getTown();
        }
        out.add(ChatTools.formatTitle(TownyFormatter.getFormattedName(owner) + ((BukkitTools.isOnline(owner.getName())) ? Colors.LightGreen + " (Online)" : "")));
        out.add(Colors.Green + " Perm: " + ((owner instanceof Resident) ? townBlock.getPermissions().getColourString() : townBlock.getPermissions().getColourString().replace("f", "r")));
        out.add(Colors.Green + "PvP: " + ((town.isPVP() || world.isForcePVP() || townBlock.getPermissions().pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Explosions: " + ((world.isForceExpl() || townBlock.getPermissions().explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Firespread: " + ((town.isFire() || world.isForceFire() || townBlock.getPermissions().fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Mob Spawns: " + ((town.hasMobs() || world.isForceTownMobs() || townBlock.getPermissions().mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
    } catch (NotRegisteredException e) {
        out.add("Error: " + e.getMessage());
    }
    return out;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) TownBlockOwner(com.palmergames.bukkit.towny.object.TownBlockOwner) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld)

Example 17 with Resident

use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.

the class CombatUtil method isAlly.

/**
	 * Is the defending resident an ally of the attacking resident?
	 * 
	 * @param attackingResident
	 * @param defendingResident
	 * @return true if the defender is an ally of the attacker.
	 */
public static boolean isAlly(String attackingResident, String defendingResident) {
    try {
        Resident residentA = TownyUniverse.getDataSource().getResident(attackingResident);
        Resident residentB = TownyUniverse.getDataSource().getResident(defendingResident);
        if (residentA.getTown() == residentB.getTown())
            return true;
        if (residentA.getTown().getNation() == residentB.getTown().getNation())
            return true;
        if (residentA.getTown().getNation().hasAlly(residentB.getTown().getNation()))
            return true;
    } catch (NotRegisteredException e) {
        return false;
    }
    return false;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident)

Example 18 with Resident

use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.

the class CombatUtil method isEnemy.

/**
	 * Is resident b an enemy of resident a?
	 * 
	 * @param a
	 * @param b
	 * @return true if b is an enemy.
	 */
public static boolean isEnemy(String a, String b) {
    try {
        Resident residentA = TownyUniverse.getDataSource().getResident(a);
        Resident residentB = TownyUniverse.getDataSource().getResident(b);
        if (residentA.getTown() == residentB.getTown())
            return false;
        if (residentA.getTown().getNation() == residentB.getTown().getNation())
            return false;
        if (residentA.getTown().getNation().hasEnemy(residentB.getTown().getNation()))
            return true;
    } catch (NotRegisteredException e) {
        return false;
    }
    return false;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident)

Example 19 with Resident

use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.

the class CombatUtil method canAttackEnemy.

/**
	 * Can resident a attack resident b?
	 * 
	 * @param a
	 * @param b
	 * @return true if they can attack.
	 */
public static boolean canAttackEnemy(String a, String b) {
    try {
        Resident residentA = TownyUniverse.getDataSource().getResident(a);
        Resident residentB = TownyUniverse.getDataSource().getResident(b);
        if (residentA.getTown() == residentB.getTown())
            return false;
        if (residentA.getTown().getNation() == residentB.getTown().getNation())
            return false;
        Nation nationA = residentA.getTown().getNation();
        Nation nationB = residentB.getTown().getNation();
        if (nationA.isNeutral() || nationB.isNeutral())
            return false;
        if (nationA.hasEnemy(nationB))
            return true;
    } catch (NotRegisteredException e) {
        return false;
    }
    return false;
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident)

Example 20 with Resident

use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.

the class PlayerCacheUtil method getTownBlockStatus.

/**
	 * Fetch the TownBlockStatus type for this player at this WorldCoord.
	 * 
	 * @param player
	 * @param worldCoord
	 * @return TownBlockStatus type.
	 */
public static TownBlockStatus getTownBlockStatus(Player player, WorldCoord worldCoord) {
    try {
        if (!worldCoord.getTownyWorld().isUsingTowny())
            return TownBlockStatus.OFF_WORLD;
    } catch (NotRegisteredException ex) {
        // Not a registered world
        return TownBlockStatus.NOT_REGISTERED;
    }
    //TownyUniverse universe = plugin.getTownyUniverse();
    TownBlock townBlock;
    Town town;
    try {
        townBlock = worldCoord.getTownBlock();
        town = townBlock.getTown();
        if (townBlock.isLocked()) {
            // Push the TownBlock location to the queue for a snapshot (if it's not already in the queue).
            if (town.getWorld().isUsingPlotManagementRevert() && (TownySettings.getPlotManagementSpeed() > 0)) {
                TownyRegenAPI.addWorldCoord(townBlock.getWorldCoord());
                return TownBlockStatus.LOCKED;
            }
            townBlock.setLocked(false);
        }
    } catch (NotRegisteredException e) {
        // Unclaimed Zone switch rights
        return TownBlockStatus.UNCLAIMED_ZONE;
    }
    /*
		 * Find the resident data for this player.
		 */
    Resident resident;
    try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
    } catch (TownyException e) {
        System.out.print("Failed to fetch resident: " + player.getName());
        return TownBlockStatus.NOT_REGISTERED;
    }
    try {
        // War Time switch rights
        if (TownyUniverse.isWarTime()) {
            if (TownySettings.isAllowWarBlockGriefing()) {
                try {
                    if (!resident.getTown().getNation().isNeutral() && !town.getNation().isNeutral())
                        return TownBlockStatus.WARZONE;
                } catch (NotRegisteredException e) {
                }
            }
            //If this town is not in a nation and we are set to non neutral status during war.
            if (!TownySettings.isWarTimeTownsNeutral() && !town.hasNation())
                return TownBlockStatus.WARZONE;
        }
        // Town Owner Override
        try {
            if (// || townBlock.getTown().hasAssistant(resident))
            townBlock.getTown().isMayor(resident))
                return TownBlockStatus.TOWN_OWNER;
        } catch (NotRegisteredException e) {
        }
        // Resident Plot rights
        try {
            Resident owner = townBlock.getResident();
            if (resident == owner)
                return TownBlockStatus.PLOT_OWNER;
            else if (owner.hasFriend(resident))
                return TownBlockStatus.PLOT_FRIEND;
            else if (resident.hasTown() && CombatUtil.isAlly(owner.getTown(), resident.getTown()))
                return TownBlockStatus.PLOT_ALLY;
            else
                // Exit out and use town permissions
                throw new TownyException();
        } catch (NotRegisteredException x) {
        } catch (TownyException x) {
        }
        // Resident with no town.
        if (!resident.hasTown()) {
            if (townBlock.isWarZone()) {
                if (!TownySettings.isWarTimeTownsNeutral())
                    return TownBlockStatus.WARZONE;
                else
                    return TownBlockStatus.OUTSIDER;
            }
            throw new TownyException();
        }
        if (resident.getTown() != town) {
            // Allied destroy rights
            if (CombatUtil.isAlly(town, resident.getTown()))
                return TownBlockStatus.TOWN_ALLY;
            else if (CombatUtil.isEnemy(resident.getTown(), town)) {
                if (townBlock.isWarZone())
                    return TownBlockStatus.WARZONE;
                else
                    return TownBlockStatus.ENEMY;
            } else
                return TownBlockStatus.OUTSIDER;
        } else if (// || resident.getTown().hasAssistant(resident))
        resident.isMayor())
            return TownBlockStatus.TOWN_OWNER;
        else
            return TownBlockStatus.TOWN_RESIDENT;
    } catch (TownyException e) {
        // Outsider destroy rights
        return TownBlockStatus.OUTSIDER;
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

Resident (com.palmergames.bukkit.towny.object.Resident)54 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)35 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)32 ArrayList (java.util.ArrayList)18 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)17 Town (com.palmergames.bukkit.towny.object.Town)17 Nation (com.palmergames.bukkit.towny.object.Nation)16 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)11 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)9 IOException (java.io.IOException)8 InvalidNameException (javax.naming.InvalidNameException)7 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)5 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)5 KeyValueFile (com.palmergames.util.KeyValueFile)5 File (java.io.File)5 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)4 LinkedList (java.util.LinkedList)4 Player (org.bukkit.entity.Player)4 EOFException (java.io.EOFException)3 FileNotFoundException (java.io.FileNotFoundException)3