Package net.citizensnpcs.api.util
Class TemporaryMinecraftComponentSerializer
java.lang.Object
net.citizensnpcs.api.util.TemporaryMinecraftComponentSerializer
- All Implemented Interfaces:
net.kyori.adventure.text.serializer.ComponentDecoder<Object,,net.kyori.adventure.text.Component> net.kyori.adventure.text.serializer.ComponentEncoder<net.kyori.adventure.text.Component,,Object> net.kyori.adventure.text.serializer.ComponentSerializer<net.kyori.adventure.text.Component,net.kyori.adventure.text.Component, Object>
@Experimental
public final class TemporaryMinecraftComponentSerializer
extends Object
implements net.kyori.adventure.text.serializer.ComponentSerializer<net.kyori.adventure.text.Component,net.kyori.adventure.text.Component,Object>
A component serializer for
net.minecraft.server.<version>.IChatBaseComponent.
Due to Bukkit version namespaces, the return type does not reflect the actual type.
Color downsampling will be performed as necessary for the running server version.
If not isSupported(), an UnsupportedOperationException will be thrown on any serialize or
deserialize operations.
- Since:
- 4.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull net.kyori.adventure.text.Componentdeserialize(@NotNull Object input) static @Nullable Class<?> Gets a class by the first name available.static @Nullable MethodHandlefindConstructor(@Nullable Class<?> holderClass, @Nullable Class<?>... parameterClasses) Gets a handle for a class constructor.static @Nullable Class<?> findCraftClass(@NotNull String className) Gets aorg.bukkit.craftbukkitclass.static <T> @Nullable Class<? extends T> findCraftClass(@NotNull String className, @NotNull Class<T> superClass) Gets aorg.bukkit.craftbukkitclass.static @Nullable StringfindCraftClassName(@NotNull String className) Gets aorg.bukkit.craftbukkitclass name.static @Nullable ObjectGets an enum value.static @Nullable ObjectGets an enum value.static @Nullable FieldGets a class field if possible and makes it accessible.static @Nullable FieldfindField(@Nullable Class<?> holderClass, @Nullable Class<?> expectedType, @NotNull String... fieldNames) Gets a class field if it exists and is of the appropriate type and makes it accessible.static @Nullable MethodHandlefindGetterOf(@Nullable Field field) Return a method handle that can get the value of the provided field.static @Nullable Class<?> findMcClass(@NotNull String... classNames) Get anet.minecraftclass.static @Nullable StringfindMcClassName(@NotNull String className) Gets anet.minecraftclass name.static @Nullable MethodHandlefindMethod(@Nullable Class<?> holderClass, @Nullable String @NotNull [] methodNames, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.static @Nullable MethodHandlefindMethod(@Nullable Class<?> holderClass, String methodName, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.static @Nullable Class<?> findNmsClass(@NotNull String className) Get anet.minecraft.serverclass.static @Nullable StringfindNmsClassName(@NotNull String className) Gets anet.minecraft.serverclass name.static @Nullable MethodHandlefindSetterOf(@Nullable Field field) Return a method handle that can set the value of the provided field.static @Nullable MethodHandlefindStaticMethod(@Nullable Class<?> holderClass, String[] methodNames, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.static @Nullable MethodHandlefindStaticMethod(@Nullable Class<?> holderClass, String methodNames, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.static @NotNull TemporaryMinecraftComponentSerializerget()Gets the component serializer.static booleanGets whether a class is available.static booleanGets whether a class has a method.static booleanGets whether a class has a method.static booleanGets whether a class has a method.static booleanGets whether CraftBukkit is available.static booleanGets whether this serializer is supported.static @NotNull MethodHandles.Lookuplookup()Gets the singleton method handle lookup.static @NotNull Class<?> Gets anet.minecraftclass.static @NotNull Class<?> needCraftClass(@NotNull String className) Gets aorg.bukkit.craftbukkitclass.static @NotNull FieldGets a class field and makes it accessible.static @NotNull Class<?> needMcClass(@NotNull String... className) Gets anet.minecraftclass.static @NotNull Class<?> needNmsClass(@NotNull String className) Gets anet.minecraft.serverclass.static MethodHandlesearchMethod(@Nullable Class<?> holderClass, @Nullable Integer modifier, @Nullable String @NotNull [] methodNames, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Search a handle for a class method.static MethodHandlesearchMethod(@Nullable Class<?> holderClass, @Nullable Integer modifier, String methodName, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Search a handle for a class method.@NotNull Objectserialize(@NotNull net.kyori.adventure.text.Component component) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.kyori.adventure.text.serializer.ComponentSerializer
deseializeOrNull, deserializeOr, deserializeOrNull, serializeOr, serializeOrNull
-
Constructor Details
-
TemporaryMinecraftComponentSerializer
public TemporaryMinecraftComponentSerializer()
-
-
Method Details
-
deserialize
@NotNull public @NotNull net.kyori.adventure.text.Component deserialize(@NotNull @NotNull Object input) - Specified by:
deserializein interfacenet.kyori.adventure.text.serializer.ComponentDecoder<Object,net.kyori.adventure.text.Component> - Specified by:
deserializein interfacenet.kyori.adventure.text.serializer.ComponentSerializer<net.kyori.adventure.text.Component,net.kyori.adventure.text.Component, Object>
-
serialize
@NotNull public @NotNull Object serialize(@NotNull @NotNull net.kyori.adventure.text.Component component) - Specified by:
serializein interfacenet.kyori.adventure.text.serializer.ComponentEncoder<net.kyori.adventure.text.Component,Object> - Specified by:
serializein interfacenet.kyori.adventure.text.serializer.ComponentSerializer<net.kyori.adventure.text.Component,net.kyori.adventure.text.Component, Object>
-
findClass
@Nullable public static @Nullable Class<?> findClass(@Nullable @Nullable String @NotNull ... classNames) Gets a class by the first name available.- Parameters:
classNames- an array of class names to try in order- Returns:
- a class or
nullif not found
-
findConstructor
@Nullable public static @Nullable MethodHandle findConstructor(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable Class<?>... parameterClasses) Gets a handle for a class constructor.- Parameters:
holderClass- a classparameterClasses- an array of method parameter classes- Returns:
- a method handle or
nullif not found
-
findCraftClass
Gets aorg.bukkit.craftbukkitclass.- Parameters:
className- a class name, without theorg.bukkit.craftbukkitprefix- Returns:
- a class or
nullif not found
-
findCraftClass
@Nullable public static <T> @Nullable Class<? extends T> findCraftClass(@NotNull @NotNull String className, @NotNull @NotNull Class<T> superClass) Gets aorg.bukkit.craftbukkitclass.- Type Parameters:
T- a super type- Parameters:
className- a class name, without theorg.bukkit.craftbukkitprefixsuperClass- a super class- Returns:
- a class or
nullif not found
-
findCraftClassName
Gets aorg.bukkit.craftbukkitclass name.- Parameters:
className- a class name, without theorg.bukkit.craftbukkitprefix- Returns:
- a class name or
nullif not found
-
findEnum
@Nullable public static @Nullable Object findEnum(@Nullable @Nullable Class<?> enumClass, @NotNull @NotNull String enumName) Gets an enum value.- Parameters:
enumClass- an enum classenumName- an enum name- Returns:
- an enum value or
nullif not found
-
findEnum
@Nullable public static @Nullable Object findEnum(@Nullable @Nullable Class<?> enumClass, @NotNull @NotNull String enumName, int enumFallbackOrdinal) Gets an enum value.- Parameters:
enumClass- an enum classenumName- an enum nameenumFallbackOrdinal- an enum ordinal, when the name is not found- Returns:
- an enum value or
nullif not found
-
findField
@Nullable public static @Nullable Field findField(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable Class<?> expectedType, @NotNull @NotNull String... fieldNames) Gets a class field if it exists and is of the appropriate type and makes it accessible.- Parameters:
holderClass- a classexpectedType- the expected type of the fieldfieldNames- a field name- Returns:
- an accessible field
-
findField
@Nullable public static @Nullable Field findField(@Nullable @Nullable Class<?> holderClass, @NotNull @NotNull String... fieldName) Gets a class field if possible and makes it accessible.- Parameters:
holderClass- a classfieldName- a field name- Returns:
- an accessible field
-
findGetterOf
Return a method handle that can get the value of the provided field.- Parameters:
field- the field to get- Returns:
- a handle, if accessible
-
findMcClass
Get anet.minecraftclass.- Parameters:
classNames- a class name, without thenet.minecraftprefix- Returns:
- a class name or
nullif not found
-
findMcClassName
Gets anet.minecraftclass name.- Parameters:
className- a class name, without thenet.minecraftprefix- Returns:
- a class name or
nullif not found
-
findMethod
@Nullable public static @Nullable MethodHandle findMethod(@Nullable @Nullable Class<?> holderClass, String methodName, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.- Parameters:
holderClass- a classmethodName- a method namereturnClass- a method return classparameterClasses- an array of method parameter classes- Returns:
- a method handle or
nullif not found
-
findMethod
@Nullable public static @Nullable MethodHandle findMethod(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable String @NotNull [] methodNames, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.- Parameters:
holderClass- a classmethodNames- a method namereturnClass- a method return classparameterClasses- an array of method parameter classes- Returns:
- a method handle or
nullif not found
-
findNmsClass
Get anet.minecraft.serverclass.- Parameters:
className- a class name, without thenet.minecraft.serverprefix- Returns:
- a class name or
nullif not found
-
findNmsClassName
Gets anet.minecraft.serverclass name.- Parameters:
className- a class name, without thenet.minecraft.serverprefix- Returns:
- a class name or
nullif not found
-
findSetterOf
Return a method handle that can set the value of the provided field.- Parameters:
field- the field to set- Returns:
- a handle, if accessible
-
findStaticMethod
@Nullable public static @Nullable MethodHandle findStaticMethod(@Nullable @Nullable Class<?> holderClass, String methodNames, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.- Parameters:
holderClass- a classmethodNames- a method namereturnClass- a method return classparameterClasses- an array of method parameter classes- Returns:
- a method handle or
nullif not found
-
findStaticMethod
@Nullable public static @Nullable MethodHandle findStaticMethod(@Nullable @Nullable Class<?> holderClass, String[] methodNames, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.- Parameters:
holderClass- a classmethodNames- a method namereturnClass- a method return classparameterClasses- an array of method parameter classes- Returns:
- a method handle or
nullif not found
-
get
Gets the component serializer.- Returns:
- a component serializer
- Since:
- 4.0.0
-
hasClass
Gets whether a class is available.- Parameters:
classNames- an array of class names to try in order- Returns:
- if the class is loaded
-
hasField
public static boolean hasField(@Nullable @Nullable Class<?> holderClass, Class<?> type, String... names) Gets whether a class has a method.- Parameters:
holderClass- a classtype- the field typenames- field name candidates, will be checked in order- Returns:
- if the method exists
-
hasMethod
public static boolean hasMethod(@Nullable @Nullable Class<?> holderClass, String methodName, Class<?>... parameterClasses) Gets whether a class has a method.- Parameters:
holderClass- a classmethodName- a method nameparameterClasses- an array of method parameter classes- Returns:
- if the method exists
-
hasMethod
public static boolean hasMethod(@Nullable @Nullable Class<?> holderClass, String[] methodNames, Class<?>... parameterClasses) Gets whether a class has a method.- Parameters:
holderClass- a classmethodNames- a method nameparameterClasses- an array of method parameter classes- Returns:
- if the method exists
-
isCraftBukkit
public static boolean isCraftBukkit()Gets whether CraftBukkit is available.- Returns:
- if CraftBukkit is available
-
isSupported
public static boolean isSupported()Gets whether this serializer is supported.- Returns:
- if the serializer is supported.
- Since:
- 4.0.0
-
lookup
Gets the singleton method handle lookup.- Returns:
- the method handle lookup
-
needClass
@NotNull public static @NotNull Class<?> needClass(@Nullable @Nullable String @NotNull ... className) Gets anet.minecraftclass.- Parameters:
className- a class name, without thenet.minecraftprefix- Returns:
- a class
- Throws:
NullPointerException- if the class was not found
-
needCraftClass
Gets aorg.bukkit.craftbukkitclass.- Parameters:
className- a class name, without theorg.bukkit.craftbukkitprefix- Returns:
- a class
- Throws:
NullPointerException- if the class was not found
-
needField
@NotNull public static @NotNull Field needField(@NotNull @NotNull Class<?> holderClass, @NotNull @NotNull String fieldName) throws NoSuchFieldException Gets a class field and makes it accessible.- Parameters:
holderClass- a classfieldName- a field name- Returns:
- an accessible field
- Throws:
NoSuchFieldException- when thrown byClass.getDeclaredField(String)
-
needMcClass
Gets anet.minecraftclass.- Parameters:
className- a class name, without thenet.minecraftprefix- Returns:
- a class
- Throws:
NullPointerException- if the class was not found
-
needNmsClass
Gets anet.minecraft.serverclass.- Parameters:
className- a class name, without theorg.bukkit.craftbukkitprefix- Returns:
- a class
- Throws:
NullPointerException- if the class was not found
-
searchMethod
public static MethodHandle searchMethod(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable Integer modifier, String methodName, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses) Search a handle for a class method.- Parameters:
holderClass- a classmodifier- method modifiersmethodName- a method namereturnClass- a method return classparameterClasses- an array of method parameter classes- Returns:
- a method handle or
nullif not found
-
searchMethod
public static MethodHandle searchMethod(@Nullable @Nullable Class<?> holderClass, @Nullable @Nullable Integer modifier, @Nullable @Nullable String @NotNull [] methodNames, @Nullable @Nullable Class<?> returnClass, Class<?>... parameterClasses) Search a handle for a class method.- Parameters:
holderClass- a classmodifier- method modifiersmethodNames- a method namesreturnClass- a method return classparameterClasses- an array of method parameter classes- Returns:
- a method handle or
nullif not found
-