Search in sources :

Example 66 with ChatComponentText

use of net.minecraft.server.v1_8_R3.ChatComponentText in project PaperDev by Kamillaova.

the class CraftChatMessage method fixComponent.

private static IChatBaseComponent fixComponent(IChatBaseComponent component, Matcher matcher) {
    if (component instanceof ChatComponentText) {
        ChatComponentText text = ((ChatComponentText) component);
        String msg = text.g();
        if (matcher.reset(msg).find()) {
            matcher.reset();
            ChatModifier modifier = text.getChatModifier() != null ? text.getChatModifier() : new ChatModifier();
            List<IChatBaseComponent> extras = new ArrayList<IChatBaseComponent>();
            List<IChatBaseComponent> extrasOld = new ArrayList<IChatBaseComponent>(text.a());
            component = text = new ChatComponentText("");
            int pos = 0;
            while (matcher.find()) {
                String match = matcher.group();
                if (!(match.startsWith("http://") || match.startsWith("https://"))) {
                    match = "http://" + match;
                }
                ChatComponentText prev = new ChatComponentText(msg.substring(pos, matcher.start()));
                prev.setChatModifier(modifier);
                extras.add(prev);
                ChatComponentText link = new ChatComponentText(matcher.group());
                ChatModifier linkModi = modifier.clone();
                linkModi.setChatClickable(new ChatClickable(EnumClickAction.OPEN_URL, match));
                link.setChatModifier(linkModi);
                extras.add(link);
                pos = matcher.end();
            }
            ChatComponentText prev = new ChatComponentText(msg.substring(pos));
            prev.setChatModifier(modifier);
            extras.add(prev);
            extras.addAll(extrasOld);
            for (IChatBaseComponent c : extras) {
                text.addSibling(c);
            }
        }
    }
    List extras = component.a();
    for (int i = 0; i < extras.size(); i++) {
        IChatBaseComponent comp = (IChatBaseComponent) extras.get(i);
        if (comp.getChatModifier() != null && comp.getChatModifier().h() == null) {
            extras.set(i, fixComponent(comp, matcher));
        }
    }
    if (component instanceof ChatMessage) {
        Object[] subs = ((ChatMessage) component).j();
        for (int i = 0; i < subs.length; i++) {
            Object comp = subs[i];
            if (comp instanceof IChatBaseComponent) {
                IChatBaseComponent c = (IChatBaseComponent) comp;
                if (c.getChatModifier() != null && c.getChatModifier().h() == null) {
                    subs[i] = fixComponent(c, matcher);
                }
            } else if (comp instanceof String && matcher.reset((String) comp).find()) {
                subs[i] = fixComponent(new ChatComponentText((String) comp), matcher);
            }
        }
    }
    return component;
}
Also used : ChatMessage(net.minecraft.server.v1_12_R1.ChatMessage) ChatClickable(net.minecraft.server.v1_12_R1.ChatClickable) ChatModifier(net.minecraft.server.v1_12_R1.ChatModifier) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_12_R1.IChatBaseComponent) ArrayList(java.util.ArrayList) List(java.util.List) ChatComponentText(net.minecraft.server.v1_12_R1.ChatComponentText)

Example 67 with ChatComponentText

use of net.minecraft.server.v1_8_R3.ChatComponentText in project PaperDev by Kamillaova.

the class StandardPaperServerListPingEventImpl method processRequest.

@SuppressWarnings("deprecation")
public static void processRequest(MinecraftServer server, NetworkManager networkManager) {
    StandardPaperServerListPingEventImpl event = new StandardPaperServerListPingEventImpl(server, networkManager, server.getServerPing());
    server.server.getPluginManager().callEvent(event);
    // Close connection immediately if event is cancelled
    if (event.isCancelled()) {
        networkManager.close(null);
        return;
    }
    // Setup response
    ServerPing ping = new ServerPing();
    // Description
    ping.setMOTD(new ChatComponentText(event.getMotd()));
    // Players
    if (!event.shouldHidePlayers()) {
        ping.setPlayerSample(new ServerPing.ServerPingPlayerSample(event.getMaxPlayers(), event.getNumPlayers()));
        ping.getPlayers().setSample(event.getPlayerSampleHandle());
    }
    // Version
    ping.setServerInfo(new ServerPing.ServerData(event.getVersion(), event.getProtocolVersion()));
    // Favicon
    if (event.getServerIcon() != null) {
        ping.setFavicon(event.getServerIcon().getData());
    }
    // Send response
    networkManager.sendPacket(new PacketStatusOutServerInfo(ping));
}
Also used : PacketStatusOutServerInfo(net.minecraft.server.v1_12_R1.PacketStatusOutServerInfo) ChatComponentText(net.minecraft.server.v1_12_R1.ChatComponentText) ServerPing(net.minecraft.server.v1_12_R1.ServerPing)

Aggregations

ArrayList (java.util.ArrayList)31 Component (me.devtec.shared.components.Component)30 ChatComponentText (net.minecraft.server.v1_12_R1.ChatComponentText)9 ChatClickable (net.minecraft.server.v1_10_R1.ChatClickable)4 ChatComponentText (net.minecraft.server.v1_10_R1.ChatComponentText)4 IChatBaseComponent (net.minecraft.server.v1_12_R1.IChatBaseComponent)4 ChatClickable (net.minecraft.server.v1_13_R1.ChatClickable)4 ChatComponentText (net.minecraft.server.v1_13_R1.ChatComponentText)4 ChatHoverable (net.minecraft.server.v1_13_R1.ChatHoverable)4 ChatModifier (net.minecraft.server.v1_13_R1.ChatModifier)4 IChatBaseComponent (net.minecraft.server.v1_13_R1.IChatBaseComponent)4 ChatClickable (net.minecraft.server.v1_8_R1.ChatClickable)4 ChatComponentText (net.minecraft.server.v1_8_R1.ChatComponentText)4 ChatHoverable (net.minecraft.server.v1_8_R1.ChatHoverable)4 ChatModifier (net.minecraft.server.v1_8_R1.ChatModifier)4 IChatBaseComponent (net.minecraft.server.v1_8_R1.IChatBaseComponent)4 ChatComponentText (net.minecraft.server.v1_8_R3.ChatComponentText)4 ChatClickable (net.minecraft.server.v1_12_R1.ChatClickable)3 ChatHoverable (net.minecraft.server.v1_12_R1.ChatHoverable)3 ChatModifier (net.minecraft.server.v1_12_R1.ChatModifier)3