Search in sources :

Example 11 with WorldCoord

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

the class TownyRegenAPI method getWorldCoord.

/**
	 * @return First WorldCoord to be processed.
	 */
public static WorldCoord getWorldCoord() {
    if (!worldCoords.isEmpty()) {
        WorldCoord wc = worldCoords.get(0);
        worldCoords.remove(0);
        return wc;
    }
    return null;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord)

Example 12 with WorldCoord

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

the class TownyRegenAPI method getDeleteTownBlockIdQueue.

public static WorldCoord getDeleteTownBlockIdQueue() {
    if (!deleteTownBlockIdQueue.isEmpty()) {
        WorldCoord wc = deleteTownBlockIdQueue.get(0);
        deleteTownBlockIdQueue.remove(0);
        return wc;
    }
    return null;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord)

Example 13 with WorldCoord

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

the class PlotClaim method run.

@Override
public void run() {
    int claimed = 0;
    if (player != null)
        TownyMessaging.sendMsg(player, "Processing " + ((claim) ? "Plot Claim..." : "Plot unclaim..."));
    if (selection != null) {
        for (WorldCoord worldCoord : selection) {
            // Make sure this is a valid world (mainly when unclaiming).
            try {
                this.world = worldCoord.getTownyWorld();
            } catch (NotRegisteredException e) {
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_err_not_configured"));
                continue;
            }
            try {
                if (claim) {
                    if (residentClaim(worldCoord))
                        claimed++;
                } else {
                    residentUnclaim(worldCoord);
                }
            } catch (EconomyException e) {
                /*
					 * Can't pay, but try the rest as we may be
					 * re-possessing and claiming for personal plots.
					 */
                TownyMessaging.sendErrorMsg(player, e.getError());
            } catch (TownyException x) {
                TownyMessaging.sendErrorMsg(player, x.getMessage());
            }
        }
    } else if (!claim) {
        residentUnclaimAll();
    }
    if (player != null) {
        if (claim) {
            if ((selection != null) && (selection.size() > 0) && (claimed > 0))
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_claimed") + ((selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
            else
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_not_claimed_1"));
        } else if (selection != null)
            TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_unclaimed") + ((selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
        else
            TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_unclaimed"));
    }
    TownyUniverse.getDataSource().saveResident(resident);
    plugin.resetCache();
}
Also used : EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 14 with WorldCoord

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

the class TownClaim method run.

