Skip to content

Commit

Permalink
Fixed missions not having all their classes loaded due to the way mis…
Browse files Browse the repository at this point in the history
…sions are loaded
  • Loading branch information
OmerBenGera committed Apr 7, 2023
1 parent b3e8e9c commit f491a57
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
@@ -1,6 +1,5 @@
package com.bgsoftware.superiorskyblock.module;
package com.bgsoftware.superiorskyblock.core.io;

import com.bgsoftware.superiorskyblock.api.modules.PluginModule;
import com.google.common.io.ByteStreams;
import org.jetbrains.annotations.Nullable;

Expand All @@ -17,15 +16,15 @@
import java.util.jar.JarFile;
import java.util.jar.Manifest;

public class ModuleClassLoader extends URLClassLoader {
public class FileClassLoader extends URLClassLoader {

private final Map<String, Class<?>> classes = new ConcurrentHashMap<>();

private final JarFile jar;
private final Manifest manifest;
private final URL url;

public ModuleClassLoader(File file, ClassLoader pluginClassLoader) throws IOException {
public FileClassLoader(File file, ClassLoader pluginClassLoader) throws IOException {
super(new URL[]{file.toURI().toURL()}, pluginClassLoader);

this.jar = new JarFile(file);
Expand Down
Expand Up @@ -11,6 +11,7 @@
import com.bgsoftware.superiorskyblock.core.Manager;
import com.bgsoftware.superiorskyblock.core.events.EventResult;
import com.bgsoftware.superiorskyblock.core.events.EventsBus;
import com.bgsoftware.superiorskyblock.core.io.FileClassLoader;
import com.bgsoftware.superiorskyblock.core.io.Files;
import com.bgsoftware.superiorskyblock.core.io.JarFiles;
import com.bgsoftware.superiorskyblock.core.itemstack.ItemBuilder;
Expand All @@ -35,7 +36,6 @@
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;

Expand Down Expand Up @@ -444,8 +444,9 @@ public Mission<?> loadMission(String missionName, File missionsFolder, Configura
if (mission == null) {
File missionJar = new File(missionsFolder, missionSection.getString("mission-file") + ".jar");

Either<Class<?>, Throwable> missionClassLookup = JarFiles.getClass(missionJar.toURL(), Mission.class,
plugin.getPluginClassLoader());
FileClassLoader missionClassLoader = new FileClassLoader(missionJar, plugin.getPluginClassLoader());

Either<Class<?>, Throwable> missionClassLookup = JarFiles.getClass(missionJar.toURL(), Mission.class, missionClassLoader);

if (missionClassLookup.getLeft() != null)
throw new RuntimeException("An unexpected error occurred while reading " + missionJar.getName() + ".", missionClassLookup.getLeft());
Expand Down
Expand Up @@ -8,6 +8,7 @@
import com.bgsoftware.superiorskyblock.core.Either;
import com.bgsoftware.superiorskyblock.core.Manager;
import com.bgsoftware.superiorskyblock.core.io.JarFiles;
import com.bgsoftware.superiorskyblock.core.io.FileClassLoader;
import com.bgsoftware.superiorskyblock.core.logging.Log;
import com.bgsoftware.superiorskyblock.module.container.ModulesContainer;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -60,7 +61,7 @@ public PluginModule registerModule(File moduleFile) throws IOException, Reflecti
Preconditions.checkArgument(moduleFile.exists(), "The file " + moduleFile.getName() + " does not exist.");
Preconditions.checkArgument(moduleFile.getName().endsWith(".jar"), "The file " + moduleFile.getName() + " is not a valid jar file.");

ModuleClassLoader moduleClassLoader = new ModuleClassLoader(moduleFile, plugin.getPluginClassLoader());
FileClassLoader moduleClassLoader = new FileClassLoader(moduleFile, plugin.getPluginClassLoader());

Either<Class<?>, Throwable> moduleClassLookup = JarFiles.getClass(moduleFile.toURL(), PluginModule.class, moduleClassLoader);

Expand Down

0 comments on commit f491a57

Please sign in to comment.