Teleporting players to same location if they have the same hashmap value?

Discussion in 'Plugin Development' started by ESSHD, Oct 18, 2015.

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

    ESSHD

    Hello,

    I am trying to teleport players who have the same HashMap value (Team number) to the same place.

    I currently have this code:

    Code:
                for (String n : UHC.getInstance().team.keySet()) {
                    Player p = Bukkit.getPlayer(n);
                    HashMap<Integer, Integer> xcoord = new HashMap<Integer, Integer>();
                    HashMap<Integer, Integer> zcoord = new HashMap<Integer, Integer>();
                    xcoord.put(UHC.getInstance().team.get(n), getRandom(-1000, 1000));
                    zcoord.put(UHC.getInstance().team.get(n), getRandom(-1000, 1000));
                    int y = Bukkit.getWorld(UHC.getInstance().worldname).getHighestBlockYAt( xcoord.get(UHC.getInstance().team.get(n)), zcoord.get(UHC.getInstance().team.get(n)));
                    Location loc = new Location(Bukkit.getWorld(UHC.getInstance().worldname), xcoord.get(UHC.getInstance().team.get(n)), y, zcoord.get(UHC.getInstance().team.get(n)));
                    p.teleport(loc);
                    p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 1.0F, 0.0F);
                    return;
                }
     
  2. Offline

    Scimiguy

    Put these two lines outside the for loop

    1. xcoord.put(UHC.getInstance().team.get(n), getRandom(-1000, 1000));
    2. zcoord.put(UHC.getInstance().team.get(n), getRandom(-1000, 1000));
    @ESSHD
     
  3. Offline

    Zombie_Striker

    So you will create a NEW HashMap for EACH String? And then after each new HashMap is created, put in ONE Random Coord into each HashMap.
     
Thread Status:
Not open for further replies.

Share This Page