Fixed hundreds of small issues, code improvements, typos, ...
This commit is contained in:
@@ -32,7 +32,7 @@ public class Json {
|
||||
boolean isFloat = value.contains(".");
|
||||
|
||||
if (isFloat) {
|
||||
// if float, will only parse to Double
|
||||
// if is float, will only parse to Double
|
||||
// (see org.yaml.snakeyaml.constructor.SafeConstructor.ConstructYamlFloat)
|
||||
try {
|
||||
Double d = Double.valueOf(value);
|
||||
|
@@ -134,30 +134,30 @@ public class ThrowableAdapter implements JsonSerializer<Throwable>, JsonDeserial
|
||||
}
|
||||
|
||||
private static <T extends Throwable> ThrowableSubAdapter<T> defaultSubAdapter(Class<T> clazz) {
|
||||
BiFunction<String, Throwable, T> constructor = null;
|
||||
BiFunction<String, Throwable, T> constructionFunction = null;
|
||||
|
||||
// try (String, Throwable) constructor
|
||||
try {
|
||||
Constructor<T> constr = clazz.getConstructor(String.class, Throwable.class);
|
||||
if (constr.canAccess(null)) {
|
||||
constructor = (m, t) -> ThrowableUtil.wrapReflectEx(() -> constr.newInstance(m, t));
|
||||
Constructor<T> constructor = clazz.getConstructor(String.class, Throwable.class);
|
||||
if (constructor.canAccess(null)) {
|
||||
constructionFunction = (m, t) -> ThrowableUtil.wrapReflectEx(() -> constructor.newInstance(m, t));
|
||||
}
|
||||
} catch (ReflectiveOperationException ignore) { }
|
||||
|
||||
// try (String) constructor
|
||||
try {
|
||||
Constructor<T> constr = clazz.getConstructor(String.class);
|
||||
if (constr.canAccess(null)) {
|
||||
constructor = ThrowableSubAdapter.messageOnly((m) -> ThrowableUtil.wrapReflectEx(() -> constr.newInstance(m)));
|
||||
Constructor<T> constructor = clazz.getConstructor(String.class);
|
||||
if (constructor.canAccess(null)) {
|
||||
constructionFunction = ThrowableSubAdapter.messageOnly((m) -> ThrowableUtil.wrapReflectEx(() -> constructor.newInstance(m)));
|
||||
}
|
||||
} catch (ReflectiveOperationException ignore) { }
|
||||
|
||||
if (constructor == null) {
|
||||
if (constructionFunction == null) {
|
||||
Log.warning("Provided Throwable class '" + clazz + "' does not have any of those constructors or are not accessible: (String, Throwable), (String).");
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ThrowableSubAdapter<>(constructor);
|
||||
return new ThrowableSubAdapter<>(constructionFunction);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -37,8 +37,8 @@ public class MinecraftVersionUtil {
|
||||
|
||||
/**
|
||||
* Decompose a version string into a series of integers.
|
||||
* @param v a string representation of a version (eg. 1.19.1).
|
||||
* @return an array of int representing the provided version (eg. [1, 19, 1]).
|
||||
* @param v a string representation of a version (e.g. 1.19.1).
|
||||
* @return an array of int representing the provided version (e.g. [1, 19, 1]).
|
||||
*/
|
||||
public static int[] decomposedVersion(String v) {
|
||||
try {
|
||||
|
@@ -68,12 +68,12 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
|
||||
private static void init() {
|
||||
// try online source first
|
||||
try {
|
||||
HttpResponse<String> response = HttpClient.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(5))
|
||||
.build()
|
||||
.send(HttpRequest.newBuilder(URI.create(ONLINE_DATA_URL)).build(),
|
||||
BodyHandlers.ofString()
|
||||
try (HttpClient cl = HttpClient.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(5))
|
||||
.build()) {
|
||||
HttpResponse<String> response = cl.send(
|
||||
HttpRequest.newBuilder(URI.create(ONLINE_DATA_URL)).build(),
|
||||
BodyHandlers.ofString()
|
||||
);
|
||||
if (response.statusCode() == 200) {
|
||||
MinecraftVersionList data = Json.gson.fromJson(response.body(), MinecraftVersionList.class);
|
||||
@@ -123,7 +123,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
|
||||
/**
|
||||
* Gets the {@link ProtocolVersion} associated with the provided Minecraft version.
|
||||
* @param version The Minecraft version, in the format "X.X[.X]" (eg. "1.17" or "1.8.8").
|
||||
* @param version The Minecraft version, in the format "X.X[.X]" (e.g. "1.17" or "1.8.8").
|
||||
* @return an instance of {@link ProtocolVersion}.
|
||||
*/
|
||||
public static ProtocolVersion ofVersion(String version) {
|
||||
|
Reference in New Issue
Block a user