Solved Block commands with onCommand() ?

Discussion in 'Plugin Development' started by To175, Dec 27, 2014.

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

    To175

    Hi,
    My code doesn't work :(
    The main command is /MECRAFT
    But I want to block /BUKKIT:...
    I had to add it in plugin.yml ??
    It doesn't work :(

    Thanks :)

    Code (open)

    Code:
        @SuppressWarnings("deprecation")
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {       
    if(cmd.getName().toLowerCase().contains("bukkit")||cmd.getName().toLowerCase().contains("plugin")){
                if(sender instanceof Player){
                    Player player = (Player) sender;
                    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "kick "+player.getName()+" Pas de /bukkit !");
                    getLogger().info(player.getName()+" Pas de /bukkit !");
                    return false;
                }
            }
    //[other commands....]
    
     
  2. Offline

    teej107

    PlayerCommandPreprocessEvent
     
    ChipDev likes this.
  3. Offline

    To175

    Please EXPLAIIIIINNNN
     
  4. Offline

    Concurrent

    @To175 self explanatory if you try it. event#getMessage returns the string entered.
     
  5. Offline

    To175

    I don't understand a word of what you are saying ! I use onCommand, I want to block the command with "bukkit"
    @Concurrent @teej107
     
    Last edited: Dec 27, 2014
  6. Offline

    teej107

    I or somebody else should make a resource about using the event.
    @To175 You can't use the onCommand method to block commands. Use the PlayerCommandPreProcessEvent
    1. Split the message by whitespaces
    2. Compare the array values returned
    3. ????
    4. profit!
     
  7. Offline

    To175

    Ok thanks, I will try
     
  8. Offline

    SuperOriginal

    @teej107 Pls make resource, will add to signature.
     
  9. Offline

    To175

  10. Offline

    teej107

  11. Offline

    To175

    @teej107
    thanks :)
    Is this issue the same origine ? I can't do that :( (false returned)
    Code:
    Boolean existe = reponse.toString().matches(player.getName());
    I tried Arrays.toString(reponse) but it sais to convert reponse to a long type :(
     
  12. Offline

    teej107

    No. Read the documentation for the matches() method for String.
     
  13. Offline

    To175

    @teej107
    Ok thanks,
    hey you are just making fun of me !!!
    (I quote your messages, there is nothing displayed...)
     
  14. Offline

    teej107

    What do you mean? When you quote a message, the quotes in that message are left out.
     
  15. Offline

    To175

  16. Offline

    teej107

    @To175 Oh. No, I wasn't making fun of you. It's just a joke not directed toward anyone.
     
  17. Offline

    To175

    @teej107
    Ho ! I already search for that ! I just don't know how to turn my List<String> into a String :( It doesn't want !
     
  18. Offline

    teej107

    @To175 What do you mean exactly?
     
  19. Offline

    To175

    @teej107
    sorry,
    Code:
    List<String> reponse = getConfig().getStringList("MecraftConnu");
    Boolean existe = reponse.toString().matches(player.getName());
     
  20. Offline

    teej107

    @To175 No that is not the way to do it. Turning any object into a String will usually return a bunch of garbley goop unless the toString() method is overridden. What do you want to achieve with that piece of code exactly?
     
  21. Offline

    To175

    @teej107 thx,
    I want to check if to175 has already sent the message. The messages are stored into "MecraftConnu"
    Example :
    Code:
    MecraftConnu:
    - hello (Bundat_)
    - test (to175)
    - lololo (miner)
     
  22. Offline

    teej107

    @To175 Maybe you should check to see if the list contains an object instead rather than matching with some player name who idk why or how his name would have regex.
     
  23. Offline

    To175

    no you didn't understand, I said message are like
    1. - test (to175)
    Are you sure THE LIST contains to175 ? I think this is only the arg, no ?
    @teej107
     
  24. Offline

    BrentHogeling

    @To175 Well, what you are doing is the completely wrong way to go, you instead want to split the different messages into ConfigurationSections, then each one will have it's own StringList containing the players names, for example:

    MecraftConnu:
    hello:
    - Bundat_
    test:
    - to175
    lololo:
    - miner

    So now, if you do file.getStringList("MecraftConnu.hello)" this will return a set which includes all the names, in this case Bundat_. To then check if the list contains that persons names, you just do listname.contains("To175"), and run any code after that. Hope it helps :)
     
    teej107 likes this.
  25. Offline

    To175

    There will be more than 1000 messages...
    @BrentHogeling
    And just for info, I don't know the message. I just know the player name
     
  26. Offline

    BrentHogeling

    @To175 I have no idea what you are even trying to achieve, fully explain
     
  27. Offline

    To175

    @BrentHogeling @teej107
    Thanks,
    I want to know how players have discovered my server ! So I ask them to do /mecraft reponse <their answer here>
    Then I store their answer. I want only 1 answer per player. :)
     
  28. Offline

    teej107

    @To175 Well check to make sure the location in the YAML exists. (hopefully it will contains the player's UUID). Then in the value, store what they wrote.
     
  29. Offline

    BrentHogeling

    @To175 Oh I see, makes it a lot clearer. What you could then do is, in the case you have a lot of responses, when the player runs the command, create a file from their UUID called UUID.yml, UUID being their UUID, in that file just add the message they had typed. When they do run the command, this applies for the first time, check whether the file you made exists, if it doesn't, carry on like normal, if it does, they have already responded, if it isn't clear tell me.
     
  30. Offline

    To175

    Why I have to use those damned UUID ????

    It seams to be to heavy... I will make like #24 said. With a purge command.
    Is date() a timestamp ?
     
Thread Status:
Not open for further replies.

Share This Page