use of net.minecraft.network.chat.IChatBaseComponent in project BedWars1058 by andrei1058.
the class v1_17_R1 method playAction.
@Override
public void playAction(Player p, String text) {
CraftPlayer cPlayer = (CraftPlayer) p;
IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + text + "\"}");
PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, ChatMessageType.c, chatUUID);
cPlayer.getHandle().b.sendPacket(ppoc);
}
use of net.minecraft.network.chat.IChatBaseComponent in project BedWars1058 by andrei1058.
the class v1_18_R1 method playAction.
@Override
public void playAction(Player p, String text) {
CraftPlayer cPlayer = (CraftPlayer) p;
IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + text + "\"}");
PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, ChatMessageType.c, chatUUID);
cPlayer.getHandle().b.a(ppoc);
}
use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.
the class v1_18_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.c();
if (c.getColor() != null && !c.getColor().isEmpty()) {
if (c.getColor().startsWith("#"))
modif = modif.a(ChatHexColor.a(c.getColor()));
else
modif = modif.a(EnumChatFormat.a(c.getColor().charAt(0)));
}
if (c.getClickEvent() != null)
modif = modif.a(new ChatClickable(EnumClickAction.a(c.getClickEvent().getAction().name().toLowerCase()), c.getClickEvent().getValue()));
if (c.getHoverEvent() != null)
modif = modif.a(EnumHoverAction.a(c.getHoverEvent().getAction().name().toLowerCase()).a((IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
modif = modif.a(c.isBold());
modif = modif.b(c.isItalic());
modif = modif.e(c.isObfuscated());
modif = modif.c(c.isUnderlined());
modif = modif.d(c.isStrikethrough());
current.a(modif);
}
return chat.toArray(new IChatBaseComponent[0]);
}
use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.
the class v1_18_R1 method processServerListPing.
@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
PacketStatusOutServerInfo status = (PacketStatusOutServerInfo) packet;
ServerPing ping = status.b();
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.c().a(), ping.c().b());
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.a(playerSample);
if (event.getMotd() != null)
ping.a((IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
else
ping.a((IChatBaseComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
if (event.getVersion() != null)
ping.a(new ServerData(event.getVersion(), event.getProtocol()));
if (event.getFalvicon() != null)
ping.a(event.getFalvicon());
return false;
}
use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.
the class v1_18_R1 method toIChatBaseComponent.
@Override
public Object toIChatBaseComponent(Component c) {
ChatComponentText main = new ChatComponentText("");
while (c != null) {
if (c.getText() == null || c.getText().isEmpty()) {
c = c.getExtra();
continue;
}
ChatComponentText current = new ChatComponentText(c.getText());
main.a(current);
ChatModifier modif = current.c();
if (c.getColor() != null && !c.getColor().isEmpty()) {
if (c.getColor().startsWith("#"))
modif = modif.a(ChatHexColor.a(c.getColor()));
else
modif = modif.a(EnumChatFormat.a(c.getColor().charAt(0)));
}
if (c.getClickEvent() != null)
modif = modif.a(new ChatClickable(EnumClickAction.a(c.getClickEvent().getAction().name().toLowerCase()), c.getClickEvent().getValue()));
if (c.getHoverEvent() != null)
modif = modif.a(EnumHoverAction.a(c.getHoverEvent().getAction().name().toLowerCase()).a((IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
modif = modif.a(c.isBold());
modif = modif.b(c.isItalic());
modif = modif.e(c.isObfuscated());
modif = modif.c(c.isUnderlined());
modif = modif.d(c.isStrikethrough());
current.a(modif);
c = c.getExtra();
}
return main.b().isEmpty() ? ChatComponentText.d : main;
}
Aggregations