Search in sources :

Example 26 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project PneumaticCraft by MineMaarten.

the class NetworkConnectionAIHandler method onSlotHack.

@Override
public void onSlotHack(int slot, boolean nuked) {
    if (!simulating && station.getStackInSlot(slot) != null && station.getStackInSlot(slot).getItemDamage() == ItemNetworkComponents.NETWORK_IO_PORT) {
        FMLClientHandler.instance().getClient().thePlayer.closeScreen();
        FMLClientHandler.instance().getClient().thePlayer.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "Hacking unsuccessful! The Diagnostic Subroutine traced to your location!"));
        if (gui instanceof GuiSecurityStationHacking)
            ((GuiSecurityStationHacking) gui).removeUpdatesOnConnectionHandlers();
    }
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation)

Example 27 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project Engine by VoltzEngine-Project.

the class PermissionsCommandManager method executeCommand.

@Override
public int executeCommand(ICommandSender sender, String cmd) {
    // Clean up command string
    cmd = cmd.trim();
    if (cmd.startsWith("/")) {
        cmd = cmd.substring(1);
    }
    // Get command name and arguments
    String[] args = cmd.split(" ");
    String command_name = args[0];
    args = dropFirstString(args);
    ICommand icommand = (ICommand) this.getCommands().get(command_name);
    int usernameIndex = this.getUsernameIndex(icommand, args);
    int j = 0;
    ChatComponentTranslation chatcomponenttranslation;
    try {
        if (icommand == null) {
            throw new CommandNotFoundException();
        }
        // Checks if the user can use the command
        if (hasPermissionForCommand(sender, icommand, args)) {
            CommandEvent event = new CommandEvent(icommand, sender, args);
            if (MinecraftForge.EVENT_BUS.post(event)) {
                if (event.exception != null) {
                    throw event.exception;
                }
                return 1;
            }
            if (usernameIndex > -1) {
                // Executes the command on several players if listed
                EntityPlayerMP[] players = PlayerSelector.matchPlayers(sender, args[usernameIndex]);
                String s2 = args[usernameIndex];
                int k = players.length;
                for (int l = 0; l < k; ++l) {
                    EntityPlayerMP entityplayermp = players[l];
                    args[usernameIndex] = entityplayermp.getCommandSenderName();
                    try {
                        icommand.processCommand(sender, args);
                        ++j;
                    } catch (CommandException commandexception1) {
                        ChatComponentTranslation chatcomponenttranslation1 = new ChatComponentTranslation(commandexception1.getMessage(), commandexception1.getErrorOjbects());
                        chatcomponenttranslation1.getChatStyle().setColor(EnumChatFormatting.RED);
                        sender.addChatMessage(chatcomponenttranslation1);
                    }
                }
                args[usernameIndex] = s2;
            } else {
                try {
                    icommand.processCommand(sender, args);
                    ++j;
                } catch (CommandException commandexception) {
                    chatcomponenttranslation = new ChatComponentTranslation(commandexception.getMessage(), commandexception.getErrorOjbects());
                    chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
                    sender.addChatMessage(chatcomponenttranslation);
                }
            }
        } else {
            ChatComponentTranslation chatcomponenttranslation2 = new ChatComponentTranslation("commands.generic.permission");
            chatcomponenttranslation2.getChatStyle().setColor(EnumChatFormatting.RED);
            sender.addChatMessage(chatcomponenttranslation2);
        }
    } catch (WrongUsageException wrongusageexception) {
        chatcomponenttranslation = new ChatComponentTranslation("commands.generic.usage", new ChatComponentTranslation(wrongusageexception.getMessage(), wrongusageexception.getErrorOjbects()));
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        sender.addChatMessage(chatcomponenttranslation);
    } catch (CommandException commandexception2) {
        chatcomponenttranslation = new ChatComponentTranslation(commandexception2.getMessage(), commandexception2.getErrorOjbects());
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        sender.addChatMessage(chatcomponenttranslation);
    } catch (Throwable throwable) {
        chatcomponenttranslation = new ChatComponentTranslation("commands.generic.exception");
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        sender.addChatMessage(chatcomponenttranslation);
        Engine.instance.logger().error("Failed to process command: \'" + cmd + "\'", throwable);
    }
    return j;
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) CommandEvent(net.minecraftforge.event.CommandEvent) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 28 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project watson by totemo.

