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