本文整理汇总了Java中com.comphenix.protocol.wrappers.WrappedChatComponent类的典型用法代码示例。如果您正苦于以下问题:Java WrappedChatComponent类的具体用法?Java WrappedChatComponent怎么用?Java WrappedChatComponent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WrappedChatComponent类属于com.comphenix.protocol.wrappers包,在下文中一共展示了WrappedChatComponent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendTitle
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
private void sendTitle(Integer fadeIn, Integer stay, Integer fadeOut, String title, TitleAction action) {
PacketContainer tp = NationZ.protocolManager.createPacket(PacketType.Play.Server.TITLE);
tp.getModifier().writeDefaults();
tp.getTitleActions().write(0, action);
tp.getChatComponents().write(0, WrappedChatComponent.fromText(title));
tp.getIntegers().write(0, fadeIn);
tp.getIntegers().write(1, stay);
tp.getIntegers().write(2, fadeOut);
try {
NationZ.protocolManager.sendServerPacket(getPlayer(), tp);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
示例2: onPacketSending
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
@Override
public void onPacketSending(PacketEvent event) {
String verifyCode = verifyCodeSupplier.get();
if (verifyCode != null) {
try {
WrappedServerPing ping = event.getPacket().getServerPings().read(0);
Object motd = jsonParser.parse(ping.getMotD().getJson());
if (motd instanceof JSONObject) {
JSONObject component = (JSONObject) motd;
component.put("text", verifyCode + ChatColor.RESET + component.get("text"));
ping.setMotD(WrappedChatComponent.fromJson(component.toJSONString()));
} else {
// Legacy String format
ping.setMotD(verifyCode + ChatColor.RESET + motd);
}
} catch (ParseException e) {
ac.getLogger().log(Level.WARNING, "Failed to parse MOTD for verify request", e);
}
}
}
示例3: onMapChunk
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
private void onMapChunk( PacketEvent event ) {
final Player player = event.getPlayer();
final PacketContainer packet = event.getPacket();
final Locale locale = this.i18n.getLocale( player.getUniqueId() );
List handleList = packet.getSpecificModifier( List.class ).read( 0 );
for ( Object compoundHandle : handleList ) {
NbtCompound compound = NbtFactory.fromNMSCompound( compoundHandle );
String id = compound.getString( "id" );
if ( id.equals( "minecraft:sign" ) || id.equals( "Sign" ) ) {
for ( int i = 1; i <= 4; ++i ) {
final String key = "Text" + i;
String message = this.gson.fromJson( compound.getString( key ), ChatComponent.class ).getUnformattedText();
String translated = this.translateMessageIfAppropriate( locale, message );
if ( message != translated ) {
compound.put( key, WrappedChatComponent.fromText( translated ).getJson() );
}
}
}
}
}
示例4: 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 );
}
}
示例5: sendPlayerInfoChangeGameModePacket
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
private void sendPlayerInfoChangeGameModePacket(Player p, Player change, boolean spectator) {
PacketContainer packet = new PacketContainer(PLAYER_INFO);
packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE);
List<PlayerInfoData> data = new ArrayList<>();
int ping = ThreadLocalRandom.current().nextInt(20) + 15;
data.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(change), ping,
spectator ? EnumWrappers.NativeGameMode.SPECTATOR
: EnumWrappers.NativeGameMode.fromBukkit(change.getGameMode()),
WrappedChatComponent.fromText(change.getPlayerListName())));
packet.getPlayerInfoDataLists().write(0, data);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot send packet", e);
}
}
示例6: sendActionMessage
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
/**
* Sends the action bar message using packets in order to be compatible with 1.8
*
* @param receiver the receiver of this message
* @param message the message content
*/
public void sendActionMessage(Player receiver, String message) {
if (supportsChatTypeEnum()) {
//the API for this action bar message is available and we could use it
receiver.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
return;
}
PacketContainer chatPacket = new PacketContainer(CHAT);
chatPacket.getChatComponents().write(0, WrappedChatComponent.fromText(message));
chatPacket.getBytes().write(0, ChatType.GAME_INFO.getId());
//ignore our own packets
chatPacket.addMetadata(getName(), true);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, chatPacket);
} catch (InvocationTargetException invokeEx) {
getLogger().log(Level.WARNING, "Failed to send action bar message", invokeEx);
}
}
示例7: sendTabFootHeader
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
public void sendTabFootHeader() {
PacketContainer pc = Vars.protocolManager
.createPacket(PacketType.Play.Server.PLAYER_LIST_HEADER_FOOTER);
pc.getChatComponents()
.write(0,
WrappedChatComponent.fromText(Util
.parseColors(Util.getConfig().getString("tab_info.header"))))
.write(1,
WrappedChatComponent.fromText(Util
.parseColors(Util.getConfig().getString("tab_info.footer"))));
try {
Vars.protocolManager.sendServerPacket(player, pc);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
示例8: send
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
public IChatMessage send(ArrayList<Player> pls) {
if (pls.isEmpty()) return this;
finish();
PacketContainer chat = new PacketContainer(PacketType.Play.Server.CHAT);
chat.getChatComponents().write(0, WrappedChatComponent.fromJson(ichat));
for (Player p : pls) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, chat);
} catch (InvocationTargetException e) {
throw new IllegalStateException("Unable to send packet " + chat, e);
}
}
return this;
}
示例9: Broadcast
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
public IChatMessage Broadcast() {
finish();
/*IChatBaseComponent comp = ChatSerializer.a(ichat);
if (!(Bukkit.getOnlinePlayers().isEmpty())) {
for (Player p : Bukkit.getOnlinePlayers()) {
PacketPlayOutChat packet = new PacketPlayOutChat(comp);
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
}
}*/
PacketContainer chat = new PacketContainer(PacketType.Play.Server.CHAT);
chat.getChatComponents().write(0, WrappedChatComponent.fromJson(ichat));
if (!(Bukkit.getOnlinePlayers().isEmpty())) {
for (Player p : Bukkit.getOnlinePlayers()) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, chat);
} catch (InvocationTargetException e) {
throw new IllegalStateException("Unable to send packet " + chat, e);
}
}
}
return this;
}
示例10: sendOverActionBar
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
public static void sendOverActionBar(Player player, String message) {
/*CraftPlayer p = (CraftPlayer) player;
IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2);
((CraftPlayer) p).getHandle().playerConnection.sendPacket(ppoc);*/
PacketContainer chat = new PacketContainer(PacketType.Play.Server.CHAT);
chat.getChatComponents().write(0, WrappedChatComponent.fromJson("{\"text\": \"" + message + "\"}"));
chat.getBytes().write(0, (byte) 2);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, chat);
} catch (InvocationTargetException e) {
throw new IllegalStateException("Unable to send packet " + chat, e);
}
}
示例11: sendSubTitle
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
public static void sendSubTitle(Player p, String subtitle, Integer FadeInTime, Integer StayOnScreenTime, Integer FadeOutTime) {
/*((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, ChatSerializer.a("{\"text\": \"\"}").a(subtitle)));
PacketPlayOutTitle length = new PacketPlayOutTitle(FadeInTime, StayOnScreenTime, FadeOutTime);
((CraftPlayer) p).getHandle().playerConnection.sendPacket(length);*/
/*Title t = new Title("", subtitle, FadeInTime, StayOnScreenTime, FadeOutTime);
try {
t.sendSub(p);
} catch (Exception e) {
e.printStackTrace();
}*/
WrapperPlayServerTitle time = new WrapperPlayServerTitle();
time.setAction(TitleAction.TIMES);
time.setFadeIn(FadeInTime);
time.setStay(StayOnScreenTime);
time.setFadeOut(FadeOutTime);
time.sendPacket(p);
WrapperPlayServerTitle t = new WrapperPlayServerTitle();
t.setAction(TitleAction.SUBTITLE);
t.setTitle(WrappedChatComponent.fromText(subtitle));
t.sendPacket(p);
}
示例12: setLines
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
/**
* Set this sign's lines of text.
* @param value - Lines, must be 4 elements long
*/
public void setLines(WrappedChatComponent[] value) {
if (value == null)
throw new IllegalArgumentException("value cannot be null!");
if (value.length != 4)
throw new IllegalArgumentException("value must have 4 elements!");
handle.getChatComponentArrays().write(0, value);
}
示例13: 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;
}
示例14: 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());
}
示例15: onPlayerInfoPacket
import com.comphenix.protocol.wrappers.WrappedChatComponent; //导入依赖的package包/类
public PlayerInfoData onPlayerInfoPacket(PlayerInfoData oldPlayerInfoData, Player objPlayer) {
return getTab(objPlayer).map(tab -> new PlayerInfoData(
oldPlayerInfoData.getProfile(),
tab.getLatency() == null ? oldPlayerInfoData.getLatency() : tab.getLatency(),
oldPlayerInfoData.getGameMode(),
tab.getDisplayName() == null ? oldPlayerInfoData.getDisplayName() : WrappedChatComponent.fromText(tab.getDisplayName()))
).orElse(oldPlayerInfoData);
}