Fix scoreboard errors, why did I use nms?
This commit is contained in:
parent
036eac42b8
commit
e80e83f969
@ -343,7 +343,7 @@ public class FlagWatcher {
|
|||||||
String name = DisguiseConfig.isScoreboardNames() && ((PlayerDisguise) getDisguise()).hasScoreboardName() ?
|
String name = DisguiseConfig.isScoreboardNames() && ((PlayerDisguise) getDisguise()).hasScoreboardName() ?
|
||||||
((PlayerDisguise) getDisguise()).getScoreboardName().getPlayer() : ((PlayerDisguise) getDisguise()).getName();
|
((PlayerDisguise) getDisguise()).getScoreboardName().getPlayer() : ((PlayerDisguise) getDisguise()).getName();
|
||||||
|
|
||||||
ReflectionManager.setScore(player.getScoreboard(), ReflectionManager.scoreboardCrtieriaHealth, name, (int) Math.ceil(health));
|
ReflectionManager.setScore(player.getScoreboard(), name, (int) Math.ceil(health));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,7 +383,7 @@ public class FlagWatcher {
|
|||||||
String name = DisguiseConfig.isScoreboardNames() && ((PlayerDisguise) getDisguise()).hasScoreboardName() ?
|
String name = DisguiseConfig.isScoreboardNames() && ((PlayerDisguise) getDisguise()).hasScoreboardName() ?
|
||||||
((PlayerDisguise) getDisguise()).getScoreboardName().getPlayer() : ((PlayerDisguise) getDisguise()).getName();
|
((PlayerDisguise) getDisguise()).getScoreboardName().getPlayer() : ((PlayerDisguise) getDisguise()).getName();
|
||||||
|
|
||||||
ReflectionManager.setScore(player.getScoreboard(), ReflectionManager.scoreboardCrtieriaHealth, name, (int) Math.ceil(health));
|
ReflectionManager.setScore(player.getScoreboard(), name, (int) Math.ceil(health));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,13 +29,14 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.plugin.SimplePluginManager;
|
import org.bukkit.plugin.SimplePluginManager;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scoreboard.Objective;
|
||||||
|
import org.bukkit.scoreboard.Score;
|
||||||
import org.bukkit.scoreboard.Scoreboard;
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
import org.bukkit.util.EulerAngle;
|
import org.bukkit.util.EulerAngle;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -108,11 +109,6 @@ public class ReflectionManager {
|
|||||||
private static Field noDamageTicks;
|
private static Field noDamageTicks;
|
||||||
private static Method isInvul;
|
private static Method isInvul;
|
||||||
private static Object genericDamage;
|
private static Object genericDamage;
|
||||||
private static Field boardField;
|
|
||||||
public static Object scoreboardCrtieriaHealth;
|
|
||||||
private static Method getObjectives;
|
|
||||||
private static Method getPlayerScoreObjective;
|
|
||||||
private static Method setScore;
|
|
||||||
private static HashMap<String, String> classLocations = new HashMap<>();
|
private static HashMap<String, String> classLocations = new HashMap<>();
|
||||||
private static Field playerConnection;
|
private static Field playerConnection;
|
||||||
private static Method incrementedInventoryStateId;
|
private static Method incrementedInventoryStateId;
|
||||||
@ -266,19 +262,6 @@ public class ReflectionManager {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
boardField = getCraftClass("CraftScoreboard").getDeclaredField("board");
|
|
||||||
boardField.setAccessible(true);
|
|
||||||
scoreboardCrtieriaHealth =
|
|
||||||
getNmsField("IScoreboardCriteria", NmsVersion.v1_17.isSupported() ? "f" : NmsVersion.v1_13.isSupported() ? "HEALTH" : "g").get(null);
|
|
||||||
setScore = getNmsMethod("ScoreboardScore", "setScore", int.class);
|
|
||||||
|
|
||||||
if (!NmsVersion.v1_13.isSupported()) {
|
|
||||||
getObjectives = getNmsMethod("Scoreboard", "getObjectivesForCriteria", getNmsClass("IScoreboardCriteria"));
|
|
||||||
getPlayerScoreObjective = getNmsMethod("Scoreboard", "getPlayerScoreForObjective", String.class, getNmsClass("ScoreboardObjective"));
|
|
||||||
} else {
|
|
||||||
getObjectives = getNmsMethod("Scoreboard", "getObjectivesForCriteria", getNmsClass("IScoreboardCriteria"), String.class, Consumer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
Method method = getNmsMethod("SoundCategory", "a");
|
Method method = getNmsMethod("SoundCategory", "a");
|
||||||
|
|
||||||
for (Enum anEnum : (Enum[]) getNmsClass("SoundCategory").getEnumConstants()) {
|
for (Enum anEnum : (Enum[]) getNmsClass("SoundCategory").getEnumConstants()) {
|
||||||
@ -2115,41 +2098,27 @@ public class ReflectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setScore(Scoreboard scoreboard, Object criteria, String name, int score) {
|
public static void setScore(Scoreboard scoreboard, String name, int score) {
|
||||||
if (!Bukkit.isPrimaryThread()) {
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
setScore(scoreboard, criteria, name, score);
|
setScore(scoreboard, name, score);
|
||||||
}
|
}
|
||||||
}.runTask(LibsDisguises.getInstance());
|
}.runTask(LibsDisguises.getInstance());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
Set<Objective> objectives = scoreboard.getObjectivesByCriteria("health");
|
||||||
Object board = boardField.get(scoreboard);
|
|
||||||
|
|
||||||
if (!NmsVersion.v1_13.isSupported()) {
|
for (Objective objective : objectives) {
|
||||||
Collection scores = (Collection) getObjectives.invoke(board, criteria);
|
Score s = objective.getScore(name);
|
||||||
|
|
||||||
for (Object obj : scores) {
|
if (s.isScoreSet() && s.getScore() == score) {
|
||||||
setScore.invoke(getPlayerScoreObjective.invoke(board, name, obj), score);
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
s.setScore(score);
|
||||||
}
|
|
||||||
|
|
||||||
Consumer con = o -> {
|
|
||||||
try {
|
|
||||||
setScore.invoke(o, score);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
getObjectives.invoke(board, criteria, name, con);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user