Skip to content

Commit

Permalink
PLAYER_COMMAND 传 / 开头的指令字符串
Browse files Browse the repository at this point in the history
  • Loading branch information
Xujiayao committed Feb 10, 2024
1 parent b9f301d commit ed54cf6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ public static void init() {
});

MinecraftEvents.PLAYER_COMMAND.register((player, command) -> {
String input = "/" + command;

for (String excludedCommand : CONFIG.generic.excludedCommands) {
if (input.startsWith(excludedCommand + " ")) {
if (command.startsWith(excludedCommand + " ")) {
return;
}
}
Expand All @@ -161,15 +159,15 @@ public static void init() {

MINECRAFT_SEND_COUNT++;
if (MINECRAFT_SEND_COUNT <= 20) {
MutableComponent message = Component.literal("<" + Objects.requireNonNull(player.getDisplayName()).getString() + "> " + input);
MutableComponent message = Component.literal("<" + Objects.requireNonNull(player.getDisplayName()).getString() + "> " + command);

SERVER.getPlayerList().getPlayers().forEach(
player1 -> player1.displayClientMessage(message, false));
SERVER.sendSystemMessage(message);

sendDiscordMessage(MarkdownSanitizer.escape(input), Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : player.getDisplayName().getString())));
sendDiscordMessage(MarkdownSanitizer.escape(command), Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : player.getDisplayName().getString())));
if (CONFIG.multiServer.enable) {
MULTI_SERVER.sendMessage(false, true, false, player.getDisplayName().getString(), MarkdownSanitizer.escape(input));
MULTI_SERVER.sendMessage(false, true, false, player.getDisplayName().getString(), MarkdownSanitizer.escape(command));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CallbackI
//#if MC > 11900
@Inject(method = "performChatCommand", at = @At("HEAD"))
private void performChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, LastSeenMessages lastSeenMessages, CallbackInfo ci) {
MinecraftEvents.PLAYER_COMMAND.invoker().command(player, serverboundChatCommandPacket.command());
MinecraftEvents.PLAYER_COMMAND.invoker().command(player, "/" + serverboundChatCommandPacket.command());
}
//#else
//$$ @Inject(method = "handleChatCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;performCommand(Lnet/minecraft/commands/CommandSourceStack;Ljava/lang/String;)V"))
//$$ private void handleChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, CallbackInfo ci) {
//$$ MinecraftEvents.PLAYER_COMMAND.invoker().command(player, serverboundChatCommandPacket.command());
//$$ MinecraftEvents.PLAYER_COMMAND.invoker().command(player, "/" + serverboundChatCommandPacket.command());
//$$ }
//#endif
}

0 comments on commit ed54cf6

Please sign in to comment.