net.minecraft.event.ClickEvent Java Examples

The following examples show how to use net.minecraft.event.ClickEvent. 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 check out the related API usage on the sidebar.
Example #1
Source File: NetworkHandler.java    From Hyperium with GNU Lesser General Public License v3.0 7 votes vote down vote up
@Override
public void handleChat(String s) {
    if (s.toLowerCase().contains("reconnecting hyperium connection")) return;
    Hyperium.LOGGER.debug("Chat: {}", s);
    s = s.replace("&", C.COLOR_CODE_SYMBOL);
    IChatComponent chatComponent = new ChatComponentText("");

    Arrays.stream(s.split(" ")).forEach(s1 -> {
        ChatComponentText iChatComponents = new ChatComponentText(s1 + " ");
        if (s1.contains(".") && !s1.startsWith(".") && !s1.endsWith(".")) {
            ChatStyle chatStyle = new ChatStyle();
            chatStyle.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, s1.startsWith("http") ? s1 : "http://" + s1));
            iChatComponents.setChatStyle(chatStyle);
        }
        chatComponent.appendSibling(iChatComponents);
    });

    GeneralChatHandler.instance().sendMessage(chatComponent);
}
 
Example #2
Source File: MixinGuiEditSign.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
@Inject(method = "actionPerformed", at = @At("HEAD"))
private void actionPerformed(GuiButton button, CallbackInfo callbackInfo) {
    switch(button.id) {
        case 0:
            if(!signCommand1.getText().isEmpty())
                tileSign.signText[0].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand1.getText())));

            if(!signCommand2.getText().isEmpty())
                tileSign.signText[1].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand2.getText())));

            if(!signCommand3.getText().isEmpty())
                tileSign.signText[2].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand3.getText())));

            if(!signCommand4.getText().isEmpty())
                tileSign.signText[3].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand4.getText())));
            break;
        case 1:
            enabled = !enabled;
            toggleButton.displayString = enabled ? "Disable Formatting codes" : "Enable Formatting codes";
            break;
    }
}
 
Example #3
Source File: MixinGuiEditSign.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
@Inject(method = "actionPerformed", at = @At("HEAD"))
private void actionPerformed(GuiButton button, CallbackInfo callbackInfo) {
    switch(button.id) {
        case 0:
            if(!signCommand1.getText().isEmpty())
                tileSign.signText[0].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand1.getText())));

            if(!signCommand2.getText().isEmpty())
                tileSign.signText[1].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand2.getText())));

            if(!signCommand3.getText().isEmpty())
                tileSign.signText[2].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand3.getText())));

            if(!signCommand4.getText().isEmpty())
                tileSign.signText[3].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand4.getText())));
            break;
        case 1:
            enabled = !enabled;
            toggleButton.displayString = enabled ? "Disable Formatting codes" : "Enable Formatting codes";
            break;
    }
}
 
Example #4
Source File: HyperiumEntityPlayer.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public IChatComponent getDisplayName() {
    if (cachedName == null || System.currentTimeMillis() - lastChangeTime > 50L) {
        IChatComponent ichatcomponent = new ChatComponentText(ScorePlayerTeam
            .formatPlayerName(parent.getTeam(), displayName));
        ichatcomponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + parent.getName() + " "));
        //Unneeded for client
        if (Minecraft.getMinecraft().isIntegratedServerRunning()) {
            ichatcomponent.getChatStyle()
                .setChatHoverEvent(((IMixinEntity) parent).callGetHoverEvent());
        }
        ichatcomponent.getChatStyle().setInsertion(parent.getName());
        cachedName = ichatcomponent;
    }

    return cachedName;
}
 
Example #5
Source File: MixinGuiScreen.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "handleComponentHover", at = @At("HEAD"))
private void handleHoverOverComponent(IChatComponent component, int x, int y, final CallbackInfo callbackInfo) {
    if (component == null || component.getChatStyle().getChatClickEvent() == null || !LiquidBounce.moduleManager.getModule(ComponentOnHover.class).getState())
        return;

    final ChatStyle chatStyle = component.getChatStyle();

    final ClickEvent clickEvent = chatStyle.getChatClickEvent();
    final HoverEvent hoverEvent = chatStyle.getChatHoverEvent();

    drawHoveringText(Collections.singletonList("§c§l" + clickEvent.getAction().getCanonicalName().toUpperCase() + ": §a" + clickEvent.getValue()), x, y - (hoverEvent != null ? 17 : 0));
}
 
