Skip to content

Commit

Permalink
fix: πŸ› fix message last arg does not greedy
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Dec 17, 2022
1 parent a64da47 commit 315c5bc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/zhanganzhi/chathub/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zhanganzhi.chathub.command;

import java.util.List;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;

Expand Down Expand Up @@ -38,12 +39,13 @@ public void execute(final Invocation invocation) {
));
}
}
} else if (args.length == 3 && args[0].equals("msg")) {
} else if (args.length >= 3 && args[0].equals("msg")) {
Optional<Player> optionalPlayer = server.getPlayer(args[1]);
if (optionalPlayer.isPresent()) {
String senderName = source instanceof Player ? ((Player) source).getUsername() : "Server";
source.sendMessage(Component.text(config.getMinecraftMsgSenderMessage(args[1], args[2])));
optionalPlayer.get().sendMessage(Component.text(config.getMinecraftMsgTargetMessage(senderName, args[2])));
String message = String.join(" ", Arrays.copyOfRange(args, 2, args.length));
source.sendMessage(Component.text(config.getMinecraftMsgSenderMessage(args[1], message)));
optionalPlayer.get().sendMessage(Component.text(config.getMinecraftMsgTargetMessage(senderName, message)));
} else {
source.sendMessage(Component.text("Player \"" + args[1] + "\" does not online!"));
}
Expand Down

0 comments on commit 315c5bc

Please sign in to comment.