Teleport Ask/Accept (tpa, tpaccapt, tpdeny) (help)

Discussion in 'Plugin Development' started by coldguy101, Apr 28, 2012.

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

    coldguy101

    Hello, I am making a TPA plugin just like what essentials has within it (just to see if I can.. not releasing it.) and I am having some trouble with the logic behind it.. It seems that I would need to store the usernames in a file until the person accepts the request but I am not sure. Is there a way to wait for a command from someone else while a command is still running? Haha.. see so many questions! Please answer either with code examples or an explanation, as “Just make files” or “put the command in a separate class” or something will not help me much :S Thanks!
     
  2. Offline

    r0306

    While the player used the command, store both player names into a hashmap, one as the keyset and the other as the value. When the player types /tpaccept, it checks the hashmap for the keyset and teleports the keyset to the value. After that, it removes both values from the map.
    Code:
    public Map<Player, Player> teleport = new HashMap<Player, Player>();
     
    public onCommand(blah blah blah){
    if (//command for /tpa goes here) {
    Player player = (Player) sender;
    Player player1 = Bukkit.getPlayer(args[1]);
    teleport.put(player, player1);
    return true;
    else if (//command for /tpaccept){
    Player player = (Player) sender;
    if(teleport.containsValue(player)){
    Player player1 = teleport.getValue(player);
    //teleport player1 to player
    return true;
     
    }
    
     
  3. Offline

    coldguy101

    Thank you very much. I dont know much about hash maps, so I didnt even think of a solution like this. I was making a configuration file to temporarly store the names in haha.
     
  4. Offline

    r0306

    Lol. Config files aren't suitable for this purpose as they are usually bulkier and take longer to read than hashmaps and that's why many people actually load their config files into a hashmap on plugin enable and save it back into the config file on disable, if I'm wrong please correct me. :)
     
  5. Offline

    coldguy101

    No Im sure hashmaps are much more sutible for this purpose :). You seem very knowledgeable on plugins and whatnot, would you mind adding me to skype? I wont bug you all the time :p Just ask the occational dumb question about plugin making/java/life :)
    If you want to you can add me, or give me your skype info, My skypename is coldguy101 :) Thanks for all your help!
     
Thread Status:
Not open for further replies.

Share This Page