Search in sources :

Example 11 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ForgeEventHandler method handleOwnableTEs.

private void handleOwnableTEs(PlaceEvent event) {
    if (event.getWorld().getTileEntity(event.getPos()) instanceof IOwnable) {
        String name = event.getPlayer().getName();
        String uuid = event.getPlayer().getGameProfile().getId().toString();
        ((IOwnable) event.getWorld().getTileEntity(event.getPos())).getOwner().set(uuid, name);
    }
}
Also used : IOwnable(net.geforcemods.securitycraft.api.IOwnable) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 12 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemCameraMonitor method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        if (BlockUtils.getBlock(worldIn, pos) == mod_SecurityCraft.securityCamera) {
            if (!((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.cameraMonitor.name"), I18n.translateToLocal("messages.cameraMonitor.cannotView"), TextFormatting.RED);
                return EnumActionResult.SUCCESS;
            }
            if (playerIn.inventory.getCurrentItem().getTagCompound() == null) {
                playerIn.inventory.getCurrentItem().setTagCompound(new NBTTagCompound());
            }
            CameraView view = new CameraView(pos, playerIn.dimension);
            if (isCameraAdded(playerIn.inventory.getCurrentItem().getTagCompound(), view)) {
                playerIn.inventory.getCurrentItem().getTagCompound().removeTag(getTagNameFromPosition(playerIn.inventory.getCurrentItem().getTagCompound(), view));
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.cameraMonitor.name"), I18n.translateToLocal("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.RED);
                return EnumActionResult.SUCCESS;
            }
            for (int i = 1; i <= 30; i++) {
                if (!playerIn.inventory.getCurrentItem().getTagCompound().hasKey("Camera" + i)) {
                    playerIn.inventory.getCurrentItem().getTagCompound().setString("Camera" + i, view.toNBTString());
                    PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.cameraMonitor.name"), I18n.translateToLocal("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
                    break;
                }
            }
            mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
            return EnumActionResult.SUCCESS;
        }
    } else if (worldIn.isRemote && BlockUtils.getBlock(worldIn, pos) != mod_SecurityCraft.securityCamera) {
        if (playerIn.getRidingEntity() != null && playerIn.getRidingEntity() instanceof EntitySecurityCamera)
            return EnumActionResult.SUCCESS;
        if (stack.getTagCompound() == null || stack.getTagCompound().hasNoTags()) {
            PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.cameraMonitor.name"), I18n.translateToLocal("messages.cameraMonitor.rightclickToView"), TextFormatting.RED);
            return EnumActionResult.SUCCESS;
        }
        playerIn.openGui(mod_SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.SUCCESS;
}
Also used : EntitySecurityCamera(net.geforcemods.securitycraft.entity.EntitySecurityCamera) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOwnable(net.geforcemods.securitycraft.api.IOwnable) PacketCUpdateNBTTag(net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag) CameraView(net.geforcemods.securitycraft.misc.CameraView)

Example 13 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemUniversalOwnerChanger method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    TileEntity te = world.getTileEntity(pos);
    String newOwner = stack.getDisplayName();
    if (!world.isRemote) {
        if (!stack.hasDisplayName()) {
            PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("item.universalOwnerChanger.name"), I18n.translateToLocal("messages.universalOwnerChanger.noName"), TextFormatting.RED);
            return EnumActionResult.FAIL;
        }
        if (!(te instanceof IOwnable)) {
            PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("item.universalOwnerChanger.name"), I18n.translateToLocal("messages.universalOwnerChanger.cantChange"), TextFormatting.RED);
            return EnumActionResult.FAIL;
        }
        if (!((IOwnable) te).getOwner().isOwner(player)) {
            PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("item.universalOwnerChanger.name"), I18n.translateToLocal("messages.universalOwnerChanger.notOwned"), TextFormatting.RED);
            return EnumActionResult.FAIL;
        }
        if (BlockUtils.getBlock(world, pos) instanceof BlockReinforcedDoor) {
            if (BlockUtils.getBlock(world, pos.up()) instanceof BlockReinforcedDoor)
                ((IOwnable) world.getTileEntity(pos.up())).getOwner().set(PlayerUtils.isPlayerOnline(newOwner) ? PlayerUtils.getPlayerFromName(newOwner).getUniqueID().toString() : "ownerUUID", newOwner);
            else
                ((IOwnable) world.getTileEntity(pos.up())).getOwner().set(PlayerUtils.isPlayerOnline(newOwner) ? PlayerUtils.getPlayerFromName(newOwner).getUniqueID().toString() : "ownerUUID", newOwner);
        }
        if (te instanceof IOwnable)
            ((IOwnable) te).getOwner().set(PlayerUtils.isPlayerOnline(newOwner) ? PlayerUtils.getPlayerFromName(newOwner).getUniqueID().toString() : "ownerUUID", newOwner);
        world.getMinecraftServer().getPlayerList().sendPacketToAllPlayers(te.getUpdatePacket());
        PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("item.universalOwnerChanger.name"), I18n.translateToLocal("messages.universalOwnerChanger.changed").replace("#", newOwner), TextFormatting.GREEN);
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.FAIL;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IOwnable(net.geforcemods.securitycraft.api.IOwnable) BlockReinforcedDoor(net.geforcemods.securitycraft.blocks.BlockReinforcedDoor)

