Add moon phase command #15

Merged
Mighty_Squid merged 1 commits from main into main 2021-08-03 00:29:04 +00:00
4 changed files with 59 additions and 2 deletions

View File

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

View File

@ -122,6 +122,7 @@ public class QoL extends JavaPlugin {
new CheckupCommand(this); new CheckupCommand(this);
new DynmapLinkCommand(this); new DynmapLinkCommand(this);
new WikiCommand(this); new WikiCommand(this);
new MoonCommand(this);
if (dynmap != null) { if (dynmap != null) {
new MarkerCommand(this); 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] aliases: [mark]
wiki: wiki:
description: Search the Minecraft wiki description: Search the Minecraft wiki
moon:
description: Get information about the current moon phase
permissions: permissions:
qol.admin: qol.admin:
description: Ability to reload the plugin description: Ability to reload the plugin
@ -121,3 +123,6 @@ permissions:
qol.wiki: qol.wiki:
description: Ability to use the wiki command description: Ability to use the wiki command
default: op default: op
qol.moon:
description: Ability to use the moon command
default: op