My plugin

Discussion in 'Plugin Development' started by Varner184, Aug 17, 2019.

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

    Varner184

    Hello, I am currently learning plugin development and am just making plugins for fun. I decided to make an AutoOp plugin as it would need to use a config file and I'd like to learn this. I've searched all over google, asked coding servers, etc. and cannot find help.

    What I need to do: I need to grab the value(s) from my config.yml and insert them into
    Code:
    ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
                    String command = "op Varner184";
                    Bukkit.dispatchCommand(console, command);
    where it says Varner184 it should be whoevers name is in the config.yml.

    Config.yml:
    ops: Varner184

    All my code:
    Code:
    package me.Varner184.AutoOp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class AutoOp extends JavaPlugin {
    
        public void onEnable() {
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "\n\nAutoOp Has Been Enabled!\n\nDeveloped By Varner184");
            int seconds = 10;
    
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                public void run() {
                    // code to run when the time is up.
                    ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
                    String command = "op Varner184";
                    Bukkit.dispatchCommand(console, command);
                }
            }, (seconds * 20)); // Always multiply by twenty because that's the amount of ticks in Minecraft
           
        }
    
        public void onDisable() {
            getServer().getConsoleSender().sendMessage(ChatColor.RED + "\n\nAutoOp Has Been Disabled!\n\nDeveloped By Varner184");
        }
       
    
    
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Varner184 Get the config.
    Get the string list ops.
    Loop over the list and op everybody.

    But it might be better to op on join instead. And just by using setOP(true)
     
Thread Status:
Not open for further replies.

Share This Page