Add moon phase command (#15)

Add moon phase command

Co-authored-by: Mighty_Squid <103967@gmail.com>
Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/15
Reviewed-by: ZeroHD <joey@ahines.net>
Co-Authored-By: Mighty_Squid <mighty_squid@noreply.git.canopymc.net>
Co-Committed-By: Mighty_Squid <mighty_squid@noreply.git.canopymc.net>
main
Mighty_Squid 2021-08-03 00:29:04 +00:00 committed by ZeroHD
parent fa2f79239e
commit df292f88c5
4 changed files with 59 additions and 2 deletions

View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId>
<artifactId>QoL</artifactId>
<!-- Version is used in plugin.yml -->
<version>1.13</version>
<version>1.14</version>
<packaging>jar</packaging>
<!-- Plugin Information -->

View File

@ -122,6 +122,7 @@ public class QoL extends JavaPlugin {
new CheckupCommand(this);
new DynmapLinkCommand(this);
new WikiCommand(this);
new MoonCommand(this);
if (dynmap != null) {
new MarkerCommand(this);

View File

@ -0,0 +1,51 @@
package xyz.etztech.qol.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import xyz.etztech.qol.QoL;
import xyz.etztech.qol.EtzTechUtil;
import xyz.etztech.qol.Lang;
import java.util.Map;
import java.lang.*;
public class MoonCommand implements CommandExecutor {
QoL plugin;
private final Map<Integer, String> moonPhases = Map.of(
0, "Full moon",
1, "Waning gibbous",
2, "Third quarter",
3, "Waning crescent",
4, "New moon",
5, "Waxing crescent",
6, "First quarter",
7, "Waxing gibbous"
);
public MoonCommand(QoL paramQoL) {
this.plugin = paramQoL;
plugin.getCommand("moon").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!commandSender.hasPermission("qol.moon")) {
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
return true;
}
String playername = commandSender.getName();
long time = commandSender.getServer().getPlayer(playername).getWorld().getFullTime();
double day = Math.floor(time / 24000);
int moonPhase = (int)(day % 8);
StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== Moon Phase Utility =====");
message.append("\n" + ChatColor.GREEN + "Current moon phase: " + moonPhases.get(moonPhase) + ".");
message.append("\n" + ChatColor.GREEN + "Full moon is " + (moonPhase == 0 ? "tonight." : "in " + (8 - moonPhase) + ((moonPhase == 7) ? " day." : " days.")));
EtzTechUtil.sms(commandSender, message.toString());
return true;
}
}

View File

@ -48,6 +48,8 @@ commands:
aliases: [mark]
wiki:
description: Search the Minecraft wiki
moon:
description: Get information about the current moon phase
permissions:
qol.admin:
description: Ability to reload the plugin
@ -121,3 +123,6 @@ permissions:
qol.wiki:
description: Ability to use the wiki command
default: op
qol.moon:
description: Ability to use the moon command
default: op