use of net.minecraft.server.v1_15_R1.IChatBaseComponent in project FunnyGuilds by FunnyGuilds.
the class V1_16R3PlayerList method send.
@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
final List<Packet<?>> packets = Lists.newArrayList();
final List<Object> addPlayerList = Lists.newArrayList();
final List<Object> updatePlayerList = Lists.newArrayList();
try {
PacketPlayOutPlayerInfo addPlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER);
PacketPlayOutPlayerInfo updatePlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
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);
Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
if (this.firstPacket) {
addPlayerList.add(playerInfoData);
}
updatePlayerList.add(playerInfoData);
}
if (this.firstPacket) {
this.firstPacket = false;
}
PLAYER_INFO_DATA_ACCESSOR.set(addPlayerPacket, addPlayerList);
packets.add(addPlayerPacket);
PLAYER_INFO_DATA_ACCESSOR.set(updatePlayerPacket, 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();
headerFooterPacket.header = headerComponent;
headerFooterPacket.footer = footerComponent;
packets.add(headerFooterPacket);
}
for (Packet<?> packet : packets) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to send PlayerList for player '%s'", player.getName()), ex);
}
}
use of net.minecraft.server.v1_15_R1.IChatBaseComponent in project FunnyGuilds by FunnyGuilds.
the class V1_12R1PlayerList method send.
@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
final List<Packet<?>> packets = Lists.newArrayList();
final List<Object> addPlayerList = Lists.newArrayList();
final List<Object> updatePlayerList = Lists.newArrayList();
try {
PacketPlayOutPlayerInfo addPlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER);
PacketPlayOutPlayerInfo updatePlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
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.fromString(text, false)[0];
Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
if (this.firstPacket) {
addPlayerList.add(playerInfoData);
}
updatePlayerList.add(playerInfoData);
}
if (this.firstPacket) {
this.firstPacket = false;
}
PLAYER_INFO_DATA_ACCESSOR.set(addPlayerPacket, addPlayerList);
packets.add(addPlayerPacket);
PLAYER_INFO_DATA_ACCESSOR.set(updatePlayerPacket, 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.fromString(header, true)[0];
}
if (footerNotEmpty) {
footerComponent = CraftChatMessage.fromString(footer, true)[0];
}
PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter();
HEADER_ACCESSOR.set(headerFooterPacket, headerComponent);
FOOTER_ACCESSOR.set(headerFooterPacket, footerComponent);
packets.add(headerFooterPacket);
}
for (Packet<?> packet : packets) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to send PlayerList for player '%s'", player.getName()), ex);
}
}
use of net.minecraft.server.v1_15_R1.IChatBaseComponent in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method updateEntityNameTagForPlayer.
@Override
public void updateEntityNameTagForPlayer(Player player, org.bukkit.entity.Entity entity, String customName, boolean customNameVisible) {
try {
List<Item<?>> dataWatchers = new ArrayList<>();
Optional<IChatBaseComponent> nameComponent = Optional.ofNullable(CraftChatMessage.fromStringOrNull(customName));
dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.f.a(2), nameComponent));
dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.i.a(3), customNameVisible));
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata();
field_PacketPlayOutEntityMetadata_a.set(packetPlayOutEntityMetadata, entity.getEntityId());
field_PacketPlayOutEntityMetadata_b.set(packetPlayOutEntityMetadata, dataWatchers);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_15_R1.IChatBaseComponent in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method convertBookToJson.
@SuppressWarnings({ "unchecked" })
@Override
public JsonObject convertBookToJson(ItemStack book) throws IllegalAccessException {
BookMeta bookMeta = (BookMeta) book.getItemMeta();
List<IChatBaseComponent> pages = bookMeta.hasPages() ? (List<IChatBaseComponent>) this.pagesField.get(bookMeta) : new ArrayList<>();
JsonArray jsonPages = new JsonArray();
for (IChatBaseComponent page : pages) {
jsonPages.add(super.gson.fromJson(IChatBaseComponent.ChatSerializer.a(page), JsonElement.class));
}
JsonPrimitive jsonAuthor = new JsonPrimitive(bookMeta.hasAuthor() ? bookMeta.getAuthor() : "Server");
JsonPrimitive jsonTitle = new JsonPrimitive(bookMeta.hasTitle() ? bookMeta.getTitle() : "Title");
JsonObject jsonBook = new JsonObject();
jsonBook.add("author", jsonAuthor);
jsonBook.add("title", jsonTitle);
jsonBook.add("pages", jsonPages);
return jsonBook;
}
use of net.minecraft.server.v1_15_R1.IChatBaseComponent in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method convertJsonToBook.
@SuppressWarnings("ConstantConditions")
@Override
public ItemStack convertJsonToBook(JsonObject jsonBook) throws IllegalAccessException {
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
BookMeta bookMeta = (BookMeta) newBook.getItemMeta();
JsonPrimitive jsonAuthor = jsonBook.getAsJsonPrimitive("author");
JsonPrimitive jsonTitle = jsonBook.getAsJsonPrimitive("title");
JsonArray jsonPages = jsonBook.getAsJsonArray("pages");
bookMeta.setAuthor(jsonAuthor.isString() ? jsonAuthor.getAsString() : "Server");
bookMeta.setTitle(jsonTitle.isString() ? jsonTitle.getAsString() : "Title");
List<IChatBaseComponent> pages = new ArrayList<>();
for (JsonElement jsonPage : jsonPages) {
pages.add(IChatBaseComponent.ChatSerializer.a(jsonPage.toString()));
}
this.pagesField.set(bookMeta, pages);
newBook.setItemMeta(bookMeta);
return newBook;
}
Aggregations