Java Code Examples for net.minecraft.entity.player.EntityPlayer#addChatComponentMessage()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#addChatComponentMessage() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if(!world.isRemote) {
        if(player.isSneaking()) {
            NBTTagCompound compound = NBTHelper.getData(stack);
            if(compound.hasKey("networkId")) {
                compound.removeTag("networkId");

                if(compound.hasNoTags()) {
                    stack.setTagCompound(null);
                }

                player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.clear"));
            }
        }
    }

    return super.onItemRightClick(stack, world, player);
}
 
Example 2
@Override
public void handleGUIButtonPress(int buttonID, EntityPlayer player){
    if(buttonID == 0) {
        redstoneMode++;
        if(redstoneMode > 2) redstoneMode = 0;
        updateNeighbours();
    } else if(buttonID == 2) {
        rebootStation();
    } else if(buttonID == 3) {
        if(!hasValidNetwork()) {
            player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "This Security Station is out of order: Its network hasn't been properly configured."));
        } else {
            player.openGui(PneumaticCraft.instance, EnumGuiId.HACKING.ordinal(), worldObj, xCoord, yCoord, zCoord);
        }
    } else if(buttonID > 3 && buttonID - 4 < sharedUsers.size()) {
        sharedUsers.remove(buttonID - 4);
    }
    sendDescriptionPacket();
}
 
Example 3
@Override
public boolean onItemUse(ItemStack tablet, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10){

    TileEntity te = world.getTileEntity(x, y, z);
    if(te instanceof IFluidHandler) {
        if(!world.isRemote) {
            setLiquidProvidingLocation(tablet, x, y, z, world.provider.dimensionId);
            player.addChatComponentMessage(new ChatComponentTranslation("message.amadronTable.setLiquidProvidingLocation", x, y, z, world.provider.dimensionId, world.provider.getDimensionName()));
        }
    } else if(te instanceof IInventory) {
        if(!world.isRemote) {
            setItemProvidingLocation(tablet, x, y, z, world.provider.dimensionId);
            player.addChatComponentMessage(new ChatComponentTranslation("message.amadronTable.setItemProvidingLocation", x, y, z, world.provider.dimensionId, world.provider.getDimensionName()));
        }
    } else {
        return false;
    }
    return true;

}
 
Example 4
@Override
public boolean itemInteractionForEntity(ItemStack iStack, EntityPlayer player, EntityLivingBase entity){
    if(!player.worldObj.isRemote) {
        if(entity instanceof IManoMeasurable) {
            if(((IPressurizable)iStack.getItem()).getPressure(iStack) > 0F) {
                List<String> curInfo = new ArrayList<String>();
                ((IManoMeasurable)entity).printManometerMessage(player, curInfo);
                if(curInfo.size() > 0) {
                    ((IPressurizable)iStack.getItem()).addAir(iStack, -30);
                    for(String s : curInfo) {
                        player.addChatComponentMessage(new ChatComponentTranslation(s));
                    }
                    return true;
                }
            } else {
                player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "The Manometer doesn't have any charge!"));
            }
        }
    }
    return false;
}
 
Example 5
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
    if(player.isSneaking()) return false;
    else {
        if(!world.isRemote) {
            TileEntitySecurityStation te = (TileEntitySecurityStation)world.getTileEntity(x, y, z);
            if(te != null) {
                if(te.isPlayerOnWhiteList(player)) {
                    player.openGui(PneumaticCraft.instance, EnumGuiId.SECURITY_STATION_INVENTORY.ordinal(), world, x, y, z);
                } else if(!te.hasValidNetwork()) {
                    player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "This Security Station is out of order: Its network hasn't been properly configured."));
                } else if(te.hasPlayerHacked(player)) {
                    player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "You've already hacked this Security Station!"));
                } else if(getPlayerHackLevel(player) < te.getSecurityLevel()) {
                    player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "You can't access or hack this Security Station. To hack it you need at least a Pneumatic Helmet upgraded with " + te.getSecurityLevel() + " Security upgrade(s)."));
                } else {
                    player.openGui(PneumaticCraft.instance, EnumGuiId.HACKING.ordinal(), world, x, y, z);
                }
            }
        }
        return true;
    }
}
 
