Skip to content

Commit

Permalink
Change plugin classes to be made available after plugins have been lo…
Browse files Browse the repository at this point in the history
…aded.
  • Loading branch information
AlexIIL committed Jun 18, 2024
1 parent 950c53f commit a358422
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ group = org.quiltmc
description = The mod loading component of Quilt
url = https://github.com/quiltmc/quilt-loader
# Don't forget to change this in QuiltLoaderImpl as well
quilt_loader = 0.26.1-beta.1
quilt_loader = 0.26.1-beta.2

# Fabric & Quilt Libraries
asm = 9.6
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/quiltmc/loader/impl/QuiltLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public final class QuiltLoaderImpl {

public static final int ASM_VERSION = Opcodes.ASM9;

public static final String VERSION = "0.26.1-beta.1";
public static final String VERSION = "0.26.1-beta.2";
public static final String MOD_ID = "quilt_loader";
public static final String DEFAULT_MODS_DIR = "mods";
public static final String DEFAULT_CACHE_DIR = ".cache";
Expand Down Expand Up @@ -604,6 +604,8 @@ private ModSolveResult runPlugins() {
temporarySourcePaths.put(mod.from(), plugins.convertToSourcePaths(mod.from()));
}

QuiltLauncherBase.getLauncher().setPluginPackages(plugins.getPluginPackages());

if (displayedMessage) {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public interface QuiltLauncher {
void setTransformCache(URL insideTransformCache);
void setHiddenClasses(Set<String> classes);
void setHiddenClasses(Map<String, String> classes);
void setPluginPackages(Map<String, ClassLoader> hiddenClasses);
void hideParentUrl(URL hidden);
void hideParentPath(Path obf);
void validateGameClassLoader(Object gameInstance);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/quiltmc/loader/impl/launch/knot/Knot.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ public void setHiddenClasses(Map<String, String> hiddenClasses) {
classLoader.getDelegate().setHiddenClasses(hiddenClasses);
}

@Override
public void setPluginPackages(Map<String, ClassLoader> hiddenClasses) {
classLoader.getDelegate().setPluginPackages(hiddenClasses);
}

@Override
public void hideParentUrl(URL parent) {
classLoader.getDelegate().hideParentUrl(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public Optional<ModContainer> getQuiltMod() {
/** Map of package to the reason why it cannot be loaded. If the package can be loaded then the value is the empty string. */
private final Map<String, String> packageLoadDenyCache = new ConcurrentHashMap<>();

private Map<String, ClassLoader> pluginPackages = Collections.emptyMap();

KnotClassDelegate(boolean isDevelopment, EnvType envType, KnotClassLoaderInterface itf, GameProvider provider) {
this.isDevelopment = isDevelopment;
this.envType = envType;
Expand Down Expand Up @@ -287,6 +289,11 @@ Class<?> tryLoadClass(String name, boolean allowFromParent) throws ClassNotFound
}
}

ClassLoader pluginCl = pluginPackages.get(pkgString);
if (pluginCl != null) {
return pluginCl.loadClass(name);
}

String hideReason = hiddenClasses.get(name);
if (hideReason != null) {
throw new RuntimeException("Cannot load " + name + " " + hideReason);
Expand Down Expand Up @@ -574,6 +581,10 @@ void setHiddenClasses(Map<String, String> hiddenClasses) {
this.hiddenClasses = hiddenClasses;
}

void setPluginPackages(Map<String, ClassLoader> map) {
pluginPackages = map;
}

void hideParentUrl(URL parentPath) {
parentHiddenUrls.add(parentPath.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,12 @@ public List<QuiltJsonGuiMessage> getErrors() {
return Collections.unmodifiableList(errors);
}

public Map<String, ClassLoader> getPluginPackages() {
Map<String, ClassLoader> map = new HashMap<>();
map.putAll(pluginsByPackage);
return map;
}

Class<?> findClass(String name, String pkg) throws ClassNotFoundException {
if (pkg == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.quiltmc.loader.impl.plugin;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -34,8 +33,6 @@
import java.util.Optional;
import java.util.Set;

import javax.imageio.ImageIO;

import org.quiltmc.loader.api.ModDependencyIdentifier;
import org.quiltmc.loader.api.ModMetadata.ProvidedMod;
import org.quiltmc.loader.api.VersionRange;
Expand All @@ -46,7 +43,6 @@
import org.quiltmc.loader.api.plugin.solver.LoadOption;
import org.quiltmc.loader.api.plugin.solver.ModLoadOption;
import org.quiltmc.loader.api.plugin.solver.Rule;
import org.quiltmc.loader.api.plugin.solver.RuleContext;
import org.quiltmc.loader.impl.plugin.quilt.DisabledModIdDefinition;
import org.quiltmc.loader.impl.plugin.quilt.MandatoryModIdDefinition;
import org.quiltmc.loader.impl.plugin.quilt.OptionalModIdDefintion;
Expand Down

0 comments on commit a358422

Please sign in to comment.