From 6c2cd6ac7ae441d9f2227e86177964e7e0d84aac Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 28 Jan 2021 18:20:26 +1300 Subject: [PATCH] Fix scores for 1.12 --- .../reflection/ReflectionManager.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 1e29b6ce..b9ca77c5 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -184,11 +184,16 @@ public class ReflectionManager { noDamageTicks = getNmsField("Entity", "noDamageTicks"); isInvul = getNmsMethod("Entity", "isInvulnerable", getNmsClass("DamageSource")); genericDamage = getNmsField("DamageSource", "GENERIC").get(null); - boardField = getCraftClass("scoreboard.CraftScoreboard").getDeclaredField("board"); + boardField = getCraftClass("scoreboard.CraftScoreboard").getDeclaredField("board"); boardField.setAccessible(true); scoreboardCrtieriaHealth = getNmsField("IScoreboardCriteria", "HEALTH").get(null); setScore = getNmsMethod("ScoreboardScore", "setScore", int.class); - getObjectives = getNmsMethod("Scoreboard", "getObjectivesForCriteria", getNmsClass("IScoreboardCriteria"), String.class, Consumer.class); + + if (!NmsVersion.v1_13.isSupported()) { + getObjectives = getNmsMethod("Scoreboard", "getScoreboardScores", getNmsClass("IScoreboardCriteria"), String.class, ArrayList.class); + } else { + getObjectives = getNmsMethod("Scoreboard", "getObjectivesForCriteria", getNmsClass("IScoreboardCriteria"), String.class, Consumer.class); + } Method method = getNmsMethod("SoundCategory", "a"); @@ -1932,6 +1937,16 @@ public class ReflectionManager { try { Object board = boardField.get(scoreboard); + if (!NmsVersion.v1_13.isSupported()) { + Collection scores = (Collection) getObjectives.invoke(board, criteria, name, new ArrayList<>()); + + for (Object obj : scores) { + setScore.invoke(obj, score); + } + + return; + } + Consumer con = o -> { try { setScore.invoke(o, score);