Random Items on Join

Status
This thread has been locked.

Hoknee

Minecraft Server Owner
Premium
Feedback score
5
Posts
156
Reactions
36
Resources
0
I have been working at trying to figure out how to give a player a random item when they join. I know what to do for the events it's just I cant figure out how to make a random item on join looping through a bunch of items. I tried with ArrayLists and stuff but I errors. Can someone give me a snippet of code to help me.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Guusz

Full-Stack Web Developer
Premium
Feedback score
0
Posts
248
Reactions
138
Resources
0
ArrayList#get(new Random().nextInt(ArrayList#size()));
 

SimonM

Java Developer
Premium
Feedback score
12
Posts
190
Reactions
58
Resources
0
ArrayList#get(new Random().nextInt(ArrayList#size()));
Instead of creating a new instance of random on the spot, use ThreadLocalRandom.current().nextInt(ArrayList#size())
 

Hoknee

Minecraft Server Owner
Premium
Feedback score
5
Posts
156
Reactions
36
Resources
0
Instead of creating a new instance of random on the spot, use ThreadLocalRandom.current().nextInt(ArrayList#size())
It's all good, I ended up figuring it out on my own, it wasn't the Random problem it was my Bukkit Runnable task, I was grabbing instance of my Main class instead of an instance of my plugin. Lol stupid mistake.
 

SimonM

Java Developer
Premium
Feedback score
12
Posts
190
Reactions
58
Resources
0
It's all good, I ended up figuring it out on my own, it wasn't the Random problem it was my Bukkit Runnable task, I was grabbing instance of my Main class instead of an instance of my plugin. Lol stupid mistake.
It may not be the problem but I am suggesting to use ThreadLocalRandom instead of creating a new instance of random everytime
 
Status
This thread has been locked.
Top