RandomChooser

Discussion in 'Plugin Requests' started by adi0115, Aug 16, 2016.

Thread Status:
Not open for further replies.
  1. This plugin prevents specific people using a command unless they get choosen by the plugin. For exmaple lest take /music, nobody can choose /music not even ops, unless a staff member does /rc spin, the plugin will chose a random player who is added in the config, if the player is choosen he can use /music until the next spin.
    Exmaple of a config:
    Commands:
    - music
    Players who can be choosen by the plugin:
    - Notch
    - JoeDoe

    If someone does /rc spin, only those people can be choosen and they have to be online.
    Permissions:
    rc.spin - allows to spin the plugin to choose the player
    rc.reload - allows a reload of the plugin
    Commands:
    /rc spin - spins the plugin to choose a random player
    /rc reload - reloads the plugin.
    I would like a message when the spin chooses a player maybe with %player% viarable.
     
  2. Offline

    szalonczuker

    With getServer().getOnlinePlayers() you can get all the players currently on the server. If you do it like this:

    Code:
            Object[] playersObj = getServer().getOnlinePlayers().toArray();
            Player[] playersOnline = new Player[playersObj.length];
           
            for(int i = 0; i < playersObj.length; i++) {
               
                playersOnline[i] = (Player) playersObj[i];
               
            }
           
            Player selected = playersOnline[(new Random()).nextInt(playersOnline.length)];
    you will get a player randomly from the server. You can add a specified permission to the player, so you can check if they were chosen.

    If you insert
    Code:
    getServer().broadcastMessage("RandomChooser selected " + selected.getDisplayName() + "!");
    or
    Code:
    getServer().broadcastMessage(getConfig().getString("path").replace("%player%", selected.getDisplayName()));
    it'll broadcast the message with your selected player.

    This is my fiiiirst answer!! :DD
    Hope it helped :)
     
  3. So people will get selected if they have a specific permission instead of adding their name to the config?
     
  4. Offline

    szalonczuker

    I wouldn't add their name in the config, instead giving them a permission or - a better way - store their "win" in a variable.
    Code:
    
    Object[] playersObj = getServer().getOnlinePlayers().toArray();
    Player[] playersOnline = new Player[playersObj.length];
    
    for(int i = 0; i < playersObj.length; i++) {
    
    playersOnline[i] = (Player) playersObj[i];
    
    }
    
    Player selected = playersOnline[(new Random()).nextInt(playersOnline.length)];
    
    currentlySelectedPlayer = selected;
    
    Code:
    public static Player currentlySelectedPlayer = null;
    Code:
    public boolean onCommand(...) {
         
            if(...) {
             
                if(sender instanceof Player) {
                 
                    Player p = (Player) sender;
                    if(currentSelectedPlayer != null) {
    
                        if(p.getName().equals(currentSelectedPlayer.getName())) {
                     
                            p.sendMessage("Here is your reward! :)");
                     
                            ...
                     
                        } else {
                     
                            p.sendMessage("The Machine didn't choose you!");
                     
                        }
                    }
                }
             
            }
         
            ...
         
        }
    Put theese in your code. It saves the player in a static variable, then when somebody executes the f.e. '/music' command, it will check if their playername are the same. (You have to check the name, because a player contains their position, it won't have to be the same, and .equals() won't work that way.)
     
    adi0115 likes this.
Thread Status:
Not open for further replies.

Share This Page