Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Advancement: fix NMS 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Nov 13, 2023
1 parent 916d927 commit 7866cec
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Optional;

// Thanks, @CroaBeast, for these methods
// Source https://github.com/CroaBeast/AdvancementInfo
Expand All @@ -20,15 +21,31 @@ public class FAdvancement {

private String title;

private static final boolean IS_19_4;
private static final boolean IS_20_2;

static {
double value = NMSUtil.getVersion();
IS_19_4 = value >= 19.4;
IS_20_2 = value >= 20.2;
}

public FAdvancement(@NotNull Advancement adv) {

Class<?> craftClass = NMSUtil.getBukkitClass("advancement.CraftAdvancement");
if (craftClass == null) return;

Object nmsAdv = NMSUtil.getObject(craftClass, craftClass.cast(adv), "getHandle");
Object display = NMSUtil.getObject(nmsAdv, is_19_4() ? "d" : "c");
if (IS_20_2) nmsAdv = NMSUtil.getObject(nmsAdv, "b");

Object display = NMSUtil.getObject(nmsAdv, IS_19_4 ? "d" : "c");
if (display == null) return;

if (IS_20_2) {
Optional<?> o = ((Optional<?>) display);
if (o.isPresent()) display = o.get();
}

Object rawTitle = NMSUtil.getObject(display, "a");
Object rawDesc = NMSUtil.getObject(display, "b");

Expand All @@ -51,10 +68,6 @@ public FAdvancement(@NotNull Advancement adv) {
}
}

private static boolean is_19_4() {
return NMSUtil.getVersion() >= 19.4;
}

private static boolean getBool(String string) {
return string.matches("(?i)true|false") && string.matches("(?i)true");
}
Expand Down

0 comments on commit 7866cec

Please sign in to comment.