How to give a player ONE random valuable item?

Discussion in 'Plugin Development' started by Peter25715, Dec 15, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Peter25715

    Hello there! :)
    I'm trying to make a new plugin for Christmas, I made a command with cooldown and it worked.
    But I'm wondering how do I give the command sender a random valuable item?

    current code : (not completed)

    Code:
         @Override
            public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            
             if (label.equalsIgnoreCase("Christmas")) {
                int cooldownTime = 60; // Get number of seconds from wherever you want
              
                if(cooldowns.containsKey(sender.getName())) {
                   
                    long secondsLeft = ((cooldowns.get(sender.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
                    if(secondsLeft>0) {
                       
                        sender.sendMessage("You cant use that commands for another "+ secondsLeft +" seconds!");
                        return true;
                    }
                }
               
                // No cooldown found or cooldown has expired, save new cooldown
                cooldowns.put(sender.getName(), System.currentTimeMillis());
                sender.sendMessage("§aHello! It worked!");
                return true;
               
            }
            return true;
         }

    Thank you. ;)
     
  2. Offline

    Gorbit99

    Make a list of the items you can get, then using a Random, get a random element of that list
     
  3. Offline

    MCMatters

    String array items has all the items
    new instace of Random
    Random#nextInt(items.size()-1);
     
  4. Offline

    Gorbit99

    Yeah, I just said that
    But why string array? A Material array or Itemstack array would be better
     
  5. Offline

    MCMatters

    @Gorbit99 wrong type sorry. Material array
     
Thread Status:
Not open for further replies.

Share This Page