mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-08-25 15:30:45 +02:00
Improve console detection on Fabric/Forge (#3673)
This commit is contained in:
@@ -29,12 +29,15 @@ import me.lucko.fabric.api.permissions.v0.Permissions;
|
|||||||
import me.lucko.luckperms.common.locale.TranslationManager;
|
import me.lucko.luckperms.common.locale.TranslationManager;
|
||||||
import me.lucko.luckperms.common.sender.Sender;
|
import me.lucko.luckperms.common.sender.Sender;
|
||||||
import me.lucko.luckperms.common.sender.SenderFactory;
|
import me.lucko.luckperms.common.sender.SenderFactory;
|
||||||
|
import me.lucko.luckperms.fabric.mixin.ServerCommandSourceAccessor;
|
||||||
import me.lucko.luckperms.fabric.model.MixinUser;
|
import me.lucko.luckperms.fabric.model.MixinUser;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.luckperms.api.util.Tristate;
|
import net.luckperms.api.util.Tristate;
|
||||||
|
import net.minecraft.server.command.CommandOutput;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.rcon.RconCommandOutput;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -107,7 +110,10 @@ public class FabricSenderFactory extends SenderFactory<LPFabricPlugin, ServerCom
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isConsole(ServerCommandSource sender) {
|
protected boolean isConsole(ServerCommandSource sender) {
|
||||||
return sender.getEntity() == null;
|
CommandOutput output = ((ServerCommandSourceAccessor) sender).getOutput();
|
||||||
|
return output == sender.getServer() || // Console
|
||||||
|
output.getClass() == RconCommandOutput.class || // Rcon
|
||||||
|
(output == CommandOutput.DUMMY && sender.getName().equals("")); // Functions
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text toNativeText(Component component) {
|
public static Text toNativeText(Component component) {
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* 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 me.lucko.luckperms.fabric.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.server.command.CommandOutput;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accessor mixin to provide access to the underlying {@link CommandOutput}
|
||||||
|
*/
|
||||||
|
@Mixin(ServerCommandSource.class)
|
||||||
|
public interface ServerCommandSourceAccessor {
|
||||||
|
|
||||||
|
@Accessor("output")
|
||||||
|
CommandOutput getOutput();
|
||||||
|
|
||||||
|
}
|
@@ -4,6 +4,7 @@
|
|||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"CommandManagerMixin",
|
"CommandManagerMixin",
|
||||||
|
"ServerCommandSourceAccessor",
|
||||||
"ServerLoginNetworkHandlerAccessor",
|
"ServerLoginNetworkHandlerAccessor",
|
||||||
"ServerPlayerEntityMixin"
|
"ServerPlayerEntityMixin"
|
||||||
],
|
],
|
||||||
|
@@ -38,8 +38,10 @@ import me.lucko.luckperms.forge.capabilities.UserCapabilityImpl;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.luckperms.api.util.Tristate;
|
import net.luckperms.api.util.Tristate;
|
||||||
|
import net.minecraft.commands.CommandSource;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.rcon.RconConsoleSource;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -107,7 +109,10 @@ public class ForgeSenderFactory extends SenderFactory<LPForgePlugin, CommandSour
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isConsole(CommandSourceStack sender) {
|
protected boolean isConsole(CommandSourceStack sender) {
|
||||||
return !(sender.getEntity() instanceof Player);
|
CommandSource output = sender.source;
|
||||||
|
return output == sender.getServer() || // Console
|
||||||
|
output.getClass() == RconConsoleSource.class || // Rcon
|
||||||
|
(output == CommandSource.NULL && sender.getTextName().equals("")); // Functions
|
||||||
}
|
}
|
||||||
|
|
||||||
public static net.minecraft.network.chat.Component toNativeText(Component component) {
|
public static net.minecraft.network.chat.Component toNativeText(Component component) {
|
||||||
|
Reference in New Issue
Block a user