Example #6
Source File: MixinGuiScreen.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "handleComponentHover", at = @At("HEAD"))
private void handleHoverOverComponent(IChatComponent component, int x, int y, final CallbackInfo callbackInfo) {
    if (component == null || component.getChatStyle().getChatClickEvent() == null || !LiquidBounce.moduleManager.getModule(ComponentOnHover.class).getState())
        return;

    final ChatStyle chatStyle = component.getChatStyle();

    final ClickEvent clickEvent = chatStyle.getChatClickEvent();
    final HoverEvent hoverEvent = chatStyle.getChatHoverEvent();

    drawHoveringText(Collections.singletonList("§c§l" + clickEvent.getAction().getCanonicalName().toUpperCase() + ": §a" + clickEvent.getValue()), x, y - (hoverEvent != null ? 17 : 0));
}
 
Example #7
Source File: UpdateChecker.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@InvokeEvent
public void serverJoinEvent(ServerJoinEvent event) {
    if (asked) return; //If they were already asked, don't even make the new thread.
    UpdateUtils updateUtils = new UpdateUtils();
    Multithreading.runAsync(() -> {
        boolean latest = updateUtils.isAbsoluteLatest();
        boolean beta = updateUtils.isBeta();
        int version = Metadata.getVersionID();
        Hyperium.LOGGER.info("version is: " + version);
        if (beta) return; // dont alert beta users
        if (latest) return; //If they're on the latest version, I don't want to mess with them.

        Hyperium.INSTANCE.getNotification().display("You have an update pending.",
            "Click here to be sent to the installer.",
            10f,
            null, () -> {
                try {
                    Desktop.getDesktop().browse(new URI("https://hyperium.cc/downloads"));
                } catch (IOException | URISyntaxException e) {
                    IChatComponent urlComponent = new
                        ChatComponentText(ChatColor.RED + "[Hyperium] " +
                        ChatColor.GRAY + "Click to be sent to update Hyperium");
                    urlComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://hyperium.cc/downloads"));
                    Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage(urlComponent);
                }
            }, new Color(200, 150, 50));
        asked = true;
    });
}
 
Example #8
Source File: CommandNickHider.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void sendMessage(String message, String hover, String click) {
    ChatComponentText chatComponent = new ChatComponentText(ChatColor.YELLOW + message);
    if (hover != null && !hover.isEmpty()) {
        chatComponent.getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
            new ChatComponentText(ChatColor.AQUA + hover + (!click.isEmpty() ? "\n" + click : ""))));
    }

    if (click != null && !click.isEmpty()) {
        chatComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, click));
    }

    Minecraft.getMinecraft().thePlayer.addChatComponentMessage(chatComponent);
}
 
Example #9
Source File: MediaModCommand.java    From MediaMod with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] args) {
    if(args.length <= 0) {
        TickScheduler.INSTANCE.schedule(1, () -> FMLClientHandler.instance().getClient().displayGuiScreen(new GuiMediaModSettings()));
    } else {
        String subcommand = args[0];
        if(subcommand.equalsIgnoreCase("party")) {
            if(args.length >= 2) {
                String function = args[1];
                if(function.equalsIgnoreCase("start")) {
                    if(!MediaMod.INSTANCE.partyManager.canStartParty()) {
                        PlayerMessager.sendMessage(ChatColor.RED + "You are already in a party!", true);
                        return;
                    }

                    PlayerMessager.sendMessage(ChatColor.GRAY + "Creating MediaMod Party... " + "(note: this only works with spotify at the moment)", true);

                    String code = MediaMod.INSTANCE.partyManager.startParty();
                    if(code.equals("")) {
                        PlayerMessager.sendMessage(ChatColor.RED + "An error occurred whilst creating your MediaMod party!", true);
                    } else {
                        IChatComponent urlComponent = new ChatComponentText(ChatColor.WHITE + "" + ChatColor.BOLD + code);
                        urlComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, code));
                        urlComponent.getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText("Copy Code")));
                        PlayerMessager.sendMessage(new ChatComponentText(ChatColor.GRAY + "Share this code with your friends to invite them to your party: ").appendSibling(urlComponent), true);
                    }
                } else if (function.equalsIgnoreCase("leave")) {
                    if(!MediaMod.INSTANCE.partyManager.canStartParty()) {
                        boolean success = MediaMod.INSTANCE.partyManager.leaveParty();
                        if(success) {
                            PlayerMessager.sendMessage((ChatColor.GRAY + "You have left the party"), true);
                        } else {
                            PlayerMessager.sendMessage(ChatColor.RED + "An error occurred whilst trying to leave the party!", true);
                        }
                    } else {
                        PlayerMessager.sendMessage(ChatColor.RED + "You are not in a party!");
                    }
                }
            } else {
                PlayerMessager.sendMessage(ChatColor.RED + "Incorrect syntax! Usage: /mm party <start/invite/info/join/leave>");
            }
        }
    }
}
 
Example #10
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setChatClickEvent", at = @At("HEAD"))
private void setChatClickEvent(ClickEvent boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}