diff --git a/build.gradle b/build.gradle index 05a1fa9..ebdbb4c 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'org.evlis' -version = '0.3.10' +version = '0.4.0' def targetJavaVersion = 21 diff --git a/src/main/java/org/evlis/lunamatic/GlobalVars.java b/src/main/java/org/evlis/lunamatic/GlobalVars.java index fbd159d..62fdf44 100644 --- a/src/main/java/org/evlis/lunamatic/GlobalVars.java +++ b/src/main/java/org/evlis/lunamatic/GlobalVars.java @@ -2,11 +2,20 @@ import org.bukkit.Difficulty; +import java.util.List; import java.util.Map; public class GlobalVars { // Test flag, makes every night a bloodmoon if true public static Boolean debug = false; + // enabled moons: + public static Boolean fullMoonEnabled = true; + public static Boolean harvestMoonEnabled = true; + public static Boolean newMoonEnabled = true; + public static Boolean bloodMoonEnabled = true; + // Dice sides for blood & harvest + public static Integer bloodMoonDieSides = 2; + public static Integer harvestMoonDieSides = 2; // is there a blood moon today? public static Boolean bloodMoonToday = false; // is there a harvest moon today? @@ -17,12 +26,16 @@ public class GlobalVars { public static Boolean harvestMoonNow = false; // how far should monsters engage the player from during a blood moon? public static final double bloodmoonDetectionRange = 32.0; + // worlds to exclude entirely from moon effects + public static List disabledWorlds = List.of(); + // map of how many armor pieces to apply public static final Map difficultyArmorMap = Map.of( Difficulty.PEACEFUL, 0, Difficulty.EASY, 2, Difficulty.NORMAL, 3, Difficulty.HARD, 4 ); + // map of what level potion effect mobs should get public static final Map difficultyPotionMap = Map.of( Difficulty.PEACEFUL, 0, Difficulty.EASY, 0, diff --git a/src/main/java/org/evlis/lunamatic/Lunamatic.java b/src/main/java/org/evlis/lunamatic/Lunamatic.java index c785eff..5a88df5 100644 --- a/src/main/java/org/evlis/lunamatic/Lunamatic.java +++ b/src/main/java/org/evlis/lunamatic/Lunamatic.java @@ -1,6 +1,7 @@ package org.evlis.lunamatic; import co.aikar.commands.PaperCommandManager; +import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.evlis.lunamatic.commands.LumaCommand; @@ -22,6 +23,8 @@ public final class Lunamatic extends JavaPlugin { public void onEnable() { //consoleLogger.sendMessage(MiniMessage.miniMessage().deserialize("")); // Plugin startup logic + saveDefaultConfig(); + // Class Initialization Scheduler schedule = new Scheduler(); timeSkip = new TimeSkip(); playerJoin = new PlayerJoin(); @@ -34,16 +37,35 @@ public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(playerSleep, this); Bukkit.getServer().getPluginManager().registerEvents(entitySpawn, this); registerCommands(); + loadGlobalConfig(); schedule.GetOmens(this); } @Override public void onDisable() { // Plugin shutdown logic + this.getComponentLogger().debug(Component.text("Lunamatic has been disabled.")); } public void registerCommands() { PaperCommandManager manager = new PaperCommandManager(this); manager.registerCommand(new LumaCommand(this)); } + + public void loadGlobalConfig() { + try { + reloadConfig(); + // moons enabled + GlobalVars.disabledWorlds = getConfig().getStringList("disabledWorlds"); + GlobalVars.fullMoonEnabled = getConfig().getBoolean("fullMoonEnabled"); + GlobalVars.fullMoonEnabled = getConfig().getBoolean("newMoonEnabled"); + GlobalVars.fullMoonEnabled = getConfig().getBoolean("harvestMoonEnabled"); + GlobalVars.fullMoonEnabled = getConfig().getBoolean("bloodMoonEnabled"); + // moon chances + GlobalVars.harvestMoonDieSides = getConfig().getInt("bloodMoonDieSides"); + GlobalVars.bloodMoonDieSides = getConfig().getInt("harvestMoonDieSides"); + } catch (Exception e) { + getLogger().severe("Failed to load configuration: " + e.getMessage()); + } + } } diff --git a/src/main/java/org/evlis/lunamatic/commands/LumaCommand.java b/src/main/java/org/evlis/lunamatic/commands/LumaCommand.java index 7eb9ac5..6bcdfba 100644 --- a/src/main/java/org/evlis/lunamatic/commands/LumaCommand.java +++ b/src/main/java/org/evlis/lunamatic/commands/LumaCommand.java @@ -21,14 +21,30 @@ public void defCommand(CommandSender sender) { sender.sendMessage("You are running Lunamatic v" + plugin.getPluginMeta().getVersion()); } + @Subcommand("reload") + @CommandPermission("luma.command.reload") + @Description("Reloads the plugin configuration") + public void onReload(CommandSender sender) { + // Display GlobalVars status + try { + plugin.reloadConfig(); + sender.sendMessage("Lunamatic reload successful!"); + } catch (Exception e) { + sender.sendMessage("Lunamatic encountered an error: " + e.getMessage()); + } + } + @Subcommand("status") @CommandPermission("luma.command.status") @Description("Displays the status of plugin variables") public void onStatus(CommandSender sender) { // Display GlobalVars status + sender.sendMessage("Blood Moon Enabled: " + GlobalVars.bloodMoonEnabled); sender.sendMessage("Blood Moon Now: " + GlobalVars.bloodMoonNow); sender.sendMessage("Blood Moon Today: " + GlobalVars.bloodMoonToday); + sender.sendMessage("Harvest Moon Enabled: " + GlobalVars.harvestMoonEnabled); sender.sendMessage("Harvest Moon Now: " + GlobalVars.harvestMoonNow); sender.sendMessage("Harvest Moon Today: " + GlobalVars.harvestMoonToday); + sender.sendMessage("Disabled worlds: " + String.join(", ", GlobalVars.disabledWorlds)); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..602e6bd --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,17 @@ +# Lunamatic configuration +## Choose which moon effects to enable (default all true): +fullMoonEnabled: true +newMoonEnabled: true +harvestMoonEnabled: true +bloodMoonEnabled: true +## Chance for Blood and Harvest Moons +# This sets the number of sides in the dice roll, +# e.g. 2 = cointoss (50/50), 6 = normal die (17% chance) +bloodMoonDieSides: 2 +harvestMoonDieSides: 2 +## Set worlds to disable moon-effects on +# by default both nether & the_end cannot have moon effects +disabledWorlds: + - world + - world_nether + - world_the_end \ No newline at end of file