Skip to content

CKATEPTb-minecraft/Nicotine

 
 

Repository files navigation

Nicotine


Instances container with automatic annotation-based dependency injection. It is useful for people with basic understanding of java, gradle, workflow and is designed for lazy people

License Sonatype Nexus (Snapshots) Publish Discord


Versioning

We use Semantic Versioning 2.0.0 to manage our releases.

Features

  • Easy to use
  • TableclothContainer implementation
  • TableclothEvent implementation
  • Automatic listeners registration
  • Automatic scheduler registration
  • Post constructor
  • Documented

Download

Download from our repository or depend via Gradle:

repositories {
    maven("https://repo.animecraft.fun/repository/maven-snapshots/")
}

dependencies {
    implementation("dev.ckateptb.minecraft:Nicotine:<version>")
}

How To

  • Import the dependency as shown above
  • Add Nicotine as a dependency to your plugin.yml
name: ...
version: ...
main: ...
depend: [ Nicotine ]
authors: ...
description: ...
  • Scan your packages in your plugin's constructor
import dev.ckateptb.common.tableclothcontainer.IoC;
import org.bukkit.plugin.java.JavaPlugin;

public class PluginExample extends JavaPlugin {
    public PluginExample() {
        // Scan component from plugin root classpath
        // You can also specify another package and filter packages
        // Look IoC#scan for mode details
        IoC.scan(PluginExample.class);
    }

    @Override
    public void onLoad() {
        // ...
    }

    @Override
    public void onEnable() {
        // ...
    }
    @Override
    public void onDisable() {
        // ...
    }
}
  • Create a class and annotate it as @Component to automatically instantiate that class
import dev.ckateptb.common.tableclothcontainer.annotation.Component;
import dev.ckateptb.common.tableclothcontainer.annotation.PostConstruct;
import dev.ckateptb.minecraft.nicotine.annotation.Schedule;

@Component
public class ComponentExample {
    private final String finalField;
    private String field;
    
    // You can pass other components to the constructor, they will be included automatically
    public ComponentExample() {
        this.finalField = "simple final field";
    }

    // The function will be called immediately after the instance is created
    @PostConstruct
    public void postConstructorExample() {
        this.field = "simple field";
    }

    // Synchronous scheduler example
    // initialDelay and fixedRate specified in ticks
    @Schedule(initialDelay = 0, fixedRate = 20)
    public void scheduleExample() {
        System.out.println("Wow, it's work!");
    }

    // Asynchronous scheduler example
    // initialDelay and fixedRate specified in ticks
    @Schedule(initialDelay = 10, fixedRate = 50, async = true)
    public void asyncScheduleExample() {
        System.out.println("Wow, it's work!");
    }
}
  • To automatically register event listeners, annotate the class implementing Listener as @Component
import dev.ckateptb.common.tableclothcontainer.annotation.Component;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

@Component
public class ExampleListener implements Listener {
    @EventHandler
    public void on(PlayerJoinEvent event) {
        // ...
    }
}

About

Bukkit implementation of TableclothContainer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%