diff options
Diffstat (limited to 'src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java')
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java b/src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java new file mode 100644 index 0000000..ba3cfc8 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java @@ -0,0 +1,33 @@ +package dev.mayaqq.ygasi.util; + +import net.minecraft.advancement.Advancement; +import net.minecraft.advancement.PlayerAdvancementTracker; +import net.minecraft.server.ServerAdvancementLoader; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; + +import static dev.mayaqq.ygasi.Ygasi.LOGGER; + +public class YgasiUtils { + public static void grantAdvancementCriterion(@NotNull ServerPlayerEntity serverPlayerEntity, Identifier advancementIdentifier, String criterion) { + if (serverPlayerEntity.getServer() == null) { + return; + } + ServerAdvancementLoader sal = serverPlayerEntity.getServer().getAdvancementLoader(); + PlayerAdvancementTracker tracker = serverPlayerEntity.getAdvancementTracker(); + + Advancement advancement = sal.get(advancementIdentifier); + if (advancement == null) { + LOGGER.error("Trying to grant a criterion \"" + criterion + "\" for an advancement that does not exist: " + advancementIdentifier); + } else { + if (!tracker.getProgress(advancement).isDone()) { + tracker.grantCriterion(advancement, criterion); + } + } + } + + public static boolean getAdvancementProgress(ServerPlayerEntity player, String advancement) { + return player.getAdvancementTracker().getProgress(player.getServer().getAdvancementLoader().get(new Identifier("minecraft", "ygasi/" + advancement))).isDone(); + } +}
\ No newline at end of file |