Search in sources :

Example 56 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_16_R3 method toIChatBaseComponents.

@Override
public Object toIChatBaseComponents(Component c) {
    List<IChatBaseComponent> chat = new ArrayList<>();
    chat.add(new ChatComponentText(""));
    while (c != null) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        chat.add(current);
        ChatModifier modif = current.getChatModifier();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            if (c.getColor().startsWith("#"))
                modif = modif.setColor(ChatHexColor.a(c.getColor()));
            else {
                for (EnumChatFormat e : EnumChatFormat.values()) if (e.character == c.getColor().charAt(0)) {
                    modif = modif.setColor(e);
                    break;
                }
            }
        }
        if (c.getClickEvent() != null)
            modif = modif.setChatClickable(new ChatClickable(EnumClickAction.valueOf(c.getClickEvent().getAction().name()), c.getClickEvent().getValue()));
        if (c.getHoverEvent() != null)
            modif = modif.setChatHoverable(EnumHoverAction.a(c.getHoverEvent().getAction().name().toLowerCase()).a((IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.setBold(c.isBold());
        modif = modif.setItalic(c.isItalic());
        modif = modif.setRandom(c.isObfuscated());
        modif = modif.setUnderline(c.isUnderlined());
        modif = modif.setStrikethrough(c.isStrikethrough());
        current.setChatModifier(modif);
        c = c.getExtra();
    }
    return chat.toArray(new IChatBaseComponent[0]);
}
Also used : EnumChatFormat(net.minecraft.server.v1_16_R3.EnumChatFormat) ChatClickable(net.minecraft.server.v1_16_R3.ChatClickable) ArrayList(java.util.ArrayList) ChatModifier(net.minecraft.server.v1_16_R3.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) ChatComponentText(net.minecraft.server.v1_16_R3.ChatComponentText)

Example 57 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_14_R1 method toIChatBaseComponent.

@Override
public Object toIChatBaseComponent(List<Component> cc) {
    ChatComponentText main = new ChatComponentText("");
    for (Component c : cc) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        main.addSibling(current);
        ChatModifier modif = current.getChatModifier();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            modif = modif.setColor(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null)
            modif = modif.setChatClickable(new ChatClickable(EnumClickAction.valueOf(c.getClickEvent().getAction().name()), c.getClickEvent().getValue()));
        if (c.getHoverEvent() != null)
            modif = modif.setChatHoverable(new ChatHoverable(EnumHoverAction.valueOf(c.getHoverEvent().getAction().name()), (IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.setBold(c.isBold());
        modif = modif.setItalic(c.isItalic());
        modif = modif.setRandom(c.isObfuscated());
        modif = modif.setUnderline(c.isUnderlined());
        modif = modif.setStrikethrough(c.isStrikethrough());
        current.setChatModifier(modif);
    }
    return main.a().isEmpty() ? empty : main;
}
Also used : ChatClickable(net.minecraft.server.v1_14_R1.ChatClickable) ChatModifier(net.minecraft.server.v1_14_R1.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_14_R1.IChatBaseComponent) Component(me.devtec.shared.components.Component) IChatBaseComponent(net.minecraft.server.v1_14_R1.IChatBaseComponent) ChatComponentText(net.minecraft.server.v1_14_R1.ChatComponentText) ChatHoverable(net.minecraft.server.v1_14_R1.ChatHoverable)

Example 58 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_14_R1 method processServerListPing.

@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
    PacketStatusOutServerInfo status = (PacketStatusOutServerInfo) packet;
    ServerPing ping;
    try {
        ping = (ServerPing) field.get(status);
    } catch (Exception e) {
        return false;
    }
    List<PlayerProfile> players = new ArrayList<>();
    for (Player p : Bukkit.getOnlinePlayers()) players.add(new PlayerProfile(p.getName(), p.getUniqueId()));
    ServerListPingEvent event = new ServerListPingEvent(Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers(), players, Bukkit.getMotd(), ping.d(), ((InetSocketAddress) ((Channel) channel).remoteAddress()).getAddress(), ping.getServerData().a(), ping.getServerData().getProtocolVersion());
    HandlerList.callEvent(event);
    if (event.isCancelled())
        return true;
    ServerPingPlayerSample playerSample = new ServerPingPlayerSample(event.getMaxPlayers(), event.getOnlinePlayers());
    if (event.getPlayersText() != null) {
        GameProfile[] profiles = new GameProfile[event.getPlayersText().size()];
        int i = -1;
        for (PlayerProfile s : event.getPlayersText()) profiles[++i] = new GameProfile(s.getUUID(), s.getName());
        playerSample.a(profiles);
    } else
        playerSample.a(new GameProfile[0]);
    ping.setPlayerSample(playerSample);
    if (event.getMotd() != null)
        ping.setMOTD((IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
    else
        ping.setMOTD((IChatBaseComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
    if (event.getVersion() != null)
        ping.setServerInfo(new ServerData(event.getVersion(), event.getProtocol()));
    if (event.getFalvicon() != null)
        ping.setFavicon(event.getFalvicon());
    return false;
}
Also used : EntityPlayer(net.minecraft.server.v1_14_R1.EntityPlayer) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_14_R1.IChatBaseComponent) ServerPing(net.minecraft.server.v1_14_R1.ServerPing) ServerPingPlayerSample(net.minecraft.server.v1_14_R1.ServerPing.ServerPingPlayerSample) GameProfile(com.mojang.authlib.GameProfile) ServerData(net.minecraft.server.v1_14_R1.ServerPing.ServerData) PacketStatusOutServerInfo(net.minecraft.server.v1_14_R1.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Example 59 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_15_R1 method toIChatBaseComponents.

@Override
public Object toIChatBaseComponents(List<Component> components) {
    List<IChatBaseComponent> chat = new ArrayList<>();
    chat.add(new ChatComponentText(""));
    for (Component c : components) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        chat.add(current);
        ChatModifier modif = current.getChatModifier();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            modif = modif.setColor(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null)
            modif = modif.setChatClickable(new ChatClickable(EnumClickAction.valueOf(c.getClickEvent().getAction().name()), c.getClickEvent().getValue()));
        if (c.getHoverEvent() != null)
            modif = modif.setChatHoverable(new ChatHoverable(EnumHoverAction.valueOf(c.getHoverEvent().getAction().name()), (IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.setBold(c.isBold());
        modif = modif.setItalic(c.isItalic());
        modif = modif.setRandom(c.isObfuscated());
        modif = modif.setUnderline(c.isUnderlined());
        modif = modif.setStrikethrough(c.isStrikethrough());
        current.setChatModifier(modif);
    }
    return chat.toArray(new IChatBaseComponent[0]);
}
Also used : ChatClickable(net.minecraft.server.v1_15_R1.ChatClickable) ArrayList(java.util.ArrayList) ChatModifier(net.minecraft.server.v1_15_R1.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_15_R1.IChatBaseComponent) IChatBaseComponent(net.minecraft.server.v1_15_R1.IChatBaseComponent) Component(me.devtec.shared.components.Component) ChatComponentText(net.minecraft.server.v1_15_R1.ChatComponentText) ChatHoverable(net.minecraft.server.v1_15_R1.ChatHoverable)

Example 60 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_15_R1 method toIChatBaseComponents.

@Override
public Object toIChatBaseComponents(Component c) {
    List<IChatBaseComponent> chat = new ArrayList<>();
    chat.add(new ChatComponentText(""));
    while (c != null) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        chat.add(current);
        ChatModifier modif = current.getChatModifier();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            modif = modif.setColor(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null)
            modif = modif.setChatClickable(new ChatClickable(EnumClickAction.valueOf(c.getClickEvent().getAction().name()), c.getClickEvent().getValue()));
        if (c.getHoverEvent() != null)
            modif = modif.setChatHoverable(new ChatHoverable(EnumHoverAction.valueOf(c.getHoverEvent().getAction().name()), (IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.setBold(c.isBold());
        modif = modif.setItalic(c.isItalic());
        modif = modif.setRandom(c.isObfuscated());
        modif = modif.setUnderline(c.isUnderlined());
        modif = modif.setStrikethrough(c.isStrikethrough());
        current.setChatModifier(modif);
        c = c.getExtra();
    }
    return chat.toArray(new IChatBaseComponent[0]);
}
Also used : ChatClickable(net.minecraft.server.v1_15_R1.ChatClickable) ArrayList(java.util.ArrayList) ChatModifier(net.minecraft.server.v1_15_R1.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_15_R1.IChatBaseComponent) ChatComponentText(net.minecraft.server.v1_15_R1.ChatComponentText) ChatHoverable(net.minecraft.server.v1_15_R1.ChatHoverable)

Aggregations

ArrayList (java.util.ArrayList)76 BookMeta (org.bukkit.inventory.meta.BookMeta)41 Component (me.devtec.shared.components.Component)30 ItemStack (org.bukkit.inventory.ItemStack)28 GameProfile (com.mojang.authlib.GameProfile)23 IChatBaseComponent (net.minecraft.server.v1_12_R1.IChatBaseComponent)18 List (java.util.List)15 ServerListPingEvent (me.devtec.theapi.bukkit.events.ServerListPingEvent)15 PlayerProfile (me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile)15 Player (org.bukkit.entity.Player)15 Channel (io.netty.channel.Channel)14 IChatBaseComponent (net.minecraft.server.v1_8_R3.IChatBaseComponent)14 IChatBaseComponent (net.minecraft.server.v1_10_R1.IChatBaseComponent)10 IChatBaseComponent (net.minecraft.server.v1_11_R1.IChatBaseComponent)10 IChatBaseComponent (net.minecraft.server.v1_14_R1.IChatBaseComponent)10 IChatBaseComponent (net.minecraft.server.v1_13_R2.IChatBaseComponent)9 IChatBaseComponent (net.minecraft.server.v1_15_R1.IChatBaseComponent)9 IChatBaseComponent (net.minecraft.server.v1_16_R3.IChatBaseComponent)9 IChatBaseComponent (net.minecraft.server.v1_16_R1.IChatBaseComponent)8 IChatBaseComponent (net.minecraft.server.v1_13_R1.IChatBaseComponent)7