Change how I grab plugin.yml from jars to fix an error with weird classloading
This commit is contained in:
parent
00507a1194
commit
28a99d91ff
@ -70,7 +70,7 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
saveResource("disguises.yml", false);
|
saveResource("disguises.yml", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
YamlConfiguration pluginYml = ReflectionManager.getPluginYAML(getClassLoader());
|
YamlConfiguration pluginYml = ReflectionManager.getPluginYAML(getFile());
|
||||||
buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
|
buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
|
||||||
|
|
||||||
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
|
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
|
||||||
|
@ -128,7 +128,7 @@ public class LibsPremium {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the plugin.yml from the jar file
|
// Fetch the plugin.yml from the jar file
|
||||||
YamlConfiguration config = ReflectionManager.getPluginYAML(cl);
|
YamlConfiguration config = ReflectionManager.getPluginYAML(file);
|
||||||
// No checks for null config as the correct error will be thrown on access
|
// No checks for null config as the correct error will be thrown on access
|
||||||
|
|
||||||
Boolean premium;
|
Boolean premium;
|
||||||
|
@ -16,22 +16,17 @@ import me.libraryaddict.disguise.utilities.LibsPremium;
|
|||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.plugin.InvalidDescriptionException;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -39,6 +34,8 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ReflectionManager {
|
public class ReflectionManager {
|
||||||
@ -159,27 +156,24 @@ public class ReflectionManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YamlConfiguration getPluginYAML(ClassLoader loader) {
|
/**
|
||||||
try {
|
* Copied from Bukkit
|
||||||
URL url = loader.getResource("plugin.yml");
|
*/
|
||||||
|
public static YamlConfiguration getPluginYAML(File file) {
|
||||||
|
try (JarFile jar = new JarFile(file)) {
|
||||||
|
JarEntry entry = jar.getJarEntry("plugin.yml");
|
||||||
|
|
||||||
if (url == null) {
|
try (InputStream stream = jar.getInputStream(entry)) {
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
URLConnection connection = url.openConnection();
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
|
|
||||||
try (InputStream stream = connection.getInputStream()) {
|
|
||||||
YamlConfiguration config = new YamlConfiguration();
|
YamlConfiguration config = new YamlConfiguration();
|
||||||
|
|
||||||
config.loadFromString(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
String configString = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
||||||
.collect(Collectors.joining("\n")));
|
.collect(Collectors.joining("\n"));
|
||||||
|
config.loadFromString(configString);
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex) {
|
||||||
catch (IOException | InvalidConfigurationException ex) {
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user