Override /plugins

Discussion in 'Plugin Development' started by Mr. X, Jul 15, 2012.

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

    Mr. X

    Hi
    I have written a plugin, that should modify the output of plugins, but i don't know how i can override the existing /plugins cmd from bukkit. I testet PlayerCommandPreprocess but that dont works. Any ideas?
     
  2. How could that not work, just check if the command is plugins, of one of its aliases, and if it is that, cancel the event, that should work, and after you canceled the event you just send the player your own message.
     
  3. Offline

    Mr. X

    i.d.k, i use this but that dosen't works:
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlayerCommandPreprocess(PlayerChatEvent event){
            if(event.getMessage().startsWith("/plugins") || event.getMessage().startsWith("/pl") || event.getMessage().startsWith("/plug")){
                String args[] = event.getMessage().replaceFirst("/plugins ", "").replaceFirst("/plugins", "").replaceFirst("/pl ", "").replaceFirst("/pl", "").replaceFirst("/plug ", "").replaceFirst("/plug", "").split(" ");   
                //do work
                event.setCancelled(true);
            }
        }
     
  4. why not revoke the permissions for the /plugins bukkit.command.plugins
     
  5. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Because that would be too simple.
     
  6. Offline

    Firefly

    I do this for one of my plugins:

    Code:
    String[] args = message.split(" ");
     
    if (Arrays.asList(args).get(0).equalsIgnoreCase("/plugins") {
        //Code
    }
     
  7. Offline

    one4me

    If you really don't want to just take away the permission that lets players use /plugins, just use this
    Code:
    @EventHandler
    public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event) {
      if(event.getMessage().toLowerCase().startsWith("/pl")) {
        event.setCancelled(true);
      }
    }
    Of course since you would be using startsWith(), anything else that starts with "pl" would also be canceled.
     
  8. Offline

    Taco

    Or you could use Firefly 's code above, and use an "or" for the case of someone using /pl. That would eliminate that issue entirely, since as far as I know, /plugins and /pl are the only aliases that goes by.
     
  9. Offline

    Mr. X

    Now i use this:
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
    public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
    String args[] = event.getMessage().split(" ");
    if(args[0].toLowerCase() == "/plugins" || args[0].toLowerCase() ==  "/pl"){
      
    onCommand(event.getPlayer(), null, null, args);
    event.setCancelled(true);
    }
    }
    but i triggers the event when i type "/plgshdj" and i want only while type "/plugins" or "/pl".
     
  10. Don't use toLowerCase() that often, store its result.
    You should use .equals() to check that... or even .equalsIgnoreCase() and you can skip the .toLowerCase() part.

    Also, why do you trigger onCommand() ?

    But why are you guys ignoring the fact that you can just revoke the permission for /plugins command like ferrybig said above ? That won't require any plugin and it's alot easier to do... just revoke "bukkit.command.plugins" permission.
     
  11. Offline

    Mr. X

    Now i use the Code below but /plttt oder /plaaa .... triggers "event.setCancelled(true);" but i don't know why :(
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
            String args[] = event.getMessage().split(" ");   
            if(args[0].equalsIgnoreCase("/plugins") || args[0].equalsIgnoreCase("/pl")){
                //this
                event.setCancelled(true);
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page