java - For Loop checking player locations -


this bukkit plugin, minecraft, using api.

i'm trying check if player in specified location, , if are, don't teleport player there. instead, check location, , spawn player there if it's empty.

it may better explained code below:

player player = (player) sender; list< player> prisoners = new arraylist< player>(); (int = 0; < prisoners.size(); i++) {     //loc(1-12) coords in form of location variable. wanted save room.     if (!(loc1 == prisoners.get(i))) {         player.teleport(loc1);     } else if (!(loc1 == prisoners.get(i).getlocation())) {         player.teleport(loc2);     } else if (!(loc2 == prisoners.get(i).getlocation())) {         player.teleport(loc3);     } else if (!(loc3 == prisoners.get(i).getlocation())) {         player.teleport(loc4);     } else if (!(loc4 == prisoners.get(i).getlocation())) {         player.teleport(loc5);     } else if (!(loc5 == prisoners.get(i).getlocation())) {         player.teleport(loc6);     } else if (!(loc6 == prisoners.get(i).getlocation())) {         player.teleport(loc7);     } else if (!(loc7 == prisoners.get(i).getlocation())) {         player.teleport(loc8);     } else if (!(loc8 == prisoners.get(i).getlocation())) {         player.teleport(loc9);     } else if (!(loc9 == prisoners.get(i).getlocation())) {         player.teleport(loc10);     } else if (!(loc10 == prisoners.get(i).getlocation())) {         player.teleport(loc11);     } else if (!(loc11 == prisoners.get(i).getlocation())) {         player.teleport(loc12);     } else {         player.sendmessage("sorry, prisoner's team full. try joining guards, or wait until next round.");         player.teleport(lobby);         prisoners.remove(player);     } 

i want check each location, , teleport player next available location going through list of players on prisoner's team, , checking location.

but, doesn't seem work, spawn in same position, how fix issue?

i use virtual players test multiple players, instead of paying accounts.

thanks in advance!

this condition

!(loc1 == prisoners.get(i)) 

will evaluate true loc1 co-ordinate , prisoners.get(i) player object. these never equal above condition evaluates to

!(false)  // meaning true 

so every iteration of loop execute player.teleport(loc1);

you need use .equals not == , make sure comparing 2 objects of same type.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -