Random Job Plugin

Discussion in 'Plugin Development' started by S431, Jun 4, 2017.

Thread Status:
Not open for further replies.
  1. 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);
    }
    
     
    Last edited: Jun 4, 2017
  2. Offline

    Zombie_Striker

    @S431
    1. 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.
    2. What plugin are you using for Jobs? Did you build your own system for jobs?
     
  3. 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.
     
    Last edited: Jun 5, 2017
  4. Offline

    ipodtouch0218

    Again, store the UUID of the player. Then, use Bukkit.getPlayer(uuid) to get the player instance.
     
  5. @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;
       
        }
    
    }
    
     
    Last edited: Jun 5, 2017
  6. Offline

    timtower Administrator Administrator Moderator

    @S431 Put the players variable in the class, not in the method.
    And make it use UUID and not Player
     
  7. 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;
       
        }
    
    }
    
    
     
    Last edited: Jun 6, 2017
  8. Offline

    timtower Administrator Administrator Moderator

    @S431 Where does the hashmap come from suddenly? If you changed your code then please post it.
     
  9. @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;
        }
    
    }
    
     
    Last edited: Jun 7, 2017
Thread Status:
Not open for further replies.

Share This Page