Example 6
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) {
    if(!world.isRemote) {
        TileInfusionClaw tile = (TileInfusionClaw) world.getTileEntity(x, y, z);
        if(tile.hasOwner()) {
            player.openGui(Gadomancy.instance, 1, world, x, y, z);
        } else if(tile.setOwner(player)) {
            player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.InfusionClaw.owner"));
        }
    }
    return true;
}
 
Example 7
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    TileRemoteJar tile = BlockRemoteJar.getJarTile(world, x, y, z);
    if (tile != null) {
        if(!world.isRemote) {
            NBTTagCompound compound = NBTHelper.getData(stack);
            if(!player.isSneaking()) {
                UUID networkId = null;
                if(tile.networkId == null) {
                    player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.new"));
                    networkId = UUID.randomUUID();
                    tile.networkId = networkId;
                    tile.markForUpdate();
                } else {
                    UUID current = NBTHelper.getUUID(compound, "networkId");
                    if(current == null || !current.equals(tile.networkId)) {
                        player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.connected"));
                        networkId = tile.networkId;
                    }
                }

                if(networkId != null) {
                    NBTHelper.setUUID(compound, "networkId", networkId);
                }
            }
            return true;
        } else {
            if(player.isSneaking()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 8
Source Project: NotEnoughItems   File: NEIServerUtils.java    License: MIT License 5 votes vote down vote up
public static void sendNotice(ICommandSender sender, IChatComponent msg, String permission) {
    ChatComponentTranslation notice = new ChatComponentTranslation("chat.type.admin", sender.getCommandSenderName(), msg.createCopy());
    notice.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true);

    if (NEIServerConfig.canPlayerPerformAction("CONSOLE", permission))
        MinecraftServer.getServer().addChatMessage(notice);

    for (EntityPlayer p : ServerUtils.getPlayers())
        if(p == sender)
            p.addChatComponentMessage(msg);
        else if (NEIServerConfig.canPlayerPerformAction(p.getCommandSenderName(), permission))
            p.addChatComponentMessage(notice);
}
 
Example 9
Source Project: OmniOcular   File: CommandEntityName.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] array) {
    EntityPlayer player = (EntityPlayer) sender;
    Minecraft minecraft = Minecraft.getMinecraft();
    MovingObjectPosition objectMouseOver = minecraft.objectMouseOver;
    if (objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
        Class pointEntityClass = objectMouseOver.entityHit.getClass();
        if (EntityList.classToStringMapping.containsKey(pointEntityClass)) {
            player.addChatComponentMessage(new ChatComponentText(EntityList.getEntityString(objectMouseOver.entityHit)));
        }
    } else {
        player.addChatComponentMessage(new ChatComponentTranslation("omniocular.info.NotPointing"));
    }
}
 
Example 10
Source Project: OmniOcular   File: CommandItemName.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] array) {
    EntityPlayer player = (EntityPlayer) sender;
    ItemStack holdItem = player.getHeldItem();
    if (holdItem == null) {
        player.addChatComponentMessage(new ChatComponentTranslation("omniocular.info.NotHolding"));
        return;
    }
    player.addChatComponentMessage(new ChatComponentText(Item.itemRegistry.getNameForObject(holdItem.getItem())));
}
 
Example 11
Source Project: wailanbt   File: CommandName.java    License: MIT License 5 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] array) {
    EntityPlayer player = (EntityPlayer) sender;
    ItemStack holdItem = player.getHeldItem();
    if (holdItem == null) {
        player.addChatComponentMessage(new ChatComponentTranslation("wailanbt.info.NotHolding"));
        return;
    }
    player.addChatComponentMessage(new ChatComponentText(Item.itemRegistry.getNameForObject(holdItem.getItem())));
}
 
