Skip to content

Commit

Permalink
Console output player command (Grasscutters#1722)
Browse files Browse the repository at this point in the history
* Console output player command

* Update CommandMap.java

* Add the Output_player_command option to the config

* Proper formatting for logging commands

* Log account usernames, not player nicknames

Co-authored-by: Melledy <52122272+Melledy@users.noreply.github.com>
  • Loading branch information
ChisatoNishikigi73 and Melledy committed Aug 31, 2022
1 parent bab6e68 commit 4f015c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/main/java/emu/grasscutter/command/CommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import emu.grasscutter.game.player.Player;
import org.reflections.Reflections;

import java.net.IDN;
import java.util.*;

import static emu.grasscutter.config.Configuration.ACCOUNT;
import static emu.grasscutter.config.Configuration.SERVER;

@SuppressWarnings({"UnusedReturnValue", "unused"})
public final class CommandMap {
private final Map<String, CommandHandler> commands = new TreeMap<>();
Expand Down Expand Up @@ -164,9 +168,9 @@ private Player getTargetPlayer(String playerId, Player player, Player targetPlay

private boolean setPlayerTarget(String playerId, Player player, String targetUid) {
if (targetUid.equals("")) { // Clears the default targetPlayer.
targetPlayerIds.remove(playerId);
CommandHandler.sendTranslatedMessage(player, "commands.execution.clear_target");
return true;
targetPlayerIds.remove(playerId);
CommandHandler.sendTranslatedMessage(player, "commands.execution.clear_target");
return true;
}

// Sets default targetPlayer to the UID provided.
Expand Down Expand Up @@ -195,6 +199,15 @@ private boolean setPlayerTarget(String playerId, Player player, String targetUid
* @param rawMessage The messaged used to invoke the command.
*/
public void invoke(Player player, Player targetPlayer, String rawMessage) {
// The console outputs in-game command. [{Account Username} (Player UID: {Player Uid})]
if (SERVER.logCommands) {
if (player != null) {
Grasscutter.getLogger().info("Command used by [" + player.getAccount().getUsername() + " (Player UID: " + player.getUid() + ")]: " + rawMessage);
} else {
Grasscutter.getLogger().info("Command used by server console: " + rawMessage);
}
}

rawMessage = rawMessage.trim();
if (rawMessage.length() == 0) {
CommandHandler.sendTranslatedMessage(player, "commands.generic.not_specified");
Expand All @@ -218,7 +231,7 @@ public void invoke(Player player, Player targetPlayer, String rawMessage) {
targetUidStr = targetUidStr.substring(1);
}
this.setPlayerTarget(playerId, player, targetUidStr);
return;
return;
} else {
this.setPlayerTarget(playerId, player, "");
return;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/emu/grasscutter/config/ConfigContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public static class Server {
public Set<Integer> debugWhitelist = Set.of();
public Set<Integer> debugBlacklist = Set.of();
public ServerRunMode runMode = ServerRunMode.HYBRID;

public boolean logCommands = false;

public HTTP http = new HTTP();
public Game game = new Game();

Expand Down

0 comments on commit 4f015c1

Please sign in to comment.