store locations in array list

Discussion in 'Plugin Development' started by Infinity_Crafter, Sep 2, 2013.

Thread Status:
Not open for further replies.
  1. im trying to make a plugin that will save the player location and after 10 seconds will teleport the player to the saved location... i saved the player location in the array list now... but - how do i take it out?
  2. Offline


  3. Offline


    You will need to use a HashMap if more than one player will be teleported:
    Location savedLocation;
    HashMap<String, Location> locs = new HashMap<String, Location>();
    // Add to map
    locs.put(playerName, savedLocation);
    // Get from list and teleport
    Location anotherLoc = locs.get(playerName);
    // Remove from map
    Infinity_Crafter likes this.
  4. Chinwe thx man :)

    EDIT: Chinwe that doesnt work :( im trying to teleport the player to anotherLoc but its doesnt do anything :(
  5. Offline


    By doesn't work do you mean it simply doesn't teleport them, or errors?
    Code + stacktrace (if you got one) please ;)
  6. Chinwe
    EDIT~: its works! :D thx :) another question :p do you know how can i use PathFinder? (easiest way :p) so il be able to make mob goes to location the player pointing at?
    here :D (i do get the message of Teleporting... after 10 sec.. its just doesnt tpa me..)
    1. @EventHandler
    2. public void onInteractM(final PlayerInteractEvent e){
    3. final Player p = e.getPlayer();
    4. if (p.getItemInHand().getTypeId() == 382 && e.getAction() == Action.RIGHT_CLICK_BLOCK &&
    5. !(p.getItemInHand() == null)) {
    6. locs.put(p.getName(), p.getLocation());
    7. new BukkitRunnable(){
    8. @SuppressWarnings("deprecation")
    9. @Override
    10. public void run(){
    11. p.sendMessage("Teleporting...");
    12. Location anotherLoc = locs.get(p.getName());
    13. p.teleport(anotherLoc);
    14. locs.remove(p);
    15. }
    16. }.runTaskLater(Mech, 200L);
    17. }
    18. }
    19. }
Thread Status:
Not open for further replies.

Share This Page