From 9e8c0c2a881100939a63ba4d610af5d26b53938d Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Mon, 13 Sep 2021 17:14:31 -0600 Subject: found lack of saving data if player joins during dead state and resurrects --- .../Resurrection/commands/CommandResurrect.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/net/brysonsteck/Resurrection/commands/CommandResurrect.java') 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"; -- cgit v1.2.3