Search in sources :

Example 1 with Town

use of com.palmergames.bukkit.towny.object.Town 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)

Example 2 with Town

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

the class War method remove.

public void remove(WorldCoord worldCoord) {
    try {
        Town town = worldCoord.getTownBlock().getTown();
        TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord, town.getName()));
        warZone.remove(worldCoord);
    } catch (NotRegisteredException e) {
        TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord));
        warZone.remove(worldCoord);
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town)

Example 3 with Town

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

the class War method getScores.

/**
	 * 
	 * @param maxListing Maximum lines to return. Value of -1 return all.
	 * @return A list of the current scores per town sorted in descending order.
	 */
public List<String> getScores(int maxListing) {
    List<String> output = new ArrayList<String>();
    output.add(ChatTools.formatTitle("War - Top Scores"));
    KeyValueTable<Town, Integer> kvTable = new KeyValueTable<Town, Integer>(townScores);
    kvTable.sortByValue();
    kvTable.revese();
    int n = 0;
    for (KeyValue<Town, Integer> kv : kvTable.getKeyValues()) {
        n++;
        if (maxListing != -1 && n > maxListing)
            break;
        Town town = (Town) kv.key;
        output.add(String.format(Colors.Blue + "%40s " + Colors.Gold + "|" + Colors.LightGray + " %4d", TownyFormatter.getFormattedName(town), (Integer) kv.value));
    }
    return output;
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) KeyValueTable(com.palmergames.util.KeyValueTable) ArrayList(java.util.ArrayList)

Example 4 with Town

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

the class War method end.

public void end() {
    for (Player player : BukkitTools.getOnlinePlayers()) if (player != null)
        sendStats(player);
    double halfWinnings;
    try {
        // Transactions might leave 1 coin. (OH noez!)
        halfWinnings = getWarSpoils().getHoldingBalance() / 2.0;
        try {
            // Again, might leave residue.
            double nationWinnings = halfWinnings / warringNations.size();
            for (Nation winningNation : warringNations) {
                getWarSpoils().payTo(nationWinnings, winningNation, "War - Nation Winnings");
                TownyMessaging.sendGlobalMessage("Winning Nation: " + winningNation.getName() + " won " + TownyEconomyHandler.getFormattedBalance(nationWinnings) + ".");
            }
        } catch (ArithmeticException e) {
        // A war ended with 0 nations.
        }
        try {
            KeyValue<Town, Integer> winningTownScore = getWinningTownScore();
            getWarSpoils().payTo(halfWinnings, winningTownScore.key, "War - Town Winnings");
            TownyMessaging.sendGlobalMessage("Highest Score: " + winningTownScore.key.getName() + " won " + TownyEconomyHandler.getFormattedBalance(halfWinnings) + " with the score " + winningTownScore.value + ".");
        } catch (TownyException e) {
        }
    } catch (EconomyException e1) {
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) Player(org.bukkit.entity.Player) Town(com.palmergames.bukkit.towny.object.Town) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 5 with Town

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

the class War method getWinningTownScore.

public KeyValue<Town, Integer> getWinningTownScore() throws TownyException {
    KeyValueTable<Town, Integer> kvTable = new KeyValueTable<Town, Integer>(townScores);
    kvTable.sortByValue();
    kvTable.revese();
    if (kvTable.getKeyValues().size() > 0)
        return kvTable.getKeyValues().get(0);
    else
        throw new TownyException();
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) KeyValueTable(com.palmergames.util.KeyValueTable) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

Town (com.palmergames.bukkit.towny.object.Town)41 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)24 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)23 Resident (com.palmergames.bukkit.towny.object.Resident)17 ArrayList (java.util.ArrayList)15 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)14 Nation (com.palmergames.bukkit.towny.object.Nation)10 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)8 IOException (java.io.IOException)8 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)7 InvalidNameException (javax.naming.InvalidNameException)5 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)4 KeyValueFile (com.palmergames.util.KeyValueFile)4 File (java.io.File)4 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)3 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)3 EOFException (java.io.EOFException)3 FileNotFoundException (java.io.FileNotFoundException)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3