mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 04:23:54 +00:00
Update templates, address JEP deprecations and place a few TODOs
This commit is contained in:
@ -305,6 +305,7 @@ public class Fawe {
|
||||
br.close();
|
||||
this.version = FaweVersion.tryParse(versionString, commitString, dateString);
|
||||
Settings.IMP.DATE = new Date(100 + version.year, version.month, version.day).toString();
|
||||
//TODO 1.18 revisit
|
||||
Settings.IMP.BUILD = "https://ci.athion.net/job/FastAsyncWorldEdit-1.17/" + version.build;
|
||||
Settings.IMP.COMMIT = "https://github.com/IntellectualSites/FastAsyncWorldEdit/commit/" + Integer.toHexString(version.hash);
|
||||
} catch (Throwable ignored) {
|
||||
|
@ -3,6 +3,7 @@ package com.fastasyncworldedit.core;
|
||||
/**
|
||||
* An internal FAWE class not meant for public use.
|
||||
**/
|
||||
//TODO 18 update to semver
|
||||
public class FaweVersion {
|
||||
|
||||
public final int year;
|
||||
|
@ -34,7 +34,7 @@ public class Config {
|
||||
/**
|
||||
* Get the value for a node. Probably throws some error if you try to get a non-existent key.
|
||||
*/
|
||||
private <T> T get(String key, Class root) {
|
||||
private <T> T get(String key, Class<?> root) {
|
||||
String[] split = key.split("\\.");
|
||||
Object instance = getInstance(split, root);
|
||||
if (instance != null) {
|
||||
@ -57,7 +57,7 @@ public class Config {
|
||||
* @param key config node
|
||||
* @param value value
|
||||
*/
|
||||
private void set(String key, Object value, Class root) {
|
||||
private void set(String key, Object value, Class<?> root) {
|
||||
String[] split = key.split("\\.");
|
||||
Object instance = getInstance(split, root);
|
||||
if (instance != null) {
|
||||
@ -201,7 +201,7 @@ public class Config {
|
||||
/**
|
||||
* Get the static fields in a section.
|
||||
*/
|
||||
private Map<String, Object> getFields(Class clazz) {
|
||||
private Map<String, Object> getFields(Class<?> clazz) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
for (Field field : clazz.getFields()) {
|
||||
if (Modifier.isStatic(field.getModifiers())) {
|
||||
@ -223,12 +223,11 @@ public class Config {
|
||||
}
|
||||
StringBuilder m = new StringBuilder();
|
||||
for (Object obj : listValue) {
|
||||
m.append(System.lineSeparator() + spacing + "- " + toYamlString(obj, spacing));
|
||||
m.append(System.lineSeparator()).append(spacing).append("- ").append(toYamlString(obj, spacing));
|
||||
}
|
||||
return m.toString();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
String stringValue = (String) value;
|
||||
if (value instanceof String stringValue) {
|
||||
if (stringValue.isEmpty()) {
|
||||
return "''";
|
||||
}
|
||||
@ -237,11 +236,11 @@ public class Config {
|
||||
return value != null ? value.toString() : "null";
|
||||
}
|
||||
|
||||
private void save(PrintWriter writer, Class clazz, final Object instance, int indent) {
|
||||
private void save(PrintWriter writer, Class<?> clazz, final Object instance, int indent) {
|
||||
try {
|
||||
String CTRF = System.lineSeparator();
|
||||
String spacing = StringMan.repeat(" ", indent);
|
||||
HashMap<Class, Object> instances = new HashMap<>();
|
||||
HashMap<Class<?>, Object> instances = new HashMap<>();
|
||||
for (Field field : clazz.getFields()) {
|
||||
if (field.getAnnotation(Ignore.class) != null) {
|
||||
continue;
|
||||
@ -272,7 +271,7 @@ public class Config {
|
||||
configBlock = new ConfigBlock();
|
||||
field.set(instance, configBlock);
|
||||
for (String blockName : blockNames.value()) {
|
||||
configBlock.put(blockName, current.newInstance());
|
||||
configBlock.put(blockName, current.getDeclaredConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
// Save each instance
|
||||
@ -299,11 +298,10 @@ public class Config {
|
||||
}
|
||||
writer.write(spacing + toNodeName(current.getSimpleName()) + ":" + CTRF);
|
||||
if (value == null) {
|
||||
field.set(instance, value = current.newInstance());
|
||||
field.set(instance, value = current.getDeclaredConstructor().newInstance());
|
||||
instances.put(current, value);
|
||||
}
|
||||
save(writer, current, value, indent + 2);
|
||||
continue;
|
||||
} else {
|
||||
writer.write(spacing + toNodeName(field.getName() + ": ") + toYamlString(
|
||||
field.get(instance),
|
||||
@ -321,7 +319,7 @@ public class Config {
|
||||
*
|
||||
* @param split the node (split by period)
|
||||
*/
|
||||
private Field getField(String[] split, Class root) {
|
||||
private Field getField(String[] split, Class<?> root) {
|
||||
Object instance = getInstance(split, root);
|
||||
if (instance == null) {
|
||||
return null;
|
||||
@ -352,74 +350,64 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
private Object getInstance(Object instance, Class clazz) throws IllegalAccessException, InstantiationException {
|
||||
try {
|
||||
Field instanceField = clazz.getDeclaredField(clazz.getSimpleName());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
return clazz.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance for a specific config node.
|
||||
*
|
||||
* @param split the node (split by period)
|
||||
* @return The instance or null
|
||||
*/
|
||||
private Object getInstance(String[] split, Class root) {
|
||||
private Object getInstance(String[] split, Class<?> root) {
|
||||
try {
|
||||
Class<?> clazz = root == null ? MethodHandles.lookup().lookupClass() : root;
|
||||
Object instance = this;
|
||||
while (split.length > 0) {
|
||||
switch (split.length) {
|
||||
case 1:
|
||||
return instance;
|
||||
default:
|
||||
Class found = null;
|
||||
Class<?>[] classes = clazz.getDeclaredClasses();
|
||||
for (Class current : classes) {
|
||||
if (StringMan.isEqual(current.getSimpleName(), toFieldName(split[0]))) {
|
||||
found = current;
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Field instanceField = clazz.getDeclaredField(toFieldName(split[0]));
|
||||
setAccessible(instanceField);
|
||||
if (instanceField.getType() != ConfigBlock.class) {
|
||||
Object value = instanceField.get(instance);
|
||||
if (value == null) {
|
||||
value = found.newInstance();
|
||||
instanceField.set(instance, value);
|
||||
}
|
||||
clazz = found;
|
||||
instance = value;
|
||||
split = Arrays.copyOfRange(split, 1, split.length);
|
||||
continue;
|
||||
}
|
||||
ConfigBlock value = (ConfigBlock) instanceField.get(instance);
|
||||
if (value == null) {
|
||||
value = new ConfigBlock();
|
||||
instanceField.set(instance, value);
|
||||
}
|
||||
instance = value.get(split[1]);
|
||||
if (instance == null) {
|
||||
instance = found.newInstance();
|
||||
value.put(split[1], instance);
|
||||
}
|
||||
clazz = found;
|
||||
split = Arrays.copyOfRange(split, 2, split.length);
|
||||
continue;
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
}
|
||||
if (found != null) {
|
||||
split = Arrays.copyOfRange(split, 1, split.length);
|
||||
clazz = found;
|
||||
instance = clazz.newInstance();
|
||||
continue;
|
||||
}
|
||||
return null;
|
||||
if (split.length == 1) {
|
||||
return instance;
|
||||
}
|
||||
Class<?> found = null;
|
||||
Class<?>[] classes = clazz.getDeclaredClasses();
|
||||
for (Class<?> current : classes) {
|
||||
if (StringMan.isEqual(current.getSimpleName(), toFieldName(split[0]))) {
|
||||
found = current;
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Field instanceField = clazz.getDeclaredField(toFieldName(split[0]));
|
||||
setAccessible(instanceField);
|
||||
if (instanceField.getType() != ConfigBlock.class) {
|
||||
Object value = instanceField.get(instance);
|
||||
if (value == null) {
|
||||
value = found.getDeclaredConstructor().newInstance();
|
||||
instanceField.set(instance, value);
|
||||
}
|
||||
clazz = found;
|
||||
instance = value;
|
||||
split = Arrays.copyOfRange(split, 1, split.length);
|
||||
continue;
|
||||
}
|
||||
ConfigBlock value = (ConfigBlock) instanceField.get(instance);
|
||||
if (value == null) {
|
||||
value = new ConfigBlock();
|
||||
instanceField.set(instance, value);
|
||||
}
|
||||
instance = value.get(split[1]);
|
||||
if (instance == null) {
|
||||
instance = found.getDeclaredConstructor().newInstance();
|
||||
value.put(split[1], instance);
|
||||
}
|
||||
clazz = found;
|
||||
split = Arrays.copyOfRange(split, 2, split.length);
|
||||
continue;
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
}
|
||||
if (found != null) {
|
||||
split = Arrays.copyOfRange(split, 1, split.length);
|
||||
clazz = found;
|
||||
instance = clazz.getDeclaredConstructor().newInstance();
|
||||
continue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
@ -354,10 +354,10 @@ public class TextureUtil implements TextureHolder {
|
||||
LOGGER.info("Downloading asset jar from Mojang, please wait...");
|
||||
new File(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/").mkdirs();
|
||||
try (BufferedInputStream in = new BufferedInputStream(
|
||||
new URL("https://launcher.mojang.com/v1/objects/8d9b65467c7913fcf6f5b2e729d44a1e00fde150/client.jar")
|
||||
new URL("https://launcher.mojang.com/v1/objects/d49eb6caed53d23927648c97451503442f9e26fd/client.jar")
|
||||
.openStream());
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(
|
||||
Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/1.17.1.jar")) {
|
||||
Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/1.18.jar")) {
|
||||
byte[] dataBuffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
|
||||
@ -370,6 +370,7 @@ public class TextureUtil implements TextureHolder {
|
||||
"folder with a `.minecraft/versions` jar in it.");
|
||||
LOGGER.error("If the file exists, please make sure the server has read access to the directory.");
|
||||
}
|
||||
//TODO 1.18 AccessControlException is deprecated and scheduled for removal as of Java 17. Exchange on sight to be prepared for future releases
|
||||
} catch (AccessControlException e) {
|
||||
LOGGER.error(
|
||||
"Could not download asset jar. It's likely your file permission are setup improperly and do not allow fetching data from the Mojang servers.");
|
||||
@ -811,10 +812,10 @@ public class TextureUtil implements TextureHolder {
|
||||
new File(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/")
|
||||
.mkdirs();
|
||||
try (BufferedInputStream in = new BufferedInputStream(
|
||||
new URL("https://launcher.mojang.com/v1/objects/8d9b65467c7913fcf6f5b2e729d44a1e00fde150/client.jar")
|
||||
new URL("https://launcher.mojang.com/v1/objects/d49eb6caed53d23927648c97451503442f9e26fd/client.jar")
|
||||
.openStream());
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(
|
||||
Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/1.17.1.jar")) {
|
||||
Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/1.18.jar")) {
|
||||
byte[] dataBuffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
|
||||
|
@ -30,6 +30,7 @@ public class UpdateNotification {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
//TODO 1.18 revisit and update to semver parsing after updating FaweVersion.java
|
||||
Document doc = db.parse(new URL("https://ci.athion.net/job/FastAsyncWorldEdit-1.17/api/xml/").openStream());
|
||||
faweVersion = doc.getElementsByTagName("lastSuccessfulBuild").item(0).getFirstChild().getTextContent();
|
||||
FaweVersion faweVersion = Fawe.get().getVersion();
|
||||
@ -42,8 +43,10 @@ public class UpdateNotification {
|
||||
hasUpdate = true;
|
||||
int versionDifference = Integer.parseInt(UpdateNotification.faweVersion) - faweVersion.build;
|
||||
LOGGER.warn(
|
||||
"An update for FastAsyncWorldEdit is available. You are {} build(s) out of date.\nYou are running " +
|
||||
"version {}, the latest version is {}-{}.\nUpdate at https://www.spigotmc.org/resources/13932/",
|
||||
"""
|
||||
An update for FastAsyncWorldEdit is available. You are {} build(s) out of date.
|
||||
You are running version {}, the latest version is {}-{}.
|
||||
Update at https://www.spigotmc.org/resources/13932/""",
|
||||
versionDifference,
|
||||
faweVersion.toString(),
|
||||
faweVersion.getSimpleVersionName(),
|
||||
|
@ -72,4 +72,11 @@ public final class Constants {
|
||||
*/
|
||||
public static final int DATA_VERSION_MC_1_17 = 2724;
|
||||
|
||||
//FAWE start - add data version for 1.18
|
||||
/**
|
||||
* The DataVersion for Minecraft 1.18
|
||||
*/
|
||||
public static final int DATA_VERSION_MC_1_18 = 2860;
|
||||
//FAWE end
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user