A collection of essential utilities and tools focusing on reflection injection, task scheduling, and common operations. Built with flexibility and ease of use in mind.
-
🔄 VarHandle Injection System
- Automated VarHandle injection via
@VarHandleAutoInjection
- Support for both direct and static method-based injection
- Thread-safe field access through VarHandle
- Flexible injection strategies with
StaticInjectorInterface
- Automated VarHandle injection via
-
⏰ Task Management
- Rich task scheduling API through
TaskInterface
- Support for both sync and async execution
- Flexible scheduling with ticks or Duration
- Auto-start capability via
@TaskAutoStartAnnotation
- Rich task scheduling API through
-
🔧 Utility Components
- Thread-safe JSON operations with
GsonUtil
- Customizable Gson configuration
- Factory patterns for component creation
- Integration with Fairy IoC container
- Thread-safe JSON operations with
dependencies {
implementation("net.legacy.library:commons:1.0-SNAPSHOT")
}
1️⃣ VarHandle Injection
public class MyClass {
@VarHandleAutoInjection(fieldName = "targetField")
private static VarHandle TARGET_FIELD_HANDLE;
private String targetField;
}
// Inject the VarHandle
StaticInjectorInterface injector = InjectorFactory.createVarHandleReflectionInjector();
injector.inject(MyClass.class);
2️⃣ Task Scheduling
@TaskAutoStartAnnotation
public class MyTask implements TaskInterface {
@Override
public ScheduledTask<?> start() {
return scheduleAtFixedRate(
() -> System.out.println("Task executed"),
Duration.ZERO,
Duration.ofSeconds(5)
);
}
}
3️⃣ JSON Operations
// Customize Gson
GsonUtil.customizeGsonBuilder(builder -> {
builder.setPrettyPrinting();
builder.serializeNulls();
});
// Use the shared Gson instance
Gson gson = GsonUtil.getGson();
VarHandleReflectionInjector
: Core injection implementationStaticInjectorInterface
: Base interface for static injectorsObjectInjectorInterface
: Base interface for object injectors@VarHandleAutoInjection
: Annotation for marking injection targets
TaskInterface
: Rich API for task scheduling@TaskAutoStartAnnotation
: Auto-start task markerTaskAutoStartAnnotationProcessor
: Annotation processor for tasks- Support for various scheduling patterns:
- Fixed-rate execution
- Delayed execution
- Conditional repetition
- Duration-based scheduling
GsonUtil
: Thread-safe JSON operationsInjectorFactory
: Factory for creating injector instances
@VarHandleAutoInjection(
fieldName = "field",
staticMethodName = "getHandle",
staticMethodPackage = "com.example.Handles"
)
private static VarHandle FIELD_HANDLE;
@Override
public ScheduledTask<?> start() {
return scheduleAtFixedRate(
() -> complexOperation(),
Duration.ofSeconds(1),
Duration.ofMinutes(5),
result -> shouldContinue(result)
);
}
GsonUtil.setNewGson(() -> new GsonBuilder()
.setPrettyPrinting()
.serializeNulls()
.registerTypeAdapter(MyType.class, new MyTypeAdapter())
);
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Made with ❤️ by LegacyLands Team