From 1f975ac0447740a99018bf0b66143f5c244fb092 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Tue, 30 Nov 2021 21:30:46 +0100 Subject: [PATCH] Update templates, address JEP deprecations and place a few TODOs --- .github/ISSUE_TEMPLATE/bug_report.yml | 5 +- COMPILING.md | 2 +- README.md | 4 +- buildSrc/src/main/kotlin/CommonJavaConfig.kt | 6 +- .../ext/fawe/v1_18_R1/PaperweightAdapter.java | 6 +- .../worldedit/bukkit/WorldEditPlugin.java | 2 - .../com/fastasyncworldedit/core/Fawe.java | 1 + .../fastasyncworldedit/core/FaweVersion.java | 1 + .../core/configuration/Config.java | 126 ++++++++---------- .../core/util/TextureUtil.java | 9 +- .../core/util/UpdateNotification.java | 7 +- .../sk89q/worldedit/internal/Constants.java | 7 + 12 files changed, 89 insertions(+), 87 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index e9824a0f1..289b5db07 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -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. multiple: false options: + - '1.18' - '1.17.1' - '1.16.5' - '1.15.2' @@ -82,7 +83,7 @@ body: attributes: label: Fawe Version 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: required: true @@ -93,7 +94,7 @@ body: options: - label: I have included a Fawe debugpaste. 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 - type: textarea diff --git a/COMPILING.md b/COMPILING.md index 0f2f9faa4..31703d4f5 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -38,7 +38,7 @@ You will find: * FastAsyncWorldEdit for Bukkit in **worldedit-bukkit/build/libs** * the CLI version in **worldedit-cli/build/libs** -If you want to use FastAsyncWorldEdit, use the `FastAsyncWorldEdit-1.17-` version obtained in **worldedit-bukkit/build/libs**. +If you want to use FastAsyncWorldEdit, use the `FastAsyncWorldEdit-` version obtained in **worldedit-bukkit/build/libs**. (The `-#` version includes FastAsyncWorldEdit + necessary libraries.) diff --git a/README.md b/README.md index d5f0ffe60..2ff28be7f 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Java Edition required. FastAsyncWorldEdit is compatible with Bukkit, Spigot, Pap * [Wiki](https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki) * [Report Issue](https://github.com/IntellectualSites/FastAsyncWorldEdit/issues) * [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 -core module](https://ci.athion.net/job/FastAsyncWorldEdit-1.17-Core-Javadocs/javadoc/) +* [JavaDocs for the -bukkit module](https://javadoc.io/doc/com.fastasyncworldedit/FastAsyncWorldEdit-Bukkit/latest/index.html) +* [JavaDocs for the -core module](https://javadoc.io/doc/com.fastasyncworldedit/FastAsyncWorldEdit-Core/latest/index.html) ## Edit The Code diff --git a/buildSrc/src/main/kotlin/CommonJavaConfig.kt b/buildSrc/src/main/kotlin/CommonJavaConfig.kt index 21c059715..a01093e68 100644 --- a/buildSrc/src/main/kotlin/CommonJavaConfig.kt +++ b/buildSrc/src/main/kotlin/CommonJavaConfig.kt @@ -60,13 +60,13 @@ fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, banSlf4j: Boolean options.encoding = "UTF-8" links( "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/com.google.guava/guava/21.0/", + "https://javadoc.io/doc/com.google.guava/guava/31.0.1/", "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/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 ) } diff --git a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_18_R1/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_18_R1/PaperweightAdapter.java index a8ce1e036..9522d3ced 100644 --- a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_18_R1/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_18_R1/PaperweightAdapter.java @@ -193,8 +193,10 @@ public final class PaperweightAdapter implements BukkitImplAdapter { serverWorldsField = CraftServer.class.getDeclaredField("worlds"); serverWorldsField.setAccessible(true); - getChunkFutureMethod = ServerChunkCache.class.getDeclaredMethod("getChunkFutureMainThread", - int.class, int.class, ChunkStatus.class, boolean.class); + getChunkFutureMethod = ServerChunkCache.class.getDeclaredMethod( + Refraction.pickName("getChunkFutureMainThread", "c"), + int.class, int.class, ChunkStatus.class, boolean.class + ); getChunkFutureMethod.setAccessible(true); chunkProviderExecutorField = ServerChunkCache.class.getDeclaredField( diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 6e93f0c19..75946fe01 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -220,8 +220,6 @@ public class WorldEditPlugin extends JavaPlugin { // Enable metrics new Metrics(this, BSTATS_ID); - // Check whether the server runs on 11 or greater - ServerLib.checkJavaLTS(); // Check if we are in a safe environment ServerLib.checkUnsafeForks(); // Check if a new build is available diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java index 01b602e24..46f934d4a 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java @@ -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) { diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweVersion.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweVersion.java index 344a9d401..811aaad41 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweVersion.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweVersion.java @@ -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; diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/configuration/Config.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/configuration/Config.java index aa6d4dda0..83dd34d95 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/configuration/Config.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/configuration/Config.java @@ -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 get(String key, Class root) { + private 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 getFields(Class clazz) { + private Map getFields(Class clazz) { HashMap 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 instances = new HashMap<>(); + HashMap, 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(); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/TextureUtil.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/TextureUtil.java index ead803939..747ed625b 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/TextureUtil.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/TextureUtil.java @@ -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) { diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/UpdateNotification.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/UpdateNotification.java index 14a987396..97efe95b4 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/UpdateNotification.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/UpdateNotification.java @@ -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(), diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java index 713458e65..a55b90f36 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java @@ -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 + }