Update templates, address JEP deprecations and place a few TODOs

This commit is contained in:
NotMyFault 2021-11-30 21:30:46 +01:00
parent d3aaf7acff
commit 1f975ac044
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C
12 changed files with 89 additions and 87 deletions

View File

@ -29,6 +29,7 @@ body:
description: Which server version version you using? If your server version is not listed, it is not supported. Update to a supported version first. description: Which server version version you using? If your server version is not listed, it is not supported. Update to a supported version first.
multiple: false multiple: false
options: options:
- '1.18'
- '1.17.1' - '1.17.1'
- '1.16.5' - '1.16.5'
- '1.15.2' - '1.15.2'
@ -82,7 +83,7 @@ body:
attributes: attributes:
label: Fawe Version label: Fawe Version
description: What version of Fawe are you running? (`/version FastAsyncWorldEdit`) description: What version of Fawe are you running? (`/version FastAsyncWorldEdit`)
placeholder: "For example: FastAsyncWorldEdit version 1.17-89;8c01959" placeholder: "For example: FastAsyncWorldEdit version 2.0.0-SNAPSHOT+1"
validations: validations:
required: true required: true
@ -93,7 +94,7 @@ body:
options: options:
- label: I have included a Fawe debugpaste. - label: I have included a Fawe debugpaste.
required: true required: true
- label: I am using the newest build from https://ci.athion.net/job/FastAsyncWorldEdit-1.17/ and the issue still persists. - label: I am using the newest build from https://ci.athion.net/job/FastAsyncWorldEdit-1.18/ and the issue still persists.
required: true required: true
- type: textarea - type: textarea

View File

@ -38,7 +38,7 @@ You will find:
* FastAsyncWorldEdit for Bukkit in **worldedit-bukkit/build/libs** * FastAsyncWorldEdit for Bukkit in **worldedit-bukkit/build/libs**
* the CLI version in **worldedit-cli/build/libs** * the CLI version in **worldedit-cli/build/libs**
If you want to use FastAsyncWorldEdit, use the `FastAsyncWorldEdit-1.17-<commitHash>` version obtained in **worldedit-bukkit/build/libs**. If you want to use FastAsyncWorldEdit, use the `FastAsyncWorldEdit-<identifier>` version obtained in **worldedit-bukkit/build/libs**.
(The `-#` version includes FastAsyncWorldEdit + necessary libraries.) (The `-#` version includes FastAsyncWorldEdit + necessary libraries.)

View File

