Skip to content

Commit

Permalink
config added & synced to global vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifiht committed Nov 3, 2024
1 parent b04fc10 commit ea70da8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'org.evlis'
version = '0.3.10'
version = '0.4.0'

def targetJavaVersion = 21

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/evlis/lunamatic/GlobalVars.java
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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<String> disabledWorlds = List.of();
// map of how many armor pieces to apply
public static final Map<Difficulty, Integer> 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<Difficulty, Integer> difficultyPotionMap = Map.of(
Difficulty.PEACEFUL, 0,
Difficulty.EASY, 0,
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/evlis/lunamatic/Lunamatic.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand All @@ -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());
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/evlis/lunamatic/commands/LumaCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
17 changes: 17 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ea70da8

Please sign in to comment.