use of com.palmergames.bukkit.towny.object.PlayerCache in project Towny by ElgarL.
the class TownyBlockListener method onBlockBreak.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
Player player = event.getPlayer();
Block block = event.getBlock();
//Get build permissions (updates cache if none exist)
boolean bDestroy = PlayerCacheUtil.getCachePermission(player, block.getLocation(), BukkitTools.getTypeId(block), BukkitTools.getData(block), TownyPermission.ActionType.DESTROY);
// Allow destroy if we are permitted
if (bDestroy)
return;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
/*
* Allow destroy in a WarZone (FlagWar) if it's an editable material.
*/
if (cache.getStatus() == TownBlockStatus.WARZONE) {
if (!TownyWarConfig.isEditableMaterialInWarZone(block.getType())) {
event.setCancelled(true);
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_warzone_cannot_edit_material"), "destroy", block.getType().toString().toLowerCase()));
}
return;
}
/*
* Queue a protectionRegenTask if we have delayed regeneration set
*/
long delay = TownySettings.getRegenDelay();
if (delay > 0) {
if (!TownyRegenAPI.isPlaceholder(block)) {
if (!TownyRegenAPI.hasProtectionRegenTask(new BlockLocation(block.getLocation()))) {
ProtectionRegenTask task = new ProtectionRegenTask(plugin, block, true);
task.setTaskId(plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, 20 * delay));
TownyRegenAPI.addProtectionRegenTask(task);
}
} else {
TownyRegenAPI.removePlaceholder(block);
BukkitTools.setTypeId(block, 0, false);
}
} else {
event.setCancelled(true);
}
/*
* display any error recorded for this plot
*/
if ((cache.hasBlockErrMsg()) && (event.isCancelled()))
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
}
use of com.palmergames.bukkit.towny.object.PlayerCache in project Towny by ElgarL.
the class TownyEntityListener method onHangingPlace.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
long start = System.currentTimeMillis();
Player player = event.getPlayer();
Entity hanging = event.getEntity();
try {
TownyWorld townyWorld = TownyUniverse.getDataSource().getWorld(hanging.getWorld().getName());
if (!townyWorld.isUsingTowny())
return;
// Get build permissions (updates if none exist)
boolean bBuild = PlayerCacheUtil.getCachePermission(player, hanging.getLocation(), 321, (byte) 0, TownyPermission.ActionType.BUILD);
// Allow placing if we are permitted
if (bBuild)
return;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
event.setCancelled(true);
if (cache.hasBlockErrMsg())
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
} catch (NotRegisteredException e1) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
event.setCancelled(true);
return;
}
TownyMessaging.sendDebugMsg("onHangingBreak took " + (System.currentTimeMillis() - start) + "ms (" + event.getEventName() + ", " + event.isCancelled() + ")");
}
use of com.palmergames.bukkit.towny.object.PlayerCache in project Towny by ElgarL.
the class TownyEntityListener method onHangingBreak.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
TownyWorld townyWorld = null;
String worldName = null;
Entity hanging = event.getEntity();
try {
worldName = hanging.getWorld().getName();
townyWorld = TownyUniverse.getDataSource().getWorld(worldName);
if (!townyWorld.isUsingTowny())
return;
} catch (NotRegisteredException e1) {
// event.setCancelled(true);
return;
}
if (event instanceof HangingBreakByEntityEvent) {
HangingBreakByEntityEvent evt = (HangingBreakByEntityEvent) event;
Object remover = evt.getRemover();
/*
* Check if this has a shooter.
*/
if (remover instanceof Projectile) {
remover = ((Projectile) remover).getShooter();
}
if (remover instanceof Player) {
Player player = (Player) remover;
// Get destroy permissions (updates if none exist)
boolean bDestroy = PlayerCacheUtil.getCachePermission(player, hanging.getLocation(), 321, (byte) 0, TownyPermission.ActionType.DESTROY);
// Allow the removal if we are permitted
if (bDestroy)
return;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
event.setCancelled(true);
if (cache.hasBlockErrMsg())
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
} else {
// Explosions are blocked in this plot
if (!locationCanExplode(townyWorld, hanging.getLocation()))
event.setCancelled(true);
}
} else {
switch(event.getCause()) {
case EXPLOSION:
if (!locationCanExplode(townyWorld, event.getEntity().getLocation()))
event.setCancelled(true);
break;
default:
}
}
}
use of com.palmergames.bukkit.towny.object.PlayerCache in project Towny by ElgarL.
the class TownyPlayerListener method onPlayerInteractEntity.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractAtEntityEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
if (event.getRightClicked() != null) {
TownyWorld World = null;
try {
World = TownyUniverse.getDataSource().getWorld(event.getPlayer().getWorld().getName());
if (!World.isUsingTowny())
return;
} catch (NotRegisteredException e) {
// World not registered with Towny.
e.printStackTrace();
return;
}
Player player = event.getPlayer();
boolean bBuild = true;
int blockID = 0;
/*
* Protect specific entity interactions.
*/
switch(event.getRightClicked().getType()) {
case ARMOR_STAND:
TownyMessaging.sendDebugMsg("ArmorStand Right Clicked");
blockID = 416;
// Get permissions (updates if none exist)
bBuild = PlayerCacheUtil.getCachePermission(player, event.getRightClicked().getLocation(), blockID, (byte) 0, TownyPermission.ActionType.DESTROY);
break;
default:
break;
}
if (blockID != 0) {
// Allow the removal if we are permitted
if (bBuild)
return;
event.setCancelled(true);
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
if (cache.hasBlockErrMsg())
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
return;
}
/*
* Item_use protection.
*/
if (event.getPlayer().getItemInHand() != null) {
/*
* Info Tool
*/
if (event.getPlayer().getItemInHand().getType() == Material.getMaterial(TownySettings.getTool())) {
Entity entity = event.getRightClicked();
TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Entity Info"), ChatTools.formatCommand("", "Entity Class", "", entity.getType().getEntityClass().getSimpleName())));
event.setCancelled(true);
}
if (TownySettings.isItemUseMaterial(event.getPlayer().getItemInHand().getType().name())) {
event.setCancelled(onPlayerInteract(event.getPlayer(), null, event.getPlayer().getItemInHand()));
return;
}
}
}
}
use of com.palmergames.bukkit.towny.object.PlayerCache in project Towny by ElgarL.
the class TownyPlayerListener method onPlayerSwitchEvent.
public boolean onPlayerSwitchEvent(Player player, Block block, String errMsg, TownyWorld world) {
if (!TownySettings.isSwitchMaterial(block.getType().name()))
return false;
// Get switch permissions (updates if none exist)
boolean bSwitch = PlayerCacheUtil.getCachePermission(player, block.getLocation(), BukkitTools.getTypeId(block), BukkitTools.getData(block), TownyPermission.ActionType.SWITCH);
// Allow switch if we are permitted
if (bSwitch)
return false;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
TownBlockStatus status = cache.getStatus();
/*
* display any error recorded for this plot
*/
if (cache.hasBlockErrMsg())
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
/*
* Flag war
*/
if (status == TownBlockStatus.WARZONE) {
if (!TownyWarConfig.isAllowingSwitchesInWarZone()) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_warzone_cannot_use_switches"));
return true;
}
return false;
} else {
return true;
}
}
Aggregations