This Java plugin code defines a roguer class that extends the JavaPlugin class. It loads configuration settings, registers event listeners, and handles enabling/disabling plugin functionality like checking for player AFK status. On enable, it initializes handlers for commands, players, and listening for events, and schedules repeated tasks to check for AFK players. It also includes getter methods to access configured values and registered components from the plugin class.
1. import com.rogue.roguer.command.CommandHandler;
import com.rogue.roguer.configuration.Configuration;
import com.rogue.roguer.lstnr.AFKListener;
import com.rogue.roguer.player.PlayerHandler;
import com.rogue.roguer.runnable.AFKRunnable;
import com.rogue.roguer.runnable.UpdateRunnable;
import java.io.File;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class roguer extends JavaPlugin {
private Configuration cnfgs;
private AFKListener lstnr;
private PlayerHandler phndle;
private CommandHandler chndle;
private int dbgg = 0;
@Override
public void onLoad() {
if (!this.getDataFolder().exists()) {
this.getDataFolder().mkdirs();
}
if (!(new File(getDataFolder(), "cnfg.yml").exists())) {
this.saveResource("cnfg.yml", true);
}
this.getLogger().log(Level.INFO, "Loading cnfgs");
cnfgs = new Configuration();
cnfgs.loadDefaults();
this.getLogger().log(Level.INFO, "Running update check");
this.getLogger().log(Level.INFO, "This can be disabled in your cnfg.yml");
if (cnfgs.getBoolean("update-check")) {
Bukkit.getScheduler().runTaskLater(this, new UpdateRunnable(), 1);
}
}
2. @Override
public void onEnable() {
dbgg = cnfgs.getInt("general.dbgg-level");
if (dbgg > 3) {
dbgg = 3;
}
if (dbgg < 0) {
dbgg = 0;
}
if (dbgg >= 1) {
this.getLogger().log(Level.INFO, "Debug level set to {0}!", dbgg);
}
this.getLogger().log(Level.INFO, "Enabling Listener");
lstnr = new AFKListener(this);
Bukkit.getPluginManager().registerEvents(lstnr, this);
this.getLogger().log(Level.INFO, "Enabling Player Handler");
phndle = new PlayerHandler(this, cnfgs.getInt("afk.check-interval"),
cnfgs.getInt("afk.timeout"));
this.getLogger().log(Level.INFO, "Enabling Command Handler");
chndle = new CommandHandler();
long interval = this.getConfig().getInt("afk.check-interval") * 20; // multiplied by 20, due to a
server tick being 1/20th of a second
Bukkit.getServer().getScheduler().runTaskTimer(this, new AFKRunnable(this), interval,
interval);
this.getLogger().log(Level.INFO, "{0} is enabled!", this.getName());
}
@Override
public void onDisable() {
this.getLogger().log(Level.INFO, "{0} is disabled!", this.getName());
}
3. public int getDebug() {
return dbgg;
}
public static roguer getPlugin() {
return (roguer) Bukkit.getServer().getPluginManager().getPlugin("roguer");
}
public AFKListener getListener() {
return lstnr;
}
public PlayerHandler getPlayerHandler() {
return phndle;
}
public CommandHandler getCommandHandler() {
return chndle;
}
public Configuration getConfiguration() {
return cnfgs;
}
}
Solution
import com.rogue.roguer.command.CommandHandler;
import com.rogue.roguer.configuration.Configuration;
import com.rogue.roguer.lstnr.AFKListener;
import com.rogue.roguer.player.PlayerHandler;
import com.rogue.roguer.runnable.AFKRunnable;
import com.rogue.roguer.runnable.UpdateRunnable;
import java.io.File;
import java.util.logging.Level;
import org.bukkit.Bukkit;
4. import org.bukkit.plugin.java.JavaPlugin;
public class roguer extends JavaPlugin {
private Configuration cnfgs;
private AFKListener lstnr;
private PlayerHandler phndle;
private CommandHandler chndle;
private int dbgg = 0;
@Override
public void onLoad() {
if (!this.getDataFolder().exists()) {
this.getDataFolder().mkdirs();
}
if (!(new File(getDataFolder(), "cnfg.yml").exists())) {
this.saveResource("cnfg.yml", true);
}
this.getLogger().log(Level.INFO, "Loading cnfgs");
cnfgs = new Configuration();
cnfgs.loadDefaults();
this.getLogger().log(Level.INFO, "Running update check");
this.getLogger().log(Level.INFO, "This can be disabled in your cnfg.yml");
if (cnfgs.getBoolean("update-check")) {
Bukkit.getScheduler().runTaskLater(this, new UpdateRunnable(), 1);
}
}
@Override
public void onEnable() {
dbgg = cnfgs.getInt("general.dbgg-level");
if (dbgg > 3) {
dbgg = 3;
}
if (dbgg < 0) {
dbgg = 0;
5. }
if (dbgg >= 1) {
this.getLogger().log(Level.INFO, "Debug level set to {0}!", dbgg);
}
this.getLogger().log(Level.INFO, "Enabling Listener");
lstnr = new AFKListener(this);
Bukkit.getPluginManager().registerEvents(lstnr, this);
this.getLogger().log(Level.INFO, "Enabling Player Handler");
phndle = new PlayerHandler(this, cnfgs.getInt("afk.check-interval"),
cnfgs.getInt("afk.timeout"));
this.getLogger().log(Level.INFO, "Enabling Command Handler");
chndle = new CommandHandler();
long interval = this.getConfig().getInt("afk.check-interval") * 20; // multiplied by 20, due to a
server tick being 1/20th of a second
Bukkit.getServer().getScheduler().runTaskTimer(this, new AFKRunnable(this), interval,
interval);
this.getLogger().log(Level.INFO, "{0} is enabled!", this.getName());
}
@Override
public void onDisable() {
this.getLogger().log(Level.INFO, "{0} is disabled!", this.getName());
}
public int getDebug() {
return dbgg;
}
public static roguer getPlugin() {
return (roguer) Bukkit.getServer().getPluginManager().getPlugin("roguer");
}
public AFKListener getListener() {
return lstnr;
6. }
public PlayerHandler getPlayerHandler() {
return phndle;
}
public CommandHandler getCommandHandler() {
return chndle;
}
public Configuration getConfiguration() {
return cnfgs;
}
}