How to block a command from executing from a player

Discussion in 'Plugin Development' started by Archie, Apr 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Archie

    Okay so I'm just working on my little trolling plugin for a friend and I want to add a exception where the command can't be executed upon certain users (pre-stated in the plugin). I would use permission nodes except for the fact that he doesn't have permissions installed. What's a efficient way to do this?
     
  2. Offline

    Tamewolf

    Create an ArrayList of names that the commands can't be executed against, and then just check when the command is executed the argument with the player's name against the ArrayList.
     
  3. Offline

    foodyling

    public final List<String> Commands = new ArrayList<>() {{
    add("help");
    //Add any commands here or something
    }}
    @EventHandler(priority = EventPriority.HIGHEST)
    public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent Event) {
    try {
    if (Commands.contains(Event.getMessage().substring(1).split(" ")[0])) {
    Event.setCancelled(true);
    }
    } catch (Throwable Error) {
    }
    }
    and of course add some code in to check the command or what not. Keep in mind this is just an example of cancelling an event
     
  4. Offline

    Tamewolf

    Rather than cancelling the event itself, would it not be simplier to act as though the command passed through? Check the strings within the ArrayList against the argument in the command that holds the player's name and if it is on the list, just return true? I suppose either way would work.
     
  5. Offline

    Deleted user


    Code:java
    1.  
    2. @EventHandler()
    3. public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent Event) {
    4. if(event.getCommand().equalsIgnoreCase("help") {
    5. event.setCancelled(true);
    6. }
    7. }
    8.  


    Something along those lines, I'm coding here in the text editor so yeah haha.
     
Thread Status:
Not open for further replies.

Share This Page