Search in sources :

Example 1 with INameable

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

the class BlockPortableRadar method searchForPlayers.

public static void searchForPlayers(World par1World, int par2, int par3, int par4, double searchRadius) {
    if (!par1World.isRemote) {
        double d0 = (searchRadius);
        AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(par2, par3, par4, par2 + 1, par3 + 1, par4 + 1).expand(d0, d0, d0);
        axisalignedbb.maxY = par1World.getHeight();
        List<?> list = par1World.getEntitiesWithinAABB(EntityPlayer.class, axisalignedbb);
        Iterator<?> iterator = list.iterator();
        EntityPlayer entityplayer;
        if (list.isEmpty())
            if (par1World.getTileEntity(par2, par3, par4) != null && par1World.getTileEntity(par2, par3, par4) instanceof TileEntityPortableRadar && ((CustomizableSCTE) par1World.getTileEntity(par2, par3, par4)).hasModule(EnumCustomModules.REDSTONE) && par1World.getBlockMetadata(par2, par3, par4) == 1) {
                togglePowerOutput(par1World, par2, par3, par4, false);
                return;
            }
        while (iterator.hasNext()) {
            EntityPlayerMP entityplayermp = MinecraftServer.getServer().getConfigurationManager().getPlayerByUsername(((TileEntityPortableRadar) par1World.getTileEntity(par2, par3, par4)).getOwner().getName());
            entityplayer = (EntityPlayer) iterator.next();
            if (par1World.getTileEntity(par2, par3, par4) == null || !(par1World.getTileEntity(par2, par3, par4) instanceof CustomizableSCTE))
                continue;
            if (((CustomizableSCTE) par1World.getTileEntity(par2, par3, par4)).hasModule(EnumCustomModules.WHITELIST) && ModuleUtils.getPlayersFromModule(par1World, par2, par3, par4, EnumCustomModules.WHITELIST).contains(entityplayermp.getCommandSenderName().toLowerCase()))
                continue;
            if (PlayerUtils.isPlayerOnline(((TileEntityPortableRadar) par1World.getTileEntity(par2, par3, par4)).getOwner().getName())) {
                if (!((TileEntityPortableRadar) par1World.getTileEntity(par2, par3, par4)).shouldSendMessage(entityplayer))
                    continue;
                PlayerUtils.sendMessageToPlayer(entityplayermp, StatCollector.translateToLocal("tile.portableRadar.name"), ((INameable) par1World.getTileEntity(par2, par3, par4)).hasCustomName() ? (StatCollector.translateToLocal("messages.portableRadar.withName").replace("#p", EnumChatFormatting.ITALIC + entityplayer.getCommandSenderName() + EnumChatFormatting.RESET).replace("#n", EnumChatFormatting.ITALIC + ((INameable) par1World.getTileEntity(par2, par3, par4)).getCustomName() + EnumChatFormatting.RESET)) : (StatCollector.translateToLocal("messages.portableRadar.withoutName").replace("#p", EnumChatFormatting.ITALIC + entityplayer.getCommandSenderName() + EnumChatFormatting.RESET).replace("#l", Utils.getFormattedCoordinates(par2, par3, par4))), EnumChatFormatting.BLUE);
                ((TileEntityPortableRadar) par1World.getTileEntity(par2, par3, par4)).setSentMessage();
            }
            if (par1World.getTileEntity(par2, par3, par4) != null && par1World.getTileEntity(par2, par3, par4) instanceof TileEntityPortableRadar && ((CustomizableSCTE) par1World.getTileEntity(par2, par3, par4)).hasModule(EnumCustomModules.REDSTONE))
                togglePowerOutput(par1World, par2, par3, par4, true);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) TileEntityPortableRadar(net.geforcemods.securitycraft.tileentity.TileEntityPortableRadar) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 2 with INameable

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

the class BlockPortableRadar method searchForPlayers.

public static void searchForPlayers(World par1World, BlockPos pos, IBlockState state) {
    if (!par1World.isRemote) {
        double d0 = (SecurityCraft.config.portableRadarSearchRadius);
        AxisAlignedBB axisalignedbb = AxisAlignedBB.fromBounds(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1).expand(d0, d0, d0).addCoord(0.0D, par1World.getHeight(), 0.0D);
        List<?> list = par1World.getEntitiesWithinAABB(EntityPlayer.class, axisalignedbb);
        Iterator<?> iterator = list.iterator();
        EntityPlayer entityplayer;
        if (list.isEmpty())
            if (par1World.getTileEntity(pos) != null && par1World.getTileEntity(pos) instanceof TileEntityPortableRadar && ((CustomizableSCTE) par1World.getTileEntity(pos)).hasModule(EnumCustomModules.REDSTONE) && ((Boolean) state.getValue(POWERED)).booleanValue()) {
                togglePowerOutput(par1World, pos, false);
                return;
            }
        if (!((CustomizableSCTE) par1World.getTileEntity(pos)).hasModule(EnumCustomModules.REDSTONE))
            togglePowerOutput(par1World, pos, false);
        while (iterator.hasNext()) {
            EntityPlayerMP entityplayermp = MinecraftServer.getServer().getConfigurationManager().getPlayerByUsername(((TileEntityPortableRadar) par1World.getTileEntity(pos)).getOwner().getName());
            entityplayer = (EntityPlayer) iterator.next();
            if (entityplayermp != null && ((CustomizableSCTE) par1World.getTileEntity(pos)).hasModule(EnumCustomModules.WHITELIST) && ModuleUtils.getPlayersFromModule(par1World, pos, EnumCustomModules.WHITELIST).contains(entityplayermp.getCommandSenderName().toLowerCase()))
                continue;
            if (PlayerUtils.isPlayerOnline(((TileEntityPortableRadar) par1World.getTileEntity(pos)).getOwner().getName())) {
                if (!((TileEntityPortableRadar) par1World.getTileEntity(pos)).shouldSendMessage(entityplayer))
                    continue;
                PlayerUtils.sendMessageToPlayer(entityplayermp, StatCollector.translateToLocal("tile.portableRadar.name"), ((INameable) par1World.getTileEntity(pos)).hasCustomName() ? (StatCollector.translateToLocal("messages.portableRadar.withName").replace("#p", EnumChatFormatting.ITALIC + entityplayer.getCommandSenderName() + EnumChatFormatting.RESET).replace("#n", EnumChatFormatting.ITALIC + ((INameable) par1World.getTileEntity(pos)).getCustomName() + EnumChatFormatting.RESET)) : (StatCollector.translateToLocal("messages.portableRadar.withoutName").replace("#p", EnumChatFormatting.ITALIC + entityplayer.getCommandSenderName() + EnumChatFormatting.RESET).replace("#l", Utils.getFormattedCoordinates(pos))), EnumChatFormatting.BLUE);
                ((TileEntityPortableRadar) par1World.getTileEntity(pos)).setSentMessage();
            }
            if (par1World.getTileEntity(pos) != null && par1World.getTileEntity(pos) instanceof TileEntityPortableRadar && ((CustomizableSCTE) par1World.getTileEntity(pos)).hasModule(EnumCustomModules.REDSTONE))
                togglePowerOutput(par1World, pos, true);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) TileEntityPortableRadar(net.geforcemods.securitycraft.tileentity.TileEntityPortableRadar) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 3 with INameable

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

the class SCEventHandler method onPlayerInteracted.

@SubscribeEvent
public void onPlayerInteracted(PlayerInteractEvent event) {
    if (!event.entityPlayer.worldObj.isRemote) {
        World world = event.entityPlayer.worldObj;
        TileEntity tileEntity = event.entityPlayer.worldObj.getTileEntity(event.pos);
        Block block = event.entityPlayer.worldObj.getBlockState(event.pos).getBlock();
        if (event.action != Action.RIGHT_CLICK_BLOCK)
            return;
        if (event.action == Action.RIGHT_CLICK_BLOCK && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.codebreaker) && handleCodebreaking(event)) {
            event.setCanceled(true);
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.universalBlockModifier)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockModifier.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.openGui(SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.entityPlayer, Items.name_tag) && event.entityPlayer.getCurrentEquippedItem().hasDisplayName()) {
            event.setCanceled(true);
            for (String character : new String[] { "(", ")" }) if (event.entityPlayer.getCurrentEquippedItem().getDisplayName().contains(character)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.error").replace("#n", event.entityPlayer.getCurrentEquippedItem().getDisplayName()).replace("#c", character), EnumChatFormatting.RED);
                return;
            }
            if (((INameable) tileEntity).getCustomName().matches(event.entityPlayer.getCurrentEquippedItem().getDisplayName())) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.getCurrentEquippedItem().stackSize--;
            ((INameable) tileEntity).setCustomName(event.entityPlayer.getCurrentEquippedItem().getDisplayName());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.universalBlockRemover)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockRemover.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            if (block == SCContent.laserBlock) {
                world.destroyBlock(event.pos, true);
                BlockLaserBlock.destroyAdjacentLasers(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            } else {
                world.destroyBlock(event.pos, true);
                world.removeTileEntity(event.pos);
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) Block(net.minecraft.block.Block) BlockLaserBlock(net.geforcemods.securitycraft.blocks.BlockLaserBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with INameable

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

the class ForgeEventHandler method onPlayerInteracted.

@SubscribeEvent
public void onPlayerInteracted(PlayerInteractEvent event) {
    if (!event.entityPlayer.worldObj.isRemote) {
        World world = event.entityPlayer.worldObj;
        TileEntity tileEntity = event.entityPlayer.worldObj.getTileEntity(event.pos);
        Block block = event.entityPlayer.worldObj.getBlockState(event.pos).getBlock();
        if (event.action != Action.RIGHT_CLICK_BLOCK)
            return;
        if (event.action == Action.RIGHT_CLICK_BLOCK && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.codebreaker) && handleCodebreaking(event)) {
            event.setCanceled(true);
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.universalBlockModifier)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockModifier.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.openGui(mod_SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.entityPlayer, Items.name_tag) && event.entityPlayer.getCurrentEquippedItem().hasDisplayName()) {
            event.setCanceled(true);
            for (String character : new String[] { "(", ")" }) {
                if (event.entityPlayer.getCurrentEquippedItem().getDisplayName().contains(character)) {
                    PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.error").replace("#n", event.entityPlayer.getCurrentEquippedItem().getDisplayName()).replace("#c", character), EnumChatFormatting.RED);
                    return;
                }
            }
            if (((INameable) tileEntity).getCustomName().matches(event.entityPlayer.getCurrentEquippedItem().getDisplayName())) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.getCurrentEquippedItem().stackSize--;
            ((INameable) tileEntity).setCustomName(event.entityPlayer.getCurrentEquippedItem().getDisplayName());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.universalBlockRemover)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockRemover.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            if (block == mod_SecurityCraft.laserBlock) {
                world.destroyBlock(event.pos, true);
                BlockLaserBlock.destroyAdjecentLasers(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            } else {
                world.destroyBlock(event.pos, true);
                world.removeTileEntity(event.pos);
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) Block(net.minecraft.block.Block) BlockLaserBlock(net.geforcemods.securitycraft.blocks.BlockLaserBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with INameable

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

the class ForgeEventHandler method onRightClickBlock.

@SubscribeEvent
public void onRightClickBlock(RightClickBlock event) {
    if (!event.getEntityPlayer().worldObj.isRemote) {
        World world = event.getEntityPlayer().worldObj;
        TileEntity tileEntity = event.getEntityPlayer().worldObj.getTileEntity(event.getPos());
        Block block = event.getEntityPlayer().worldObj.getBlockState(event.getPos()).getBlock();
        if (PlayerUtils.isHoldingItem(event.getEntityPlayer(), mod_SecurityCraft.codebreaker) && handleCodebreaking(event)) {
            event.setCanceled(true);
            return;
        }
        if (tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.getEntityPlayer(), mod_SecurityCraft.universalBlockModifier)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.getEntityPlayer())) {
                PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), I18n.translateToLocal("item.universalBlockModifier.name"), I18n.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), TextFormatting.RED);
                return;
            }
            event.getEntityPlayer().openGui(mod_SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
            return;
        }
        if (tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.getEntityPlayer(), Items.NAME_TAG) && event.getEntityPlayer().inventory.getCurrentItem().hasDisplayName()) {
            event.setCanceled(true);
            for (String character : new String[] { "(", ")" }) {
                if (event.getEntityPlayer().inventory.getCurrentItem().getDisplayName().contains(character)) {
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), "Naming", I18n.translateToLocal("messages.naming.error").replace("#n", event.getEntityPlayer().inventory.getCurrentItem().getDisplayName()).replace("#c", character), TextFormatting.RED);
                    return;
                }
            }
            if (((INameable) tileEntity).getCustomName().matches(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName())) {
                PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), "Naming", I18n.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), TextFormatting.RED);
                return;
            }
            event.getEntityPlayer().inventory.getCurrentItem().stackSize--;
            ((INameable) tileEntity).setCustomName(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName());
            return;
        }
        if (tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.getEntityPlayer(), mod_SecurityCraft.universalBlockRemover)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.getEntityPlayer())) {
                PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), I18n.translateToLocal("item.universalBlockRemover.name"), I18n.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), TextFormatting.RED);
                return;
            }
            if (block == mod_SecurityCraft.laserBlock) {
                world.destroyBlock(event.getPos(), true);
                BlockLaserBlock.destroyAdjacentLasers(event.getWorld(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
                event.getEntityPlayer().inventory.getCurrentItem().damageItem(1, event.getEntityPlayer());
            } else {
                world.destroyBlock(event.getPos(), true);
                world.removeTileEntity(event.getPos());
                event.getEntityPlayer().inventory.getCurrentItem().damageItem(1, event.getEntityPlayer());
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) RightClickBlock(net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock) Block(net.minecraft.block.Block) BlockLaserBlock(net.geforcemods.securitycraft.blocks.BlockLaserBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) TextComponentString(net.minecraft.util.text.TextComponentString) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)6 INameable (net.geforcemods.securitycraft.api.INameable)6 IOwnable (net.geforcemods.securitycraft.api.IOwnable)4 BlockLaserBlock (net.geforcemods.securitycraft.blocks.BlockLaserBlock)3 Block (net.minecraft.block.Block)3 TileEntity (net.minecraft.tileentity.TileEntity)3 World (net.minecraft.world.World)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 TileEntityPortableRadar (net.geforcemods.securitycraft.tileentity.TileEntityPortableRadar)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)2 IPasswordProtected (net.geforcemods.securitycraft.api.IPasswordProtected)1 EnumCustomModules (net.geforcemods.securitycraft.misc.EnumCustomModules)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 RightClickBlock (net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock)1