Example 12
@Override
protected void onSlotHack(int slot, boolean nuked){
    if(!nuked && gui instanceof GuiSecurityStationHacking) {
        ((GuiSecurityStationHacking)gui).onSlotHack(slot);
    }
    if(station.getStackInSlot(slot) != null && (station.getStackInSlot(slot).getItemDamage() == ItemNetworkComponents.NETWORK_REGISTRY || station.getStackInSlot(slot).getItemDamage() == ItemNetworkComponents.DIAGNOSTIC_SUBROUTINE)) {
        hackedSuccessfully = true;
        EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
        NetworkHandler.sendToServer(new PacketSecurityStationAddHacker(station, player.getCommandSenderName()));
        FMLClientHandler.instance().getClient().thePlayer.closeScreen();
        player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "Hacking successful! This Security Station now doesn't protect the area any longer!"));
        if(gui instanceof GuiSecurityStationHacking) ((GuiSecurityStationHacking)gui).removeUpdatesOnConnectionHandlers();
    }
}
 
Example 13
@Override
public void onDeath(DamageSource par1DamageSource){
    for(int i = 0; i < inventory.getSizeInventory(); i++) {
        if(inventory.getStackInSlot(i) != null) {
            entityDropItem(inventory.getStackInSlot(i), 0);
            inventory.setInventorySlotContents(i, null);
        }
    }
    if(naturallySpawned) {

    } else {
        ItemStack drone = getDroppedStack();
        if(hasCustomNameTag()) drone.setStackDisplayName(getCustomNameTag());

        entityDropItem(drone, 0);

        if(!worldObj.isRemote) {
            EntityPlayer owner = getOwner();
            if(owner != null) {
                int x = (int)Math.floor(posX);
                int y = (int)Math.floor(posY);
                int z = (int)Math.floor(posZ);
                if(hasCustomNameTag()) {
                    owner.addChatComponentMessage(new ChatComponentTranslation("death.drone.named", getCustomNameTag(), x, y, z));
                } else {
                    owner.addChatComponentMessage(new ChatComponentTranslation("death.drone", x, y, z));
                }
            }
        }
    }
    if(!worldObj.isRemote) ((FakePlayerItemInWorldManager)getFakePlayer().theItemInWorldManager).cancelDigging();
    super.onDeath(par1DamageSource);
}
 
Example 14
@Override
public boolean onItemUse(ItemStack IStack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10){
    setGPSLocation(IStack, x, y, z);
    if(!world.isRemote) player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "[GPS Tool] Set Coordinates to " + x + ", " + y + ", " + z + "."));
    return true; // we don't want to use the item.

}
 
Example 15
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10){
    if(!world.isRemote) {
        int testingY = y;
        while(testingY > 0) {
            testingY--;
            if(world.getBlock(x, testingY, z) == FluidRegistry.getFluid(Fluids.oil.getName()).getBlock()) {
                Set<ChunkPosition> oilPositions = new HashSet<ChunkPosition>();
                Stack<ChunkPosition> pendingPositions = new Stack<ChunkPosition>();
                pendingPositions.add(new ChunkPosition(x, testingY, z));
                while(!pendingPositions.empty()) {
                    ChunkPosition checkingPos = pendingPositions.pop();
                    for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                        ChunkPosition newPos = new ChunkPosition(checkingPos.chunkPosX + d.offsetX, checkingPos.chunkPosY + d.offsetY, checkingPos.chunkPosZ + d.offsetZ);
                        if(world.getBlock(newPos.chunkPosX, newPos.chunkPosY, newPos.chunkPosZ) == Fluids.oil.getBlock() && world.getBlockMetadata(newPos.chunkPosX, newPos.chunkPosY, newPos.chunkPosZ) == 0 && oilPositions.add(newPos)) {
                            pendingPositions.add(newPos);
                        }
                    }
                }
                player.addChatComponentMessage(new ChatComponentTranslation("message.seismicSensor.foundOilDetails", EnumChatFormatting.GREEN.toString() + (y - testingY), EnumChatFormatting.GREEN.toString() + oilPositions.size() / 10 * 10));
                return true;
            }
        }
        player.addChatComponentMessage(new ChatComponentTranslation("message.seismicSensor.noOilFound"));
    }
    return true; // we don't want to use the item.

}
 
