From d497b01c8197c8d1790c67ab1fb18d970a11a4c2 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sun, 28 Jul 2024 20:10:42 -0700 Subject: [PATCH] brig/authlib mixins don't work on neo --- .../impl/mixin/authlib/GameProfileMixin.java | 2 +- .../CommandSyntaxExceptionMixin.java | 2 +- .../adventure-platform-fabric.mixins.json | 2 + .../modcommon/MinecraftAudiences.java | 16 +++++-- .../impl/CommandSyntaxExceptionWrapper.java | 45 +++++++++++++++++++ .../world/entity/player/PlayerMixin.java | 3 +- .../adventure-platform-mod-shared.mixins.json | 2 - 7 files changed, 64 insertions(+), 8 deletions(-) rename {mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon => fabric/src/mixin/java/net/kyori/adventure/platform/fabric}/impl/mixin/authlib/GameProfileMixin.java (96%) rename {mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon => fabric/src/mixin/java/net/kyori/adventure/platform/fabric}/impl/mixin/brigadier/exceptions/CommandSyntaxExceptionMixin.java (96%) create mode 100644 mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/CommandSyntaxExceptionWrapper.java diff --git a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/authlib/GameProfileMixin.java b/fabric/src/mixin/java/net/kyori/adventure/platform/fabric/impl/mixin/authlib/GameProfileMixin.java similarity index 96% rename from mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/authlib/GameProfileMixin.java rename to fabric/src/mixin/java/net/kyori/adventure/platform/fabric/impl/mixin/authlib/GameProfileMixin.java index 60bc4a07..0d532dee 100644 --- a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/authlib/GameProfileMixin.java +++ b/fabric/src/mixin/java/net/kyori/adventure/platform/fabric/impl/mixin/authlib/GameProfileMixin.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.adventure.platform.modcommon.impl.mixin.authlib; +package net.kyori.adventure.platform.fabric.impl.mixin.authlib; import com.mojang.authlib.GameProfile; import java.util.UUID; diff --git a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/brigadier/exceptions/CommandSyntaxExceptionMixin.java b/fabric/src/mixin/java/net/kyori/adventure/platform/fabric/impl/mixin/brigadier/exceptions/CommandSyntaxExceptionMixin.java similarity index 96% rename from mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/brigadier/exceptions/CommandSyntaxExceptionMixin.java rename to fabric/src/mixin/java/net/kyori/adventure/platform/fabric/impl/mixin/brigadier/exceptions/CommandSyntaxExceptionMixin.java index 591ab91e..9ddd0b71 100644 --- a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/brigadier/exceptions/CommandSyntaxExceptionMixin.java +++ b/fabric/src/mixin/java/net/kyori/adventure/platform/fabric/impl/mixin/brigadier/exceptions/CommandSyntaxExceptionMixin.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.adventure.platform.modcommon.impl.mixin.brigadier.exceptions; +package net.kyori.adventure.platform.fabric.impl.mixin.brigadier.exceptions; import com.mojang.brigadier.Message; import com.mojang.brigadier.exceptions.CommandSyntaxException; diff --git a/fabric/src/mixin/resources/adventure-platform-fabric.mixins.json b/fabric/src/mixin/resources/adventure-platform-fabric.mixins.json index 7d5d78c7..d433a583 100644 --- a/fabric/src/mixin/resources/adventure-platform-fabric.mixins.json +++ b/fabric/src/mixin/resources/adventure-platform-fabric.mixins.json @@ -4,6 +4,8 @@ "mixins": [ "api.KeyMixin", "api.SignedMessageMixin", + "authlib.GameProfileMixin", + "brigadier.exceptions.CommandSyntaxExceptionMixin", "minecraft.commands.CommandsMixin", "minecraft.commands.synchronization.ArgumentTypeInfosMixin", "minecraft.commands.synchronization.ArgumentUtilsMixin", diff --git a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftAudiences.java b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftAudiences.java index 3b396331..f135261f 100644 --- a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftAudiences.java +++ b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftAudiences.java @@ -33,6 +33,7 @@ import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Keyed; import net.kyori.adventure.platform.modcommon.impl.AdventureCommon; +import net.kyori.adventure.platform.modcommon.impl.CommandSyntaxExceptionWrapper; import net.kyori.adventure.platform.modcommon.impl.MinecraftAudiencesInternal; import net.kyori.adventure.platform.modcommon.impl.NonWrappingComponentSerializer; import net.kyori.adventure.platform.modcommon.impl.PlayerChatMessageBridge; @@ -161,8 +162,11 @@ static Sound.Emitter asEmitter(final Entity entity) { * @since 6.0.0 */ @Contract("null -> null; !null -> !null") - static ComponentMessageThrowable asComponentThrowable(final CommandSyntaxException ex) { - return (ComponentMessageThrowable) ex; + default ComponentMessageThrowable asComponentThrowable(final CommandSyntaxException ex) { + if (ex == null) { + return null; + } + return new CommandSyntaxExceptionWrapper(ex, this); } /** @@ -198,7 +202,13 @@ static Identified identified(final Player player) { */ @Contract("null -> null; !null -> !null") static Identity identity(final GameProfile profile) { - return (Identity) profile; + if (profile == null) { + return null; + } + if (profile instanceof Identity identity) { + return identity; + } + return Identity.identity(profile.getId()); } /** diff --git a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/CommandSyntaxExceptionWrapper.java b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/CommandSyntaxExceptionWrapper.java new file mode 100644 index 00000000..b3e573ab --- /dev/null +++ b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/CommandSyntaxExceptionWrapper.java @@ -0,0 +1,45 @@ +/* + * This file is part of adventure-platform-mod, licensed under the MIT License. + * + * Copyright (c) 2024 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.platform.modcommon.impl; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.kyori.adventure.platform.modcommon.MinecraftAudiences; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.util.ComponentMessageThrowable; +import net.minecraft.network.chat.ComponentUtils; +import org.jetbrains.annotations.Nullable; + +public final class CommandSyntaxExceptionWrapper extends CommandSyntaxException implements ComponentMessageThrowable { + private final @Nullable Component componentMessage; + + public CommandSyntaxExceptionWrapper(final CommandSyntaxException wrapped, final MinecraftAudiences audiences) { + super(wrapped.getType(), wrapped.getRawMessage(), wrapped.getInput(), wrapped.getCursor()); + this.componentMessage = wrapped.getRawMessage() == null ? null : audiences.asAdventure(ComponentUtils.fromMessage(wrapped.getRawMessage())); + } + + @Override + public @Nullable Component componentMessage() { + return this.componentMessage; + } +} diff --git a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/world/entity/player/PlayerMixin.java b/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/world/entity/player/PlayerMixin.java index c6a4b29d..3142b05c 100644 --- a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/world/entity/player/PlayerMixin.java +++ b/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/world/entity/player/PlayerMixin.java @@ -26,6 +26,7 @@ import com.mojang.authlib.GameProfile; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.platform.modcommon.IdentifiedAtRuntime; +import net.kyori.adventure.platform.modcommon.MinecraftAudiences; import net.kyori.adventure.platform.modcommon.impl.AdventureCommon; import net.kyori.adventure.platform.modcommon.impl.NonWrappingComponentSerializer; import net.kyori.adventure.platform.modcommon.impl.PointerProviderBridge; @@ -56,7 +57,7 @@ protected PlayerMixin(final EntityType entityType, final @Override public @NotNull Identity identity() { - return (Identity) this.gameProfile; + return MinecraftAudiences.identity(this.gameProfile); } @Override diff --git a/mod-shared/src/mixin/resources/adventure-platform-mod-shared.mixins.json b/mod-shared/src/mixin/resources/adventure-platform-mod-shared.mixins.json index 01e5bfd3..52977965 100644 --- a/mod-shared/src/mixin/resources/adventure-platform-mod-shared.mixins.json +++ b/mod-shared/src/mixin/resources/adventure-platform-mod-shared.mixins.json @@ -2,8 +2,6 @@ "package": "net.kyori.adventure.platform.modcommon.impl.mixin", "parent": "adventure-platform-mod-shared.parent.mixins.json", "mixins": [ - "authlib.GameProfileMixin", - "brigadier.exceptions.CommandSyntaxExceptionMixin", "minecraft.commands.CommandSourceStackMixin", "minecraft.network.FriendlyByteBufMixin", "minecraft.network.chat.ClickEvent_ActionMixin",