This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gregory Mitchell
authored
Dec 7, 2023
1 parent
19b47fd
commit 37c77b4
Showing
10 changed files
with
1,684 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...3/src/main/java/me/gamercoder215/superadvancements/v1_20_R3/ACriteriaProgress1_20_R3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
nms/1_20_R3/src/main/java/me/gamercoder215/superadvancements/v1_20_R3/AProgress1_20_R3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
nms/1_20_R3/src/main/java/me/gamercoder215/superadvancements/v1_20_R3/NMSDisplay1_20_R3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.