So i'm making a plugin and I need the code to dispatch a command while a 2 string lists.hasNext(). the two lists have different numbers of names inside of them so the while code won't run when one of the lists runs out of names. And I dont want it to stop if string list #1 or list #2 is out of names but only if both of them are out of names. Does anyone know how i would go about doing this?
You obviously need to add your own code as well Code (Text): while (list1.hasNext() && list2.hasNext()) { list1.next(); list2.next(); }[CODE]
Here's the code that regards this: Code (Text): if (args[1].equalsIgnoreCase("confirm")) { Iterator<String> it = allsubmits.iterator(); Iterator<String> i = world.iterator(); while(Stuff i need help on) { String submitting = it.next(); String worldz = i.next(); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),"lp user " + submitting + " permission unset worldguard.build.* global " + worldz); }
Code (Text): if (args[1].equalsIgnoreCase("confirm")) { Iterator<String> it = allsubmits.iterator(); Iterator<String> i = world.iterator(); while(it.hasNext() && i.hasNext()) { String submitting = it.next(); String worldz = i.next(); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),"lp user " + submitting + " permission unset worldguard.build.* global " + worldz); } ... Wouldn't this be the solution then?
i've tried that but. lets say "it" only has 1 name in it and "i" has 2. The command won't dispatch after it's read "it" because it only has 1 and it just read that one and now the && statement is now false because "it" doesn't have next.
Make 2 Strings which are null Code (Text): while (! list1.hasNext() && !list2.hasNext()) { if (list1.hasNext()) { String last1 = list1.next(); } if ( list2.hasNext()) { String last2 = list2.next(); } //Run code here }
Wouldn't you want to nest two for loops? Code (Java): for each world: for each player: dispatchCommand ...