diff --git a/build.gradle b/build.gradle index 6c3195d..8bdf00b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,11 @@ plugins { id 'java' id 'xyz.jpenilla.run-paper' version '2.3.1' + id 'com.gradleup.shadow' version '8.3.3' } group = 'org.evlis' -version = '0.3.6' +version = '0.3.8' repositories { mavenCentral() @@ -16,10 +17,15 @@ repositories { name = "sonatype" url = "https://oss.sonatype.org/content/groups/public/" } + maven { + name = "aikars-framework" + url = "https://repo.aikar.co/content/groups/aikar/" + } } dependencies { compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT") + implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT") testImplementation 'com.github.seeseemelk:MockBukkit-v1.21:3.133.1' testImplementation('org.junit.jupiter:junit-jupiter-api:5.10.0') testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.10.0') @@ -43,6 +49,17 @@ tasks.withType(JavaCompile).configureEach { } } +compileJava { + options.compilerArgs += ["-parameters"] + options.fork = true + //options.forkOptions.executable = System.getProperty("java.home") + "/bin/javac" +} + +shadowJar { + relocate 'co.aikar.commands', 'Lunamatic.acf' + relocate 'co.aikar.locales', 'Lunamatic.locales' +} + processResources { def props = [version: version] inputs.properties props diff --git a/src/main/java/org/evlis/lunamatic/Lunamatic.java b/src/main/java/org/evlis/lunamatic/Lunamatic.java index 01a346e..c785eff 100644 --- a/src/main/java/org/evlis/lunamatic/Lunamatic.java +++ b/src/main/java/org/evlis/lunamatic/Lunamatic.java @@ -1,7 +1,9 @@ package org.evlis.lunamatic; +import co.aikar.commands.PaperCommandManager; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import org.evlis.lunamatic.commands.LumaCommand; import org.evlis.lunamatic.events.*; import org.evlis.lunamatic.triggers.Scheduler; @@ -31,6 +33,7 @@ public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(playerQuit, this); Bukkit.getServer().getPluginManager().registerEvents(playerSleep, this); Bukkit.getServer().getPluginManager().registerEvents(entitySpawn, this); + registerCommands(); schedule.GetOmens(this); } @@ -38,4 +41,9 @@ public void onEnable() { public void onDisable() { // Plugin shutdown logic } + + public void registerCommands() { + PaperCommandManager manager = new PaperCommandManager(this); + manager.registerCommand(new LumaCommand(this)); + } } diff --git a/src/main/java/org/evlis/lunamatic/commands/LumaCommand.java b/src/main/java/org/evlis/lunamatic/commands/LumaCommand.java new file mode 100644 index 0000000..c7feb75 --- /dev/null +++ b/src/main/java/org/evlis/lunamatic/commands/LumaCommand.java @@ -0,0 +1,34 @@ +package org.evlis.lunamatic.commands; + +import co.aikar.commands.BaseCommand; +import co.aikar.commands.annotation.*; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; +import org.evlis.lunamatic.GlobalVars; + +@CommandAlias("luma") +public class LumaCommand extends BaseCommand { + + private final Plugin plugin; // stores the reference to your main plugin + + public LumaCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Default + public void defCommand(CommandSender sender) { + // Display GlobalVars status + sender.sendMessage("You are running Lunamatic v" + plugin.getPluginMeta().getVersion()); + } + + @Subcommand("status") + @CommandPermission("myplugin.command.status") + @Description("Displays the status of plugin variables") + public void onStatus(CommandSender sender) { + // Display GlobalVars status + sender.sendMessage("Blood Moon Now: " + GlobalVars.bloodMoonNow); + sender.sendMessage("Blood Moon Today: " + GlobalVars.bloodMoonToday); + sender.sendMessage("Harvest Moon Now: " + GlobalVars.harvestMoonNow); + sender.sendMessage("Harvest Moon Today: " + GlobalVars.harvestMoonToday); + } +} diff --git a/src/main/java/org/evlis/lunamatic/events/EntitySpawn.java b/src/main/java/org/evlis/lunamatic/events/EntitySpawn.java index eb92569..09329e1 100644 --- a/src/main/java/org/evlis/lunamatic/events/EntitySpawn.java +++ b/src/main/java/org/evlis/lunamatic/events/EntitySpawn.java @@ -29,7 +29,7 @@ public class EntitySpawn implements Listener { public void onEntitySpawn(EntitySpawnEvent event) { Entity entity = event.getEntity(); World world = entity.getWorld(); - if (GlobalVars.bloodMoonNow) { + if (GlobalVars.bloodMoonToday && GlobalVars.bloodMoonNow) { Difficulty difficulty = world.getDifficulty(); long time = world.getTime(); if (entity instanceof Monster) { // Check if the entity is a hostile mob @@ -56,7 +56,7 @@ public void onEntitySpawn(EntitySpawnEvent event) { monster.setTarget(nearestPlayer); } } - } else if (GlobalVars.harvestMoonNow) { + } else if (GlobalVars.harvestMoonToday && GlobalVars.harvestMoonNow) { // don't allow monster spawning during harvest moon if (entity instanceof Monster) { event.setCancelled(true); diff --git a/src/main/java/org/evlis/lunamatic/triggers/Scheduler.java b/src/main/java/org/evlis/lunamatic/triggers/Scheduler.java index b6505ee..ee83931 100644 --- a/src/main/java/org/evlis/lunamatic/triggers/Scheduler.java +++ b/src/main/java/org/evlis/lunamatic/triggers/Scheduler.java @@ -10,6 +10,7 @@ import org.bukkit.plugin.Plugin; import org.evlis.lunamatic.GlobalVars; import org.evlis.lunamatic.utilities.PlayerMessage; +import org.evlis.lunamatic.utilities.ResetFlags; import org.evlis.lunamatic.utilities.TotoroDance; import org.jetbrains.annotations.NotNull; @@ -40,11 +41,9 @@ public void GetOmens(Plugin plugin) { plugin.getComponentLogger().debug(Component.text("Resetting defaults for the day...")); } // Reset defaults every dawn - totoroDance.setRandomTickSpeed(world, 3); - GlobalVars.harvestMoonToday = false; - GlobalVars.harvestMoonNow = false; - GlobalVars.bloodMoonToday = false; - GlobalVars.bloodMoonNow = false; + ResetFlags.resetAll(); + ResetFlags.resetTickSpeed(world); + // get the moon phase tonight @NotNull MoonPhase moonPhase = world.getMoonPhase(); // handle debugging flag @@ -70,8 +69,13 @@ public void GetOmens(Plugin plugin) { } // Execute immediately after sunset starts if (time >= 12010 && time < 12030) { - if (GlobalVars.harvestMoonToday && !GlobalVars.bloodMoonNow) { + if (GlobalVars.harvestMoonToday && !GlobalVars.harvestMoonNow) { GlobalVars.harvestMoonNow = true; + // Ensure global var reset + plugin.getServer().getScheduler().runTaskLater(plugin, () -> { + ResetFlags.resetTickSpeed(world); + }, 24000 - (int)time); + plugin.getServer().getScheduler().runTaskLater(plugin, ResetFlags::resetAll, 24000 - (int)time); totoroDance.setRandomTickSpeed(world, 30); totoroDance.setClearSkies(world, (24000 - (int)time)); PlayerMessage.Send(playerList, "You.. hear grass growing?", NamedTextColor.GOLD); @@ -89,6 +93,8 @@ public void GetOmens(Plugin plugin) { } if (GlobalVars.bloodMoonToday && !GlobalVars.bloodMoonNow) { GlobalVars.bloodMoonNow = true; + // Ensure global var reset + plugin.getServer().getScheduler().runTaskLater(plugin, ResetFlags::resetAll, 24000 - (int)time); } else { // if for some reason both flags are still true, we have an invalid state plugin.getComponentLogger().debug(Component.text("Invalid blood moon detected!")); GlobalVars.bloodMoonToday = false; diff --git a/src/main/java/org/evlis/lunamatic/utilities/ResetFlags.java b/src/main/java/org/evlis/lunamatic/utilities/ResetFlags.java new file mode 100644 index 0000000..94ff134 --- /dev/null +++ b/src/main/java/org/evlis/lunamatic/utilities/ResetFlags.java @@ -0,0 +1,21 @@ +package org.evlis.lunamatic.utilities; + +import org.bukkit.World; +import org.evlis.lunamatic.GlobalVars; + +public class ResetFlags { + + static TotoroDance totoroDance = new TotoroDance(); + + public static void resetAll() { + + GlobalVars.harvestMoonToday = false; + GlobalVars.harvestMoonNow = false; + GlobalVars.bloodMoonToday = false; + GlobalVars.bloodMoonNow = false; + } + + public static void resetTickSpeed(World world) { + totoroDance.setRandomTickSpeed(world, 3); + } +}