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.Component
deserialize
(@NotNull Object input) static @Nullable Class
<?> Gets a class by the first name available.static @Nullable MethodHandle
findConstructor
(@Nullable Class<?> holderClass, @Nullable Class<?>... parameterClasses) Gets a handle for a class constructor.static @Nullable Class
<?> findCraftClass
(@NotNull String className) Gets aorg.bukkit.craftbukkit
class.static <T> @Nullable Class
<? extends T> findCraftClass
(@NotNull String className, @NotNull Class<T> superClass) Gets aorg.bukkit.craftbukkit
class.static @Nullable String
findCraftClassName
(@NotNull String className) Gets aorg.bukkit.craftbukkit
class name.static @Nullable Object
Gets an enum value.static @Nullable Object
Gets an enum value.static @Nullable Field
Gets a class field if possible and makes it accessible.static @Nullable Field
findField
(@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 MethodHandle
findGetterOf
(@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.minecraft
class.static @Nullable String
findMcClassName
(@NotNull String className) Gets anet.minecraft
class name.static @Nullable MethodHandle
findMethod
(@Nullable Class<?> holderClass, @Nullable String @NotNull [] methodNames, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.static @Nullable MethodHandle
findMethod
(@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.server
class.static @Nullable String
findNmsClassName
(@NotNull String className) Gets anet.minecraft.server
class name.static @Nullable MethodHandle
findSetterOf
(@Nullable Field field) Return a method handle that can set the value of the provided field.static @Nullable MethodHandle
findStaticMethod
(@Nullable Class<?> holderClass, String[] methodNames, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.static @Nullable MethodHandle
findStaticMethod
(@Nullable Class<?> holderClass, String methodNames, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Gets a handle for a class method.static @NotNull TemporaryMinecraftComponentSerializer
get()
Gets the component serializer.static boolean
Gets whether a class is available.static boolean
Gets whether a class has a method.static boolean
Gets whether a class has a method.static boolean
Gets whether a class has a method.static boolean
Gets whether CraftBukkit is available.static boolean
Gets whether this serializer is supported.static @NotNull MethodHandles.Lookup
lookup()
Gets the singleton method handle lookup.static @NotNull Class
<?> Gets anet.minecraft
class.static @NotNull Class
<?> needCraftClass
(@NotNull String className) Gets aorg.bukkit.craftbukkit
class.static @NotNull Field
Gets a class field and makes it accessible.static @NotNull Class
<?> needMcClass
(@NotNull String... className) Gets anet.minecraft
class.static @NotNull Class
<?> needNmsClass
(@NotNull String className) Gets anet.minecraft.server
class.static MethodHandle
searchMethod
(@Nullable Class<?> holderClass, @Nullable Integer modifier, @Nullable String @NotNull [] methodNames, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Search a handle for a class method.static MethodHandle
searchMethod
(@Nullable Class<?> holderClass, @Nullable Integer modifier, String methodName, @Nullable Class<?> returnClass, Class<?>... parameterClasses) Search a handle for a class method.@NotNull Object
serialize
(@NotNull net.kyori.adventure.text.Component component) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
deserialize
in interfacenet.kyori.adventure.text.serializer.ComponentDecoder<Object,
net.kyori.adventure.text.Component> - Specified by:
deserialize
in 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:
serialize
in interfacenet.kyori.adventure.text.serializer.ComponentEncoder<net.kyori.adventure.text.Component,
Object> - Specified by:
serialize
in 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
null
if 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
null
if not found
-
findCraftClass
Gets aorg.bukkit.craftbukkit
class.- Parameters:
className
- a class name, without theorg.bukkit.craftbukkit
prefix- Returns:
- a class or
null
if not found
-
findCraftClass
@Nullable public static <T> @Nullable Class<? extends T> findCraftClass(@NotNull @NotNull String className, @NotNull @NotNull Class<T> superClass) Gets aorg.bukkit.craftbukkit
class.- Type Parameters:
T
- a super type- Parameters:
className
- a class name, without theorg.bukkit.craftbukkit
prefixsuperClass
- a super class- Returns:
- a class or
null
if not found
-
findCraftClassName
Gets aorg.bukkit.craftbukkit
class name.- Parameters:
className
- a class name, without theorg.bukkit.craftbukkit
prefix- Returns:
- a class name or
null
if 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
null
if 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
null
if 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.minecraft
class.- Parameters:
classNames
- a class name, without thenet.minecraft
prefix- Returns:
- a class name or
null
if not found
-
findMcClassName
Gets anet.minecraft
class name.- Parameters:
className
- a class name, without thenet.minecraft
prefix- Returns:
- a class name or
null
if 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
null
if 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
null
if not found
-
findNmsClass
Get anet.minecraft.server
class.- Parameters:
className
- a class name, without thenet.minecraft.server
prefix- Returns:
- a class name or
null
if not found
-
findNmsClassName
Gets anet.minecraft.server
class name.- Parameters:
className
- a class name, without thenet.minecraft.server
prefix- Returns:
- a class name or
null
if 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
null
if 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
null
if 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.minecraft
class.- Parameters:
className
- a class name, without thenet.minecraft
prefix- Returns:
- a class
- Throws:
NullPointerException
- if the class was not found
-
needCraftClass
Gets aorg.bukkit.craftbukkit
class.- Parameters:
className
- a class name, without theorg.bukkit.craftbukkit
prefix- 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.minecraft
class.- Parameters:
className
- a class name, without thenet.minecraft
prefix- Returns:
- a class
- Throws:
NullPointerException
- if the class was not found
-
needNmsClass
Gets anet.minecraft.server
class.- Parameters:
className
- a class name, without theorg.bukkit.craftbukkit
prefix- 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
null
if 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
null
if not found
-