Skip to content

Commit

Permalink
brig/authlib mixins don't work on neo
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Jul 29, 2024
1 parent 217e78a commit d497b01
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +57,7 @@ protected PlayerMixin(final EntityType<? extends LivingEntity> entityType, final

@Override
public @NotNull Identity identity() {
return (Identity) this.gameProfile;
return MinecraftAudiences.identity(this.gameProfile);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d497b01

Please sign in to comment.