Example 16
private boolean isAllowedToEdit(EntityPlayer player, ItemStack remote){
    NBTTagCompound tag = remote.getTagCompound();
    if(tag != null) {
        if(tag.hasKey("securityX")) {
            int x = tag.getInteger("securityX");
            int y = tag.getInteger("securityY");
            int z = tag.getInteger("securityZ");
            int dimensionId = tag.getInteger("securityDimension");
            WorldServer world = null;
            for(WorldServer w : MinecraftServer.getServer().worldServers) {
                if(w.provider.dimensionId == dimensionId) {
                    world = w;
                    break;
                }
            }
            if(world != null) {
                TileEntity te = world.getTileEntity(x, y, z);
                if(te instanceof TileEntitySecurityStation) {
                    boolean canAccess = ((TileEntitySecurityStation)te).doesAllowPlayer(player);
                    if(!canAccess) {
                        player.addChatComponentMessage(new ChatComponentTranslation("gui.remote.noEditRights", x, y, z));
                    }
                    return canAccess;
                }
            }
        }
    }
    return true;
}
 
Example 17
Source Project: Cyberware   File: BlockSurgeryTable.java    License: MIT License 4 votes vote down vote up
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
	if (worldIn.isRemote)
	{
		return true;
	}
	else
	{
		if (state.getValue(PART) != BlockBed.EnumPartType.HEAD)
		{
			pos = pos.offset((EnumFacing)state.getValue(FACING));
			state = worldIn.getBlockState(pos);

			if (state.getBlock() != this)
			{
				return true;
			}
		}

		if (worldIn.provider.canRespawnHere() && worldIn.getBiomeGenForCoords(pos) != Biomes.HELL)
		{
			if (((Boolean)state.getValue(OCCUPIED)).booleanValue())
			{
				EntityPlayer entityplayer = this.getPlayerInBed(worldIn, pos);

				if (entityplayer != null)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.occupied", new Object[0]));
					return true;
				}

				state = state.withProperty(OCCUPIED, Boolean.valueOf(false));
				worldIn.setBlockState(pos, state, 4);
			}

			EntityPlayer.SleepResult entityplayer$sleepresult = playerIn.trySleep(pos);

			if (entityplayer$sleepresult == EntityPlayer.SleepResult.OK)
			{
				state = state.withProperty(OCCUPIED, Boolean.valueOf(true));
				worldIn.setBlockState(pos, state, 4);
				return true;
			}
			else
			{
				if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_POSSIBLE_NOW)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.noSleep", new Object[0]));
				}
				else if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_SAFE)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.notSafe", new Object[0]));
				}

				return true;
			}
		}
		else
		{
			worldIn.setBlockToAir(pos);
			BlockPos blockpos = pos.offset(((EnumFacing)state.getValue(FACING)).getOpposite());

			if (worldIn.getBlockState(blockpos).getBlock() == this)
			{
				worldIn.setBlockToAir(blockpos);
			}

			worldIn.newExplosion((Entity)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 5.0F, true, true);
			return true;
		}
	}
}
 
Example 18
Source Project: CodeChickenCore   File: ServerUtils.java    License: MIT License 4 votes vote down vote up
public static void sendChatToAll(IChatComponent msg) {
    for(EntityPlayer p : getPlayers())
        p.addChatComponentMessage(msg);
}
 
