Add classes with the correct minor version to the start of the adapter candidates list

This commit is contained in:
dordsor21 2021-12-22 12:19:20 +00:00
parent 1715f35341
commit 34f971c729
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.bukkit.adapter; package com.sk89q.worldedit.bukkit.adapter;
import com.fastasyncworldedit.bukkit.util.MinecraftVersion;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.util.io.Closer; import com.sk89q.worldedit.util.io.Closer;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -39,6 +40,8 @@ public class BukkitImplLoader {
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private final List<String> adapterCandidates = new ArrayList<>(); private final List<String> adapterCandidates = new ArrayList<>();
private final String minorMCVersion = String.valueOf(new MinecraftVersion().getMinor());
private int zeroth = 0;
private String customCandidate; private String customCandidate;
private static final String SEARCH_PACKAGE = "com.sk89q.worldedit.bukkit.adapter.impl.fawe"; private static final String SEARCH_PACKAGE = "com.sk89q.worldedit.bukkit.adapter.impl.fawe";
@ -73,6 +76,7 @@ public class BukkitImplLoader {
String className = System.getProperty("worldedit.bukkit.adapter"); String className = System.getProperty("worldedit.bukkit.adapter");
if (className != null) { if (className != null) {
customCandidate = className; customCandidate = className;
zeroth = 1;
adapterCandidates.add(className); adapterCandidates.add(className);
LOGGER.info("-Dworldedit.bukkit.adapter used to add " + className + " to the list of available Bukkit adapters"); LOGGER.info("-Dworldedit.bukkit.adapter used to add " + className + " to the list of available Bukkit adapters");
} }
@ -101,7 +105,11 @@ public class BukkitImplLoader {
int beginIndex = 0; int beginIndex = 0;
int endIndex = className.length() - CLASS_SUFFIX.length(); int endIndex = className.length() - CLASS_SUFFIX.length();
className = className.substring(beginIndex, endIndex); className = className.substring(beginIndex, endIndex);
adapterCandidates.add(className); if (className.contains(minorMCVersion)) {
adapterCandidates.add(zeroth, className);
} else {
adapterCandidates.add(className);
}
} }
} finally { } finally {
closer.close(); closer.close();
@ -142,7 +150,11 @@ public class BukkitImplLoader {
int beginIndex = 0; int beginIndex = 0;
int endIndex = resource.length() - CLASS_SUFFIX.length(); int endIndex = resource.length() - CLASS_SUFFIX.length();
String className = resource.substring(beginIndex, endIndex); String className = resource.substring(beginIndex, endIndex);
adapterCandidates.add(className); if (className.contains(minorMCVersion)) {
adapterCandidates.add(zeroth, className);
} else {
adapterCandidates.add(className);
}
} }
} }