Issue with accepting TPA request

Discussion in 'Plugin Development' started by jamiemac262, Sep 15, 2013.

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


    hi, i have recently been working hard to introduce teleport requests (my own version of tpa requests) to my plugin, for the most part the TPA feature works perfectly, except a small little bug.

    when a player accepts a TPA request the plugin doesnt do anything! that is, until the accepting player says something else, and as long as the request hasnt timed out, i have looked over the code thoroughly and cannot see the issue :/ could someone help please?

    Here is the code for sending a request - it creates a new thread to handle it
    1. if ((containsString(Playermessage, "sai") && containsString(Playermessage, "tpa")))
    2. {
    3. if (p.hasPermission("sai.tpa")) {
    5. senderTPA = p;//Set temp vars to be used in the threaded tpa
    6. targetTPA = finder.findPlayerInArray(Playermessage);
    7. if (targetTPA != null)//make sure its a real player
    8. {
    10. chat.setCancelled(true);//cancel chat so everyone doesnt see it.
    11. new Thread(new TeleportRequestable()).start();//Start a new thread of teleportRequestable @ run function
    12. } else {
    13. new SendPrivateAIMessage(p, 0.5, "Im sorry, who would you like to teleport to?", "You didnt say who you wanted to go to!", "No players recognized!");
    14. }//^^Standard stuff...
    15. } else {
    16. noPerms();
    17. }

    Here is the code from the thread

    1. public void run() {//Main thread
    3. Player target = ServerChatListener.targetTPA;//Creates a local threaded variable for target and sender
    4. Player sender = ServerChatListener.senderTPA;//from the temp one in ServerChatListener
    5. publicSender = sender;//New public vars, as the ones in ServerChatListener will get rewrote with each tpa
    6. publicTarget = target;
    7. SendMeToMsg(target, sender);//Sends Sais PM to ask about the tpa request
    8. for (Checks = 0; Checks < 60; Checks++) {//for 60 intervals of half a second, the telecheck variable is set
    9. try { // to true, and false after the 30th second to expire request
    10. TeleCheck = true;
    11. Thread.sleep(500); // Refer to ServerChatListener for the rest...
    13. if (Checks == 59) {
    14. TeleCheck = false;
    15. }
    16. } catch (InterruptedException ex) {
    17. Logger.getLogger(TeleportRequestable.class.getName()).log(Level.SEVERE, null, ex);
    18. }
    19. }
    21. }

    Here is the code for checking if a player has accepted the request
    1. if ((targetTPA == p && TeleportRequestable.TeleCheck) && (containsString(Playermessage, "yes") || containsString(Playermessage, "sure") || containsString(Playermessage, "yep") || containsString(Playermessage, "yeah"))) { //^^ is the player the target who excepts? and do they say yes...
    2. //TODO add deny function
    3. TeleportRequestable.toMe(TeleportRequestable.publicSender, p);//Commence teleport
    4. new SendAIMessage(0.5, "Haha it worked! Not bad!", "Wait what, how did I do that?", "To infinity and beyond! okay, that was a little cheesy...");
    5. TeleportRequestable.Checks = 59;//Set the checks to 59 to emulate teleport request expiring
    6. chat.setCancelled(true); //cancel chat so no spam from everyone teleporting

    if you require any additional information, such as the declaration of the variables used or any other methods, i will be only too happy to help :)
  2. Offline


    Why create new threads? Just save a HashMap<String, String>, the key being the player requesting to teleport and the value being the player to teleport to. Then, on the onCommand(), use map.put(player.getName(), target.getName()), player being the player who sent the command and target being the player to teleport to, and then send a message to the target player saying that this player wants to teleport to them.
  3. Offline


    i should have mentioned SAI simulates a real life player, everythings done in the chat listener, no commands

    and i didnt right this code, it was a contribution from a friend. nor do i have the faintest idea what a HashMap is :/
Thread Status:
Not open for further replies.

Share This Page