How can i make a random Picker for Potions with codes like these? Code: event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 20)); I want that that the picker picks a random potioneffect. push/ i need quick help EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code: Random num = new Random(); int gotNum = num.nextInt(5) This will generate a number from 0->5 and then from this just have Code: if(gotNum==1) //Potion 1 if(gotNum==2) //Potion 2
PotionEffectType is an enum, right? You can use .values() to get an array of all values, that's way more simple (but you ca neither weight the results nor only take specific ones). Code: PotionEffectType[] allTypes = PotionEffectType.values(); PotionEffectType type = allTypes[yourRandom.nextInt(allTypes.length)];
But with the other solution i can add other things like sendmessage etc... I will give you a like too because your solution works too ;D