use of net.minecraft.block.ContainerBlock 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 net.minecraft.block.ContainerBlock in project Structurize by ldtteam.
the class ItemStackUtils method getItemStacksOfTileEntity.
/**
* Get itemStack of tileEntityData. Retrieve the data from the tileEntity.
*
* @param compound the tileEntity stored in a compound.
* @param state the block.
* @return the list of itemstacks.
*/
public static List<ItemStack> getItemStacksOfTileEntity(final CompoundNBT compound, final BlockState state) {
if (state.getBlock() instanceof ContainerBlock && compound.contains("Items")) {
final NonNullList<ItemStack> items = NonNullList.create();
ItemStackHelper.loadAllItems(compound, items);
return items;
}
final TileEntity tileEntity = TileEntity.loadStatic(state, compound);
if (tileEntity == null) {
return Collections.emptyList();
}
final List<ItemStack> items = new ArrayList<>();
for (final IItemHandler handler : getItemHandlersFromProvider(tileEntity)) {
for (int slot = 0; slot < handler.getSlots(); slot++) {
final ItemStack stack = handler.getStackInSlot(slot);
if (!ItemStackUtils.isEmpty(stack)) {
items.add(stack);
}
}
}
return items;
}
use of net.minecraft.block.ContainerBlock 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