Search in sources :

Example 1 with ModsManagerImplementation

use of io.xol.chunkstories.content.mods.ModsManagerImplementation in project chunkstories by Hugobros3.

the class DefaultPluginManager method reloadPlugins.

@Override
public /**
 * Implementation : Checks %gamedir%/plugins/ folder, loads what it can within, checks enabled mods and their plugins/ folder, enables what it can
 */
void reloadPlugins() {
    // First disable any leftover plugins
    disablePlugins();
    // We make a list
    LinkedList<PluginInformationImplementation> pluginsToLoad = new LinkedList<PluginInformationImplementation>();
    // Creates plugins folder if it isn't present.
    File pluginsFolder = new File(GameDirectory.getGameFolderPath() + "/plugins/");
    pluginsFolder.mkdirs();
    // Iterates over files of the folder
    for (File file : pluginsFolder.listFiles()) {
        if (file.getName().endsWith(".jar")) {
            try {
                PluginInformationImplementation pluginInformation = new PluginInformationImplementation(file, ((ModsManagerImplementation) pluginExecutionContext.getContent().modsManager()).getFinalClassLoader());
                // Client only plugins require actually being a client
                if (pluginInformation.getPluginType() == PluginType.CLIENT_ONLY && !(this instanceof ClientPluginManager))
                    continue;
                else // Server only plugins require the same
                if (pluginInformation.getPluginType() == PluginType.MASTER && !(this instanceof ServerPluginManager))
                    continue;
                pluginsToLoad.add(pluginInformation);
            } catch (PluginLoadException | IOException e) {
                logger().error("Failed to load plugin file " + file + e.getMessage());
                e.printStackTrace();
            }
        }
    }
    // Mods too can bundle plugins
    for (PluginInformationImplementation pluginInformation : ((ModsManagerImplementation) this.pluginExecutionContext.getContent().modsManager()).getAllModsPlugins()) {
        // Client only plugins require actually being a client
        if (pluginInformation.getPluginType() == PluginType.CLIENT_ONLY && !(this instanceof ClientPluginManager))
            continue;
        else // Server only plugins require the same
        if (pluginInformation.getPluginType() == PluginType.MASTER && !(this instanceof ServerPluginManager))
            continue;
        pluginsToLoad.add(pluginInformation);
    }
    // Enables the found plugins
    enablePlugins(pluginsToLoad);
}
Also used : ModsManagerImplementation(io.xol.chunkstories.content.mods.ModsManagerImplementation) ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PluginLoadException(io.xol.chunkstories.api.exceptions.plugins.PluginLoadException) ServerPluginManager(io.xol.chunkstories.api.plugin.ServerPluginManager) IOException(java.io.IOException) File(java.io.File) LinkedList(java.util.LinkedList)

Example 2 with ModsManagerImplementation

use of io.xol.chunkstories.content.mods.ModsManagerImplementation in project chunkstories by Hugobros3.

the class ModsManagerTest method testModsManager.

@Test
public void testModsManager() {
    String coreContentLocation = System.getProperty("coreContentLocation", "../chunkstories-core/build/distributions/core_content.zip");
    try {
        ModsManager modsManager = new ModsManagerImplementation(new File(coreContentLocation));
        modsManager.loadEnabledMods();
    } catch (NonExistentCoreContent e) {
        e.printStackTrace();
        fail();
    } catch (NotAllModsLoadedException e) {
        e.printStackTrace();
    }
}
Also used : ModsManagerImplementation(io.xol.chunkstories.content.mods.ModsManagerImplementation) ModsManager(io.xol.chunkstories.api.content.mods.ModsManager) File(java.io.File) NotAllModsLoadedException(io.xol.chunkstories.api.exceptions.content.mods.NotAllModsLoadedException) NonExistentCoreContent(io.xol.chunkstories.content.mods.ModsManagerImplementation.NonExistentCoreContent) Test(org.junit.Test)

Aggregations

ModsManagerImplementation (io.xol.chunkstories.content.mods.ModsManagerImplementation)2 File (java.io.File)2 ModsManager (io.xol.chunkstories.api.content.mods.ModsManager)1 NotAllModsLoadedException (io.xol.chunkstories.api.exceptions.content.mods.NotAllModsLoadedException)1 PluginLoadException (io.xol.chunkstories.api.exceptions.plugins.PluginLoadException)1 ClientPluginManager (io.xol.chunkstories.api.plugin.ClientPluginManager)1 ServerPluginManager (io.xol.chunkstories.api.plugin.ServerPluginManager)1 NonExistentCoreContent (io.xol.chunkstories.content.mods.ModsManagerImplementation.NonExistentCoreContent)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1