Solved How i check if a player has executed a specific command?

Discussion in 'Plugin Development' started by Gonmarte, Mar 21, 2016.

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

    Gonmarte

    Its all in title :)
    Thank you!
     
  2. Offline

    mine-care

    @Gonmarte
    It is in the title indeed, but a litle elaboration about the perticular situation you are refering to wouldnt be that bad ;)
    Well, if you want to handle a command for your plugin, you need either a command handler or to override the onCommand method in your main class (and in both cases, register the command in Plugin.yml).
    If you want to catch a specific command that is not registered/handled by your plugin, you need to listent for CommandPreProcessEvent.
     
  3. Offline

    Gonmarte

    Imagine, i invite a player to my party/team/clan/guild whatever, and he has to accept. So in my command /clan add <target> i want to check inside it if the target (the <target>) executed the command /clan accept., if so i can run the command suceffuly.
     
  4. Offline

    mine-care

    @Gonmarte Ah see, giving the senario is truly useful!
    So for this, you may want to add players in a map along with who invited them (or what party invited them) and listen out for /clan accept. Once a player performs the command, check if they are in the map (so if they have any invitation) and if they do, it means they accept the request. Otherwise if they do /clan decline, remove them from the map.
     
    Gonmarte likes this.
  5. Offline

    Gonmarte

    AHH i think i got it, so i dont need to run a command inside a command i just create them separately and then use the hashmap for the checks. I will give it a try and share the results with you. Thank you!
    @mine-care So when i create a clan i need to do add the player who created that clan to the map of the requests. So can i do this ??

    Code:
    myMap.put(null , player.getName());
    
    and then whem the player do /clan add <target> i do
    Code:
    myMap.put(target.getName() , player.getName());
    
    It is ok?
    Ik i still need to work on /clan accept and /clan decline, but i just want to confirm if it is correct to put a null key in a map.
    Ty
     
    Last edited: Mar 21, 2016
  6. Offline

    mine-care

    @Gonmarte Not really.
    I dont see the reason for the use of null key :/
    Let me outline the structure once more because above i wasn't very clear,
    1. Create a Map.
    2. Once a player invokes /clan invite <Player>, send the target the message that they where invited in a clan, and then add the name of the target as key, and the one who invited them as value or lets say, a Clan object in the map.
    3. Once the other side invokes /clan accept, check if the map contains their name/UUID (remember it is set as key value) and if it does, get the associated value which is the one who invited them or anything else you set in step 2, and add them to the clan ;) (Depends on your implementation currently, i cant help on that)
    4. remove them from the map.
    5. In case they do /clan decline, check if they are in the map, and if they are, remove them.
     
    Gonmarte likes this.
  7. Offline

    Gonmarte

    Thank you so much, it worked. Now im going to be solving a problem that i got with this new features -but its not about this - and then im going to work on a delay task to accept the request. Im not going to mark this as solved once i might need help to squash that bugs.
    Thank you once again.
    EDITED: Squashed the bug, now im going to work on the delay task :)
    @mine-care Just for curious what would happend if two clans invite the same player? If the player puts /clan accept it would join to the last invite? Or it wouldnt work once the player name would be in 2 different values in the map?
    EDIT: Nvm, just tested and it will be added to the last invite!

    @mine-care Thank you for the help, i solved everything! :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 21, 2016
    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page