Example 19
Source Project: wailanbt   File: config.java    License: MIT License 4 votes vote down vote up
public static void loadConfig(EntityPlayer player) {
        configJson = new JsonObject();
        NBTHandler.manager = new ScriptEngineManager(null);
        NBTHandler.engine = NBTHandler.manager.getEngineByName("javascript");
        NBTHandler.scriptSet = new HashSet<String>();
//        try {
//            NBTHandler.engine.eval("var names={}");
//        } catch (ScriptException e) {
//            e.printStackTrace();
//        }
//        for (Object item : Item.itemRegistry) {
//            String ID = String.valueOf(Item.itemRegistry.getIDForObject(item));
//            String name = StatCollector.translateToLocal(((Item)item).getUnlocalizedName()+".name").trim();
//            try {
//                NBTHandler.engine.eval("names['"+ID+"']='"+name+"'");
//            } catch (ScriptException e) {
//                e.printStackTrace();
//            }
//        }
        File[] configFiles = configDir.listFiles(new FilenameFilter(){
            public boolean accept(File dir, String name) {
                return name.endsWith(".json");
            }
        });
        if (!(configFiles == null)) {
            for (File configFile : configFiles) {
                if (configFile.isFile()) {
                    try {
                        InputStream inputStream = new FileInputStream(configFile);
                        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                        JsonParser parser = new JsonParser();
                        JsonElement jsonElementCurrent = parser.parse(inputStreamReader);
                        if (jsonElementCurrent.isJsonObject()) {
                            JsonObject jsonObjectCurrent = jsonElementCurrent.getAsJsonObject();
                            mergeJson(jsonObjectCurrent);
                        } else {
                            LogHelper.error("Parse " + configFile.getName() + " failed");
                            player.addChatComponentMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("wailanbt.info.JsonContentError"),configFile.getName())));
                        }
                    } catch (Exception e) {
                        //e.printStackTrace();
                        LogHelper.error("Error parsing file '" + configFile.getName() + "'. Possible error: " + e.getCause().getMessage());
                        player.addChatComponentMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("wailanbt.info.ParsingError"),configFile.getName())));
                    }
                }
            }
        }
        LogHelper.info("Config Loaded");
        System.out.println(configJson);
        player.addChatMessage(new ChatComponentTranslation("wailanbt.info.ConfigLoaded"));
    }
 
Example 20
Source Project: WirelessRedstone   File: ParamJam.java    License: MIT License 4 votes vote down vote up
public static void jamOpenCommand(String playername, String[] args, WCommandSender listener, boolean jam) {
    RedstoneEtherServer ether = RedstoneEther.server();

    if (args.length == 0) {
        listener.chatT("wrcbe_core.param.invalidno");
        return;
    }

    if ((args.length == 1 && ServerUtils.getPlayer(playername) == null)) {
        listener.chatT("wrcbe_core.param.jam.noplayer");
        return;
    }

    String range = args[args.length - 1];
    String jamPlayer = args.length == 1 ? playername : args[0];

    int startfreq;
    int endfreq;

    if (range.equals("all")) {
        startfreq = 1;
        endfreq = RedstoneEther.numfreqs;
    } else if (range.equals("default")) {
        startfreq = ether.getLastSharedFrequency() + 1;
        endfreq = RedstoneEther.numfreqs;
    } else {
        int[] freqrange = RedstoneEther.parseFrequencyRange(range);
        startfreq = freqrange[0];
        endfreq = freqrange[1];
    }

    if (startfreq < 1 || endfreq > RedstoneEther.numfreqs || endfreq < startfreq) {
        listener.chatT("wrcbe_core.param.invalidfreqrange");
        return;
    }

    ether.setFrequencyRangeCommand(jamPlayer, startfreq, endfreq, jam);

    int publicend = ether.getLastPublicFrequency();
    EntityPlayer player = ServerUtils.getPlayer(jamPlayer);
    String paramName = jam ? "jam" : "open";
    ChatStyle playerStyle = new ChatStyle().setColor(EnumChatFormatting.YELLOW);
    if (startfreq == endfreq) {
        if (startfreq <= publicend) {
            listener.chatT("wrcbe_core.param.jam.errpublic");
            return;
        }
        listener.chatOpsT("wrcbe_core.param."+paramName+".opjammed", playername, jamPlayer, startfreq);
        if (player != null)
            player.addChatComponentMessage(new ChatComponentTranslation("wrcbe_core.param."+paramName+".jammed", startfreq).setChatStyle(playerStyle));
    } else {
        if (startfreq <= publicend && endfreq <= publicend) {
            listener.chatT("wrcbe_core.param.jam.errpublic");
            return;
        }
        if (startfreq <= publicend)
            startfreq = publicend + 1;

        listener.chatOpsT("wrcbe_core.param."+paramName+".opjammed2", playername, jamPlayer, startfreq + "-" + endfreq);
        if (player != null)
            player.addChatComponentMessage(new ChatComponentTranslation("wrcbe_core.param."+paramName+".jammed2", startfreq + "-" + endfreq).setChatStyle(playerStyle));
    }
}