@ -24,8 +24,8 @@ Java Edition required. FastAsyncWorldEdit is compatible with Bukkit, Spigot, Pap
* [Wiki](https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki) * [Wiki](https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki)
* [Report Issue](https://github.com/IntellectualSites/FastAsyncWorldEdit/issues) * [Report Issue](https://github.com/IntellectualSites/FastAsyncWorldEdit/issues)
* [Crowdin (Translations)](https://intellectualsites.crowdin.com/fastasyncworldedit) * [Crowdin (Translations)](https://intellectualsites.crowdin.com/fastasyncworldedit)
* [JavaDocs for the -bukkit module](https://ci.athion.net/job/FastAsyncWorldEdit-1.17-Bukkit-Javadocs/javadoc/) * [JavaDocs for the -bukkit module](https://javadoc.io/doc/com.fastasyncworldedit/FastAsyncWorldEdit-Bukkit/latest/index.html)
* [JavaDocs for the -core module](https://ci.athion.net/job/FastAsyncWorldEdit-1.17-Core-Javadocs/javadoc/) * [JavaDocs for the -core module](https://javadoc.io/doc/com.fastasyncworldedit/FastAsyncWorldEdit-Core/latest/index.html)
## Edit The Code ## Edit The Code

View File

@ -60,13 +60,13 @@ fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, banSlf4j: Boolean
options.encoding = "UTF-8" options.encoding = "UTF-8"
links( links(
"https://javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/", "https://javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/",
"https://jd.adventure.kyori.net/api/4.9.1/", "https://jd.adventure.kyori.net/api/4.9.3/",
"https://javadoc.io/doc/org.apache.logging.log4j/log4j-api/2.14.1/", "https://javadoc.io/doc/org.apache.logging.log4j/log4j-api/2.14.1/",
"https://javadoc.io/doc/com.google.guava/guava/21.0/", "https://javadoc.io/doc/com.google.guava/guava/31.0.1/",
"https://www.antlr.org/api/Java/", "https://www.antlr.org/api/Java/",
"https://docs.enginehub.org/javadoc/org.enginehub.piston/core/0.5.7/", "https://docs.enginehub.org/javadoc/org.enginehub.piston/core/0.5.7/",
"https://docs.enginehub.org/javadoc/org.enginehub.piston/default-impl/0.5.7/", "https://docs.enginehub.org/javadoc/org.enginehub.piston/default-impl/0.5.7/",
"https://papermc.io/javadocs/paper/1.17/", "https://papermc.io/javadocs/paper/1.18/",
"https://ci.athion.net/job/FastAsyncWorldEdit-1.17-Core-Javadocs/javadoc/" // needed for other module linking "https://ci.athion.net/job/FastAsyncWorldEdit-1.17-Core-Javadocs/javadoc/" // needed for other module linking
) )
} }

View File

@ -193,8 +193,10 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
serverWorldsField = CraftServer.class.getDeclaredField("worlds"); serverWorldsField = CraftServer.class.getDeclaredField("worlds");
serverWorldsField.setAccessible(true); serverWorldsField.setAccessible(true);
getChunkFutureMethod = ServerChunkCache.class.getDeclaredMethod("getChunkFutureMainThread", getChunkFutureMethod = ServerChunkCache.class.getDeclaredMethod(
int.class, int.class, ChunkStatus.class, boolean.class); Refraction.pickName("getChunkFutureMainThread", "c"),
int.class, int.class, ChunkStatus.class, boolean.class
);
getChunkFutureMethod.setAccessible(true); getChunkFutureMethod.setAccessible(true);
chunkProviderExecutorField = ServerChunkCache.class.getDeclaredField( chunkProviderExecutorField = ServerChunkCache.class.getDeclaredField(

View File

@ -220,8 +220,6 @@ public class WorldEditPlugin extends JavaPlugin {
// Enable metrics // Enable metrics
new Metrics(this, BSTATS_ID); new Metrics(this, BSTATS_ID);
// Check whether the server runs on 11 or greater
ServerLib.checkJavaLTS();
// Check if we are in a safe environment // Check if we are in a safe environment
ServerLib.checkUnsafeForks(); ServerLib.checkUnsafeForks();
// Check if a new build is available // Check if a new build is available

View File

@ -305,6 +305,7 @@ public class Fawe {
br.close(); br.close();
this.version = FaweVersion.tryParse(versionString, commitString, dateString); this.version = FaweVersion.tryParse(versionString, commitString, dateString);
Settings.IMP.DATE = new Date(100 + version.year, version.month, version.day).toString(); 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.BUILD = "https://ci.athion.net/job/FastAsyncWorldEdit-1.17/" + version.build;
Settings.IMP.COMMIT = "https://github.com/IntellectualSites/FastAsyncWorldEdit/commit/" + Integer.toHexString(version.hash); Settings.IMP.COMMIT = "https://github.com/IntellectualSites/FastAsyncWorldEdit/commit/" + Integer.toHexString(version.hash);
} catch (Throwable ignored) { } catch (Throwable ignored) {

View File

@ -3,6 +3,7 @@ package com.fastasyncworldedit.core;
/** /**
* An internal FAWE class not meant for public use. * An internal FAWE class not meant for public use.
**/ **/
//TODO 18 update to semver
public class FaweVersion { public class FaweVersion {
public final int year; public final int year;

View File

@ -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. * 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("\\."); String[] split = key.split("\\.");
Object instance = getInstance(split, root); Object instance = getInstance(split, root);
if (instance != null) { if (instance != null) {
@ -57,7 +57,7 @@ public class Config {
* @param key config node * @param key config node
* @param value value * @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("\\."); String[] split = key.split("\\.");
Object instance = getInstance(split, root); Object instance = getInstance(split, root);
if (instance != null) { if (instance != null) {
@ -201,7 +201,7 @@ public class Config {
/** /**
* Get the static fields in a section. * 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<>(); HashMap<String, Object> map = new HashMap<>();
for (Field field : clazz.getFields()) { for (Field field : clazz.getFields()) {
if (Modifier.isStatic(field.getModifiers())) { if (Modifier.isStatic(field.getModifiers())) {
@ -223,12 +223,11 @@ public class Config {
} }
StringBuilder m = new StringBuilder(); StringBuilder m = new StringBuilder();
for (Object obj : listValue) { 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(); return m.toString();
} }
if (value instanceof String) { if (value instanceof String stringValue) {
String stringValue = (String) value;
if (stringValue.isEmpty()) { if (stringValue.isEmpty()) {
return "''"; return "''";
} }
@ -237,11 +236,11 @@ public class Config {
return value != null ? value.toString() : "null"; 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 { try {
String CTRF = System.lineSeparator(); String CTRF = System.lineSeparator();
String spacing = StringMan.repeat(" ", indent); String spacing = StringMan.repeat(" ", indent);
HashMap<Class, Object> instances = new HashMap<>(); HashMap<Class<?>, Object> instances = new HashMap<>();
for (Field field : clazz.getFields()) { for (Field field : clazz.getFields()) {
if (field.getAnnotation(Ignore.class) != null) { if (field.getAnnotation(Ignore.class) != null) {
continue; continue;
@ -272,7 +271,7 @@ public class Config {
configBlock = new ConfigBlock(); configBlock = new ConfigBlock();
field.set(instance, configBlock); field.set(instance, configBlock);
for (String blockName : blockNames.value()) { for (String blockName : blockNames.value()) {
configBlock.put(blockName, current.newInstance()); configBlock.put(blockName, current.getDeclaredConstructor().newInstance());
} }
} }
// Save each instance // Save each instance
@ -299,11 +298,10 @@ public class Config {
} }
writer.write(spacing + toNodeName(current.getSimpleName()) + ":" + CTRF); writer.write(spacing + toNodeName(current.getSimpleName()) + ":" + CTRF);
if (value == null) { if (value == null) {
field.set(instance, value = current.newInstance()); field.set(instance, value = current.getDeclaredConstructor().newInstance());
instances.put(current, value); instances.put(current, value);
} }
save(writer, current, value, indent + 2); save(writer, current, value, indent + 2);
continue;
} else { } else {
writer.write(spacing + toNodeName(field.getName() + ": ") + toYamlString( writer.write(spacing + toNodeName(field.getName() + ": ") + toYamlString(
field.get(instance), field.get(instance),
@ -321,7 +319,7 @@ public class Config {
* *
* @param split the node (split by period) * @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); Object instance = getInstance(split, root);
if (instance == null) { if (instance == null) {
return 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. * Get the instance for a specific config node.
* *
* @param split the node (split by period) * @param split the node (split by period)
* @return The instance or null * @return The instance or null
*/ */
private Object getInstance(String[] split, Class root) { private Object getInstance(String[] split, Class<?> root) {
try { try {
Class<?> clazz = root == null ? MethodHandles.lookup().lookupClass() : root; Class<?> clazz = root == null ? MethodHandles.lookup().lookupClass() : root;
Object instance = this; Object instance = this;
while (split.length > 0) { while (split.length > 0) {
switch (split.length) { if (split.length == 1) {
case 1: return instance;
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;
} }
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) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -354,10 +354,10 @@ public class TextureUtil implements TextureHolder {
LOGGER.info("Downloading asset jar from Mojang, please wait..."); LOGGER.info("Downloading asset jar from Mojang, please wait...");
new File(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/").mkdirs(); new File(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/").mkdirs();
try (BufferedInputStream in = new BufferedInputStream( 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()); .openStream());
FileOutputStream fileOutputStream = new FileOutputStream( 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]; byte[] dataBuffer = new byte[1024];
int bytesRead; int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) { 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."); "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."); 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) { } catch (AccessControlException e) {
LOGGER.error( 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."); "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 + "/") new File(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/")
.mkdirs(); .mkdirs();
try (BufferedInputStream in = new BufferedInputStream( 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()); .openStream());
FileOutputStream fileOutputStream = new FileOutputStream( 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]; byte[] dataBuffer = new byte[1024];
int bytesRead; int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) { while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {

View File

@ -30,6 +30,7 @@ public class UpdateNotification {
try { try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder(); 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()); 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 = doc.getElementsByTagName("lastSuccessfulBuild").item(0).getFirstChild().getTextContent();
FaweVersion faweVersion = Fawe.get().getVersion(); FaweVersion faweVersion = Fawe.get().getVersion();
@ -42,8 +43,10 @@ public class UpdateNotification {
hasUpdate = true; hasUpdate = true;
int versionDifference = Integer.parseInt(UpdateNotification.faweVersion) - faweVersion.build; int versionDifference = Integer.parseInt(UpdateNotification.faweVersion) - faweVersion.build;
LOGGER.warn( 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, versionDifference,
faweVersion.toString(), faweVersion.toString(),
faweVersion.getSimpleVersionName(), faweVersion.getSimpleVersionName(),

View File

@ -72,4 +72,11 @@ public final class Constants {
*/ */
public static final int DATA_VERSION_MC_1_17 = 2724; 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
} }