/** * Set the message of the day. * @param message - the message. */ public void setMotD(String message) { setMotD(WrappedChatComponent.fromText(message)); }
public void setCustomName(String name) { if (Strings.isNullOrEmpty(name)) { setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty()); } else { if (name.length() > 64) { name = name.substring(0, 64); } setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent.fromText(name))); } sendData(MetaIndex.ENTITY_CUSTOM_NAME); }
@Override public WrappedChatComponent[] getSpecific(Object generic) { NbtBase<?> nbtBase = nbtConverter.getSpecific(generic); NbtCompound compound = (NbtCompound) nbtBase; WrappedChatComponent[] components = new WrappedChatComponent[lines]; for (int i = 0; i < lines; i++) { if (compound.containsKey("Text" + (i + 1))) { components[i] = WrappedChatComponent.fromJson(compound.getString("Text" + (i + 1))); } else { components[i] = WrappedChatComponent.fromText(""); } } return components; }
@Override public Object getGeneric(WrappedChatComponent[] specific) { NbtCompound compound = NbtFactory.ofCompound(""); for (int i = 0; i < lines; i++) { WrappedChatComponent component; if (i < specific.length && specific[i] != null) { component = specific[i]; } else { component = WrappedChatComponent.fromText(""); } compound.put("Text" + (i + 1), component.getJson()); } return nbtConverter.getGeneric(compound); }
public TargetedDisguise addPlayer(String playername) { if (!disguiseViewers.contains(playername)) { disguiseViewers.add(playername); if (DisguiseAPI.isDisguiseInUse(this)) { DisguiseUtilities.checkConflicts(this, playername); DisguiseUtilities.refreshTracker(this, playername); if (isHidePlayer() && getEntity() instanceof Player) { try { Player player = Bukkit.getPlayerExact(playername); if (player != null) { PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); deleteTab.getPlayerInfoAction().write(0, canSee(player) ? PlayerInfoAction.REMOVE_PLAYER : PlayerInfoAction.ADD_PLAYER); deleteTab.getPlayerInfoDataLists().write(0, Arrays.asList( new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL, WrappedChatComponent .fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))))); ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); } } catch (InvocationTargetException e) { e.printStackTrace(); } } } } return this; }
public TargetedDisguise removePlayer(String playername) { if (disguiseViewers.contains(playername)) { disguiseViewers.remove(playername); if (DisguiseAPI.isDisguiseInUse(this)) { DisguiseUtilities.checkConflicts(this, playername); DisguiseUtilities.refreshTracker(this, playername); if (isHidePlayer() && getEntity() instanceof Player) { try { Player player = Bukkit.getPlayerExact(playername); if (player != null) { PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); deleteTab.getPlayerInfoAction().write(0, canSee(player) ? PlayerInfoAction.ADD_PLAYER : PlayerInfoAction.REMOVE_PLAYER); deleteTab.getPlayerInfoDataLists().write(0, Arrays.asList( new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL, WrappedChatComponent .fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))))); ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); } } catch (InvocationTargetException e) { e.printStackTrace(); } } } } return this; }
private void sendPacketsSelf(WrappedGameProfile gameProfile) { PacketContainer removeInfo; PacketContainer addInfo; PacketContainer respawn; PacketContainer teleport; try { NativeGameMode gamemode = NativeGameMode.fromBukkit(receiver.getGameMode()); WrappedChatComponent displayName = WrappedChatComponent.fromText(receiver.getPlayerListName()); PlayerInfoData playerInfoData = new PlayerInfoData(gameProfile, 0, gamemode, displayName); //remove the old skin - client updates it only on a complete remove and add removeInfo = new PacketContainer(PLAYER_INFO); removeInfo.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); removeInfo.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData)); //add info containing the skin data addInfo = removeInfo.deepClone(); addInfo.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); // Respawn packet - notify the client that it should update the own skin respawn = createRespawnPacket(gamemode); //prevent the moved too quickly message teleport = createTeleportPacket(receiver.getLocation().clone()); } catch (ReflectiveOperationException reflectiveEx) { plugin.getLog().error("Error occured preparing packets. Cancelling self update", reflectiveEx); return; } sendPackets(removeInfo, addInfo, respawn, teleport); }
deleteTab.getPlayerInfoDataLists().write(0, Collections.singletonList( new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getName())))); PlayerInfoData playerInfo = new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.fromBukkit(((Player) getEntity()).getGameMode()), WrappedChatComponent.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity())));
if (customName != null && !customName.isEmpty()) { if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { dataWatcher.setObject(new WrappedDataWatcherObject(customNameWatcherIndex, chatComponentSerializer), Optional.of(WrappedChatComponent.fromText(customName).getHandle())); } else { dataWatcher.setObject(new WrappedDataWatcherObject(customNameWatcherIndex, stringSerializer), customName);
addTab.getPlayerInfoDataLists().write(0, Arrays.asList( new PlayerInfoData(getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getName()))));
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getGameProfile().getName()))));
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getName())))); addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(""))));