use of net.minecraftforge.server.permission.context.BlockPosContext in project EnderIO by SleepyTrousers.
the class ItemSoulVial method onItemUse.
@Override
@Nonnull
public EnumActionResult onItemUse(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return EnumActionResult.PASS;
}
ItemStack itemstack = player.getHeldItem(hand);
CapturedMob capturedMob = CapturedMob.create(itemstack);
if (capturedMob == null) {
return EnumActionResult.SUCCESS;
}
if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionPlace, new BlockPosContext(player, pos, null, side))) {
player.sendMessage(Lang.SOUL_VIAL_DENIED.toChatServer());
return EnumActionResult.SUCCESS;
}
if (!capturedMob.spawn(world, pos, side, true)) {
return EnumActionResult.SUCCESS;
}
if (!player.capabilities.isCreativeMode) {
itemstack.shrink(1);
final ItemStack emptyVial = new ItemStack(this);
if (Prep.isInvalid(itemstack)) {
player.setHeldItem(hand, emptyVial);
} else if (!player.inventory.addItemStackToInventory(emptyVial)) {
player.dropItem(emptyVial, false);
}
player.inventoryContainer.detectAndSendChanges();
}
return EnumActionResult.SUCCESS;
}
use of net.minecraftforge.server.permission.context.BlockPosContext in project EnderIO by SleepyTrousers.
the class ToolUtil method breakBlockWithTool.
public static boolean breakBlockWithTool(@Nonnull Block block, @Nonnull World world, @Nonnull BlockPos pos, @Nullable EnumFacing side, @Nonnull EntityPlayer entityPlayer, @Nonnull EnumHand hand, @Nonnull String permissionNode) {
ItemStack heldItem = entityPlayer.getHeldItem(hand);
ITool tool = ToolUtil.getToolFromStack(heldItem);
if (tool != null && entityPlayer.isSneaking() && tool.canUse(hand, entityPlayer, pos)) {
IBlockState bs = world.getBlockState(pos);
if (!PermissionAPI.hasPermission(entityPlayer.getGameProfile(), permissionNode, new BlockPosContext(entityPlayer, pos, bs, side))) {
entityPlayer.sendMessage(Lang.WRENCH_DENIED.toChatServer());
return false;
}
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, bs, entityPlayer);
event.setExpToDrop(0);
if (MinecraftForge.EVENT_BUS.post(event)) {
return false;
}
if (block.removedByPlayer(bs, world, pos, entityPlayer, true)) {
block.harvestBlock(world, entityPlayer, pos, world.getBlockState(pos), world.getTileEntity(pos), heldItem);
}
tool.used(hand, entityPlayer, pos);
return true;
}
return false;
}
use of net.minecraftforge.server.permission.context.BlockPosContext in project EnderIO by SleepyTrousers.
the class TileFarmStation method doTick.
protected void doTick() {
IFarmer farmer = getFarmer();
BlockPos farmingPos = null;
IBlockState bs = null;
int infiniteLoop = 20;
while (farmingPos == null || bs == null || farmingPos.equals(getPos()) || !world.isBlockLoaded(farmingPos) || !PermissionAPI.hasPermission(getOwner().getAsGameProfile(), BlockFarmStation.permissionFarming, new BlockPosContext(farmer.getFakePlayer(), farmingPos, bs, null))) {
if (infiniteLoop-- <= 0) {
return;
}
farmingPos = getNextCoord();
bs = world.getBlockState(farmingPos);
}
Block block = bs.getBlock();
if (isOpen(farmingPos, block)) {
Commune.instance.prepareBlock(farmer, farmingPos, block, bs);
bs = world.getBlockState(farmingPos);
block = bs.getBlock();
}
if (!isOpen(farmingPos, block)) {
if (!executeHarvest(farmer, farmingPos, bs, block)) {
executeBonemeal(farmer, farmingPos, block);
}
}
}
use of net.minecraftforge.server.permission.context.BlockPosContext in project EnderIO by SleepyTrousers.
the class BlockConduitBundle method handleWrenchClick.
private boolean handleWrenchClick(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
ITool tool = ToolUtil.getEquippedTool(player, hand);
if (tool != null) {
if (tool.canUse(hand, player, pos)) {
if (!world.isRemote) {
IBlockState bs = world.getBlockState(pos);
if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionNodeWrenching, new BlockPosContext(player, pos, bs, null))) {
player.sendMessage(new TextComponentString(EnderIO.lang.localize("wrench.permission.denied")));
return false;
}
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, bs, player);
event.setExpToDrop(0);
if (MinecraftForge.EVENT_BUS.post(event)) {
return false;
}
removedByPlayer(bs, world, pos, player, true);
tool.used(hand, player, pos);
}
return true;
}
}
return false;
}
Aggregations