use of com.minecolonies.coremod.items.ItemScanTool in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* PlayerInteractEvent handler.
* <p>
* Check, if a player right clicked a block.
* Deny if:
* - If the block is in colony
* - block is AbstractBlockHut
* - player has not permission
*
* @param event PlayerInteractEvent
*/
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
// Huts
if (block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getEntityPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getEntityPlayer());
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(event.getWorld().getBlockState(event.getPos()).getBlock(), event.getPos()) && perms.hasPermission(event.getEntityPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (Configurations.enableColonyProtection) {
if (!perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_BLOCK) && event.getWorld().getBlockState(event.getPos()).getBlock() != null) {
cancelEvent(event, event.getEntityPlayer());
}
if (event.getWorld().getBlockState(event.getPos()).getBlock() instanceof BlockContainer && !perms.hasPermission(event.getEntityPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getEntityPlayer());
}
if (event.getWorld().getTileEntity(event.getPos()) != null && !perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_ENTITY)) {
cancelEvent(event, event.getEntityPlayer());
}
if (event.getItemStack() != null && event.getItemStack().getItem() instanceof ItemPotion && !perms.hasPermission(event.getEntityPlayer(), Action.THROW_POTION)) {
cancelEvent(event, event.getEntityPlayer());
}
if (event.getItemStack() != null && event.getItemStack().getItem() instanceof ItemScanTool && !perms.hasPermission(event.getEntityPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getEntityPlayer());
}
}
}
}
Aggregations