Skip to content

Commit

Permalink
fix: Re-added support for modifying native commands
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Sep 5, 2023
1 parent 4556d3b commit 1132007
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github._4drian3d.signedvelocity.velocity.listener;

import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.event.EventManager;
import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.PostOrder;
Expand All @@ -19,6 +20,8 @@ public final class PlayerCommandListener implements Listener<CommandExecuteEvent
@Inject
private EventManager eventManager;
@Inject
private CommandManager commandManager;
@Inject
private SignedVelocity plugin;

@Override
Expand Down Expand Up @@ -88,7 +91,11 @@ public void register() {
.append(finalCommand);
final byte[] data = builder.build();
server.sendPluginMessage(SignedVelocity.SIGNEDVELOCITY_CHANNEL, data);
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer(finalCommand));
if (this.isProxyCommand(event.getCommand())) {
event.setResult(CommandExecuteEvent.CommandResult.command(finalCommand));
} else {
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer(finalCommand));
}
continuation.resume();
});
}
Expand All @@ -102,4 +109,18 @@ private void allowedData(Player player, RegisteredServer server) {
final byte[] data = builder.build();
server.sendPluginMessage(SignedVelocity.SIGNEDVELOCITY_CHANNEL, data);
}

private boolean isProxyCommand(final String command) {
final int firstIndexOfSpace = command.indexOf(' ');
// In case the command executed is for example "/ test asd"
if (firstIndexOfSpace == 0) {
final String[] arguments = command.split(" ");
for (final String argument : arguments) {
if (argument.isBlank()) continue;
return this.commandManager.hasCommand(argument);
}
}
final String firstArgument = command.substring(0, firstIndexOfSpace);
return this.commandManager.hasCommand(firstArgument);
}
}

0 comments on commit 1132007

Please sign in to comment.