Skip to content

Latest commit

 

History

History
106 lines (78 loc) · 3.28 KB

README.md

File metadata and controls

106 lines (78 loc) · 3.28 KB

🌟 Commons Module

JDK License

This module is packed with useful utilities and features that can enhance your projects in various ways. It's a versatile collection that will be updated regularly with new content.

📋 Contents

📦 Installation

Gradle

dependencies {
    compileOnly(files("libs/commons-1.0-SNAPSHOT.jar"))
}

🔧 VarHandleReflectionInjector

The VarHandleReflectionInjector is an injector designed to work seamlessly with VarHandleAutoInjection. It simplifies the process of assigning VarHandle without the need for verbose code.

Example Usage

public class Example {
    public static void main(String[] args) {
        Test test = new Test();

        // Use TField_HANDLE to set the value
        Test.TField_HANDLE.set(test, 2);

        // Prints 2
        System.out.println(test.getTField());
    }
}
@Getter
@Setter
public class Test {
    private volatile int tField = 100;

    @VarHandleAutoInjection(fieldName = "tField")
    public static VarHandle TField_HANDLE;

    static {
        // Managed by Fairy IoC or can be created directly
        InjectorFactory.createVarHandleReflectionInjector().inject(Test.class);
    }
}

⏰ Task Management

The TaskInterface simplifies task scheduling by providing convenient methods that align with the Fairy Framework's MCScheduler.

Example Usage

public class Example {
    public static void main(String[] args) {
        TaskInterface taskInterface = new TaskInterface() {
            @Override
            public ScheduledTask<?> start() {
                // Prints "Hello, world!" every second
                return scheduleAtFixedRate(() -> System.out.println("Hello, world!"), 0, 1000);
            }
        };

        // Start the task
        taskInterface.start();
    }
}

Task Automation

Utilize TaskAutoStartAnnotation to automate the start of tasks at specific times, reducing manual management.

@TaskAutoStartAnnotation(isFromFairyIoC = false)
public class Example implements TaskInterface {
    @Override
    public ScheduledTask<?> start() {
        // Prints "Hello, world!" every second
        return scheduleAtFixedRate(() -> System.out.println("Hello, world!"), 0, 1000);
    }
}

🔗 Related Modules

For details on making annotation processors work with your plugins, refer to the annotation module.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.