Search in sources :

Example 1 with GenericTileEntity

use of mcjty.lib.entity.GenericTileEntity in project RFTools by McJty.

the class OrphaningCardItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof GenericTileEntity) {
            // Generalize with a security API interface @todo
            GenericTileEntity genericTileEntity = (GenericTileEntity) te;
            if (genericTileEntity.getOwnerUUID() == null) {
                Logging.message(player, TextFormatting.RED + "This block has no owner!");
            } else {
                if (isPrivileged(player, world)) {
                    genericTileEntity.clearOwner();
                    Logging.message(player, "Cleared owner!");
                } else if (genericTileEntity.getOwnerUUID().equals(player.getPersistentID())) {
                    genericTileEntity.clearOwner();
                    Logging.message(player, "Cleared owner!");
                } else {
                    Logging.message(player, TextFormatting.RED + "You cannot clear ownership of a block you don't own!");
                }
            }
        } else {
            Logging.message(player, TextFormatting.RED + "Onwership is not supported on this block!");
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) GenericTileEntity(mcjty.lib.entity.GenericTileEntity)

Example 2 with GenericTileEntity

use of mcjty.lib.entity.GenericTileEntity in project RFTools by McJty.

the class GenericRFToolsBlock method checkAccess.

@Override
protected boolean checkAccess(World world, EntityPlayer player, TileEntity te) {
    if (SecurityConfiguration.enabled && te instanceof GenericTileEntity) {
        GenericTileEntity genericTileEntity = (GenericTileEntity) te;
        if ((!OrphaningCardItem.isPrivileged(player, world)) && (!player.getPersistentID().equals(genericTileEntity.getOwnerUUID()))) {
            int securityChannel = genericTileEntity.getSecurityChannel();
            if (securityChannel != -1) {
                SecurityChannels securityChannels = SecurityChannels.getChannels(world);
                SecurityChannels.SecurityChannel channel = securityChannels.getChannel(securityChannel);
                boolean playerListed = channel.getPlayers().contains(player.getDisplayNameString());
                if (channel.isWhitelist() != playerListed) {
                    Logging.message(player, TextFormatting.RED + "You have no permission to use this block!");
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : GenericTileEntity(mcjty.lib.entity.GenericTileEntity) SecurityChannels(mcjty.rftools.blocks.security.SecurityChannels)

Example 3 with GenericTileEntity

use of mcjty.lib.entity.GenericTileEntity in project RFTools by McJty.

the class ShardWandItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        Block block = world.getBlockState(pos).getBlock();
        if (block instanceof Infusable) {
            TileEntity te = world.getTileEntity(pos);
            if (te instanceof GenericTileEntity) {
                GenericTileEntity genericTileEntity = (GenericTileEntity) te;
                int infused = genericTileEntity.getInfused();
                if (infused < GeneralConfig.maxInfuse) {
                    infused = GeneralConfig.maxInfuse;
                    Logging.message(player, "Maximized infusion level!");
                } else {
                    infused = 0;
                    Logging.message(player, "Cleared infusion level!");
                }
                genericTileEntity.setInfused(infused);
            } else {
                Logging.message(player, "This block doesn't have the right tile entity!");
            }
        } else {
            Logging.message(player, "This block is not infusable!");
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.SUCCESS;
}
Also used : Infusable(mcjty.lib.api.Infusable) TileEntity(net.minecraft.tileentity.TileEntity) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) Block(net.minecraft.block.Block)

Example 4 with GenericTileEntity

use of mcjty.lib.entity.GenericTileEntity in project RFTools by McJty.

the class SecurityCardItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote) {
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof GenericTileEntity) {
            // @tod security api
            GenericTileEntity genericTileEntity = (GenericTileEntity) te;
            if (genericTileEntity.getOwnerUUID() == null) {
                Logging.message(player, TextFormatting.RED + "This block has no owner!");
            } else {
                if (OrphaningCardItem.isPrivileged(player, world) || isOwner(player, genericTileEntity)) {
                    NBTTagCompound tagCompound = stack.getTagCompound();
                    if (tagCompound == null || !tagCompound.hasKey("channel")) {
                        int blockSecurity = genericTileEntity.getSecurityChannel();
                        if (blockSecurity == -1) {
                            Logging.message(player, TextFormatting.RED + "This security card is not setup correctly!");
                        } else {
                            if (tagCompound == null) {
                                tagCompound = new NBTTagCompound();
                                stack.setTagCompound(tagCompound);
                            }
                            tagCompound.setInteger("channel", blockSecurity);
                            Logging.message(player, TextFormatting.RED + "Copied security channel from block to card!");
                        }
                    } else {
                        int channel = tagCompound.getInteger("channel");
                        toggleSecuritySettings(player, genericTileEntity, channel);
                    }
                } else {
                    Logging.message(player, TextFormatting.RED + "You cannot change security settings of a block you don't own!");
                }
            }
        } else {
            Logging.message(player, TextFormatting.RED + "Security is not supported on this block!");
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Aggregations

GenericTileEntity (mcjty.lib.entity.GenericTileEntity)4 TileEntity (net.minecraft.tileentity.TileEntity)3 Infusable (mcjty.lib.api.Infusable)1 SecurityChannels (mcjty.rftools.blocks.security.SecurityChannels)1 Block (net.minecraft.block.Block)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1