/** * Set the message of the day. * @param message - the message. */ public void setMotD(String message) { setMotD(WrappedChatComponent.fromText(message)); }
/** * Set the message of the day. * @param description - message of the day. */ public void setMotD(WrappedChatComponent description) { DESCRIPTION.set(handle, description.getHandle()); }
/** * Construct a new chat component wrapper from the given JSON string. * @param json - the json. * @return The chat component wrapper. */ public static WrappedChatComponent fromJson(String json) { return new WrappedChatComponent(deserialize(json), json); }
WrappedChatComponent componentWrapper = WrappedChatComponent.fromHandle(customNameOptional.get()); customName = componentWrapper.getJson(); customNameWatchableObject.setValue(Optional.of(WrappedChatComponent.fromJson(customName).getHandle())); } else { customNameWatchableObject.setValue(customName);
@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); }
@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 String toString() { return "WrappedChatComponent[json=" + getJson() + "]"; } }
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);
@Override public WrappedChatComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonPrimitive()) { return WrappedChatComponent.fromJson(json.getAsString()); } return null; }
/** * Construct a wrapper around a new text chat component with the given text. * @param text - the text of the text chat component. * @return The wrapper around the new chat component. */ public static WrappedChatComponent fromText(String text) { Preconditions.checkNotNull(text, "text cannot be NULL."); return fromHandle(CONSTRUCT_TEXT_COMPONENT.invoke(text)); }
/** * Construct a new chat component wrapper around the given NMS object. * @param handle - the NMS object. * @return The wrapper. */ public static WrappedChatComponent fromHandle(Object handle) { return new WrappedChatComponent(handle, null); }
/** * Retrieve a deep copy of the current wrapper object. * @return The current object. */ public WrappedServerPing deepClone() { WrappedServerPing copy = new WrappedServerPing(); WrappedChatComponent motd = getMotD(); copy.setPlayers(getPlayers()); copy.setFavicon(getFavicon()); copy.setMotD(motd != null ? motd.deepClone() : null); copy.setVersionName(getVersionName()); copy.setVersionProtocol(getVersionProtocol()); if (isPlayersVisible()) { copy.setPlayersMaximum(getPlayersMaximum()); copy.setPlayersOnline(getPlayersOnline()); } else { copy.setPlayersVisible(false); } return copy; }
/** * Converts a {@link WrappedChatComponent} into an array of {@link BaseComponent}s * @param wrapper ProtocolLib wrapper * @return BaseComponent array */ public static BaseComponent[] fromWrapper(WrappedChatComponent wrapper) { return ComponentSerializer.parse(wrapper.getJson()); }
/** * Converts an array of {@link BaseComponent}s into a ProtocolLib wrapper * @param components BaseComponent array * @return ProtocolLib wrapper */ public static WrappedChatComponent fromBaseComponent(BaseComponent... components) { return WrappedChatComponent.fromJson(ComponentSerializer.toString(components)); } }
/** * Retrieve the message of the day. * @return The messge of the day. */ public WrappedChatComponent getMotD() { return WrappedChatComponent.fromHandle(DESCRIPTION.get(handle)); }
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 JsonElement serialize(WrappedChatComponent src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.getJson()); } }
return Optional.of(val); } else if (val instanceof WrappedChatComponent) { return Optional.of(((WrappedChatComponent) val).getHandle());
/** * Construct an array of chat components from a standard Minecraft message. * <p> * This uses {@link ChatColor} for formating. * @param message - the message. * @return The equivalent chat components. */ public static WrappedChatComponent[] fromChatMessage(String message) { Object[] components = (Object[]) CONSTRUCT_COMPONENT.invoke(null, message); WrappedChatComponent[] result = new WrappedChatComponent[components.length]; for (int i = 0; i < components.length; i++) { result[i] = fromHandle(components[i]); } return result; }