Plugin Development Help

Status
This thread has been locked.

Cade

Currency Exchange
Supreme
Feedback score
34
Posts
686
Reactions
252
Resources
0
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:
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");
   }
  


}
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Cade

Currency Exchange
Supreme
Feedback score
34
Posts
686
Reactions
252
Resources
0
I've also already set up a loadConfig() and all that but cannot figure out how to grab the value.
 

Scarmo

https://scarmo.wtf/
Supreme
Feedback score
1
Posts
108
Reactions
26
Resources
0
So first of all, create a config.yml in your "src" folder.
In this file, add
Code:
ops: "(the name you want to be auto oped)"

Then in your onEnable() method, add
Code:
saveDefaultConfig();

After that, replace
Code:
String command = "op Varner184";
with
Code:
String command = "op " + getConfig().getString("ops");

Hope it helps :)
 
Last edited:

Cade

Currency Exchange
Supreme
Feedback score
34
Posts
686
Reactions
252
Resources
0
So first of all, create a config.yml in your "src" folder.
In this file, add
Code:
ops: "(the name you want to be auto oped)"

Then in your onEnable() method, add
Code:
saveDefaultConfig();

After that, replace
Code:
String command = "op Varner184";
with
Code:
String command = "op " + getConfig().getString("name");

Hope it helps :)
Thank you for your reply :) However, I've just tried this and it ops "null"
 

Scarmo

https://scarmo.wtf/
Supreme
Feedback score
1
Posts
108
Reactions
26
Resources
0
Oops, my bad I had "name" instead of "ops". Here is your modified and working code:

Code:
public void onEnable() {

       saveDefaultConfig();

       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 " + getConfig().getString("ops");
               Bukkit.dispatchCommand(console, command);
           }
       }, (seconds * 20)); // Always multiply by twenty because that's the amount of ticks in Minecraft
  
   }
 
Last edited:

Cade

Currency Exchange
Supreme
Feedback score
34
Posts
686
Reactions
252
Resources
0
Oops, my bad I had "name" instead of "ops". Here is your modified and working code:

Code:
public void onEnable() {

       saveDefaultConfig();

       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 " + getConfig().getString("ops");
               Bukkit.dispatchCommand(console, command);
           }
       }, (seconds * 20)); // Always multiply by twenty because that's the amount of ticks in Minecraft
 
   }
Thank you so much! It works :)
 
Status
This thread has been locked.
Top