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;
}
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;
}
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();
}
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"));
}
}
}
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;
}
Aggregations