fix for 1.20.2 and 1.17
This commit is contained in:
1 parent
96677233af
commit
8066116d7e
4 files changed
+48
-39
No files matched your search
+2
-2
@@ -23,7 +23,7 @@ public final class ScoreboardPlugin extends JavaPlugin implements Listener {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
GlobalTranslator.translator().addSource(this.translator);
|
||||
GlobalTranslator.get().addSource(this.translator);
|
||||
|
||||
try {
|
||||
lib = ScoreboardLibrary.loadScoreboardLibrary(this);
|
||||
@@ -52,7 +52,7 @@ public final class ScoreboardPlugin extends JavaPlugin implements Listener {
|
||||
this.modules = null;
|
||||
this.lib.close();
|
||||
this.lib = null;
|
||||
GlobalTranslator.translator().removeSource(this.translator);
|
||||
GlobalTranslator.get().removeSource(this.translator);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
+7
-7
@@ -41,15 +41,15 @@ public final class PacketAccessors {
|
||||
SET_OBJECTIVE_PKT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.protocol.game.ClientboundSetObjectivePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective");
|
||||
SET_DISPLAY_OBJECTIVE_PKT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardDisplayObjective");
|
||||
SET_SCORE_PKT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.protocol.game.ClientboundSetScorePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore");
|
||||
RESET_SCORE_PKT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.protocol.game.ClientboundResetScorePacket", "net.minecraft.network.protocol.game.ClientboundResetScorePacket");
|
||||
RESET_SCORE_PKT_CLASS = ReflectUtil.getOptionalClass("net.minecraft.network.protocol.game.ClientboundResetScorePacket", "net.minecraft.network.protocol.game.ClientboundResetScorePacket");
|
||||
SET_PLAYER_TEAM_PKT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam");
|
||||
TEAM_PARAMETERS_PKT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket$Parameters", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam$b");
|
||||
COMPONENT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.Component", "net.minecraft.network.chat.IChatBaseComponent");
|
||||
MUTABLE_COMPONENT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.MutableComponent", "net.minecraft.network.chat.IChatMutableComponent");
|
||||
COMPONENT_SERIALIZATION_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.ComponentSerialization");
|
||||
COMPONENT_SERIALIZATION_CLASS = ReflectUtil.getOptionalClass("net.minecraft.network.chat.ComponentSerialization");
|
||||
STYLE_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.Style", "net.minecraft.network.chat.ChatModifier");
|
||||
STYLE_SERIALIZER_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.Style$Serializer", "net.minecraft.network.chat.ChatModifier$ChatModifierSerializer");
|
||||
NUMBER_FORMAT_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.numbers.NumberFormat");
|
||||
NUMBER_FORMAT_CLASS = ReflectUtil.getOptionalClass("net.minecraft.network.chat.numbers.NumberFormat");
|
||||
DISPLAY_SLOT_CLASS = ReflectUtil.getOptionalClass("net.minecraft.world.scores.DisplaySlot");
|
||||
OBJECTIVE_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.world.scores.Objective", "net.minecraft.world.scores.ScoreboardObjective");
|
||||
TEAM_VISIBILITY_CLASS = ReflectUtil.getClassOrThrow("net.minecraft.world.scores.Team$Visibility", "net.minecraft.world.scores.ScoreboardTeamBase$EnumNameTagVisibility");
|
||||
@@ -122,8 +122,8 @@ public final class PacketAccessors {
|
||||
}
|
||||
|
||||
static {
|
||||
if (IS_1_20_2_OR_ABOVE) {
|
||||
RESET_SCORE_CONSTRUCTOR = ReflectUtil.findConstructor(RESET_SCORE_PKT_CLASS, String.class, String.class);
|
||||
if (IS_1_20_3_OR_ABOVE) {
|
||||
RESET_SCORE_CONSTRUCTOR = ReflectUtil.findConstructor(Objects.requireNonNull(RESET_SCORE_PKT_CLASS), String.class, String.class);
|
||||
} else {
|
||||
RESET_SCORE_CONSTRUCTOR = null;
|
||||
}
|
||||
@@ -167,7 +167,7 @@ public final class PacketAccessors {
|
||||
public static final Object JSON_OPS;
|
||||
|
||||
public static final MethodAccessor CHAT_FORMATTING_GET_BY_CODE =
|
||||
ReflectUtil.findMethod(CHAT_FORMATTING_CLASS,true, MethodType.methodType(CHAT_FORMATTING_CLASS, char.class), "getByCode", "a");
|
||||
ReflectUtil.findMethod(CHAT_FORMATTING_CLASS, true, MethodType.methodType(CHAT_FORMATTING_CLASS, char.class), "getByCode", "a");
|
||||
|
||||
public static final Object NAME_TAG_VISIBILITY_ALWAYS = ReflectUtil.getEnumInstance(TEAM_VISIBILITY_CLASS, "ALWAYS");
|
||||
public static final Object NAME_TAG_VISIBILITY_NEVER = ReflectUtil.getEnumInstance(TEAM_VISIBILITY_CLASS, "NEVER");
|
||||
@@ -201,7 +201,7 @@ public final class PacketAccessors {
|
||||
ReflectUtil.findFieldUnchecked(SET_OBJECTIVE_PKT_CLASS, 0, int.class);
|
||||
|
||||
public static final ConstructorAccessor<?> DISPLAY_1_20_2_CONSTRUCTOR =
|
||||
ReflectUtil.findOptionalConstructor(SET_DISPLAY_OBJECTIVE_PKT_CLASS, DISPLAY_SLOT_CLASS, OBJECTIVE_CLASS);
|
||||
DISPLAY_SLOT_CLASS != null ? ReflectUtil.findOptionalConstructor(SET_DISPLAY_OBJECTIVE_PKT_CLASS, DISPLAY_SLOT_CLASS, OBJECTIVE_CLASS) : null;
|
||||
public static final ConstructorAccessor<?> DISPLAY_1_20_1_CONSTRUCTOR =
|
||||
ReflectUtil.findOptionalConstructor(SET_DISPLAY_OBJECTIVE_PKT_CLASS, int.class, OBJECTIVE_CLASS);
|
||||
public static final FieldAccessor<Object, String> DISPLAY_OBJECTIVE_NAME =
|
||||
|
||||
+14
-7
@@ -20,16 +20,23 @@ public final class ScoreFormatConverter {
|
||||
private static final ConstructorAccessor<?> FIXED_CONSTRUCTOR;
|
||||
|
||||
static {
|
||||
STYLE_CODEC = ReflectUtil.findFieldUnchecked(PacketAccessors.STYLE_SERIALIZER_CLASS, 0, PacketAccessors.CODEC_CLASS, true).get(null);
|
||||
if (PacketAccessors.IS_1_20_3_OR_ABOVE) {
|
||||
STYLE_CODEC = ReflectUtil.findFieldUnchecked(PacketAccessors.STYLE_SERIALIZER_CLASS, 0, PacketAccessors.CODEC_CLASS, true).get(null);
|
||||
|
||||
Class<?> blankFormatClass = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.numbers.BlankFormat");
|
||||
BLANK = ReflectUtil.findFieldUnchecked(blankFormatClass, 0, blankFormatClass, true).get(null);
|
||||
Class<?> blankFormatClass = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.numbers.BlankFormat");
|
||||
BLANK = ReflectUtil.findFieldUnchecked(blankFormatClass, 0, blankFormatClass, true).get(null);
|
||||
|
||||
Class<?> styledFormatClass = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.numbers.StyledFormat");
|
||||
STYLED_CONSTRUCTOR = ReflectUtil.findConstructor(styledFormatClass, PacketAccessors.STYLE_CLASS);
|
||||
Class<?> styledFormatClass = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.numbers.StyledFormat");
|
||||
STYLED_CONSTRUCTOR = ReflectUtil.findConstructor(styledFormatClass, PacketAccessors.STYLE_CLASS);
|
||||
|
||||
Class<?> fixedFormatClass = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.numbers.FixedFormat");
|
||||
FIXED_CONSTRUCTOR = ReflectUtil.findConstructor(fixedFormatClass, PacketAccessors.COMPONENT_CLASS);
|
||||
Class<?> fixedFormatClass = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.numbers.FixedFormat");
|
||||
FIXED_CONSTRUCTOR = ReflectUtil.findConstructor(fixedFormatClass, PacketAccessors.COMPONENT_CLASS);
|
||||
} else {
|
||||
STYLE_CODEC = null;
|
||||
BLANK = null;
|
||||
STYLED_CONSTRUCTOR = null;
|
||||
FIXED_CONSTRUCTOR = null;
|
||||
}
|
||||
}
|
||||
|
||||
private ScoreFormatConverter() {
|
||||
|
||||
+25
-23
@@ -6,7 +6,6 @@ import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.PacketAccessors;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.MinecraftClasses;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ReflectUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -19,39 +18,42 @@ import java.util.Optional;
|
||||
|
||||
import static net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson;
|
||||
|
||||
public class ModernComponentProvider {
|
||||
public final class ModernComponentProvider {
|
||||
public static final boolean IS_NATIVE_ADVENTURE;
|
||||
|
||||
private static final Object MINECRAFT_REGISTRY;
|
||||
private static final Object CODEC;
|
||||
|
||||
private static final MethodHandle FROM_JSON_METHOD;
|
||||
|
||||
private ModernComponentProvider() {
|
||||
}
|
||||
|
||||
static {
|
||||
Class<?> craftRegistry;
|
||||
try {
|
||||
craftRegistry = Class.forName(MinecraftClasses.craftBukkit("CraftRegistry"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Method method = craftRegistry.getMethod("getMinecraftRegistry");
|
||||
MINECRAFT_REGISTRY = method.invoke(null);
|
||||
CODEC = ReflectUtil.findFieldUnchecked(PacketAccessors.COMPONENT_SERIALIZATION_CLASS, 0, PacketAccessors.CODEC_CLASS, true).get(null);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// Hide from relocation checkers
|
||||
String notRelocatedPackage = "net.ky".concat("ori.adventure.text");
|
||||
|
||||
// The native adventure optimisations only work when the adventure library isn't relocated
|
||||
IS_NATIVE_ADVENTURE = PacketAccessors.ADVENTURE_COMPONENT_CLASS != null && Component.class.getPackage().getName().equals(notRelocatedPackage);
|
||||
}
|
||||
|
||||
private static final MethodHandle FROM_JSON_METHOD;
|
||||
if (PacketAccessors.IS_1_21_6_OR_ABOVE) {
|
||||
Class<?> craftRegistry;
|
||||
try {
|
||||
craftRegistry = Class.forName(MinecraftClasses.craftBukkit("CraftRegistry"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
|
||||
static {
|
||||
if (!PacketAccessors.IS_1_21_6_OR_ABOVE) {
|
||||
try {
|
||||
Method method = craftRegistry.getMethod("getMinecraftRegistry");
|
||||
MINECRAFT_REGISTRY = method.invoke(null);
|
||||
CODEC = ReflectUtil.findFieldUnchecked(PacketAccessors.COMPONENT_SERIALIZATION_CLASS, 0, PacketAccessors.CODEC_CLASS, true).get(null);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
FROM_JSON_METHOD = null;
|
||||
} else {
|
||||
Class<?> serializerClass = ReflectUtil.getClassOrThrow("net.minecraft.network.chat.Component$Serializer", "net.minecraft.network.chat.IChatBaseComponent$ChatSerializer");
|
||||
MethodHandle handle = null;
|
||||
for (Method method : serializerClass.getMethods()) {
|
||||
@@ -74,8 +76,8 @@ public class ModernComponentProvider {
|
||||
}
|
||||
|
||||
FROM_JSON_METHOD = handle;
|
||||
} else {
|
||||
FROM_JSON_METHOD = null;
|
||||
MINECRAFT_REGISTRY = null;
|
||||
CODEC = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user