Skip to content

Commit

Permalink
add commands to create different moon phases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifiht committed Nov 9, 2024
1 parent 19045f3 commit 121d9cb
Show file tree
Hide file tree
Showing 3 changed files with 65 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.4.1'
version = '0.4.2'

def targetJavaVersion = 21

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/evlis/lunamatic/GlobalVars.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.evlis.lunamatic;

import io.papermc.paper.world.MoonPhase;
import org.bukkit.Difficulty;

import java.util.List;
Expand Down Expand Up @@ -42,4 +43,26 @@ public class GlobalVars {
Difficulty.NORMAL, 1,
Difficulty.HARD, 2
);
// map for time between current moon phase and the next new moon
public static final Map<MoonPhase, Integer> newMoonOffset = Map.of(
MoonPhase.FULL_MOON, 96000,
MoonPhase.WANING_GIBBOUS, 72000,
MoonPhase.LAST_QUARTER, 48000,
MoonPhase.WANING_CRESCENT, 24000,
MoonPhase.NEW_MOON, 0,
MoonPhase.WAXING_CRESCENT, 120000,
MoonPhase.FIRST_QUARTER, 144000,
MoonPhase.WAXING_GIBBOUS, 168000
);
// map for time between current moon phase and the next full moon
public static final Map<MoonPhase, Integer> fullMoonOffset = Map.of(
MoonPhase.FULL_MOON, 0,
MoonPhase.WANING_GIBBOUS, 168000,
MoonPhase.LAST_QUARTER, 144000,
MoonPhase.WANING_CRESCENT, 120000,
MoonPhase.NEW_MOON, 96000,
MoonPhase.WAXING_CRESCENT, 72000,
MoonPhase.FIRST_QUARTER, 48000,
MoonPhase.WAXING_GIBBOUS, 24000
);
}
41 changes: 41 additions & 0 deletions src/main/java/org/evlis/lunamatic/commands/LumaCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.evlis.lunamatic.GlobalVars;
import org.evlis.lunamatic.utilities.ResetFlags;
import org.jetbrains.annotations.NotNull;

@CommandAlias("luma")
Expand Down Expand Up @@ -56,4 +57,44 @@ public void onStatus(Player player) {
player.sendMessage("Disabled worlds: " + String.join(", ", GlobalVars.disabledWorlds));
player.sendMessage("Current moon phase for world " + world.getName() + ": " + moonPhase);
}

@Subcommand("makebloodmoon")
@CommandPermission("luma.command.makebloodmoon")
@Description("Changes the current world state to Blood Moon")
public void makeBloodMoon(Player player) {
// this command is player only!!!
// get the current world & moon state:
World world = player.getWorld();
@NotNull MoonPhase moonPhase = world.getMoonPhase();
if(moonPhase != MoonPhase.NEW_MOON) {
ResetFlags.resetAll();
world.setTime(world.getTime() + (long)GlobalVars.newMoonOffset.getOrDefault(moonPhase, 0));
}
if(!GlobalVars.bloodMoonToday){
GlobalVars.bloodMoonToday = true;
}
if(world.getTime() >= 13000 && !GlobalVars.bloodMoonNow) {
GlobalVars.bloodMoonNow = true;
}
}

@Subcommand("makeharvestmoon")
@CommandPermission("luma.command.makeharvestmoon")
@Description("Changes the current world state to Harvest Moon")
public void makeHarvestMoon(Player player) {
// this command is player only!!!
// get the current world & moon state:
World world = player.getWorld();
@NotNull MoonPhase moonPhase = world.getMoonPhase();
if(moonPhase != MoonPhase.FULL_MOON) {
ResetFlags.resetAll();
world.setTime(world.getTime() + (long)GlobalVars.fullMoonOffset.getOrDefault(moonPhase, 0));
}
if(!GlobalVars.harvestMoonToday){
GlobalVars.harvestMoonToday = true;
}
if(world.getTime() >= 13000 && !GlobalVars.harvestMoonNow) {
GlobalVars.harvestMoonNow = true;
}
}
}

0 comments on commit 121d9cb

Please sign in to comment.