From f7670f7812d47868932a698bcca5a3c154089caa Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sun, 28 Apr 2019 18:47:28 +1000 Subject: [PATCH] Temporary fix for forge having terrible classpath issues. --- .../worldedit/util/io/ResourceLoader.java | 43 +++++++++++++++++++ .../world/registry/BundledBlockData.java | 3 +- .../world/registry/BundledItemData.java | 3 +- .../world/registry/LegacyMapper.java | 3 +- 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ResourceLoader.java diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ResourceLoader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ResourceLoader.java new file mode 100644 index 000000000..09ac4724f --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ResourceLoader.java @@ -0,0 +1,43 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.io; + +import java.io.IOException; +import java.net.URL; + +public class ResourceLoader { + + private ResourceLoader() { + } + + public static URL getResource(Class clazz, String name) throws IOException { + URL url = clazz.getResource(name); + if (url == null) { + try { + return new URL("modjar://worldedit/" + clazz.getName().substring(0, clazz.getName().lastIndexOf('.')).replace(".", "/") + "/" + + name); + } catch (Exception e) { + // Not forge. + } + throw new IOException("Could not find " + name); + } + return url; + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java index 4dffdb38f..76cd902ef 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java @@ -25,6 +25,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.gson.VectorAdapter; +import com.sk89q.worldedit.util.io.ResourceLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,7 +75,7 @@ public class BundledBlockData { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); Gson gson = gsonBuilder.create(); - URL url = BundledBlockData.class.getResource("blocks.json"); + URL url = ResourceLoader.getResource(BundledBlockData.class, "blocks.json"); if (url == null) { throw new IOException("Could not find blocks.json"); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java index 4bdac0c8a..4e1af0422 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java @@ -25,6 +25,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.gson.VectorAdapter; +import com.sk89q.worldedit.util.io.ResourceLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,7 +75,7 @@ public class BundledItemData { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); Gson gson = gsonBuilder.create(); - URL url = BundledItemData.class.getResource("items.json"); + URL url = ResourceLoader.getResource(BundledItemData.class,"items.json"); if (url == null) { throw new IOException("Could not find items.json"); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index a41814abc..05acbeb1d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -29,6 +29,7 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.gson.VectorAdapter; +import com.sk89q.worldedit.util.io.ResourceLoader; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; @@ -74,7 +75,7 @@ public class LegacyMapper { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); Gson gson = gsonBuilder.disableHtmlEscaping().create(); - URL url = LegacyMapper.class.getResource("legacy.json"); + URL url = ResourceLoader.getResource(LegacyMapper.class, "legacy.json"); if (url == null) { throw new IOException("Could not find legacy.json"); }