Example 14 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemAdminTool method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        if (worldIn.getTileEntity(pos) != null) {
            TileEntity te = worldIn.getTileEntity(pos);
            boolean hasInfo = false;
            if (te instanceof IOwnable) {
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.adminTool.name"), I18n.translateToLocal("messages.adminTool.owner.name").replace("#", (((IOwnable) te).getOwner().getName() == null ? "????" : ((IOwnable) te).getOwner().getName())), TextFormatting.DARK_PURPLE);
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.adminTool.name"), I18n.translateToLocal("messages.adminTool.owner.uuid").replace("#", (((IOwnable) te).getOwner().getUUID() == null ? "????" : ((IOwnable) te).getOwner().getUUID())), TextFormatting.DARK_PURPLE);
                hasInfo = true;
            }
            if (te instanceof IPasswordProtected) {
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.adminTool.name"), I18n.translateToLocal("messages.adminTool.password").replace("#", (((IPasswordProtected) te).getPassword() == null ? "????" : ((IPasswordProtected) te).getPassword())), TextFormatting.DARK_PURPLE);
                hasInfo = true;
            }
            if (te instanceof CustomizableSCTE) {
                List<EnumCustomModules> modules = ((CustomizableSCTE) te).getModules();
                if (!modules.isEmpty()) {
                    PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.adminTool.name"), I18n.translateToLocal("messages.adminTool.equippedModules"), TextFormatting.DARK_PURPLE);
                    for (EnumCustomModules module : modules) {
                        PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.adminTool.name"), "-" + module.getName(), TextFormatting.DARK_PURPLE);
                    }
                    hasInfo = true;
                }
            }
            if (!hasInfo) {
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.adminTool.name"), I18n.translateToLocal("messages.adminTool.noInfo"), TextFormatting.DARK_PURPLE);
            }
            return EnumActionResult.FAIL;
        }
        PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.adminTool.name"), I18n.translateToLocal("messages.adminTool.noInfo"), TextFormatting.DARK_PURPLE);
    }
    return EnumActionResult.FAIL;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPasswordProtected(net.geforcemods.securitycraft.api.IPasswordProtected) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) IOwnable(net.geforcemods.securitycraft.api.IOwnable) EnumCustomModules(net.geforcemods.securitycraft.misc.EnumCustomModules)

Example 15 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemBlockReinforcedWoodSlabs method tryPlace.

private boolean tryPlace(ItemStack stack, World worldIn, EntityPlayer player, BlockPos pos, Object variantInStack) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Owner owner = null;
    if (worldIn.getTileEntity(pos) instanceof IOwnable) {
        owner = ((IOwnable) worldIn.getTileEntity(pos)).getOwner();
    }
    if (iblockstate.getBlock() == this.singleSlab) {
        Comparable<?> comparable = iblockstate.getValue(this.singleSlab.getVariantProperty());
        if (comparable == variantInStack) {
            IBlockState iblockstate1 = this.makeState(this.singleSlab.getVariantProperty(), comparable);
            if (worldIn.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBox(iblockstate1, worldIn, pos)) && worldIn.setBlockState(pos, iblockstate1, 3)) {
                worldIn.playSound(player, pos, this.doubleSlab.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (this.doubleSlab.getSoundType().getVolume() + 1.0F) / 2.0F, this.doubleSlab.getSoundType().getPitch() * 0.8F);
                --stack.stackSize;
                if (owner != null) {
                    ((IOwnable) worldIn.getTileEntity(pos)).getOwner().set(owner.getUUID(), owner.getName());
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Owner(net.geforcemods.securitycraft.api.Owner) IBlockState(net.minecraft.block.state.IBlockState) IOwnable(net.geforcemods.securitycraft.api.IOwnable)

Aggregations

IOwnable (net.geforcemods.securitycraft.api.IOwnable)32 Owner (net.geforcemods.securitycraft.api.Owner)13 TileEntity (net.minecraft.tileentity.TileEntity)10 CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)8 IPasswordProtected (net.geforcemods.securitycraft.api.IPasswordProtected)6 PacketCUpdateNBTTag (net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag)6 Block (net.minecraft.block.Block)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 IExplosive (net.geforcemods.securitycraft.api.IExplosive)5 EnumCustomModules (net.geforcemods.securitycraft.misc.EnumCustomModules)4 IBlockState (net.minecraft.block.state.IBlockState)4 ItemBlock (net.minecraft.item.ItemBlock)4 INameable (net.geforcemods.securitycraft.api.INameable)3 BlockReinforcedDoor (net.geforcemods.securitycraft.blocks.BlockReinforcedDoor)3 CameraView (net.geforcemods.securitycraft.misc.CameraView)3 TileEntitySCTE (net.geforcemods.securitycraft.api.TileEntitySCTE)2 BlockLaserBlock (net.geforcemods.securitycraft.blocks.BlockLaserBlock)2 EntitySecurityCamera (net.geforcemods.securitycraft.entity.EntitySecurityCamera)2 CustomHoverChecker (net.geforcemods.securitycraft.gui.components.CustomHoverChecker)2 ITileEntityProvider (net.minecraft.block.ITileEntityProvider)2