Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Confirmation Commands

Comments in 'Plugin Development' started by Tethered_, Nov 24, 2014.

  1. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    What I want to be able to do is when someone runs a command, they are prompted with a confirmation command. Ex:

    /command
    (to player) Are you sure? /y or /n
    /y
    (to player) Confirmed
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I would suggest just using "y" and "n" instead of "/y" and "/n".
  3. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    oh so do something like on chat event get player, if its the player who ran the code and it says y then execute code?
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Exactly.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I'll make an example plugin (or API) for doing this soon.
    iJoshuaHD likes this.
  6. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    Would I make a separate event that only runs when I'm looking for y or n, or should I do something like declare a global variable ( $scanYorN = false ) and set it to true for say 1 minute when I need an answer. Then under the event add something like:

    if( $scanYorN == true ) {
    $player = $event->getPlayer();
    if ( $player == ( player I need a y or n from ) {
    if( $event->getMessage() == "y" {
    //code to be executed​
    }
    if ( $event->getMessage() == "n" {
    //code to be executed​
    }​
    }

    or is there a more simple and efficient way to do this?

    *side note: how do I paste code and make it appear in the "code" box here?

  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You have to do some sessioning. Initialize an array field, when you want confirmation $this->sessions[$player->getID()] = true, when confirmation done unset that element or set to false.
    P.S. [PHP][/PHP]

Share This Page

Advertisement