diff options
author | Bryson Steck <steck.bryson@gmail.com> | 2021-09-13 17:14:31 -0600 |
---|---|---|
committer | Bryson Steck <steck.bryson@gmail.com> | 2021-09-13 17:14:31 -0600 |
commit | 9e8c0c2a881100939a63ba4d610af5d26b53938d (patch) | |
tree | 430ac0be6ad787a63212d9465549436f0a0af01b /src/net/brysonsteck/Resurrection/commands | |
parent | eec11316107edbd69d97080cebc369e042ce5183 (diff) | |
download | resurrection-9e8c0c2a881100939a63ba4d610af5d26b53938d.tar resurrection-9e8c0c2a881100939a63ba4d610af5d26b53938d.tar.gz resurrection-9e8c0c2a881100939a63ba4d610af5d26b53938d.tar.bz2 |
found lack of saving data if player joins during dead state and resurrects
Diffstat (limited to 'src/net/brysonsteck/Resurrection/commands')
5 files changed, 123 insertions, 7 deletions
diff --git a/src/net/brysonsteck/Resurrection/commands/CommandAbout.java b/src/net/brysonsteck/Resurrection/commands/CommandAbout.java index 08f0437..a820432 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandAbout.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandAbout.java @@ -8,24 +8,24 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class CommandAbout implements CommandExecutor { - boolean debug; + boolean DEBUG; String currentVersion; boolean outdated; public CommandAbout(String debug, String currentVersion, boolean outdated) { - this.debug = Boolean.parseBoolean(debug); + this.DEBUG = Boolean.parseBoolean(debug); this.currentVersion = currentVersion; this.outdated = outdated; } @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { - if (debug) { + if (DEBUG) { Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: The `/about` command was ran by " + commandSender.getName()); } if (commandSender instanceof Player) { - if (debug) { + if (DEBUG) { Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player."); } Player p = (Player) commandSender; @@ -40,7 +40,7 @@ public class CommandAbout implements CommandExecutor { p.sendMessage(ChatColor.YELLOW + "For more info on this plugin or to download it, visit the GitHub repository at " + ChatColor.AQUA + "https://github.com/brysonsteck/resurrection"); p.sendMessage(ChatColor.YELLOW + "\u00a9 2021 Bryson Steck"); } else { - if (debug) { + if (DEBUG) { Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console."); } System.out.println("[Resurrection] --- Resurrection ---"); diff --git a/src/net/brysonsteck/Resurrection/commands/CommandBug.java b/src/net/brysonsteck/Resurrection/commands/CommandBug.java index 75ed5cf..c5c53a1 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandBug.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandBug.java @@ -1,6 +1,7 @@ package net.brysonsteck.Resurrection.commands; import net.brysonsteck.Resurrection.Resurrection; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -10,13 +11,23 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; public class CommandBug implements CommandExecutor { + boolean DEBUG; public CommandBug(String debug) { + this.DEBUG = Boolean.parseBoolean(debug); } @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: The `/bug` command was ran by " + commandSender.getName()); + } + if (commandSender instanceof Player) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player."); + } + commandSender.sendMessage(ChatColor.YELLOW + "Did you find a bug? Well that sucks for you."); new BukkitRunnable() { @Override @@ -30,6 +41,10 @@ public class CommandBug implements CommandExecutor { }.runTaskLater(JavaPlugin.getProvidingPlugin(Resurrection.class), 60); return true; } else { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console"); + } + System.out.println("[Resurrection] Did you find a bug? Well that sucks for you."); new BukkitRunnable() { @Override diff --git a/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java b/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java index 29314d7..32662a0 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java @@ -10,20 +10,38 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class CommandHowLong implements CommandExecutor { + boolean DEBUG; public CommandHowLong(String debug) { + this.DEBUG = Boolean.parseBoolean(debug); } @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: The `/howlong` command was ran by " + commandSender.getName()); + } + if (commandSender instanceof Player) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player."); + } + boolean self = false; boolean valid = false; if (strings.length == 0) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Valid; no arguments given. Assuming sender wants to check own time"); + } + self = true; valid = true; } else if (strings.length == 1) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Valid; one argument given. Assuming sender wants to check another player's time"); + } + valid = true; } @@ -37,6 +55,10 @@ public class CommandHowLong implements CommandExecutor { commandSender.sendMessage(ChatColor.RED + "ERROR: That player is not online/doesn't exist!"); return false; } + + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player " + p.getDisplayName() + " exists."); + } } PlayerData playerData = new PlayerData(); playerData.readData(); @@ -46,6 +68,10 @@ public class CommandHowLong implements CommandExecutor { if (players.startsWith(p.getDisplayName())) { String[] playerSplit = players.split(","); if (Boolean.parseBoolean(playerSplit[1])) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player is dead according to file. Calculating time until resurrection"); + } + long currentTime = System.currentTimeMillis(); long resurrectionTime = Long.parseLong(playerSplit[2]); @@ -70,12 +96,20 @@ public class CommandHowLong implements CommandExecutor { return false; } } else { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console."); + } + 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) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Valid; console specified player to check."); + } + valid = true; } @@ -87,6 +121,10 @@ public class CommandHowLong implements CommandExecutor { return false; } + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player " + p.getDisplayName() + " exists."); + } + PlayerData playerData = new PlayerData(); playerData.readData(); String rawData = playerData.getRawData(); @@ -95,6 +133,9 @@ public class CommandHowLong implements CommandExecutor { if (players.startsWith(p.getDisplayName())) { String[] playerSplit = players.split(","); if (Boolean.parseBoolean(playerSplit[1])) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player is dead according to file. Calculating time until resurrection"); + } long currentTime = System.currentTimeMillis(); long resurrectionTime = Long.parseLong(playerSplit[2]); diff --git a/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java b/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java index 9f97c29..3d206c4 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java @@ -12,22 +12,45 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; public class CommandResurrect implements CommandExecutor { + boolean DEBUG; + public CommandResurrect(String debug) { + this.DEBUG = Boolean.parseBoolean(debug); } @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: The `resurrect` command was ran by " + commandSender.getName()); + } + boolean valid = (strings.length == 1); + if (commandSender instanceof Player) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player."); + } + Player p = (Player) commandSender; if (valid) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Valid; an argument was specified. Assuming it as name of player to resurrect"); + } + Player resurrectPlayer = Bukkit.getPlayer(strings[0]); if (resurrectPlayer == null) { p.sendMessage(ChatColor.RED + "ERROR: That player is not online/doesn't exist! Failed to resurrect."); return false; } + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player \"" + resurrectPlayer.getDisplayName() + "\" exists"); + } + if (resurrectPlayer.getGameMode() == GameMode.SPECTATOR) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player in spectator mode, assuming dead"); + } for (PotionEffect effect : resurrectPlayer.getActivePotionEffects()) resurrectPlayer.removePotionEffect(effect.getType()); resurrectPlayer.setGameMode(GameMode.SURVIVAL); @@ -37,6 +60,10 @@ public class CommandResurrect implements CommandExecutor { Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + strings[0] + " has been resurrected manually by an admin!"); removeDeath(resurrectPlayer); if (p.getBedSpawnLocation() != null) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: A bed for the specified player was found. Teleporting"); + } + p.teleport(p.getBedSpawnLocation()); } return true; @@ -49,13 +76,28 @@ public class CommandResurrect implements CommandExecutor { return false; } } else { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console."); + } + if (valid) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Valid; an argument was specified. Assuming it as name of player to resurrect"); + } + Player resurrectPlayer = Bukkit.getPlayer(strings[0]); if (resurrectPlayer == null) { System.out.println("[Resurrection] ERROR: That player is not online/doesn't exist! Failed to resurrect."); return false; } + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player \"" + resurrectPlayer.getDisplayName() + "\" exists"); + } + if (resurrectPlayer.getGameMode() == GameMode.SPECTATOR) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player in spectator mode, assuming dead"); + } for (PotionEffect effect : resurrectPlayer.getActivePotionEffects()) resurrectPlayer.removePotionEffect(effect.getType()); resurrectPlayer.setGameMode(GameMode.SURVIVAL); @@ -65,6 +107,10 @@ public class CommandResurrect implements CommandExecutor { Bukkit.broadcastMessage(strings[0] + " has been resurrected manually by an admin!"); removeDeath(resurrectPlayer); if (resurrectPlayer.getBedSpawnLocation() != null) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: A bed for the specified player was found. Teleporting"); + } + resurrectPlayer.teleport(resurrectPlayer.getBedSpawnLocation()); } return true; @@ -87,6 +133,9 @@ public class CommandResurrect implements CommandExecutor { int index = 0; for (String players : rawPlayers) { if (players.startsWith(p.getDisplayName())) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Removing the death from the resurrected player"); + } String[] playerSplit = players.split(","); playerSplit[1] = "false"; playerSplit[2] = "0"; diff --git a/src/net/brysonsteck/Resurrection/commands/CommandSource.java b/src/net/brysonsteck/Resurrection/commands/CommandSource.java index 92e51c6..5ac7666 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandSource.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandSource.java @@ -1,6 +1,7 @@ package net.brysonsteck.Resurrection.commands; import net.brysonsteck.Resurrection.Resurrection; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -10,15 +11,22 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; public class CommandSource implements CommandExecutor { - boolean debug; + boolean DEBUG; public CommandSource(String debug) { - this.debug = Boolean.parseBoolean(debug); + this.DEBUG = Boolean.parseBoolean(debug); } @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: The `/source` command was ran by " + commandSender.getName()); + } + if (commandSender instanceof Player) { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player"); + } commandSender.sendMessage(ChatColor.YELLOW + "Resurrection is FREE AND OPEN SOURCE under the"); commandSender.sendMessage(ChatColor.YELLOW + "GNU Affero General Public License v3.0 via GitHub."); commandSender.sendMessage(ChatColor.YELLOW + "You can view the repository at " + ChatColor.AQUA + "https://github.com/brysonsteck/resurrection"); @@ -26,6 +34,9 @@ public class CommandSource implements CommandExecutor { return true; } else { + if (DEBUG) { + Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console"); + } System.out.println("[Resurrection] Resurrection is FREE AND OPEN SOURCE under the"); System.out.println("[Resurrection] GNU Affero General Public License v3.0 via GitHub."); System.out.println("[Resurrection] You can view the repository at https://github.com/brysonsteck/resurrection"); |