use of net.minecraft.server.v1_8_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_8_R1.IChatBaseComponent in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method applyPlaceholders.
@SuppressWarnings({ "unchecked" })
@Override
public ItemStack applyPlaceholders(Player player, ItemStack book, NPC npc) throws IllegalAccessException {
Validate.notNull(book, "The ItemStack is null! This is not an error with CitizensBooks," + " so please don't report it. Make sure the plugins that uses CitizensBooks as dependency are correctly configured.");
Validate.isTrue(book.getType() == Material.WRITTEN_BOOK, "The ItemStack is not a written book! This is not an error with CitizensBooks," + " so please don't report it. Make sure the plugins that uses CitizensBooks as dependency are correctly configured.");
BookMeta bookMeta = (BookMeta) book.getItemMeta();
List<String> pages = bookMeta.hasPages() ? super.papiReplaceStrList.apply(player, ((List<IChatBaseComponent>) this.pagesField.get(bookMeta)).stream().map(IChatBaseComponent.ChatSerializer::a).toList(), Optional.ofNullable(npc)) : new ArrayList<>();
String author = bookMeta.hasAuthor() ? super.papiReplaceStr.apply(player, bookMeta.getAuthor(), Optional.ofNullable(npc)) : "Server";
String title = bookMeta.hasTitle() ? super.papiReplaceStr.apply(player, bookMeta.getTitle(), Optional.ofNullable(npc)) : "Title";
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
bookMeta.setAuthor(author);
bookMeta.setTitle(title);
this.pagesField.set(bookMeta, pages.stream().map(IChatBaseComponent.ChatSerializer::a).toList());
newBook.setItemMeta(bookMeta);
return newBook;
}
use of net.minecraft.server.v1_8_R1.IChatBaseComponent in project HitW-plugin by Blackoutburst.
the class GameUtils method sendTitle.
public static void sendTitle(Player player, String title, String subtitle, int fadeIn, int stay, int fadeOut) {
CraftPlayer craftplayer = (CraftPlayer) player;
PlayerConnection connection = craftplayer.getHandle().playerConnection;
IChatBaseComponent titleJSON = ChatSerializer.a("{'text': '" + title + "'}");
IChatBaseComponent subtitleJSON = ChatSerializer.a("{'text': '" + subtitle + "'}");
PacketPlayOutTitle timePacket = new PacketPlayOutTitle(fadeIn, stay, fadeOut);
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleJSON);
PacketPlayOutTitle subtitlePacket = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, subtitleJSON);
connection.sendPacket(timePacket);
connection.sendPacket(titlePacket);
connection.sendPacket(subtitlePacket);
}
use of net.minecraft.server.v1_8_R1.IChatBaseComponent in project PowerBoard by Xitee1.
the class version_1_11 method sendTab.
@SuppressWarnings("deprecation")
public static void sendTab(Player player, String head, String foot) {
IChatBaseComponent header = new ChatMessage(head);
IChatBaseComponent footer = new ChatMessage(foot);
PacketPlayOutPlayerListHeaderFooter tablist = new PacketPlayOutPlayerListHeaderFooter();
try {
Field headerField = tablist.getClass().getDeclaredField("a");
headerField.setAccessible(true);
headerField.set(tablist, header);
headerField.setAccessible(!headerField.isAccessible());
Field footerField = tablist.getClass().getDeclaredField("b");
footerField.setAccessible(true);
footerField.set(tablist, footer);
footerField.setAccessible(!footerField.isAccessible());
} catch (Exception e) {
e.printStackTrace();
}
CraftPlayer cp = (CraftPlayer) player;
cp.getHandle().playerConnection.sendPacket(tablist);
}
use of net.minecraft.server.v1_8_R1.IChatBaseComponent in project TheAPI by TheDevTec.
the class v1_10_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]);
}
Aggregations