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

Commit

Permalink
Add 1.20.3 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Mitchell authored Dec 7, 2023
1 parent 19b47fd commit 37c77b4
Show file tree
Hide file tree
Showing 10 changed files with 1,684 additions and 3 deletions.
33 changes: 33 additions & 0 deletions nms/1_20_R3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import io.github.patrick.gradle.remapper.RemapTask

plugins {
id("io.github.patrick.remapper") version "1.4.0"
}

val mcVersion = "1.20.3"

dependencies {
api(project(":superadvancements-abstract"))

compileOnly("org.spigotmc:spigot:$mcVersion-R0.1-SNAPSHOT:remapped-mojang")
testImplementation("org.spigotmc:spigot:$mcVersion-R0.1-SNAPSHOT:remapped-mojang")
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

tasks {
assemble {
dependsOn("remap")
}

remap {
dependsOn("shadowJar")

version.set(mcVersion)
action.set(RemapTask.Action.MOJANG_TO_SPIGOT)
archiveName.set("${project.name}-${project.version}.jar")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.gamercoder215.superadvancements.v1_20_R3;

import me.gamercoder215.superadvancements.advancement.criteria.ACriteriaProgress;
import net.minecraft.advancements.CriterionProgress;
import org.jetbrains.annotations.Nullable;

import java.util.Date;

final class ACriteriaProgress1_20_R3 implements ACriteriaProgress {

private final CriterionProgress handle;

ACriteriaProgress1_20_R3(CriterionProgress handle) {
this.handle = handle;
}

@Override
public @Nullable Date getObtained() {
return Date.from(handle.getObtained());
}

@Override
public boolean isDone() {
return handle.isDone();
}

@Override
public void grant() {
handle.grant();
}

@Override
public void revoke() {
handle.revoke();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package me.gamercoder215.superadvancements.v1_20_R3;

import me.gamercoder215.superadvancements.advancement.AProgress;
import me.gamercoder215.superadvancements.advancement.criteria.ACriteriaProgress;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.advancements.CriterionProgress;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.util.Map;
import java.util.stream.Collectors;

import static me.gamercoder215.superadvancements.v1_20_R3.Wrapper1_20_R3.toNMS;

@SuppressWarnings("unchecked")
final class AProgress1_20_R3 implements AProgress {

private final Player p;
private final ServerPlayer sp;
private final PlayerAdvancements manager;

private final net.minecraft.advancements.AdvancementHolder advancement;
private final AdvancementProgress handle;

AProgress1_20_R3(Player p, net.minecraft.advancements.AdvancementHolder advancement, AdvancementProgress handle) {
this.p = p;
this.sp = toNMS(p);
this.manager = sp.getAdvancements();

this.advancement = advancement;
this.handle = handle;
}

@Override
public @NotNull Player getPlayer() {
return p;
}

@Override
public boolean grant() {
getRemainingCriteria().keySet().forEach(s -> manager.award(advancement, s));
manager.flushDirty(sp);
manager.save();
return true;
}

@Override
public boolean revoke() {
getAwardedCriteria().keySet().forEach(s -> manager.revoke(advancement, s));
manager.flushDirty(sp);
manager.save();
return true;
}

@Override
public boolean isDone() {
return handle.isDone();
}

@Override
public @NotNull Map<String, ACriteriaProgress> getCriteria() {
try {
Field criteriaF = AdvancementProgress.class.getDeclaredField("a");
criteriaF.setAccessible(true);
Map<String, CriterionProgress> criteria = (Map<String, CriterionProgress>) criteriaF.get(handle);
return criteria.entrySet()
.stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ACriteriaProgress1_20_R3(e.getValue())));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}

@Override
public float getPercentageCompleted() {
return handle.getPercent();
}

@Override
public @Nullable String getProgressText() {
return handle.getProgressText().getString();
}

@Override
public boolean grantCriteria(@NotNull String name) {
return handle.grantProgress(name);
}

@Override
public boolean revokeCriteria(@NotNull String name) {
return handle.revokeProgress(name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.gamercoder215.superadvancements.v1_20_R3;

import me.gamercoder215.superadvancements.advancement.ADisplay;
import me.gamercoder215.superadvancements.advancement.AFrame;
import net.minecraft.advancements.DisplayInfo;

import java.util.Arrays;

final class NMSDisplay1_20_R3 extends ADisplay {

private final DisplayInfo handle;

NMSDisplay1_20_R3(DisplayInfo handle) {
this.handle = handle;

this.setFrame(Arrays.stream(AFrame.values()).filter(f -> f.name().equalsIgnoreCase(handle.getType().getSerializedName())).findFirst().orElse(AFrame.TASK));
this.setIcon(Wrapper1_20_R3.fromNMS(handle.getIcon()));
this.setX(handle.getX());
this.setY(handle.getY());

if (handle.getBackground() != null) this.setBackgroundTexture(handle.getBackground().toString());
}


@Override
public String getTitleAsString() {
return handle.getTitle().getString();
}

@Override
public String getDescriptionAsString() {
return handle.getDescription().getString();
}
}
Loading

0 comments on commit 37c77b4

Please sign in to comment.