This commit is contained in:
TheTechRobo 2022-10-09 15:00:17 -04:00
commit 0750d89f21
12 changed files with 282 additions and 0 deletions

38
.classpath Normal file
View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
target/
doc/
*.[wj]ar
*.pom
*.class

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RLtime</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -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

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

12
plugin.yml Normal file
View File

@ -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 <true|false>"

37
pom.xml Normal file
View File

@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ca.thetechrobo.rltime</groupId>
<artifactId>RLtime</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>RLtime</name>
<description>Adds a /ctime command that returns the current real-life time (in the server's timezone)</description>
<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -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;
}
}

View File

@ -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() {
}
}

View File

@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("true");
list.add("false");
return list;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,5 @@
package ca.thetechrobo.rltime;
record VerificationStatus(boolean succeeded, String error) {
}