diff --git a/src/de/steamwar/velocitycore/listeners/ChatListener.java b/src/de/steamwar/velocitycore/listeners/ChatListener.java index a5fbb7ab..ad40d313 100644 --- a/src/de/steamwar/velocitycore/listeners/ChatListener.java +++ b/src/de/steamwar/velocitycore/listeners/ChatListener.java @@ -19,11 +19,13 @@ package de.steamwar.velocitycore.listeners; +import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.TabCompleteEvent; +import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.api.proxy.Player; import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; @@ -43,10 +45,13 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; public class ChatListener extends BasicListener { + private static final Logger rootLogger = Logger.getGlobal(); + private static final List rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).toList(); @Subscribe(order = PostOrder.FIRST) @@ -67,8 +72,20 @@ public class ChatListener extends BasicListener { @Subscribe(order = PostOrder.LAST) public void logCommands(CommandExecuteEvent e) { - if(e.getResult().isAllowed()) - VelocityCore.getLogger().log(Level.INFO, "%s -> executed command %s".formatted(e.getCommandSource(), e.getCommand())); + String command = 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 @@ -100,7 +117,7 @@ public class ChatListener extends BasicListener { private static boolean isMistypedCommand(Player player, String message) { 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(command.startsWith("7")) command = "/" + command.substring(1);