本文整理汇总了Java中com.comphenix.protocol.wrappers.WrappedChatComponent.fromText方法的典型用法代码示例。如果您正苦于以下问题:Java WrappedChatComponent.fromText方法的具体用法?Java WrappedChatComponent.fromText怎么用?Java WrappedChatComponent.fromText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.comphenix.protocol.wrappers.WrappedChatComponent
的用法示例。
在下文中一共展示了WrappedChatComponent.fromText方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPacketSending
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入方法依赖的package包/类
@Override
public void onPacketSending( PacketEvent event ) {
final Player player = event.getPlayer();
final PacketContainer packet = event.getPacket();
// Translate all four lines if necessary:
boolean changed = false;
WrappedChatComponent[] chatComponents = packet.getChatComponentArrays().read( 0 );
for ( int i = 0; i < chatComponents.length; ++i ) {
WrappedChatComponent chat = chatComponents[i];
if ( chat != null ) {
String message = this.restoreTextFromChatComponent( chat );
String translated = this.translateMessageIfAppropriate( this.i18n.getLocale( player.getUniqueId() ), message );
if ( message != translated ) {
chatComponents[i] = WrappedChatComponent.fromText( translated );
changed = true;
}
}
}
if ( changed ) {
// Only write back when really needed:
packet.getChatComponentArrays().write( 0, chatComponents );
}
}
示例2: playerInfoPacket
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入方法依赖的package包/类
public static PacketContainer playerInfoPacket(
String displayName,
Integer latency,
GameMode gameMode,
String name,
UUID uuid,
Skin skin,
EnumWrappers.PlayerInfoAction action
) {
PacketContainer result = new PacketContainer(PLAYER_INFO);
WrappedGameProfile profile = new WrappedGameProfile(uuid, name);
if (action == EnumWrappers.PlayerInfoAction.ADD_PLAYER) {
if (skin == null) {
skin = Tablist.DEFAULT_SKIN_TEXTURE;
}
profile.getProperties().put(Skin.MULTIMAP_KEY, skin.toWrappedSignedProperty());
}
PlayerInfoData playerInfoData = new PlayerInfoData(
profile,
Optional.ofNullable(latency).map(PacketUtil::getPossibleLatency).orElse(0),
Optional.ofNullable(gameMode).map(EnumWrappers.NativeGameMode::fromBukkit).orElse(EnumWrappers.NativeGameMode.NOT_SET),
WrappedChatComponent.fromText(Optional.ofNullable(displayName).orElse(""))
);
result.getPlayerInfoDataLists().writeSafely(0, Collections.singletonList(playerInfoData));
result.getPlayerInfoAction().writeSafely(0, action);
return result;
}
示例3: 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());
}
示例4: getInfoWrapper
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入方法依赖的package包/类
public static WrapperPlayServerPlayerInfo getInfoWrapper(UUID playeruuid, PlayerInfoAction action) {
WrapperPlayServerPlayerInfo wrapper = new WrapperPlayServerPlayerInfo();
wrapper.setAction(action);
WrappedGameProfile profile = new WrappedGameProfile(playeruuid, NameGenerator.newName());
PlayerInfoData data = new PlayerInfoData(profile, 1, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(NameGenerator.newName()));
List<PlayerInfoData> listdata = new ArrayList<>();
listdata.add(data);
wrapper.setData(listdata);
return wrapper;
}
示例5: getPlayerInfoData
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入方法依赖的package包/类
private PlayerInfoData getPlayerInfoData(WrappedGameProfile profile, int ping, String displayName) {
if (displayName != null) {
// min width
while (displayName.length() < this.minColumnWidth)
displayName += " ";
// max width
if (this.maxColumnWidth > 0)
while (displayName.length() > this.maxColumnWidth)
displayName = displayName.substring(0, displayName.length() - 1);
}
return new PlayerInfoData(profile, ping, NativeGameMode.SURVIVAL, displayName == null ? null : WrappedChatComponent.fromText(displayName));
}