Skip to content

Commit

Permalink
move day value resets to own class, add commands, build integrates sh…
Browse files Browse the repository at this point in the history
…adowjar
  • Loading branch information
Ifiht committed Oct 26, 2024
1 parent ce69cb0 commit fdc6016
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 9 deletions.
19 changes: 18 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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')
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/evlis/lunamatic/Lunamatic.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -31,11 +33,17 @@ 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);
}

@Override
public void onDisable() {
// Plugin shutdown logic
}

public void registerCommands() {
PaperCommandManager manager = new PaperCommandManager(this);
manager.registerCommand(new LumaCommand(this));
}
}
34 changes: 34 additions & 0 deletions src/main/java/org/evlis/lunamatic/commands/LumaCommand.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/evlis/lunamatic/events/EntitySpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/org/evlis/lunamatic/triggers/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/evlis/lunamatic/utilities/ResetFlags.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit fdc6016

Please sign in to comment.