Use slightly different YAML loading, try fix an issue on a Chinese user's server
This commit is contained in:
parent
a309b24004
commit
00507a1194
@ -70,7 +70,7 @@ public class LibsDisguises extends JavaPlugin {
|
||||
saveResource("disguises.yml", false);
|
||||
}
|
||||
|
||||
YamlConfiguration pluginYml = ReflectionManager.getPluginYaml(getClassLoader());
|
||||
YamlConfiguration pluginYml = ReflectionManager.getPluginYAML(getClassLoader());
|
||||
buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
|
||||
|
||||
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
|
||||
|
@ -128,7 +128,7 @@ public class LibsPremium {
|
||||
}
|
||||
|
||||
// Fetch the plugin.yml from the jar file
|
||||
YamlConfiguration config = ReflectionManager.getPluginYaml(cl);
|
||||
YamlConfiguration config = ReflectionManager.getPluginYAML(cl);
|
||||
// No checks for null config as the correct error will be thrown on access
|
||||
|
||||
Boolean premium;
|
||||
|
@ -30,6 +30,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@ -157,16 +159,28 @@ public class ReflectionManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static YamlConfiguration getPluginYaml(ClassLoader loader) {
|
||||
try (InputStream stream = loader.getResourceAsStream("plugin.yml")) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.loadFromString(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
||||
.collect(Collectors.joining("\n")));
|
||||
public static YamlConfiguration getPluginYAML(ClassLoader loader) {
|
||||
try {
|
||||
URL url = loader.getResource("plugin.yml");
|
||||
|
||||
return config;
|
||||
if (url == null) {
|
||||
return null;
|
||||
} else {
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setUseCaches(false);
|
||||
|
||||
try (InputStream stream = connection.getInputStream()) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
config.loadFromString(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
||||
.collect(Collectors.joining("\n")));
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
catch (IOException | InvalidConfigurationException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -7,7 +7,7 @@ build-number: ${build.number}
|
||||
author: libraryaddict
|
||||
authors: [Byteflux, Navid K.]
|
||||
depend: [ProtocolLib]
|
||||
api-version: 1.13
|
||||
api-version: '1.13'
|
||||
commands:
|
||||
libsdisguises:
|
||||
aliases: [libsdisg, ld]
|
||||
|
Loading…
Reference in New Issue
Block a user