use of com.palmergames.bukkit.towny.object.TownyWorld in project Towny by ElgarL.
the class TownyPlayerListener method onPlayerInteract.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
Player player = event.getPlayer();
Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
TownyWorld World = null;
try {
World = TownyUniverse.getDataSource().getWorld(block.getLocation().getWorld().getName());
if (!World.isUsingTowny())
return;
} catch (NotRegisteredException e) {
// World not registered with Towny.
e.printStackTrace();
return;
}
if ((event.getAction() == Action.PHYSICAL)) {
if ((block.getType() == Material.SOIL) || (block.getType() == Material.CROPS))
if (World.isDisablePlayerTrample() || !PlayerCacheUtil.getCachePermission(player, block.getLocation(), BukkitTools.getTypeId(block), BukkitTools.getData(block), TownyPermission.ActionType.DESTROY)) {
event.setCancelled(true);
return;
}
}
if (event.hasItem()) {
/*
* Info Tool
*/
if (event.getPlayer().getItemInHand().getType() == Material.getMaterial(TownySettings.getTool())) {
if (TownyUniverse.getPermissionSource().isTownyAdmin(player)) {
if (event.getClickedBlock() instanceof Block) {
block = (Block) event.getClickedBlock();
TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Block Info"), ChatTools.formatCommand("", "Block Type", "", block.getType().name()), ChatTools.formatCommand("", "Data value", "", Byte.toString(BukkitTools.getData(block)))));
event.setCancelled(true);
}
}
}
if (TownySettings.isItemUseMaterial(event.getItem().getType().name())) {
event.setCancelled(onPlayerInteract(player, event.getClickedBlock(), event.getItem()));
}
}
if (event.getClickedBlock() != null) {
// Towny regen
if (TownySettings.getRegenDelay() > 0) {
if (event.getClickedBlock().getState().getData() instanceof Attachable) {
Attachable attachable = (Attachable) event.getClickedBlock().getState().getData();
BlockLocation attachedToBlock = new BlockLocation(event.getClickedBlock().getRelative(attachable.getAttachedFace()).getLocation());
// Prevent attached blocks from falling off when interacting
if (TownyRegenAPI.hasProtectionRegenTask(attachedToBlock)) {
event.setCancelled(true);
return;
}
}
}
if (TownySettings.isSwitchMaterial(event.getClickedBlock().getType().name()) || event.getAction() == Action.PHYSICAL) {
onPlayerSwitchEvent(event, null, World);
return;
}
}
}
use of com.palmergames.bukkit.towny.object.TownyWorld 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.TownyWorld in project Towny by ElgarL.
the class TownyPlayerListener method onPlayerInteractEntity.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent 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 ITEM_FRAME:
TownyMessaging.sendDebugMsg("ItemFrame Right Clicked");
blockID = 389;
// Get permissions (updates if none exist)
bBuild = PlayerCacheUtil.getCachePermission(player, event.getRightClicked().getLocation(), blockID, (byte) 0, TownyPermission.ActionType.DESTROY);
break;
case PAINTING:
blockID = 321;
// Get permissions (updates if none exist)
bBuild = PlayerCacheUtil.getCachePermission(player, event.getRightClicked().getLocation(), blockID, (byte) 0, TownyPermission.ActionType.DESTROY);
break;
case MINECART:
if (event.getRightClicked() instanceof org.bukkit.entity.minecart.StorageMinecart) {
blockID = 342;
} else if (event.getRightClicked() instanceof org.bukkit.entity.minecart.RideableMinecart) {
blockID = 328;
} else if (event.getRightClicked() instanceof org.bukkit.entity.minecart.PoweredMinecart) {
blockID = 343;
} else if (event.getRightClicked() instanceof org.bukkit.entity.minecart.HopperMinecart) {
blockID = 408;
} else {
blockID = 321;
}
if ((blockID != 0) && (!TownySettings.isSwitchMaterial(BukkitTools.getMaterial(blockID).name())))
return;
// Get permissions (updates if none exist)
bBuild = PlayerCacheUtil.getCachePermission(player, event.getRightClicked().getLocation(), blockID, (byte) 0, TownyPermission.ActionType.SWITCH);
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;
}
}
}
}
Aggregations