mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-09-27 14:52:52 +02:00
c5f0550953
* don't enforce async calls for thread-safe listeners (closes #1551) * cleanups, remove structure compiling * improve cloning a bit * fix small issue in no-op structure modifier * remove last usages of FieldUtils * improve and fix equality check in container test
71 lines
2.0 KiB
Java
71 lines
2.0 KiB
Java
package com.comphenix.protocol.utility;
|
|
|
|
import net.bytebuddy.ByteBuddy;
|
|
import net.bytebuddy.dynamic.DynamicType;
|
|
import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
|
|
|
|
/**
|
|
* Represents a shared ByteBuddy factory.
|
|
*
|
|
* @author Kristian
|
|
*/
|
|
public final class ByteBuddyFactory {
|
|
|
|
private static final ByteBuddyFactory INSTANCE = new ByteBuddyFactory();
|
|
|
|
// The current class loader
|
|
private ClassLoader loader = ByteBuddyFactory.class.getClassLoader();
|
|
|
|
public static ByteBuddyFactory getInstance() {
|
|
return INSTANCE;
|
|
}
|
|
|
|
/**
|
|
* Get the current class loader we are using.
|
|
*
|
|
* @return The current class loader.
|
|
*/
|
|
public ClassLoader getClassLoader() {
|
|
return this.loader;
|
|
}
|
|
|
|
/**
|
|
* Set the current class loader to use when constructing enhancers.
|
|
*
|
|
* @param loader - the class loader
|
|
*/
|
|
public void setClassLoader(ClassLoader loader) {
|
|
this.loader = loader;
|
|
}
|
|
|
|
/**
|
|
* Creates a type builder for a subclass of a given {@link Class}.
|
|
*
|
|
* @param clz The class for which to create a subclass.
|
|
* @return A type builder for creating a new class extending the provided clz and implementing {@link
|
|
* ByteBuddyGenerated}.
|
|
*/
|
|
public <T> DynamicType.Builder.MethodDefinition.ImplementationDefinition.Optional<T> createSubclass(Class<T> clz) {
|
|
return new ByteBuddy()
|
|
.subclass(clz)
|
|
.implement(ByteBuddyGenerated.class);
|
|
}
|
|
|
|
/**
|
|
* Creates a type builder for a subclass of a given {@link Class}.
|
|
*
|
|
* @param clz The class for which to create a subclass.
|
|
* @param constructorStrategy The constructor strategy to use.
|
|
* @return A type builder for creating a new class extending the provided clz and implementing {@link
|
|
* ByteBuddyGenerated}.
|
|
*/
|
|
public <T> DynamicType.Builder.MethodDefinition.ImplementationDefinition.Optional<T> createSubclass(
|
|
Class<T> clz,
|
|
ConstructorStrategy.Default constructorStrategy
|
|
) {
|
|
return new ByteBuddy()
|
|
.subclass(clz, constructorStrategy)
|
|
.implement(ByteBuddyGenerated.class);
|
|
}
|
|
}
|