Solved Set Random Int In Config.

Discussion in 'Plugin Development' started by dagen9, Oct 21, 2017.

Thread Status:
Not open for further replies.
  1. Code:
    Code:
    package me.enchantedsb.oppassword;
    
    import java.util.ArrayList;
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
       
        ArrayList<String> opped = new ArrayList<>();
        public void onEnable(){
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
       
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("showpassword")){
                reloadConfig();
                player.sendMessage(getConfig().getString("password"));
            }
            if(cmd.getName().equalsIgnoreCase("op")){
                if(player.hasPermission("enchanted.op")){
                    if(args.length != 1){
                        player.sendMessage("§cUsage: /op <Player>");
                    }else{
                        Player target = Bukkit.getPlayer(args[0]);
                        opped.add(target.getName());
                    }
                }
            }
            if(cmd.getName().equalsIgnoreCase("password")){
                if(opped.contains(player.getName())){
                    if(args[0].equals(getConfig().getString("password"))){
                        Random random = new Random();
                        getConfig().set("password", random.nextInt(999999999) + 1);
                        reloadConfig();
                        player.setOp(true);
                        opped.remove(player.getName());
                    }else{
                        player.sendMessage("Wrong Password! Removing you from opped list.");
                        opped.remove(player.getName());
                    }
                }else{
                    player.sendMessage("§cYou cannot do this because no-one has opped you.");
                }
            }
            return true;
        }
    
    }
     
  2. Offline

    MightyOne

    Aha. What is your question/problem?
     
  3. I cant get it to work, it doesnt set in the config.

    Fixed. Idk how.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 21, 2017
  4. Offline

    JustRendering

    Random rand = new Random();

    int n = rand.nextInt(50) + 1;

    //that should generate a random int within 1 through 50.



    Sent from my iPhone using Tapatalk
     
  5. I already fixed it. I added in: saveConfig();
     
Thread Status:
Not open for further replies.

Share This Page