From 55b58444bd1b3f4c72ef829364b17be81e479061 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Sun, 28 May 2023 11:18:48 +0200 Subject: [PATCH] Fixed Via commands for the CLi interface --- .../raphimc/viaproxy/cli/ConsoleHandler.java | 5 +- .../viaproxy/ConsoleCommandSender.java | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/ConsoleCommandSender.java diff --git a/src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java b/src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java index b235b23..631ea08 100644 --- a/src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java +++ b/src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java @@ -18,11 +18,10 @@ package net.raphimc.viaproxy.cli; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.connection.UserConnectionImpl; import net.lenni0451.classtransform.utils.log.Logger; -import net.raphimc.viaprotocolhack.commands.UserCommandSender; import net.raphimc.viaproxy.plugins.PluginManager; import net.raphimc.viaproxy.plugins.events.ConsoleCommandEvent; +import net.raphimc.viaproxy.protocolhack.viaproxy.ConsoleCommandSender; import net.raphimc.viaproxy.util.ArrayHelper; import java.io.BufferedReader; @@ -50,7 +49,7 @@ public class ConsoleHandler { System.gc(); System.out.println("GC Done"); } else if (command.equalsIgnoreCase("via")) { - Via.getManager().getCommandHandler().onCommand(new UserCommandSender(new UserConnectionImpl(null, true)), args.getAsArray()); + Via.getManager().getCommandHandler().onCommand(new ConsoleCommandSender(), args.getAsArray()); } else if (command.equalsIgnoreCase("threaddump")) { System.out.println("Thread Dump:"); for (Thread thread : Thread.getAllStackTraces().keySet()) { diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/ConsoleCommandSender.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/ConsoleCommandSender.java new file mode 100644 index 0000000..eef69d2 --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/ConsoleCommandSender.java @@ -0,0 +1,50 @@ +/* + * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy + * Copyright (C) 2023 RK_01/RaphiMC and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.raphimc.viaproxy.protocolhack.viaproxy; + +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.command.ViaCommandSender; +import net.raphimc.viaproxy.cli.ConsoleFormatter; + +import java.util.UUID; + +public class ConsoleCommandSender implements ViaCommandSender { + + private static final UUID CONSOLE_UUID = new UUID(0, 0); + + @Override + public boolean hasPermission(String permission) { + return true; + } + + @Override + public void sendMessage(String msg) { + Via.getPlatform().getLogger().info(ConsoleFormatter.convert(msg)); + } + + @Override + public UUID getUUID() { + return CONSOLE_UUID; + } + + @Override + public String getName() { + return "Console"; + } + +}