Skip to content

Commit

Permalink
Clean up accessor a little
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed May 13, 2024
1 parent 59b21a1 commit 1e94844
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions plugin/src/main/java/com/lishid/openinv/InternalAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Constructor;

class InternalAccessor {

private final @NotNull Plugin plugin;
private final String versionPackage;
private final @Nullable String versionPackage;
private boolean supported = false;
private IPlayerDataManager playerDataManager;
private IAnySilentContainer anySilentContainer;
Expand All @@ -42,18 +43,10 @@ class InternalAccessor {
this.plugin = plugin;
this.versionPackage = getVersionPackage();
checkSupported();

/*
* TODO more loose versioning support:
* - Prefer classes if available
* - Use ASM to rewrite best class if not available? I.e. unversion packages on Paper
* - should verify OBC/NMS calls' existence!
* - could possibly be expanded to tentatively support unknown versions
*/
}

private void checkSupported() {
if ("nope".equals(this.versionPackage)) { // TODO this is a terrible way to handle things
if (versionPackage == null) {
return;
}
try {
Expand All @@ -65,18 +58,18 @@ private void checkSupported() {
} catch (Exception ignored) {}
}

private String getVersionPackage() {
private @Nullable String getVersionPackage() {
if (BukkitVersions.MINECRAFT.lessThan(Version.of(1, 20, 3))) { // Min supported version: 1.20.3
return "nope";
return null;
}
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 20, 4))) { // 1.20.3, 1.20.4
return "v1_20_R3";
}
if (BukkitVersions.MINECRAFT.greaterThanOrEqual(Version.of(1, 21))) {
return "nope";
return null;
}
if (BukkitVersions.MINECRAFT.greaterThan(Version.of(1, 20, 6))) {
return "nope"; // TODO: use at your own risk flag?
return null; // TODO: use at your own risk flag?
}
// 1.20.5, 1.20.6
return "v1_20_R4";
Expand Down

0 comments on commit 1e94844

Please sign in to comment.