PaperMC / PaperMC/Velocity

Check if a Plugin main class is a Guice module

Open
#540 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: feature
Dominant language
Java
Stars
2.3k
Forks
959
Avg merge
5d 10h
Merged PRs (30d)
2

Description

At the moment in order to create your own bindings, you have to create a child injector. This isn't ideal (due to bugs such as https://github.com/google/guice/issues/973 - injecting an Injector will inject the parent, not the child that the module was bound with).

I believe the logic in JavaPluginLoader#loadPlugin should be something similar to:

Class<?> mainClass = ((JavaVelocityPluginDescription) description).getMainClass();
Object instance;
if (Module.class.isAssignableFrom(mainClass)) {
    instance = mainClass.newInstance();

    Module[] tmp = new Module[modules.length + 1];
    System.arraycopy(modules, 0, tmp, 0, modules.length);
    tmp[modules.length] = (Module) instance;

    Guice.createInjector(tmp);
} else {
    Injector injector = Guice.createInjector(modules);
    instance = injector.getInstance(mainClass);
}

if (instance == null) {
    throw new IllegalStateException("Got nothing from injector for plugin " + description.getId());
}
((VelocityPluginContainer) container).setInstance(instance);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java at JavaPluginLoader#loadPlugin, then review the linked Guice issue for the injector behavior. Check how plugin main classes and existing modules are loaded. Done means a main class that is a Guice Module can provide bindings without a child injector while regular plugin loading still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.