Reloading plugins from code


#1

Hi! How to correct reload plugins from code, i.e. do the same as the “/sponge plugins reload” command?


#2

I think there are two ways to achieve it.

  1. Listen to Sponge’s reload event which can be triggered by running /sponge plugins reload
    Example taken from Sponge docs:
import org.spongepowered.api.event.game.GameReloadEvent;

@Listener
public void reload(GameReloadEvent event) {
    // Do reload stuff
}
  1. Create your own reload command and reload what you want. I.e reload cache, classes’ or object’s fields etc.

#3

No, you did not understand. :slight_smile: I need to post this event in the core, as if I had called a command.
For example, something like Sponge.getPluginManager().reloadPlugins().


#4

Well, then let’s wait for sombody that will able to help because I still don’t understand.


#5

I’ve not tested but something like this should work:

Sponge.getEventManager().post(SpongeEventFactory.createGameReloadEvent(Sponge.getCauseStackManager().getCurrentCause()));

#6

This is a internal class of SpongeCommon. Internal classes are categorically unacceptable in the plugin code.


#7

You’re wrong. org.spongepowered.api.event.SpongeEventFactory is part of SpongeAPI.


#8

Very strange. Its not in the documentation, and the source code does not exist in the SpongeAPI repository. However, it is highlighted in the IDE.


#9

That’s because there is no source code, this class is generated dynamically. :slight_smile: