[Concept] Multi-Player commands

Discussion in 'Plugin Development' started by Ahniolator, Sep 29, 2011.

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

    Ahniolator

    I was wondering if this concept was possible:

    player1 types a command, and initiates the command sequence /tp player1 player2. The command then waits for player2 to type /accept or /deny. Depending on the result, the command executes the "accept" or "deny" code. If a response is not given within x seconds, the deny code (or a "noresponse" code chunk) gets executed.

    If this is possible, would someone care to explain how it would work? Any constructive input is greatly appreciated :D

    Please not that this does not necessarily have to apply to a teleport command. /tp was just used as an example.
     
  2. Offline

    alexanderpas

    this question is a two parter:
    1) letting player 2 respond to player 1
    2) the timeout.

    Point 1 is easy.

    there are two onCommand sections involved:
    - the request.
    - the response.

    In the request, you store the request in the queue of your plugin (using the playername of player2 or similar as a key), and just send the messages.

    In the response, you check what the request was for that player, and execute the requested command (if applicable).

    this is no different than single player commands that require confirmation. (just need some additional checks to see if player is online etc.)

    regarding point 2, I'm sorry, but can't help you with that.
     
  3. Offline

    desht

  4. Offline

    Ahniolator

    @desht @alexanderpas

    I understand how to use the scheduler tasks, but I'm not sure how I would store the request. Would you happen to have some example code that I could base mine on? Running on 1 hour of sleep isn't doing well for my coding right now :p
     
  5. Offline

    oyasunadev

    This is basic Java. Use a HashMap.
     
  6. Offline

    Ahniolator

    I was already aware that the use of a HashMap would be required. In context, I wasn't exactly sure what data I wanted to store in it for the keys and values. Maybe I should just tackle this after I get some sleep :/
     
  7. Key: Target player's name
    Value: Sender player's name
     
  8. Offline

    Ahniolator

    Let me clarify a bit:

    Along with the request in and of itself, I'm also trying to store 2 Integers as well as a Byte. That is why I was confused as to what I should be using.
     
  9. Offline

    desht

    Create a class which contains all the fields you need (sounds like you want target player plus 2 integers plus a byte), along with the appropriate constructor(s), accessors/mutators, etc.

    Then store an object of type HashMap<String,YourNewClass> in your plugin. That hashmap is keyed by the the sending player and the values are instances of your new class.
     
Thread Status:
Not open for further replies.

Share This Page