the class Screenshot method save.

// --------------------------------------------------------------------------
/**
 * Save a screenshot.
 *
 * @param file the file to write.
 * @param width the screen width.
 * @param height the screen height.
 */
public static IChatComponent save(File file, int width, int height) {
    try {
        file.getParentFile().mkdirs();
        ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 4);
        GL11.glReadBuffer(GL11.GL_FRONT);
        // GL11.glReadBuffer() unexpectedly sets an error state (invalid enum).
        GL11.glGetError();
        GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                int i = (x + width * y) * 4;
                int r = buffer.get(i) & 0xFF;
                int g = buffer.get(i + 1) & 0xFF;
                int b = buffer.get(i + 2) & 0xFF;
                image.setRGB(x, (height - 1) - y, (0xFF << 24) | (r << 16) | (g << 8) | b);
            }
        }
        ImageIO.write(image, "png", file);
        ChatComponentText text = new ChatComponentText(file.getName());
        text.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()));
        text.getChatStyle().setUnderlined(Boolean.valueOf(true));
        return new ChatComponentTranslation("screenshot.success", new Object[] { text });
    } catch (Exception ex) {
        return new ChatComponentTranslation("screenshot.failure", new Object[] { ex.getMessage() });
    }
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) ClickEvent(net.minecraft.event.ClickEvent) ByteBuffer(java.nio.ByteBuffer) ChatComponentText(net.minecraft.util.ChatComponentText) BufferedImage(java.awt.image.BufferedImage)

Example 29 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project BetterStorage by copygirl.

the class TileBackpack method onBlockClicked.

@Override
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
    if (world.isRemote && player.isSneaking() && !ItemBackpack.canEquipBackpack(player) && BetterStorage.globalConfig.getBoolean(GlobalConfig.enableHelpTooltips) && (System.currentTimeMillis() > lastHelpMessage + 10 * 1000)) {
        boolean backpack = (ItemBackpack.getBackpack(player) != null);
        player.addChatMessage(new ChatComponentTranslation("tile.betterstorage.backpack.cantEquip." + (backpack ? "backpack" : "chestplate")));
        lastHelpMessage = System.currentTimeMillis();
    }
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation)

Example 30 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project NyaSamaRailway by NSDN.

the class TileEntityTrackSideSniffer method configure.

public static boolean configure(World world, int x, int y, int z, EntityPlayer player) {
    if (world.getTileEntity(x, y, z) == null)
        return false;
    if (world.getTileEntity(x, y, z) instanceof TileEntityTrackSideSniffer) {
        TileEntityTrackSideSniffer sniffer = (TileEntityTrackSideSniffer) world.getTileEntity(x, y, z);
        ItemStack stack = player.getCurrentEquippedItem();
        if (stack != null) {
            NBTTagList list = Util.getTagListFromNGT(stack);
            if (list == null)
                return false;
            if (!world.isRemote) {
                String code = NSASM.getCodeString(list);
                sniffer.nsasmState = TileEntityTrackSideSniffer.NSASM_IDLE;
                sniffer.nsasmCode = code;
                player.addChatComponentMessage(new ChatComponentTranslation("info.sniffer.set"));
            }
            return true;
        }
    }
    return false;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)77 ItemStack (net.minecraft.item.ItemStack)19 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 TileEntity (net.minecraft.tileentity.TileEntity)13 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)11 ArrayList (java.util.ArrayList)5 Block (net.minecraft.block.Block)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 World (net.minecraft.world.World)4 Item1N4148 (club.nsdn.nyasamarailway.item.tool.Item1N4148)3 ItemNTP32Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP32Bit)3 ItemNTP8Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP8Bit)3 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)3 TileEntityActuator (club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator)3 EntityItem (net.minecraft.entity.item.EntityItem)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 TileEntityRailSniffer (club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer)2 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2 Side (cpw.mods.fml.relauncher.Side)2