Search in sources :

Example 1 with ClickEvent

use of net.minecraft.event.ClickEvent 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 2 with ClickEvent

use of net.minecraft.event.ClickEvent in project watson by totemo.

the class WatsonCommand method help.

// handleConfigCommand
// --------------------------------------------------------------------------
/**
   * Show a help message.
   */
public void help(ICommandSender sender) {
    String w = Configuration.instance.getWatsonPrefix();
    localOutput(sender, "Usage:");
    localOutput(sender, "  /" + w + " help");
    localOutput(sender, "  /" + w + " display [on|off]");
    localOutput(sender, "  /" + w + " outline [on|off]");
    localOutput(sender, "  /" + w + " anno [on|off]");
    localOutput(sender, "  /" + w + " vector [on|off]");
    localOutput(sender, "  /" + w + " vector (creations|destructions) [on|off]");
    localOutput(sender, "  /" + w + " vector length <decimal>");
    localOutput(sender, "  /" + w + " label [on|off]");
    localOutput(sender, "  /" + w + " clear");
    localOutput(sender, "  /" + w + " pre [<count>]");
    localOutput(sender, "  /" + w + " post [<count>]");
    localOutput(sender, "  /" + w + " ore [<page>]");
    localOutput(sender, "  /" + w + " ratio");
    localOutput(sender, "  /" + w + " tp [next|prev|<number>]");
    localOutput(sender, "  /" + w + " edits [list]");
    localOutput(sender, "  /" + w + " edits (hide|show|remove) <player> ...");
    localOutput(sender, "  /" + w + " filter [list|clear]");
    localOutput(sender, "  /" + w + " filter (add|remove) <player> ...");
    localOutput(sender, "  /" + w + " servertime");
    localOutput(sender, "  /" + w + " file list [*|<playername>] [<page>]");
    localOutput(sender, "  /" + w + " file delete *|<filename>|<playername>");
    localOutput(sender, "  /" + w + " file expire <YYYY-MM-DD>");
    localOutput(sender, "  /" + w + " file load <filename>|<playername>");
    localOutput(sender, "  /" + w + " file save [<filename>]");
    localOutput(sender, "  /" + w + " config <name> [<value>]");
    localOutput(sender, "  /hl help");
    localOutput(sender, "  /anno help");
    // Make the documentation link clickable.
    IChatComponent docs = new ChatComponentText("Documentation: ");
    ChatStyle style = new ChatStyle().setColor(EnumChatFormatting.AQUA);
    docs.setChatStyle(style);
    String url = "http://github.com/totemo/watson";
    IChatComponent link = new ChatComponentText(url);
    ChatStyle linkStyle = new ChatStyle();
    linkStyle.setUnderlined(true);
    link.setChatStyle(linkStyle);
    linkStyle.setChatClickEvent(new ClickEvent(Action.OPEN_URL, url));
    docs.appendSibling(link);
    sender.addChatMessage(docs);
    if (!Configuration.instance.isEnabled()) {
        localOutput(sender, "Watson is currently disabled.");
        localOutput(sender, "To re-enable, use: /" + w + " config watson on");
    }
}
Also used : ChatStyle(net.minecraft.util.ChatStyle) ClickEvent(net.minecraft.event.ClickEvent) IChatComponent(net.minecraft.util.IChatComponent) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

ClickEvent (net.minecraft.event.ClickEvent)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 BufferedImage (java.awt.image.BufferedImage)1 ByteBuffer (java.nio.ByteBuffer)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1 ChatStyle (net.minecraft.util.ChatStyle)1 IChatComponent (net.minecraft.util.IChatComponent)1