Class Plugins

java.lang.Object
com.xpdustry.claj.server.plugin.Plugins
All Implemented Interfaces:
arc.ApplicationListener

public class Plugins extends Object implements arc.ApplicationListener
Simplified
invalid reference
mindustry.mod.Mods
that only handles plugins.
  • Field Details

    • directory

      public final arc.files.Fi directory
    • commands

      public final arc.util.CommandHandler commands
    • mainLoader

      public final PluginClassLoader mainLoader
    • json

      public final arc.util.serialization.Json json
  • Constructor Details

    • Plugins

      public Plugins(arc.files.Fi directory, arc.util.CommandHandler commands)
  • Method Details

    • getConfigFolder

      public arc.files.Fi getConfigFolder(Plugin plugin)
      Returns:
      the folder where configuration files for this plugin should go. Call this in init().
    • getConfigFolder

      public arc.files.Fi getConfigFolder(Class<? extends Plugin> plugin)
      Returns:
      the folder where configuration files for this plugin should go. Call this in init().
    • getConfig

      public JsonSettings getConfig(Plugin plugin)
      Returns:
      a settings handle of 'plugins/<plugin-name>/config.json'. Call this in init().
    • getConfig

      public JsonSettings getConfig(Class<? extends Plugin> plugin)
      Returns:
      a settings handle of 'plugins/<plugin-name>/config.json'. Call this in init().
    • getMeta

      public Plugins.PluginMeta getMeta(Plugin plugin)
      Returns:
      the plugin meta data. Call this in init().
    • getMeta

      public Plugins.PluginMeta getMeta(Class<? extends Plugin> plugin)
      Returns:
      the plugin meta. Call this in init().
    • getLogger

      public PluginLogger getLogger(Plugin plugin)
      Returns:
      a new main logger for the plugin.
    • getLogger

      public PluginLogger getLogger(Class<? extends Plugin> plugin, Void aVoid)
      Returns:
      a new main logger for the plugin.
    • getLogger

      public PluginLogger getLogger(Plugin plugin, Class<?> topicClass)
      Returns:
      a new logger for the plugin with the specified topicClass.
    • getLogger

      public PluginLogger getLogger(Class<? extends Plugin> plugin, Class<?> topicClass)
      Returns:
      a new logger for the plugin with the specified topicClass.
    • getLogger

      public PluginLogger getLogger(Plugin plugin, String topic)
      Returns:
      a new logger for the plugin with the specified topic.
    • getLogger

      public PluginLogger getLogger(Class<? extends Plugin> plugin, String topic)
      Returns:
      a new logger for the plugin with the specified topic.
    • getConfigFolder

      public arc.files.Fi getConfigFolder()
      Same as getConfigFolder(Class) but tries to detect the plugin by the class calling this method.
    • getConfig

      public JsonSettings getConfig()
      Same as getConfig(Class) but tries to detect the plugin by the class calling this method.
    • getMeta

      public Plugins.PluginMeta getMeta()
      Same as getMeta(Class) but tries to detect the plugin by the class calling this method.
    • getLogger

      public PluginLogger getLogger()
      Same as getLogger(Plugin) but tries to detect the plugin by the class calling this method.
    • getLogger

      public PluginLogger getLogger(Class<?> topicClass)
      Same as getLogger(Plugin, Class) but tries to detect the plugin by the class calling this method.
    • getLogger

      public PluginLogger getLogger(String topic)
      Same as getLogger(Plugin, String) but tries to detect the plugin by the class calling this method.
    • detectCallingPlugin

      public <T extends Plugin> Class<T> detectCallingPlugin()
      Inspect the current thread stack to find which plugin (based on its ClassLoader) is calling the method.
      Returns:
      the plugin main class or null.
    • listFiles

      public void listFiles(String directory, arc.func.Cons2<Plugins.LoadedPlugin, arc.files.Fi> cons)
      Returns a list of files per plugin subdirectory.
    • getPlugin

      @Nullable public Plugins.LoadedPlugin getPlugin(String name)
      Returns:
      the loaded plugin found by name, or null if not found.
    • getPlugin

      @Nullable public Plugins.LoadedPlugin getPlugin(Class<? extends Plugin> type)
      Returns:
      the loaded plugin found by class, or null if not found.
    • init

      public void init()
      Specified by:
      init in interface arc.ApplicationListener
    • dispose

      public void dispose()
      Specified by:
      dispose in interface arc.ApplicationListener
    • load

      public void load()
      Loads all plugins from the folder, but does not call any methods on them.
    • orderedPlugins

      public arc.struct.Seq<Plugins.LoadedPlugin> orderedPlugins()
      Returns:
      plugins ordered in the correct way needed for dependencies.
    • locatePlugin

      public Plugins.LoadedPlugin locatePlugin(String name)
    • getPluginStrings

      public arc.struct.Seq<String> getPluginStrings()
      Returns:
      a list of plugins and versions, in the format name:version.
    • getIncompatibility

      public arc.struct.Seq<String> getIncompatibility(arc.struct.Seq<String> out)
      Returns:
      The plugins that the client is missing, in the format name:version.
      The inputed array must be in the same format, and is changed to contain the extra plugins that the client has but the server doesn't.
    • list

      public arc.struct.Seq<Plugins.LoadedPlugin> list()
    • eachClass

      public void eachClass(arc.func.Cons<Plugin> cons)
      Iterates through each plugin with a main class.
    • eachEnabled

      public void eachEnabled(arc.func.Cons<Plugins.LoadedPlugin> cons)
      Iterates through each enabled plugin.
    • contextRun

      public void contextRun(Plugins.LoadedPlugin plugin, Runnable run)
    • findMeta

      @Nullable public Plugins.PluginMeta findMeta(arc.files.Fi file)
      Tries to find the config file of a plugin.
    • resolveDependencies

      public arc.struct.OrderedMap<String, Plugins.PluginState> resolveDependencies(arc.struct.Seq<Plugins.PluginMeta> metas)
      Resolves the loading order of a list plugins using their internal names.