aboutsummaryrefslogtreecommitdiff
path: root/src/net/brysonsteck/Resurrection/commands
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2021-07-04 00:15:56 -0600
committerBryson Steck <steck.bryson@gmail.com>2021-07-04 00:15:56 -0600
commit2bc8c99f5a0155e374d84a6f7e0f68761e99a14a (patch)
treed70199f89ae83f40cb6c2bb309a89238d4866c87 /src/net/brysonsteck/Resurrection/commands
parent2352b42b13db966b76f97d8af62fb22339841c83 (diff)
downloadresurrection-2bc8c99f5a0155e374d84a6f7e0f68761e99a14a.tar
resurrection-2bc8c99f5a0155e374d84a6f7e0f68761e99a14a.tar.gz
resurrection-2bc8c99f5a0155e374d84a6f7e0f68761e99a14a.tar.bz2
added howlong command
Diffstat (limited to 'src/net/brysonsteck/Resurrection/commands')
-rw-r--r--src/net/brysonsteck/Resurrection/commands/CommandAbout.java16
-rw-r--r--src/net/brysonsteck/Resurrection/commands/CommandHowLong.java105
2 files changed, 120 insertions, 1 deletions
diff --git a/src/net/brysonsteck/Resurrection/commands/CommandAbout.java b/src/net/brysonsteck/Resurrection/commands/CommandAbout.java
index ac95f20..40ea0a8 100644
--- a/src/net/brysonsteck/Resurrection/commands/CommandAbout.java
+++ b/src/net/brysonsteck/Resurrection/commands/CommandAbout.java
@@ -1,14 +1,28 @@
package net.brysonsteck.Resurrection.commands;
+import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandAbout implements CommandExecutor {
+ String currentVersion;
+ boolean checked = false;
+
+ public CommandAbout(String currentVersion) {
+ this.currentVersion = currentVersion;
+ }
+
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
- String aboutMessage = "This is the about message for Resurrection.";
+ String aboutMessage = ChatColor.GREEN + "" + ChatColor.BOLD + "Resurrection\n\n" + ChatColor.RESET +
+ "Resurrection is a Spigot Minecraft plugin that forces players to wait 24 hours before respawning.\n" +
+ "The current version of this plugin is " + currentVersion + ".\n\n" +
+ "This plugin is licensed under the GNU Affero General Public License v3.0. Read more here: " +
+ "For more information on this plugin or to download it for yourself, visit the GitHub repository at https://github.com/brysonsteck/resurrection" +
+ "\u00a9 2021 Bryson Steck.";
+
if (commandSender instanceof Player) {
Player p = (Player) commandSender;
p.sendMessage(aboutMessage);
diff --git a/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java b/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java
new file mode 100644
index 0000000..72daf30
--- /dev/null
+++ b/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java
@@ -0,0 +1,105 @@
+package net.brysonsteck.Resurrection.commands;
+
+import net.brysonsteck.Resurrection.player.PlayerData;
+import net.brysonsteck.Resurrection.player.TimeCheck;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class CommandHowLong implements CommandExecutor {
+
+ @Override
+ public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
+ if (commandSender instanceof Player) {
+ boolean self = false;
+ boolean valid = false;
+
+ if (strings.length == 0) {
+ self = true;
+ valid = true;
+ } else if (strings.length == 1) {
+ valid = true;
+ }
+
+ if (valid) {
+ Player p;
+ if (self) {
+ p = (Player) commandSender;
+ } else {
+ p = Bukkit.getPlayer(strings[0]);
+ if (p == null) {
+ commandSender.sendMessage(ChatColor.RED + "ERROR: Player does not exist or is offline!");
+ return false;
+ }
+ }
+ PlayerData playerData = new PlayerData();
+ playerData.readData();
+ String rawData = playerData.getRawData();
+ String[] rawPlayers = rawData.split(";");
+ for (String players : rawPlayers) {
+ if (players.startsWith(p.getDisplayName())) {
+ String[] playerSplit = players.split(",");
+ if (Boolean.parseBoolean(playerSplit[1])) {
+ long currentTime = System.currentTimeMillis();
+ long resurrectionTime = Long.parseLong(playerSplit[2]);
+
+ TimeCheck timeCheck = new TimeCheck(resurrectionTime - currentTime);
+ if (self) {
+ commandSender.sendMessage("You will respawn in " + timeCheck.formatTime());
+ } else {
+ commandSender.sendMessage(p.getDisplayName() + " will respawn in " + timeCheck.formatTime());
+ }
+ return true;
+ }
+ }
+ }
+ commandSender.sendMessage("ERROR: An error has occurred while trying to get time information. This is a bug in the program and not your fault.");
+ return false;
+ }
+ } else {
+ boolean valid = false;
+
+ if (strings.length == 0) {
+ System.out.println("[Resurrection] ERROR: The /howlong command requires the name of a player when ran through the console.");
+ return false;
+ } else if (strings.length == 1) {
+ valid = true;
+ }
+
+ if (valid) {
+
+ Player p = Bukkit.getPlayer(strings[0]);
+ if (p == null) {
+ commandSender.sendMessage(ChatColor.RED + "ERROR: Player does not exist or is offline!");
+ return false;
+ }
+
+ PlayerData playerData = new PlayerData();
+ playerData.readData();
+ String rawData = playerData.getRawData();
+ String[] rawPlayers = rawData.split(";");
+ for (String players : rawPlayers) {
+ if (players.startsWith(p.getDisplayName())) {
+ String[] playerSplit = players.split(",");
+ if (Boolean.parseBoolean(playerSplit[1])) {
+ long currentTime = System.currentTimeMillis();
+ long resurrectionTime = Long.parseLong(playerSplit[2]);
+
+ TimeCheck timeCheck = new TimeCheck(resurrectionTime - currentTime);
+
+ commandSender.sendMessage(p.getDisplayName() + " will respawn in " + timeCheck.formatTime());
+
+ return true;
+ }
+ }
+ }
+ commandSender.sendMessage("ERROR: An error has occurred while trying to get time information. This is a bug in the program and not your fault.");
+ return false;
+ }
+ }
+ return false;
+ }
+}