HomeJavaModsPluginInject
PluginInject

PluginInject is the fourth in a series of attempts I have made to provide easy dependency injection into Bukkit plugins. I consider it to be the most simple and successful so far. It is built around HK2, the reference implementation of JSR 330(Dependency Injection for Java). HK2 was chosen as it provides scanning for services at compile time, lifecycle support, and full support for providing extensions to the injection mechanisms.

Detailed documentation can be found at the github link. Currently PluginInject isn't hosted on any public maven repositories, so you'll have to build it locally in order to reference it from your project.

Example plugin:
Code (Text):
package example;

import com.natemortensen.plugininject.InjectedPlugin;
import com.natemortensen.plugininject.PluginInject;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

public class ExamplePlugin extends InjectedPlugin
{
    // Don't ever inject PluginInject, it's useless.
    // This is simply to demonstrate how one would inject another plugin
    @Inject
    private PluginInject inject;
    @Inject
    @Named("PluginInject")
    private JavaPlugin plugin;

    // InjectedPlugin doesn't allow onEnable to be overridden; use @PostConstruct instead
    @PostConstruct
    public void postConstruct()
    {
        getLogger().info("Are they the same plugin? " + (inject == plugin));
    }
    // InjectedPlugin implements Listener and is registered automatically
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event)
    {
        event.getPlayer().sendMessage("Welcome!");
    }
}
Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

PluginInject is a free Minecraft Java mod. Compatible with Minecraft 1.9, 1.10, 1.11. Downloaded 309 times (via Spigot). Download it and open it directly in the game.

Explore more