use of com.ldtteam.structurize.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 (event instanceof PlayerInteractEvent.RightClickBlock && block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
return;
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (MineColonies.getConfig().getServer().enableColonyProtection.get()) {
if (!perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_BLOCK) && !(block instanceof AirBlock)) {
checkEventCancelation(Action.RIGHTCLICK_BLOCK, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (block instanceof ContainerBlock && !perms.hasPermission(event.getPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
return;
}
if (event.getWorld().getBlockEntity(event.getPos()) != null && !perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_ENTITY)) {
checkEventCancelation(Action.RIGHTCLICK_ENTITY, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
final ItemStack stack = event.getItemStack();
if (ItemStackUtils.isEmpty(stack) || stack.getItem().isEdible()) {
return;
}
if (stack.getItem() instanceof PotionItem) {
checkEventCancelation(Action.THROW_POTION, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
}
}
}
}
use of com.ldtteam.structurize.items.ItemScanTool in project minecolonies by ldtteam.
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 (event instanceof PlayerInteractEvent.RightClickBlock && block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
return;
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (MineColonies.getConfig().getServer().enableColonyProtection.get()) {
if (!perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_BLOCK) && !(block instanceof AirBlock)) {
checkEventCancelation(Action.RIGHTCLICK_BLOCK, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (block instanceof ContainerBlock && !perms.hasPermission(event.getPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
return;
}
if (event.getWorld().getBlockEntity(event.getPos()) != null && !perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_ENTITY)) {
checkEventCancelation(Action.RIGHTCLICK_ENTITY, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
final ItemStack stack = event.getItemStack();
if (ItemStackUtils.isEmpty(stack) || stack.getItem().isEdible()) {
return;
}
if (stack.getItem() instanceof PotionItem) {
checkEventCancelation(Action.THROW_POTION, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
}
}
}
}
Aggregations