Search in sources :

Example 31 with TownBlock

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

the class TownyFlatFileSource method utilSaveTownBlocks.

@Deprecated
public String utilSaveTownBlocks(List<TownBlock> townBlocks) {
    HashMap<TownyWorld, ArrayList<TownBlock>> worlds = new HashMap<TownyWorld, ArrayList<TownBlock>>();
    String out = "";
    // Sort all town blocks according to what world its in
    for (TownBlock townBlock : townBlocks) {
        TownyWorld world = townBlock.getWorld();
        if (!worlds.containsKey(world))
            worlds.put(world, new ArrayList<TownBlock>());
        worlds.get(world).add(townBlock);
    }
    for (TownyWorld world : worlds.keySet()) {
        out += world.getName() + ":";
        for (TownBlock townBlock : worlds.get(world)) {
            out += "[" + townBlock.getType().getId();
            out += "," + (townBlock.isOutpost() ? "1" : "0");
            out += "]" + townBlock.getX() + "," + townBlock.getZ() + "," + townBlock.getPlotPrice() + ";";
        }
        out += "|";
    }
    return out;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 32 with TownBlock

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

the class War method remove.

public void remove(Town attacker, Town town) throws NotRegisteredException {
    townScored(attacker, TownySettings.getWarPointsForTown());
    for (TownBlock townBlock : town.getTownBlocks()) remove(townBlock.getWorldCoord());
    warringTowns.remove(town);
    try {
        if (!townsLeft(town.getNation()))
            eliminate(town.getNation());
    } catch (NotRegisteredException e) {
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 33 with TownBlock

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

the class WarTimerTask method run.

@Override
public void run() {
    //TODO: check if war has ended and end gracefully
    if (!warEvent.isWarTime()) {
        warEvent.end();
        universe.clearWarEvent();
        plugin.resetCache();
        TownyMessaging.sendDebugMsg("War ended.");
        return;
    }
    int numPlayers = 0;
    for (Player player : BukkitTools.getOnlinePlayers()) {
        if (player != null) {
            numPlayers += 1;
            TownyMessaging.sendDebugMsg("[War] " + player.getName() + ": ");
            try {
                Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                if (resident.hasNation()) {
                    Nation nation = resident.getTown().getNation();
                    TownyMessaging.sendDebugMsg("[War]   hasNation");
                    if (nation.isNeutral()) {
                        if (warEvent.isWarringNation(nation))
                            warEvent.nationLeave(nation);
                        continue;
                    }
                    TownyMessaging.sendDebugMsg("[War]   notNeutral");
                    if (!warEvent.isWarringNation(nation))
                        continue;
                    TownyMessaging.sendDebugMsg("[War]   warringNation");
                    //TODO: Cache player coord & townblock
                    WorldCoord worldCoord = new WorldCoord(player.getWorld().getName(), Coord.parseCoord(player));
                    if (!warEvent.isWarZone(worldCoord))
                        continue;
                    TownyMessaging.sendDebugMsg("[War]   warZone");
                    if (player.getLocation().getBlockY() < TownySettings.getMinWarHeight())
                        continue;
                    TownyMessaging.sendDebugMsg("[War]   aboveMinHeight");
                    //universe.getWorld(player.getWorld().getName()).getTownBlock(worldCoord);
                    TownBlock townBlock = worldCoord.getTownBlock();
                    if (nation == townBlock.getTown().getNation() || townBlock.getTown().getNation().hasAlly(nation))
                        continue;
                    TownyMessaging.sendDebugMsg("[War]   notAlly");
                    //Enemy nation
                    warEvent.damage(resident.getTown(), townBlock);
                    TownyMessaging.sendDebugMsg("[War]   damaged");
                }
            } catch (NotRegisteredException e) {
                continue;
            }
        }
    }
    TownyMessaging.sendDebugMsg("[War] # Players: " + numPlayers);
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Player(org.bukkit.entity.Player) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 34 with TownBlock

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

the class PlayerCacheUtil method getPermission.

/**
	 * Test if the player has permission to perform a certain action at this
	 * WorldCoord.
	 * 
	 * @param player
	 * @param status
	 * @param pos
	 * @param id
	 * @param data
	 * @param action
	 * @return true if allowed.
	 */
private static boolean getPermission(Player player, TownBlockStatus status, WorldCoord pos, Integer blockId, byte data, TownyPermission.ActionType action) {
    if (// || plugin.isTownyAdmin(player)) // status == TownBlockStatus.ADMIN ||
    status == TownBlockStatus.OFF_WORLD || status == TownBlockStatus.WARZONE || status == TownBlockStatus.PLOT_OWNER || status == TownBlockStatus.TOWN_OWNER)
        return true;
    if (status == TownBlockStatus.NOT_REGISTERED) {
        cacheBlockErrMsg(player, TownySettings.getLangString("msg_cache_block_error"));
        return false;
    }
    if (status == TownBlockStatus.LOCKED) {
        cacheBlockErrMsg(player, TownySettings.getLangString("msg_cache_block_error_locked"));
        return false;
    }
    TownBlock townBlock = null;
    Town playersTown = null;
    Town targetTown = null;
    try {
        playersTown = TownyUniverse.getDataSource().getResident(player.getName()).getTown();
    } catch (NotRegisteredException e1) {
    }
    try {
        townBlock = pos.getTownBlock();
        targetTown = townBlock.getTown();
    } catch (NotRegisteredException e) {
        try {
            // Wilderness Permissions
            if (status == TownBlockStatus.UNCLAIMED_ZONE) {
                if (TownyUniverse.getPermissionSource().hasWildOverride(pos.getTownyWorld(), player, blockId, data, action)) {
                    return true;
                } else {
                    // Don't have permission to build/destroy/switch/item_use here
                    cacheBlockErrMsg(player, String.format(TownySettings.getLangString("msg_cache_block_error_wild"), action.toString()));
                    return false;
                }
            }
        } catch (NotRegisteredException e2) {
            TownyMessaging.sendErrorMsg(player, "Error updating " + action.toString() + " permission.");
            return false;
        }
    }
    // Allow admins to have ALL permissions over towns.
    if (TownyUniverse.getPermissionSource().isTownyAdmin(player))
        return true;
    if (townBlock.hasResident()) {
        /*
			 * Check town overrides before testing plot permissions
			 */
        if (targetTown.equals(playersTown) && (TownyUniverse.getPermissionSource().hasOwnTownOverride(player, blockId, data, action))) {
            return true;
        } else if (!targetTown.equals(playersTown) && (TownyUniverse.getPermissionSource().hasAllTownOverride(player, blockId, data, action))) {
            return true;
        } else if (status == TownBlockStatus.PLOT_FRIEND) {
            if (townBlock.getPermissions().getResidentPerm(action)) {
                if (townBlock.getType() == TownBlockType.WILDS) {
                    try {
                        if (TownyUniverse.getPermissionSource().unclaimedZoneAction(pos.getTownyWorld(), blockId, action))
                            return true;
                    } catch (NotRegisteredException e) {
                    }
                } else {
                    return true;
                }
            }
            cacheBlockErrMsg(player, String.format(TownySettings.getLangString("msg_cache_block_error_plot"), "friends", action.toString()));
            return false;
        } else if (status == TownBlockStatus.PLOT_ALLY) {
            if (townBlock.getPermissions().getAllyPerm(action)) {
                if (townBlock.getType() == TownBlockType.WILDS) {
                    try {
                        if (TownyUniverse.getPermissionSource().unclaimedZoneAction(pos.getTownyWorld(), blockId, action))
                            return true;
                    } catch (NotRegisteredException e) {
                    }
                } else {
                    return true;
                }
            }
            cacheBlockErrMsg(player, String.format(TownySettings.getLangString("msg_cache_block_error_plot"), "allies", action.toString()));
            return false;
        } else {
            if (townBlock.getPermissions().getOutsiderPerm(action)) {
                if (townBlock.getType() == TownBlockType.WILDS) {
                    try {
                        if (TownyUniverse.getPermissionSource().unclaimedZoneAction(pos.getTownyWorld(), blockId, action))
                            return true;
                    } catch (NotRegisteredException e) {
                    }
                } else {
                    return true;
                }
            }
            cacheBlockErrMsg(player, String.format(TownySettings.getLangString("msg_cache_block_error_plot"), "outsiders", action.toString()));
            return false;
        }
    }
    // Town Permissions
    if (status == TownBlockStatus.TOWN_RESIDENT) {
        /*
			 * Check town overrides before testing town permissions
			 */
        if (targetTown.equals(playersTown) && (TownyUniverse.getPermissionSource().hasTownOwnedOverride(player, blockId, data, action))) {
            return true;
        } else if (!targetTown.equals(playersTown) && (TownyUniverse.getPermissionSource().hasAllTownOverride(player, blockId, data, action))) {
            return true;
        } else if (townBlock.getPermissions().getResidentPerm(action)) {
            if (townBlock.getType() == TownBlockType.WILDS) {
                try {
                    if (TownyUniverse.getPermissionSource().unclaimedZoneAction(pos.getTownyWorld(), blockId, action))
                        return true;
                } catch (NotRegisteredException e) {
                }
            } else {
                return true;
            }
        }
        cacheBlockErrMsg(player, String.format(TownySettings.getLangString("msg_cache_block_error_town_resident"), action.toString()));
        return false;
    } else if (status == TownBlockStatus.TOWN_ALLY) {
        /*
			 * Check town overrides before testing town permissions
			 */
        if (targetTown.equals(playersTown) && (TownyUniverse.getPermissionSource().hasOwnTownOverride(player, blockId, data, action))) {
            return true;
        } else if (!targetTown.equals(playersTown) && (TownyUniverse.getPermissionSource().hasAllTownOverride(player, blockId, data, action))) {
            return true;
        } else if (townBlock.getPermissions().getAllyPerm(action)) {
            if (townBlock.getType() == TownBlockType.WILDS) {
                try {
                    if (TownyUniverse.getPermissionSource().unclaimedZoneAction(pos.getTownyWorld(), blockId, action))
                        return true;
                } catch (NotRegisteredException e) {
                }
            } else {
                return true;
            }
        }
        cacheBlockErrMsg(player, String.format(TownySettings.getLangString("msg_cache_block_error_town_allies"), action.toString()));
        return false;
    } else if (status == TownBlockStatus.OUTSIDER || status == TownBlockStatus.ENEMY) {
        /*
			 * Check town overrides before testing town permissions
			 */
        if (TownyUniverse.getPermissionSource().hasAllTownOverride(player, blockId, data, action)) {
            return true;
        } else if (townBlock.getPermissions().getOutsiderPerm(action)) {
            if (townBlock.getType() == TownBlockType.WILDS) {
                try {
                    if (TownyUniverse.getPermissionSource().unclaimedZoneAction(pos.getTownyWorld(), blockId, action))
                        return true;
                } catch (NotRegisteredException e) {
                }
            } else {
                return true;
            }
        }
        cacheBlockErrMsg(player, String.format(TownySettings.getLangString("msg_cache_block_error_town_outsider"), action.toString()));
        return false;
    }
    TownyMessaging.sendErrorMsg(player, "Error updating " + action.toString() + " permission.");
    return false;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Aggregations

TownBlock (com.palmergames.bukkit.towny.object.TownBlock)34 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)28 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)16 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)12 Resident (com.palmergames.bukkit.towny.object.Resident)11 Town (com.palmergames.bukkit.towny.object.Town)8 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)7 Coord (com.palmergames.bukkit.towny.object.Coord)7 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)7 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)5 Location (org.bukkit.Location)5 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)4 World (org.bukkit.World)4 Block (org.bukkit.block.Block)4 Nation (com.palmergames.bukkit.towny.object.Nation)3 EventHandler (org.bukkit.event.EventHandler)3 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)2 KeyValueFile (com.palmergames.util.KeyValueFile)2 EOFException (java.io.EOFException)2