use of net.minecraft.network.chat.IChatBaseComponent in project FunnyGuilds by FunnyGuilds.
the class V1_18R1PlayerList method send.
@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
final List<Packet<?>> packets = Lists.newArrayList();
final List<PacketPlayOutPlayerInfo.PlayerInfoData> addPlayerList = Lists.newArrayList();
final List<PacketPlayOutPlayerInfo.PlayerInfoData> updatePlayerList = Lists.newArrayList();
try {
for (int i = 0; i < this.cellCount; i++) {
if (this.profileCache[i] == null) {
this.profileCache[i] = new GameProfile(UUID.fromString(String.format(PlayerListConstants.UUID_PATTERN, StringUtils.leftPad(String.valueOf(i), 2, '0'))), " ");
}
String text = playerListCells[i];
GameProfile gameProfile = this.profileCache[i];
IChatBaseComponent component = CraftChatMessage.fromStringOrNull(text, false);
PacketPlayOutPlayerInfo.PlayerInfoData playerInfoData = new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, ping, DEFAULT_GAME_MODE, component);
if (this.firstPacket) {
addPlayerList.add(playerInfoData);
}
updatePlayerList.add(playerInfoData);
}
if (this.firstPacket) {
this.firstPacket = false;
}
PacketPlayOutPlayerInfo addPlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.a);
addPlayerPacket.b().addAll(addPlayerList);
packets.add(addPlayerPacket);
PacketPlayOutPlayerInfo updatePlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.d);
updatePlayerPacket.b().addAll(updatePlayerList);
packets.add(updatePlayerPacket);
boolean headerNotEmpty = !header.isEmpty();
boolean footerNotEmpty = !footer.isEmpty();
if (headerNotEmpty || footerNotEmpty) {
IChatBaseComponent headerComponent = EMPTY_COMPONENT;
IChatBaseComponent footerComponent = EMPTY_COMPONENT;
if (headerNotEmpty) {
headerComponent = CraftChatMessage.fromStringOrNull(header, true);
}
if (footerNotEmpty) {
footerComponent = CraftChatMessage.fromStringOrNull(footer, true);
}
PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter(headerComponent, footerComponent);
packets.add(headerFooterPacket);
}
for (Packet<?> packet : packets) {
((CraftPlayer) player).getHandle().b.a(packet);
}
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to send PlayerList for player '%s'", player.getName()), ex);
}
}
use of net.minecraft.network.chat.IChatBaseComponent in project FunnyGuilds by FunnyGuilds.
the class V1_17R1PlayerList method send.
@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
final List<Packet<?>> packets = Lists.newArrayList();
final List<PacketPlayOutPlayerInfo.PlayerInfoData> addPlayerList = Lists.newArrayList();
final List<PacketPlayOutPlayerInfo.PlayerInfoData> updatePlayerList = Lists.newArrayList();
try {
for (int i = 0; i < this.cellCount; i++) {
if (this.profileCache[i] == null) {
this.profileCache[i] = new GameProfile(UUID.fromString(String.format(PlayerListConstants.UUID_PATTERN, StringUtils.leftPad(String.valueOf(i), 2, '0'))), " ");
}
String text = playerListCells[i];
GameProfile gameProfile = this.profileCache[i];
IChatBaseComponent component = CraftChatMessage.fromStringOrNull(text, false);
PacketPlayOutPlayerInfo.PlayerInfoData playerInfoData = new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, ping, DEFAULT_GAME_MODE, component);
if (this.firstPacket) {
addPlayerList.add(playerInfoData);
}
updatePlayerList.add(playerInfoData);
}
if (this.firstPacket) {
this.firstPacket = false;
}
PacketPlayOutPlayerInfo addPlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.a);
addPlayerPacket.b().addAll(addPlayerList);
packets.add(addPlayerPacket);
PacketPlayOutPlayerInfo updatePlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.d);
updatePlayerPacket.b().addAll(updatePlayerList);
packets.add(updatePlayerPacket);
boolean headerNotEmpty = !header.isEmpty();
boolean footerNotEmpty = !footer.isEmpty();
if (headerNotEmpty || footerNotEmpty) {
IChatBaseComponent headerComponent = EMPTY_COMPONENT;
IChatBaseComponent footerComponent = EMPTY_COMPONENT;
if (headerNotEmpty) {
headerComponent = CraftChatMessage.fromStringOrNull(header, true);
}
if (footerNotEmpty) {
footerComponent = CraftChatMessage.fromStringOrNull(footer, true);
}
PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter(headerComponent, footerComponent);
packets.add(headerFooterPacket);
}
for (Packet<?> packet : packets) {
((CraftPlayer) player).getHandle().b.sendPacket(packet);
}
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to send PlayerList for player '%s'", player.getName()), ex);
}
}
use of net.minecraft.network.chat.IChatBaseComponent in project SwornAPI by dmulloy2.
the class Volatile method sendMessage.
public static boolean sendMessage(Player player, ChatPosition position, BaseComponent... message) {
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(ComponentSerializer.toString(message));
ChatMessageType type = ChatMessageType.a(position.getValue());
((org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) player).getHandle().b.a(new PacketPlayOutChat(component, type, SERVER_UUID));
return true;
}
use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.
the class v1_18_R2 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_17_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()) {
if (c.getColor().startsWith("#"))
modif = modif.setColor(ChatHexColor.a(c.getColor()));
else
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(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);
}
return chat.toArray(new IChatBaseComponent[0]);
}
Aggregations