@Override
public void run() {
    List<TownyWorld> worlds = new ArrayList<TownyWorld>();
    List<Town> towns = new ArrayList<Town>();
    TownyWorld world;
    if (player != null)
        TownyMessaging.sendMsg(player, "Processing " + ((claim) ? "Town Claim..." : "Town unclaim..."));
    if (selection != null) {
        for (WorldCoord worldCoord : selection) {
            try {
                world = worldCoord.getTownyWorld();
                if (!worlds.contains(world))
                    worlds.add(world);
                if (claim) {
                    // Claim
                    townClaim(town, worldCoord, outpost);
                    // Reset so we only flag the first plot as an outpost.
                    outpost = false;
                } else {
                    // Unclaim
                    this.town = worldCoord.getTownBlock().getTown();
                    townUnclaim(town, worldCoord, forced);
                }
                // Mark this town as modified for saving.
                if (!towns.contains(town))
                    towns.add(town);
            } catch (NotRegisteredException e) {
                // Invalid world
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_err_not_configured"));
            } catch (TownyException x) {
                TownyMessaging.sendErrorMsg(player, x.getMessage());
            }
        }
    } else if (!claim) {
        if (town == null) {
            TownyMessaging.sendMsg(player, "Nothing to unclaim!");
            return;
        }
        townUnclaimAll(town);
    }
    if (!towns.isEmpty())
        for (Town test : towns) TownyUniverse.getDataSource().saveTown(test);
    if (!worlds.isEmpty())
        for (TownyWorld test : worlds) TownyUniverse.getDataSource().saveWorld(test);
    plugin.resetCache();
    if (player != null) {
        if (claim) {
            TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_annexed_area"), (selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
            if (town.getWorld().isUsingPlotManagementRevert())
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_wait_locked"));
        } else if (forced) {
            TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_admin_unclaim_area"), (selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
            if ((town != null) && (town.getWorld().isUsingPlotManagementRevert()))
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_wait_locked"));
        }
    }
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 15 with WorldCoord

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

the class TownyPlayerListener method onPlayerInteract.

public boolean onPlayerInteract(Player player, Block block, ItemStack item) {
    boolean cancelState = false;
    WorldCoord worldCoord;
    try {
        String worldName = player.getWorld().getName();
        if (block != null)
            worldCoord = new WorldCoord(worldName, Coord.parseCoord(block));
        else
            worldCoord = new WorldCoord(worldName, Coord.parseCoord(player));
        // Get itemUse permissions (updates if none exist)
        boolean bItemUse;
        if (block != null)
            bItemUse = PlayerCacheUtil.getCachePermission(player, block.getLocation(), BukkitTools.getTypeId(item), BukkitTools.getDataData(item), TownyPermission.ActionType.ITEM_USE);
        else
            bItemUse = PlayerCacheUtil.getCachePermission(player, player.getLocation(), BukkitTools.getTypeId(item), BukkitTools.getDataData(item), TownyPermission.ActionType.ITEM_USE);
        boolean wildOverride = TownyUniverse.getPermissionSource().hasWildOverride(worldCoord.getTownyWorld(), player, BukkitTools.getTypeId(item), BukkitTools.getDataData(item), TownyPermission.ActionType.ITEM_USE);
        PlayerCache cache = plugin.getCache(player);
        // cache.updateCoord(worldCoord);
        try {
            TownBlockStatus status = cache.getStatus();
            if (status == TownBlockStatus.UNCLAIMED_ZONE && wildOverride)
                return cancelState;
            // Allow item_use if we have an override
            if (((status == TownBlockStatus.TOWN_RESIDENT) && (TownyUniverse.getPermissionSource().hasOwnTownOverride(player, BukkitTools.getTypeId(item), BukkitTools.getDataData(item), TownyPermission.ActionType.ITEM_USE))) || (((status == TownBlockStatus.OUTSIDER) || (status == TownBlockStatus.TOWN_ALLY) || (status == TownBlockStatus.ENEMY)) && (TownyUniverse.getPermissionSource().hasAllTownOverride(player, BukkitTools.getTypeId(item), BukkitTools.getDataData(item), TownyPermission.ActionType.ITEM_USE))))
                return cancelState;
            if (status == TownBlockStatus.WARZONE) {
                if (!TownyWarConfig.isAllowingItemUseInWarZone()) {
                    cancelState = true;
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_warzone_cannot_use_item"));
                }
                return cancelState;
            }
            if (((status == TownBlockStatus.UNCLAIMED_ZONE) && (!wildOverride)) || ((!bItemUse) && (status != TownBlockStatus.UNCLAIMED_ZONE))) {
                // if (status == TownBlockStatus.UNCLAIMED_ZONE)
                // TownyMessaging.sendErrorMsg(player,
                // String.format(TownySettings.getLangString("msg_err_cannot_perform_action"),
                // world.getUnclaimedZoneName()));
                cancelState = true;
            }
            if (// && (status !=
            (cache.hasBlockErrMsg()))
                // TownBlockStatus.UNCLAIMED_ZONE))
                TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
        } catch (NullPointerException e) {
            System.out.print("NPE generated!");
            System.out.print("Player: " + player.getName());
            System.out.print("Item: " + item.getData().getItemType().name());
        // System.out.print("Block: " + block.getType().toString());
        }
    } catch (NotRegisteredException e1) {
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
        cancelState = true;
        return cancelState;
    }
    return cancelState;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) PlayerCache(com.palmergames.bukkit.towny.object.PlayerCache) TownBlockStatus(com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus)

Aggregations

WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)19 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)12 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)8 Resident (com.palmergames.bukkit.towny.object.Resident)5 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)5 ArrayList (java.util.ArrayList)5 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)4 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 TownBlockStatus (com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus)3 Town (com.palmergames.bukkit.towny.object.Town)3 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)3 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)2 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)2 CellBorder (com.palmergames.bukkit.towny.object.CellBorder)2 Nation (com.palmergames.bukkit.towny.object.Nation)2 EOFException (java.io.EOFException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InvalidNameException (javax.naming.InvalidNameException)2