Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Fix some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Sep 6, 2023
1 parent 2aad61d commit e1946cf
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
11 changes: 7 additions & 4 deletions src/fmllauncher/java/com/mohistmc/MohistMCStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ public static void main() throws Exception {
Class.forName("com.mohistmc.util.MohistModuleManager", false, URLClassLoader.newInstance(new java.net.URL[]{universalJar.toURI().toURL()})).getDeclaredConstructor().newInstance();
}

// make sure gson use this EnumTypeAdapter
Class.forName("com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter").getClassLoader();
// Used to avoid mods using BusBuilder.builder().build() themselves
Class.forName("net.minecraftforge.eventbus.EventBus").getClassLoader();
try {
// make sure gson use this EnumTypeAdapter
Class.forName("com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter").getClassLoader();
// Used to avoid mods using BusBuilder.builder().build() themselves
Class.forName("net.minecraftforge.eventbus.EventBus").getClassLoader();
} catch (Exception ignored) {
}

System.setOut(new LoggingPrintStream("STDOUT", System.out, Level.INFO));
System.setErr(new LoggingPrintStream("STDERR", System.err, Level.ERROR));
Expand Down
26 changes: 16 additions & 10 deletions src/fmllauncher/java/com/mohistmc/libraries/DefaultLibraries.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.mohistmc.util.i18n.i18n;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -38,7 +39,7 @@ public class DefaultLibraries {
public static HashMap<String, String> fail = new HashMap<>();
public static final AtomicLong allSize = new AtomicLong(); // global

public static void run() throws Exception {
public static void run() {
System.out.println(i18n.get("libraries.checking.start"));
System.out.println(i18n.get("libraries.downloadsource", DownloadSource.get().name()));
String url = DownloadSource.get().getUrl();
Expand Down Expand Up @@ -80,16 +81,21 @@ public static void run() throws Exception {
} else System.out.println(i18n.get("libraries.check.end"));
}

public static LinkedHashMap<File, String> getDefaultLibs() throws Exception {
public static LinkedHashMap<File, String> getDefaultLibs() {
LinkedHashMap<File, String> temp = new LinkedHashMap<>();
BufferedReader b = new BufferedReader(new InputStreamReader(DefaultLibraries.class.getClassLoader().getResourceAsStream("libraries.txt")));
String str;
while ((str = b.readLine()) != null) {
String[] s = str.split("\\|");
temp.put(new File(JarTool.getJarDir() + "/" + s[0]), s[1]);
allSize.addAndGet(Long.parseLong(s[2]));
try {
BufferedReader b = new BufferedReader(new InputStreamReader(DefaultLibraries.class.getClassLoader().getResourceAsStream("libraries.txt")));
String str;
while (true) {
if (!((str = b.readLine()) != null)) break;
String[] s = str.split("\\|");
temp.put(new File(JarTool.getJarDir() + "/" + s[0]), s[1]);
allSize.addAndGet(Long.parseLong(s[2]));
}
b.close();
return temp;
} catch (IOException e) {
return temp;
}
b.close();
return temp;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/mohistmc/inventory/InventoryOwner.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock;
import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockEntityState;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
Expand Down Expand Up @@ -58,7 +59,7 @@ public static InventoryHolder get(IInventory inventory) {
public static InventoryHolder get(World world, BlockPos pos, boolean useSnapshot) {
if (world == null) return null;
// Spigot start
org.bukkit.block.Block block = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
org.bukkit.block.Block block = CraftBlock.at(world, pos);
if (block == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private void constructMod()
{
try
{
LOGGER.debug(LOADING, i18n.get("fmlmodcontainer.4", getModId(), modClass.getName()));
this.modInstance = modClass.newInstance();
LOGGER.debug(LOADING, i18n.get("fmlmodcontainer.4", getModId(), modClass.getName()));
}
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.Attributes;
Expand All @@ -24,6 +25,7 @@

import com.mohistmc.bukkit.nms.model.ClassMapping;
import com.mohistmc.bukkit.pluginfix.PluginFixManager;
import cpw.mods.modlauncher.EnumerationHelper;
import cpw.mods.modlauncher.TransformingClassLoader;
import org.apache.commons.lang.Validate;
import org.bukkit.plugin.InvalidPluginException;
Expand Down Expand Up @@ -104,12 +106,26 @@ public final class PluginClassLoader extends URLClassLoader {

@Override
public URL getResource(String name) {
return findResource(name);
Objects.requireNonNull(name);
URL url = findResource(name);
if (url == null) {
if (getParent() != null) {
url = getParent().getResource(name);
}
}
return url;
}

@Override
public Enumeration<URL> getResources(String name) throws IOException {
return findResources(name);
Objects.requireNonNull(name);
@SuppressWarnings("unchecked")
Enumeration<URL>[] tmp = (Enumeration<URL>[]) new Enumeration<?>[2];
if (getParent()!= null) {
tmp[1] = getParent().getResources(name);
}
tmp[0] = findResources(name);
return EnumerationHelper.merge(tmp[0], tmp[1]);
}

@Override
Expand All @@ -119,7 +135,11 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE

Class<?> loadClass0(@NotNull String name, boolean resolve, boolean checkGlobal, boolean checkLibraries) throws ClassNotFoundException {
try {
return super.loadClass(name, resolve);
Class<?> result = super.loadClass(name, resolve);
// SPIGOT-6749: Library classes will appear in the above, but we don't want to return them to other plugins
if (checkGlobal || result.getClassLoader() == this) {
return result;
}
} catch (ClassNotFoundException ex) {
}

Expand Down

0 comments on commit e1946cf

Please sign in to comment.