I'd like 8 players to add themselves to an arraylist using the /join command and send them each a different random job(8 in total) if they use the /randomjob command.I'd like to know how to add players to an arraylist(when they use the command) and how to send them a random job. This is my current code: Code: List<Player> player = new ArrayList<>(); Random r = new Random(); List<Job> job for(int i = 0;i < 8;i++) { int rand = r.nextInt(jobs.size()); jobs.remove(rand); }
@S431 onCommand, if the player issues the /join command, use ArrayList#add(Player's Value) to add the player to the arraylist. Remember, you should not add the full player instance to the array. Instead, provide the player's UUID or name. What plugin are you using for Jobs? Did you build your own system for jobs?
I want to send them each a message saying what job they have using the Random() method.(They'll each have a different job).I've created a random list for the jobs but I don't know how to give the 8 players each a different job.
@Zombie_Striker Thanks!Would you mind helping me store the Player's UUID? Code: public class Join implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { ArrayList<Player> players = new ArrayList<>(); if(cmd.getName().equalsIgnoreCase("join")){ Bukkit.getPlayer(id) } return false; } }
I changed it so that it uses the UUID and put the variable in the class.I rarely use ArrayLists so..I don't know how to add players to the Arraylist and send a random message to them.Could you help me?-do I need to predetermine the player's UUID value? Code: public class Join implements CommandExecutor { ArrayList<UUID> playeruuid = new ArrayList<>(); @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if(cmd.getName().equalsIgnoreCase("join")){ } return false; } }
@timtower Code: public class RandJob implements CommandExecutor{ HashMap<String,UUID> Joinuuid = new HashMap<>(); @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { } } return false; } }