Is there a way to simplify if(player.getWorld().getName().equals("something") || player.getWorld().getName().equals("something1")) Thanks!
The line? Well, you can make them variables instead or you can for-loop through an array if you have a bunch of worlds you are checking.
Yes, using a for-loop. Add all the worlds you want in the array or list. For-loop through the array or list to get its values. Or, check if the world if is in the array by doing array.contains vvvvvvvv
@timtower @mehboss @GRocksMc Wouldn't that be a waste of resources? Alocating a list, adding the two values and all that to make an if condition check a single boolean rather than two? Why not just: Code: String wName = player.getWorld().getName(); if(wName.equals("something") || wName.equals("something1")){ ... }
@timtower Well then you can make a method(String one, String... rest) and then compare 'one' to each of 'rest' and return true if one is equal to at least one of 'rest': Code: boolean isOneEqual(String one, String... rest){ FOREACH String s from rest: IF one.equals(s) then: return true; endIF; endFor; return false; } But judging by the OP's posts i deduced that he was aiming to check just two words
@timtower Yes. I am forth to knowing what things do before using them if the OP was to use a List then depending on the implementation the contains method would be different, for ArrayList it is very similar to the one above however using a linkedlist its not But again my main point is this If thats not the case then a list sounds like a good solution