How would I do /twerk accept?

Discussion in 'Plugin Development' started by JustinsCool15, Aug 7, 2014.

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

    JustinsCool15

    So I need to make it so when a player starts my micro game with another player it sends the other player a message asking them to accept or decline or if they wait 60 seconds it will time out. I've tried a few things. I've tried to listen for a PlayerCommandPreprocessEvent that used a bunch of Hashmaps to see who the original sender was and make the game start but that completely failed. I just want it so when Player1 types /twerk start <player2> it prompts Player2 to /twerk accept or decline then if they accept the game says "Game starting in 5 seconds." then the game starts. This is a micro game so It's all just in one class file.

    Here's how I have it now with just /twerk start <player> <player> which an admin has to do.
    http://pastebin.com/nuHr5sg4
     
  2. Offline

    Neymar11

    First save the player1(the one who executes the command /Twerk start player2)
    in a global variable, something like this:
    string twerkSender = "";
    Then in the onCommand where player1 does the command add following:
    twerkSender = sender.getName();

    Then add this under it:
    Code:java
    1.  
    2. Player target = Bukkit.getPlayer(args[1]);
    3. if(target != null){
    4. target.sendMessage(twerkSender + " asks you to twerk! /twerk accept/decline :)");
    5. if ([SIZE=12px][FONT=Consolas][COLOR=#000000]args[/COLOR][/FONT][/SIZE][SIZE=12px][FONT=Consolas][COLOR=#009900][[/COLOR][/FONT][/SIZE][SIZE=12px][FONT=Consolas][COLOR=#cc66cc]0[/COLOR][/FONT][/SIZE][SIZE=12px][FONT=Consolas][COLOR=#009900]][/COLOR][/FONT][/SIZE][SIZE=12px][FONT=Consolas][COLOR=#000000].[/COLOR][/FONT][/SIZE][SIZE=12px][FONT=Consolas][COLOR=#006633]equalsIgnoreCase[/COLOR][/FONT][/SIZE][SIZE=12px][FONT=Consolas][COLOR=#009900]([/COLOR][/FONT][/SIZE][SIZE=12px][FONT=Consolas][COLOR=#0000ff]"accept"[/COLOR][/FONT][/SIZE][SIZE=12px][FONT=Consolas][COLOR=#009900])[/COLOR][/FONT][/SIZE]
    6. {
    7. target.sendMessage(wm + gry + " The twerk off will begin in 5 seconds!");
    8. twerkSender .sendMessage(taget + " has accepted!");
    9. twerkSender.sendMessage(wm + gry + " The twerk off will begin in 5 seconds!");
    10. }
    11. else {
    12. twerkSender .sendMessage(taget + " has declined!");
    13. }
    14. }else{
    15. sender.sendMessage("You entered an invalid player name!");
    16. }
    17.  
    18.  


    EDIT: I am not sure I understand what you exactly mean, but hope it helps though :3
     
  3. Offline

    artish1

    JustinsCool15
    You can always create a new Class called Invitations and create an InvitationHandler/InviteHandler (again the names are just my opinion, name them w/e you want, ex: Challenge, ChallengeHandler).

    In the invitehandler, create your HashMap<String,Invitation> there and make it static so you can access it with InviteHandler.map, or InviteHandler.getMap(); (if you want to create a getter).

    And basically create a new instance of Invitation when a player does /invite <Player>, and create the Constructor to recieve Player sender, Player reciever, and the Plugin (if you want to schedule a delayed task to remove the Invitation from the handler ("This invitation has expired", "Invitation will expire in 20 seconds")).

    Then when a player does /accept, or /deny. Check if they are in the InviteHandler's reciever Invitation map.
    If so get the Invitation, and do something like Invitation invite = map.get(uuid).accept(), (if you have made an accept() method in your invitation.)
     
Thread Status:
Not open for further replies.

Share This Page