SteamWar/BungeeCore
Archiviert
13
2

Fix command logging
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <git-5w3l@lixfel.de>
Dieser Commit ist enthalten in:
Lixfel 2024-06-29 08:46:02 +02:00
Ursprung 6350a99392
Commit dbe27e92d2

Datei anzeigen

@ -19,11 +19,13 @@
package de.steamwar.velocitycore.listeners; package de.steamwar.velocitycore.listeners;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.event.player.TabCompleteEvent; import com.velocitypowered.api.event.player.TabCompleteEvent;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import de.steamwar.messages.Chatter; import de.steamwar.messages.Chatter;
import de.steamwar.messages.ChatterGroup; import de.steamwar.messages.ChatterGroup;
@ -43,10 +45,13 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ChatListener extends BasicListener { public class ChatListener extends BasicListener {
private static final Logger rootLogger = Logger.getGlobal();
private static final List<String> rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).toList(); private static final List<String> rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).toList();
@Subscribe(order = PostOrder.FIRST) @Subscribe(order = PostOrder.FIRST)
@ -67,8 +72,20 @@ public class ChatListener extends BasicListener {
@Subscribe(order = PostOrder.LAST) @Subscribe(order = PostOrder.LAST)
public void logCommands(CommandExecuteEvent e) { public void logCommands(CommandExecuteEvent e) {
if(e.getResult().isAllowed()) String command = e.getCommand();
VelocityCore.getLogger().log(Level.INFO, "%s -> executed command %s".formatted(e.getCommandSource(), e.getCommand())); int space = command.indexOf(' ');
if(e.getResult().isAllowed() && VelocityCore.getProxy().getCommandManager().hasCommand(space != -1 ? command.substring(0, space) : command)) {
CommandSource source = e.getCommandSource();
String name;
if(source instanceof Player player)
name = player.getUsername();
else if(source instanceof ConsoleCommandSource)
name = "«CONSOLE»";
else
name = source.toString();
rootLogger.log(Level.INFO, "%s -> executed command /%s".formatted(name, command));
}
} }
@Subscribe @Subscribe
@ -100,7 +117,7 @@ public class ChatListener extends BasicListener {
private static boolean isMistypedCommand(Player player, String message) { private static boolean isMistypedCommand(Player player, String message) {
String command = message.substring(1); String command = message.substring(1);
boolean isCommand = message.startsWith("7") && command.split(" ", 2)[0].matches("[7/]?[A-Za-z]+"); boolean isCommand = message.startsWith("7") && command.matches("^[7/]?[A-Za-z]+");
if(isCommand && Boolean.FALSE.equals(VelocityCore.getProxy().getCommandManager().executeAsync(player, command).join())) { if(isCommand && Boolean.FALSE.equals(VelocityCore.getProxy().getCommandManager().executeAsync(player, command).join())) {
if(command.startsWith("7")) if(command.startsWith("7"))
command = "/" + command.substring(1); command = "/" + command.substring(1);