Solved Event Ecxeption - Ban Plugin

Discussion in 'Plugin Help/Development/Requests' started by ScorixEar, May 24, 2015.

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

    ScorixEar

    And how can I implement this on the code?
    like this:
    Code:
    @EventHandler
        public void onCommand(PlayerCommandPreprocessEvent cv)
        {
            String cmd=cv.getMessage();
            if(cmd=="/ban")
                cv.setCancelled(true);
        }
        @Override
        public void onCommandUse(Player p, String[] args) {
    //what should I write here?
     
  2. Offline

    I Al Istannen

    Your code from the "CommandHandler" PlayerPreProcessCommandEvent. I added one comment.

    Code:
         
                Command com = null;
               
                for(Command comm : this.commandlist)
                {
                    if(comm.getCommand().equalsIgnoreCase(command))
                    {
                        com=comm;
                    }
                }
               
                if(com!=null) // A custom command was detected. Now, cancel the Event right after this if.
                {
    
                }
    
     
  3. Offline

    ScorixEar

    Oh thanks xD the german devs failed at this but you are great :D
    How can I change the CommandHandler that it works with all other plugin-commands except this? (just a additional question)

    Ok it doesn't work... I skip the mojang command with the plugin.yml but it skips not all /ban commands

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  4. Offline

    I Al Istannen

    @ScorixEar Could you explain it a bit further? If you cancel the PlayerPreProcessCommandEvent (with HIGHEST priority), no other Plugin will get the command. It won't be passed. That's why it is cancellable.

    To cancel "all other commands", simply cancel the PlayerPreProcessCommandEvent every time. Your commands will be detected and don't rely on the "onCommand" method, so they will work.
    The only problem would be other plugins using the PlayerPreProcessCommandEvent with HIGHEST priority too.
     
  5. Offline

    ScorixEar

    I'm sorry xD it works. Now how can I change the code so, that all Mojang-Commands, if they are in this plugin, skipped?
    Code:
    if(com!=null)
                {
                    if(com.getPermission()==null||e.getPlayer().hasPermission(com.getPermission()))
                    {
                        int arglength=argm.length;
                        if(arglength <com.getMinArgs())
                        {
                            e.getPlayer().sendMessage("§4Du hast zu wenig Argumente eingegeben. Bitte überprüfe deine Eingabe!");
                        }
                        else if(arglength >com.getMaxArgs())
                        {
                            e.getPlayer().sendMessage("§4Du hast zu viele Argumente eingegeben. Bitte überprüfe deine Eingabe!");
                        }
                       
                        else
                        {
                            if(command.equals("/ban"))
                            {
                                e.setCancelled(true);
                                com.onCommandUse(p, argm);
                            }
                            else if(command.equals("/kick"))
                            {
                                e.setCancelled(true);
                                com.onCommandUse(p, argm);
                            }
                            else
                                com.onCommandUse(p, argm);
                           
                           
                        }
    
     
  6. Offline

    I Al Istannen

    @ScorixEar Just write the "e.setCancelled()" right after the "com!=null". This way, EVERY time a custom command is detected the event gets cancelled wether it has enaugh args, the user has the permission or sth else fails.
     
  7. Offline

    ScorixEar

    Oh good, thank you, i think, this theme is finished :) Bye ;)
     
Thread Status:
Not open for further replies.

Share This Page