From 0750d89f21ecb09e531f3acecd6d5ff95e6fc778 Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Sun, 9 Oct 2022 15:00:17 -0400 Subject: [PATCH] Init --- .classpath | 38 +++++++++++++++ .gitignore | 5 ++ .project | 23 +++++++++ .settings/org.eclipse.jdt.core.prefs | 8 ++++ .settings/org.eclipse.m2e.core.prefs | 4 ++ plugin.yml | 12 +++++ pom.xml | 37 ++++++++++++++ .../java/ca/thetechrobo/rltime/GetTime.java | 48 +++++++++++++++++++ .../java/ca/thetechrobo/rltime/RLTime.java | 20 ++++++++ .../ca/thetechrobo/rltime/Set24HourTime.java | 44 +++++++++++++++++ .../java/ca/thetechrobo/rltime/Setter.java | 38 +++++++++++++++ .../rltime/VerificationStatus.java | 5 ++ 12 files changed, 282 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 plugin.yml create mode 100644 pom.xml create mode 100644 src/main/java/ca/thetechrobo/rltime/GetTime.java create mode 100644 src/main/java/ca/thetechrobo/rltime/RLTime.java create mode 100644 src/main/java/ca/thetechrobo/rltime/Set24HourTime.java create mode 100644 src/main/java/ca/thetechrobo/rltime/Setter.java create mode 100644 src/main/java/ca/thetechrobo/rltime/VerificationStatus.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3bc452e --- /dev/null +++ b/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e34ccad --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +target/ +doc/ +*.[wj]ar +*.pom +*.class diff --git a/.project b/.project new file mode 100644 index 0000000..0a4ba54 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + RLtime + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..eeac0e7 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..5628773 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,12 @@ +name: RLtime +main: ca.thetechrobo.rltime.RLTime +version: 0.0.1 +api-version: 1.17 + +commands: + ctime: + description: "Gets the current time (server's timezone)." + usage: "Usage: /ctime" + set24HourTime: + description: "Sets whether /ctime shows in 24 hour time or not. [default: true]" + usage: "Usage: /set24HourTime " \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bda6fa4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + ca.thetechrobo.rltime + RLtime + 0.0.1-SNAPSHOT + RLtime + Adds a /ctime command that returns the current real-life time (in the server's timezone) + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + io.papermc.paper + paper-api + 1.17.1-R0.1-SNAPSHOT + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + + + + + + + \ No newline at end of file diff --git a/src/main/java/ca/thetechrobo/rltime/GetTime.java b/src/main/java/ca/thetechrobo/rltime/GetTime.java new file mode 100644 index 0000000..3f74a27 --- /dev/null +++ b/src/main/java/ca/thetechrobo/rltime/GetTime.java @@ -0,0 +1,48 @@ +package ca.thetechrobo.rltime; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import org.bukkit.NamespacedKey; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.TextColor; + +public class GetTime implements CommandExecutor { + + private JavaPlugin pl; + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, + @NotNull String[] args) { + + SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss z"); + if (sender instanceof Player) { + Player p = (Player) sender; + PersistentDataContainer c = p.getPersistentDataContainer(); + NamespacedKey key = new NamespacedKey(this.pl, "24HourTime"); + if (c.has(key, PersistentDataType.STRING) && c.get(key, PersistentDataType.STRING).equals("false")) { + format = new SimpleDateFormat("h:mm:ss a z"); + } + } + Date now = Calendar.getInstance().getTime(); + TextComponent time = Component.text(format.format(now)).color(TextColor.color(255, 0, 255)); + sender.sendMessage(Component.text("I think it's ").color(TextColor.color(64, 254, 127)).append(time)); + return true; + } + + public GetTime(JavaPlugin pl) { + this.pl = pl; + } + +} diff --git a/src/main/java/ca/thetechrobo/rltime/RLTime.java b/src/main/java/ca/thetechrobo/rltime/RLTime.java new file mode 100644 index 0000000..94c239f --- /dev/null +++ b/src/main/java/ca/thetechrobo/rltime/RLTime.java @@ -0,0 +1,20 @@ +package ca.thetechrobo.rltime; + +import org.bukkit.plugin.java.JavaPlugin; + +public class RLTime extends JavaPlugin { + @Override + public void onEnable() { + GetTime gettime = new GetTime(this); + this.getCommand("ctime").setExecutor(gettime); + + Set24HourTime set24 = new Set24HourTime(this); + this.getCommand("set24HourTime").setExecutor(set24); + this.getCommand("set24HourTime").setTabCompleter(set24); + } + + @Override + public void onDisable() { + } + +} diff --git a/src/main/java/ca/thetechrobo/rltime/Set24HourTime.java b/src/main/java/ca/thetechrobo/rltime/Set24HourTime.java new file mode 100644 index 0000000..79fc68e --- /dev/null +++ b/src/main/java/ca/thetechrobo/rltime/Set24HourTime.java @@ -0,0 +1,44 @@ +package ca.thetechrobo.rltime; + +import java.util.ArrayList; + +import org.bukkit.NamespacedKey; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +public class Set24HourTime extends Setter { + + public Set24HourTime(JavaPlugin pl) { + this.pl = pl; + } + + @Override + protected VerificationStatus set(@NotNull String[] args, @NotNull Player p) { + if (args.length != 1) { + return new VerificationStatus(false, "Incorrect amount of arguments (expected 1)"); + } + String setTo = args[0].toLowerCase(); + if (setTo.equals("true") || setTo.equals("false")) { + } else { + return new VerificationStatus(false, "Invalid argument (must be 'true' or 'false')"); + } + p.getPersistentDataContainer().set(new NamespacedKey(this.pl, "24HourTime"), PersistentDataType.STRING, setTo); + if (setTo.equals("true")) { + return new VerificationStatus(true, "Successfully changed to 24-hour time!"); + } + return new VerificationStatus(true, "Successfully changed to 12-hour time!"); + } + + @Override + public ArrayList onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + ArrayList list = new ArrayList(); + list.add("true"); + list.add("false"); + return list; + } + +} diff --git a/src/main/java/ca/thetechrobo/rltime/Setter.java b/src/main/java/ca/thetechrobo/rltime/Setter.java new file mode 100644 index 0000000..c3cd7ca --- /dev/null +++ b/src/main/java/ca/thetechrobo/rltime/Setter.java @@ -0,0 +1,38 @@ +package ca.thetechrobo.rltime; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; + +public abstract class Setter implements TabExecutor { + + protected @NotNull JavaPlugin pl; + + abstract protected VerificationStatus set(@NotNull String[] args, @NotNull Player p); + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, + @NotNull String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(Component.text("Needs to be run by a player.")); + return false; + } + Player p = (Player) sender; + VerificationStatus verification = this.set(args, p); + if (!verification.succeeded()) { + // p.sendMessage(Component.text("Invalid input: ") + // .append(Component.text(verification.error()).color(TextColor.color(255, 20, + // 20)))); + return false; + } + p.sendMessage(Component.text(verification.error()).color(TextColor.color(40, 255, 64))); + return true; + } + +} diff --git a/src/main/java/ca/thetechrobo/rltime/VerificationStatus.java b/src/main/java/ca/thetechrobo/rltime/VerificationStatus.java new file mode 100644 index 0000000..af4e26b --- /dev/null +++ b/src/main/java/ca/thetechrobo/rltime/VerificationStatus.java @@ -0,0 +1,5 @@ +package ca.thetechrobo.rltime; + +record VerificationStatus(boolean succeeded, String error) { + +}