diff --git a/src/main/java/org/gecko/wauh/Main.java b/src/main/java/org/gecko/wauh/Main.java index dd744cf..7697584 100644 --- a/src/main/java/org/gecko/wauh/Main.java +++ b/src/main/java/org/gecko/wauh/Main.java @@ -24,9 +24,46 @@ public final class Main extends JavaPlugin { private TNTListener tntListener; private CreeperListener creeperListener; private ScaleReverse scaleReverse; - private final Main plugin = Main.getPlugin(Main.class); - private ConfigurationManager configManager = new ConfigurationManager(plugin); - private FileConfiguration config = configManager.getConfig(); + private ConfigurationManager configManager; + private FileConfiguration config; + + @Override + public void onEnable() { + // Plugin startup logic + Bukkit.getConsoleSender().sendMessage(""); + Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA + "Yay"); + + // Create instances of the listeners + bucketListener = new BucketListener(); + barrierListener = new BarrierListener(); + bedrockListener = new BedrockListener(); + waterBucketListener = new WaterBucketListener(); + tntListener = new TNTListener(); + creeperListener = new CreeperListener(); + configManager = new ConfigurationManager(Main.getPlugin(Main.class)); + config = configManager.getConfig(); + + // Register the listeners + getServer().getPluginManager().registerEvents(bucketListener, this); + getServer().getPluginManager().registerEvents(barrierListener, this); + getServer().getPluginManager().registerEvents(bedrockListener, this); + getServer().getPluginManager().registerEvents(waterBucketListener, this); + getServer().getPluginManager().registerEvents(tntListener, this); + getServer().getPluginManager().registerEvents(creeperListener, this); + + // Register the StopWauh command with the listeners as arguments + this.getCommand("stopwauh").setExecutor(new StopWauh(bucketListener, barrierListener, bedrockListener, waterBucketListener)); + this.getCommand("setradiuslimit").setExecutor(new SetRadiusLimitCommand(this)); + this.getCommand("setradiuslimit").setTabCompleter(new SetRadiusLimitCommand(this)); + this.getCommand("toggleremovalview").setExecutor(new ToggleRemovalView(this)); + } + + @Override + public void onDisable() { + // Plugin shutdown logic + Bukkit.getConsoleSender().sendMessage(""); + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "kys"); + } public int getRadiusLimit() { return playerRadiusLimit + 2; @@ -86,39 +123,4 @@ public ScaleReverse getScaleReverse() { return scaleReverse; } - @Override - public void onEnable() { - // Plugin startup logic - Bukkit.getConsoleSender().sendMessage(""); - Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA + "Yay"); - - // Create instances of the listeners - bucketListener = new BucketListener(); - barrierListener = new BarrierListener(); - bedrockListener = new BedrockListener(); - waterBucketListener = new WaterBucketListener(); - tntListener = new TNTListener(); - creeperListener = new CreeperListener(); - - // Register the listeners - getServer().getPluginManager().registerEvents(bucketListener, this); - getServer().getPluginManager().registerEvents(barrierListener, this); - getServer().getPluginManager().registerEvents(bedrockListener, this); - getServer().getPluginManager().registerEvents(waterBucketListener, this); - getServer().getPluginManager().registerEvents(tntListener, this); - getServer().getPluginManager().registerEvents(creeperListener, this); - - // Register the StopWauh command with the listeners as arguments - this.getCommand("stopwauh").setExecutor(new StopWauh(bucketListener, barrierListener, bedrockListener, waterBucketListener)); - this.getCommand("setradiuslimit").setExecutor(new SetRadiusLimitCommand(this)); - this.getCommand("setradiuslimit").setTabCompleter(new SetRadiusLimitCommand(this)); - this.getCommand("toggleremovalview").setExecutor(new ToggleRemovalView(this)); - } - - @Override - public void onDisable() { - // Plugin shutdown logic - Bukkit.getConsoleSender().sendMessage(""); - Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "kys"); - } } diff --git a/src/main/java/org/gecko/wauh/data/ConfigurationManager.java b/src/main/java/org/gecko/wauh/data/ConfigurationManager.java index a6c48db..d071646 100644 --- a/src/main/java/org/gecko/wauh/data/ConfigurationManager.java +++ b/src/main/java/org/gecko/wauh/data/ConfigurationManager.java @@ -1,24 +1,33 @@ package org.gecko.wauh.data; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.FileConfiguration; import org.gecko.wauh.Main; import java.io.File; import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; public class ConfigurationManager { - private final Main plugin; private final File configFile; - private FileConfiguration config; - + private final FileConfiguration config; + private final Logger logger = Logger.getLogger(Main.class.getName()); public ConfigurationManager(Main plugin) { - this.plugin = plugin; this.configFile = new File(plugin.getDataFolder(), "data.yml"); // Create the data.yml file if it doesn't exist if (!configFile.exists()) { - plugin.saveResource("data.yml", false); + File dir = new File("Wauh"); + boolean dirCreated = dir.mkdirs(); + if (!dirCreated) { + logger.log(Level.SEVERE, "Config folder could not be created"); + } else { + Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config folder created!"); + } + plugin.saveResource("Wauh/data.yml", false); } // Load the config @@ -33,7 +42,7 @@ public void saveConfig() { try { config.save(configFile); } catch (IOException e) { - e.printStackTrace(); + logger.log(Level.SEVERE, "Unable to save config", e); } }