本文整理汇总了Java中com.comphenix.protocol.wrappers.WrappedChatComponent.fromJson方法的典型用法代码示例。如果您正苦于以下问题:Java WrappedChatComponent.fromJson方法的具体用法?Java WrappedChatComponent.fromJson怎么用?Java WrappedChatComponent.fromJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.comphenix.protocol.wrappers.WrappedChatComponent
的用法示例。
在下文中一共展示了WrappedChatComponent.fromJson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stringsToChatComponent
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入方法依赖的package包/类
public static WrappedChatComponent stringsToChatComponent(String[] strings) {
if (strings.length == 0) {
return WrappedChatComponent.fromText("");
}
StringJoiner joiner = new StringJoiner(", {\"text\":\"\n\"}, ", "{\"extra\":[", "],\"text\":\"\"}");
for (String string : strings) {
joiner.add(WrappedChatComponent.fromText(string).getJson());
}
Logging.debug(PacketUtil.class, "Final JSON: " + joiner.toString());
return WrappedChatComponent.fromJson(joiner.toString());
}
示例2: sendMessage
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入方法依赖的package包/类
@Override
public boolean sendMessage(Player player, ChatPosition position, BaseComponent... message)
{
try
{
PacketContainer packet = manager.createPacket(PacketType.Play.Server.CHAT);
// Write our message to the packet
WrappedChatComponent component = WrappedChatComponent.fromJson(ComponentSerializer.toString(message));
packet.getChatComponents().write(0, component);
// Nullify Spigot's components
packet.getModifier().write(1, null);
// Write the position
packet.getBytes().write(0, position != null ? position.getValue() : 1);
// Send the packet
manager.sendServerPacket(player, packet);
return true;
}
catch (Throwable ex)
{
LogHandler.globalDebug(Util.getUsefulStack(ex, "sending chat packet to {0}", player.getName()));
return false;
}
}
示例3: getChatComponent
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入方法依赖的package包/类
private WrappedChatComponent getChatComponent(String text) {
return WrappedChatComponent.fromJson("{\"text\": \"" + text + "\"}");
}