Skip to content

Commit

Permalink
Add CommandExecuteEvent handler to forward unauthorized commands
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Jul 29, 2024
1 parent 7b9e599 commit ee3ff1a
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
import com.velocitypowered.api.permission.Tristate;
import lombok.RequiredArgsConstructor;
Expand All @@ -21,4 +22,13 @@ public void onCommandSend(PlayerAvailableCommandsEvent event) {
return !event.getPlayer().hasPermission(permission);
});
}

@Subscribe(order = PostOrder.LAST)
public void onPlayerChat(CommandExecuteEvent event) {
if (!event.getResult().isAllowed()) return;
var command = event.getCommand().replaceFirst("/", "").stripLeading();
var permission = commander.permissionOverride().permission(command);
if (permission != null && event.getCommandSource().hasPermission(permission)) return;
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
}
}

0 comments on commit ee3ff1a

Please sign in to comment.