Getting players last location

Discussion in 'Plugin Development' started by TaiSmoove, Jun 28, 2013.

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

    TaiSmoove

    Code:java
    1. package me.taismoove.lists;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.List;
    6.  
    7. import me.taismoove.main.Main;
    8.  
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Location;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandExecutor;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.entity.Player;
    15.  
    16. public class EventCommandExecutor implements CommandExecutor{
    17. public static Main plugin;
    18.  
    19. public boolean isInArena = false;
    20.  
    21. private final String cPrefix = ChatColor.RED + "[" + ChatColor.BLUE
    22. + "CodeCraft" + ChatColor.RED + "]";
    23. private final String noPerms = cPrefix + " " + ChatColor.BLUE
    24. + "Insufficient permissions!";
    25.  
    26. HashMap<String, Location> plLastLoc = new HashMap<String, Location>();
    27.  
    28. List<Player> joinArena = new ArrayList<Player>();
    29.  
    30. public EventCommandExecutor(Main main) {
    31. main = plugin;
    32. }
    33.  
    34. public boolean onCommand(CommandSender se, Command cmd, String cmdl, String[] args){
    35. Player pl = (Player) se;
    36. if(cmd.getName().equalsIgnoreCase("join")){
    37. if(se.hasPermission(new Permissions().join)){
    38. if(se instanceof Player){
    39. if(args.length == 0){
    40. if(!isInArena){
    41. isInArena = true;
    42. joinArena.add(pl);
    43. se.sendMessage(cPrefix + " " + ChatColor.BLUE + "FIGHT!");
    44. public Location l = plLastLoc.put(pl.getName(), pl.getLocation());
    45. }else{
    46. isInArena = false;
    47. joinArena.remove(pl);
    48. se.sendMessage(cPrefix + " " + ChatColor.BLUE + "BYE");
    49. pl.teleport(l);
    50. }
    51. }
    52. }
    53. }
    54. }
    55. return false;
    56. }
    57. }
    58.  


    I need help. I'm trying to get the players last location and then when he/she types /join again it will teleport he/she where he/she was when he/she executed the command
     
  2. Offline

    CubieX

    One possible way:
    Add the players name as key and the last location as value to a HashMap, if the player types /join and is not yet on the map.
    And if he issues the command while he is already on the map, teleport him back to this location stored in the map and delete him from the map.
     
Thread Status:
Not open for further replies.

Share This Page