found lack of saving data if player joins during dead state and resurrects
This commit is contained in:
parent
eec1131610
commit
9e8c0c2a88
8 changed files with 223 additions and 8 deletions
|
@ -5,6 +5,7 @@ import net.brysonsteck.Resurrection.player.PlayerListener;
|
||||||
import net.brysonsteck.Resurrection.startup.CheckForUpdate;
|
import net.brysonsteck.Resurrection.startup.CheckForUpdate;
|
||||||
import net.brysonsteck.Resurrection.startup.ParseSettings;
|
import net.brysonsteck.Resurrection.startup.ParseSettings;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
@ -100,16 +101,43 @@ public class Resurrection extends JavaPlugin implements Listener {
|
||||||
System.out.println("[Resurrection] ---------------------------------------------------------");
|
System.out.println("[Resurrection] ---------------------------------------------------------");
|
||||||
|
|
||||||
if (parseSettings.isSettingsComplete() && !fileFail) {
|
if (parseSettings.isSettingsComplete() && !fileFail) {
|
||||||
|
boolean DEBUG = false;
|
||||||
|
if (Boolean.parseBoolean(parseSettings.getSetting("debug"))) {
|
||||||
|
DEBUG = true;
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Resurrection's debug mode has been enabled in the settings file.");
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: All debug messages will be broadcasted (sent to everyone) prefaced with the tag \"[Res. DEBUG]\" and sent in bold yellow text.");
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Several messages may be sent at a time. Therefore, debug mode should be disabled for anything other than, well, debugging.");
|
||||||
|
System.out.println("[Resurrection] ---------------------------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("[Resurrection] Registering listeners and adding commands...");
|
System.out.println("[Resurrection] Registering listeners and adding commands...");
|
||||||
// register listener
|
// register listener
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerListener(parseSettings), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerListener(parseSettings), this);
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player listener registered.");
|
||||||
|
}
|
||||||
|
|
||||||
// register commands
|
// register commands
|
||||||
this.getCommand("about").setExecutor(new CommandAbout(parseSettings.getSetting("debug"), pluginInfo.getVersion(), outdated));
|
this.getCommand("about").setExecutor(new CommandAbout(parseSettings.getSetting("debug"), pluginInfo.getVersion(), outdated));
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: `/about` registered.");
|
||||||
|
}
|
||||||
this.getCommand("bug").setExecutor(new CommandBug(parseSettings.getSetting("debug")));
|
this.getCommand("bug").setExecutor(new CommandBug(parseSettings.getSetting("debug")));
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: `/bug` registered.");
|
||||||
|
}
|
||||||
this.getCommand("resurrect").setExecutor(new CommandResurrect(parseSettings.getSetting("debug")));
|
this.getCommand("resurrect").setExecutor(new CommandResurrect(parseSettings.getSetting("debug")));
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: `/resurrect` registered.");
|
||||||
|
}
|
||||||
this.getCommand("howlong").setExecutor(new CommandHowLong(parseSettings.getSetting("debug")));
|
this.getCommand("howlong").setExecutor(new CommandHowLong(parseSettings.getSetting("debug")));
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: `/howlong` registered.");
|
||||||
|
}
|
||||||
this.getCommand("source").setExecutor(new CommandSource(parseSettings.getSetting("debug")));
|
this.getCommand("source").setExecutor(new CommandSource(parseSettings.getSetting("debug")));
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: `/source` registered.");
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("[Resurrection] ---------------------------------------------------------");
|
System.out.println("[Resurrection] ---------------------------------------------------------");
|
||||||
System.out.println("[Resurrection] Successfully Started!");
|
System.out.println("[Resurrection] Successfully Started!");
|
||||||
|
|
|
@ -8,24 +8,24 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class CommandAbout implements CommandExecutor {
|
public class CommandAbout implements CommandExecutor {
|
||||||
boolean debug;
|
boolean DEBUG;
|
||||||
String currentVersion;
|
String currentVersion;
|
||||||
boolean outdated;
|
boolean outdated;
|
||||||
|
|
||||||
public CommandAbout(String 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.currentVersion = currentVersion;
|
||||||
this.outdated = outdated;
|
this.outdated = outdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
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());
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: The `/about` command was ran by " + commandSender.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandSender instanceof Player) {
|
if (commandSender instanceof Player) {
|
||||||
if (debug) {
|
if (DEBUG) {
|
||||||
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player.");
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player.");
|
||||||
}
|
}
|
||||||
Player p = (Player) commandSender;
|
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 + "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");
|
p.sendMessage(ChatColor.YELLOW + "\u00a9 2021 Bryson Steck");
|
||||||
} else {
|
} else {
|
||||||
if (debug) {
|
if (DEBUG) {
|
||||||
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console.");
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console.");
|
||||||
}
|
}
|
||||||
System.out.println("[Resurrection] --- Resurrection ---");
|
System.out.println("[Resurrection] --- Resurrection ---");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.brysonsteck.Resurrection.commands;
|
package net.brysonsteck.Resurrection.commands;
|
||||||
|
|
||||||
import net.brysonsteck.Resurrection.Resurrection;
|
import net.brysonsteck.Resurrection.Resurrection;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -10,13 +11,23 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class CommandBug implements CommandExecutor {
|
public class CommandBug implements CommandExecutor {
|
||||||
|
boolean DEBUG;
|
||||||
|
|
||||||
public CommandBug(String debug) {
|
public CommandBug(String debug) {
|
||||||
|
this.DEBUG = Boolean.parseBoolean(debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
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 (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.");
|
commandSender.sendMessage(ChatColor.YELLOW + "Did you find a bug? Well that sucks for you.");
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,6 +41,10 @@ public class CommandBug implements CommandExecutor {
|
||||||
}.runTaskLater(JavaPlugin.getProvidingPlugin(Resurrection.class), 60);
|
}.runTaskLater(JavaPlugin.getProvidingPlugin(Resurrection.class), 60);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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.");
|
System.out.println("[Resurrection] Did you find a bug? Well that sucks for you.");
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,20 +10,38 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class CommandHowLong implements CommandExecutor {
|
public class CommandHowLong implements CommandExecutor {
|
||||||
|
boolean DEBUG;
|
||||||
|
|
||||||
public CommandHowLong(String debug) {
|
public CommandHowLong(String debug) {
|
||||||
|
this.DEBUG = Boolean.parseBoolean(debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
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 (commandSender instanceof Player) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player.");
|
||||||
|
}
|
||||||
|
|
||||||
boolean self = false;
|
boolean self = false;
|
||||||
boolean valid = false;
|
boolean valid = false;
|
||||||
|
|
||||||
if (strings.length == 0) {
|
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;
|
self = true;
|
||||||
valid = true;
|
valid = true;
|
||||||
} else if (strings.length == 1) {
|
} 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;
|
valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +55,10 @@ public class CommandHowLong implements CommandExecutor {
|
||||||
commandSender.sendMessage(ChatColor.RED + "ERROR: That player is not online/doesn't exist!");
|
commandSender.sendMessage(ChatColor.RED + "ERROR: That player is not online/doesn't exist!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player " + p.getDisplayName() + " exists.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PlayerData playerData = new PlayerData();
|
PlayerData playerData = new PlayerData();
|
||||||
playerData.readData();
|
playerData.readData();
|
||||||
|
@ -46,6 +68,10 @@ public class CommandHowLong implements CommandExecutor {
|
||||||
if (players.startsWith(p.getDisplayName())) {
|
if (players.startsWith(p.getDisplayName())) {
|
||||||
String[] playerSplit = players.split(",");
|
String[] playerSplit = players.split(",");
|
||||||
if (Boolean.parseBoolean(playerSplit[1])) {
|
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 currentTime = System.currentTimeMillis();
|
||||||
long resurrectionTime = Long.parseLong(playerSplit[2]);
|
long resurrectionTime = Long.parseLong(playerSplit[2]);
|
||||||
|
|
||||||
|
@ -70,12 +96,20 @@ public class CommandHowLong implements CommandExecutor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console.");
|
||||||
|
}
|
||||||
|
|
||||||
boolean valid = false;
|
boolean valid = false;
|
||||||
|
|
||||||
if (strings.length == 0) {
|
if (strings.length == 0) {
|
||||||
System.out.println("[Resurrection] ERROR: The /howlong command requires the name of a player when ran through the console.");
|
System.out.println("[Resurrection] ERROR: The /howlong command requires the name of a player when ran through the console.");
|
||||||
return false;
|
return false;
|
||||||
} else if (strings.length == 1) {
|
} else if (strings.length == 1) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Valid; console specified player to check.");
|
||||||
|
}
|
||||||
|
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +121,10 @@ public class CommandHowLong implements CommandExecutor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player " + p.getDisplayName() + " exists.");
|
||||||
|
}
|
||||||
|
|
||||||
PlayerData playerData = new PlayerData();
|
PlayerData playerData = new PlayerData();
|
||||||
playerData.readData();
|
playerData.readData();
|
||||||
String rawData = playerData.getRawData();
|
String rawData = playerData.getRawData();
|
||||||
|
@ -95,6 +133,9 @@ public class CommandHowLong implements CommandExecutor {
|
||||||
if (players.startsWith(p.getDisplayName())) {
|
if (players.startsWith(p.getDisplayName())) {
|
||||||
String[] playerSplit = players.split(",");
|
String[] playerSplit = players.split(",");
|
||||||
if (Boolean.parseBoolean(playerSplit[1])) {
|
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 currentTime = System.currentTimeMillis();
|
||||||
long resurrectionTime = Long.parseLong(playerSplit[2]);
|
long resurrectionTime = Long.parseLong(playerSplit[2]);
|
||||||
|
|
||||||
|
|
|
@ -12,22 +12,45 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
public class CommandResurrect implements CommandExecutor {
|
public class CommandResurrect implements CommandExecutor {
|
||||||
|
boolean DEBUG;
|
||||||
|
|
||||||
public CommandResurrect(String debug) {
|
public CommandResurrect(String debug) {
|
||||||
|
this.DEBUG = Boolean.parseBoolean(debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
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);
|
boolean valid = (strings.length == 1);
|
||||||
|
|
||||||
|
|
||||||
if (commandSender instanceof Player) {
|
if (commandSender instanceof Player) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is a player.");
|
||||||
|
}
|
||||||
|
|
||||||
Player p = (Player) commandSender;
|
Player p = (Player) commandSender;
|
||||||
if (valid) {
|
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]);
|
Player resurrectPlayer = Bukkit.getPlayer(strings[0]);
|
||||||
if (resurrectPlayer == null) {
|
if (resurrectPlayer == null) {
|
||||||
p.sendMessage(ChatColor.RED + "ERROR: That player is not online/doesn't exist! Failed to resurrect.");
|
p.sendMessage(ChatColor.RED + "ERROR: That player is not online/doesn't exist! Failed to resurrect.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player \"" + resurrectPlayer.getDisplayName() + "\" exists");
|
||||||
|
}
|
||||||
|
|
||||||
if (resurrectPlayer.getGameMode() == GameMode.SPECTATOR) {
|
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())
|
for (PotionEffect effect : resurrectPlayer.getActivePotionEffects())
|
||||||
resurrectPlayer.removePotionEffect(effect.getType());
|
resurrectPlayer.removePotionEffect(effect.getType());
|
||||||
resurrectPlayer.setGameMode(GameMode.SURVIVAL);
|
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!");
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + strings[0] + " has been resurrected manually by an admin!");
|
||||||
removeDeath(resurrectPlayer);
|
removeDeath(resurrectPlayer);
|
||||||
if (p.getBedSpawnLocation() != null) {
|
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());
|
p.teleport(p.getBedSpawnLocation());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -49,13 +76,28 @@ public class CommandResurrect implements CommandExecutor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: CommandSender is console.");
|
||||||
|
}
|
||||||
|
|
||||||
if (valid) {
|
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]);
|
Player resurrectPlayer = Bukkit.getPlayer(strings[0]);
|
||||||
if (resurrectPlayer == null) {
|
if (resurrectPlayer == null) {
|
||||||
System.out.println("[Resurrection] ERROR: That player is not online/doesn't exist! Failed to resurrect.");
|
System.out.println("[Resurrection] ERROR: That player is not online/doesn't exist! Failed to resurrect.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Specified player \"" + resurrectPlayer.getDisplayName() + "\" exists");
|
||||||
|
}
|
||||||
|
|
||||||
if (resurrectPlayer.getGameMode() == GameMode.SPECTATOR) {
|
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())
|
for (PotionEffect effect : resurrectPlayer.getActivePotionEffects())
|
||||||
resurrectPlayer.removePotionEffect(effect.getType());
|
resurrectPlayer.removePotionEffect(effect.getType());
|
||||||
resurrectPlayer.setGameMode(GameMode.SURVIVAL);
|
resurrectPlayer.setGameMode(GameMode.SURVIVAL);
|
||||||
|
@ -65,6 +107,10 @@ public class CommandResurrect implements CommandExecutor {
|
||||||
Bukkit.broadcastMessage(strings[0] + " has been resurrected manually by an admin!");
|
Bukkit.broadcastMessage(strings[0] + " has been resurrected manually by an admin!");
|
||||||
removeDeath(resurrectPlayer);
|
removeDeath(resurrectPlayer);
|
||||||
if (resurrectPlayer.getBedSpawnLocation() != null) {
|
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());
|
resurrectPlayer.teleport(resurrectPlayer.getBedSpawnLocation());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -87,6 +133,9 @@ public class CommandResurrect implements CommandExecutor {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (String players : rawPlayers) {
|
for (String players : rawPlayers) {
|
||||||
if (players.startsWith(p.getDisplayName())) {
|
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(",");
|
String[] playerSplit = players.split(",");
|
||||||
playerSplit[1] = "false";
|
playerSplit[1] = "false";
|
||||||
playerSplit[2] = "0";
|
playerSplit[2] = "0";
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.brysonsteck.Resurrection.commands;
|
package net.brysonsteck.Resurrection.commands;
|
||||||
|
|
||||||
import net.brysonsteck.Resurrection.Resurrection;
|
import net.brysonsteck.Resurrection.Resurrection;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -10,15 +11,22 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class CommandSource implements CommandExecutor {
|
public class CommandSource implements CommandExecutor {
|
||||||
boolean debug;
|
boolean DEBUG;
|
||||||
|
|
||||||
public CommandSource(String debug) {
|
public CommandSource(String debug) {
|
||||||
this.debug = Boolean.parseBoolean(debug);
|
this.DEBUG = Boolean.parseBoolean(debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
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 (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 + "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 + "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");
|
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;
|
return true;
|
||||||
} else {
|
} 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] 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] GNU Affero General Public License v3.0 via GitHub.");
|
||||||
System.out.println("[Resurrection] You can view the repository at https://github.com/brysonsteck/resurrection");
|
System.out.println("[Resurrection] You can view the repository at https://github.com/brysonsteck/resurrection");
|
||||||
|
|
|
@ -2,7 +2,9 @@ package net.brysonsteck.Resurrection.player;
|
||||||
|
|
||||||
|
|
||||||
import net.brysonsteck.Resurrection.Resurrection;
|
import net.brysonsteck.Resurrection.Resurrection;
|
||||||
|
import net.brysonsteck.Resurrection.startup.ParseSettings;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -11,20 +13,38 @@ import java.util.Hashtable;
|
||||||
public class PlayerData {
|
public class PlayerData {
|
||||||
Hashtable<String, Hashtable<String, String>> playerData = new Hashtable<>();
|
Hashtable<String, Hashtable<String, String>> playerData = new Hashtable<>();
|
||||||
String rawData;
|
String rawData;
|
||||||
|
boolean DEBUG = Boolean.parseBoolean(new ParseSettings()
|
||||||
|
.getSetting("debug"));
|
||||||
|
|
||||||
public void saveData(String write) {
|
public void saveData(String write) {
|
||||||
try {
|
try {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Attempting to save player data");
|
||||||
|
}
|
||||||
FileWriter writer = new FileWriter("plugins/playerData.resurrection");
|
FileWriter writer = new FileWriter("plugins/playerData.resurrection");
|
||||||
writer.write(write);
|
writer.write(write);
|
||||||
writer.close();
|
writer.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Error occurred while trying to save player data, avoid shutting down the server");
|
||||||
|
}
|
||||||
|
System.out.println("[Resurrection] There was an issue saving the player data file.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
System.out.println("[Resurrection] Resurrection will continue to run despite this error, but avoid shutting down the server until a successful save occurs.");
|
||||||
|
System.out.println("[Resurrection] In the mean time, check to make sure the playerData file exists and you have permissions to write to it.");
|
||||||
}
|
}
|
||||||
readData();
|
readData();
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player data saved successfully");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readData() {
|
public void readData() {
|
||||||
try {
|
try {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Attempting to read player data");
|
||||||
|
}
|
||||||
rawData = "";
|
rawData = "";
|
||||||
BufferedReader reader = new BufferedReader(new FileReader("plugins/playerData.resurrection"));
|
BufferedReader reader = new BufferedReader(new FileReader("plugins/playerData.resurrection"));
|
||||||
String line;
|
String line;
|
||||||
|
@ -40,13 +60,24 @@ public class PlayerData {
|
||||||
playerHash.put("dead", playerData[1]);
|
playerHash.put("dead", playerData[1]);
|
||||||
playerHash.put("timeLeft", playerData[2]);
|
playerHash.put("timeLeft", playerData[2]);
|
||||||
this.playerData.put(playerData[0], playerHash);
|
this.playerData.put(playerData[0], playerHash);
|
||||||
|
if (DEBUG) {
|
||||||
|
TimeCheck timeCheck = new TimeCheck(Long.parseLong(playerData[2]));
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: player: " + playerData[0] + " | dead: " + playerData[1] + " | ms to resurrect at: " + playerData[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Error occurred while trying to read player data. Resurrection is shutting down");
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("[Resurrection] There was an issue reading the player data file.");
|
System.out.println("[Resurrection] There was an issue reading the player data file.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file could not be read, the plugin will now stop.");
|
System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file could not be read, the plugin will now stop.");
|
||||||
Bukkit.getPluginManager().disablePlugin(JavaPlugin.getProvidingPlugin(Resurrection.class));
|
Bukkit.getPluginManager().disablePlugin(JavaPlugin.getProvidingPlugin(Resurrection.class));
|
||||||
}
|
}
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player data read successfully");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Hashtable<String, Hashtable<String, String>> getPlayers() {
|
// public Hashtable<String, Hashtable<String, String>> getPlayers() {
|
||||||
|
|
|
@ -25,14 +25,20 @@ public class PlayerListener implements Listener {
|
||||||
Location spawn = world.getSpawnLocation();
|
Location spawn = world.getSpawnLocation();
|
||||||
Hashtable<String, Location> playerSpawns = new Hashtable<>();
|
Hashtable<String, Location> playerSpawns = new Hashtable<>();
|
||||||
ParseSettings parseSettings;
|
ParseSettings parseSettings;
|
||||||
|
boolean DEBUG;
|
||||||
|
|
||||||
public PlayerListener(ParseSettings parseSettings) {
|
public PlayerListener(ParseSettings parseSettings) {
|
||||||
this.parseSettings = parseSettings;
|
this.parseSettings = parseSettings;
|
||||||
|
this.DEBUG = Boolean.parseBoolean(parseSettings.getSetting("debug"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player " + p.getDisplayName() + " has joined");
|
||||||
|
}
|
||||||
|
|
||||||
PlayerData playerData = new PlayerData();
|
PlayerData playerData = new PlayerData();
|
||||||
playerData.readData();
|
playerData.readData();
|
||||||
String rawData = playerData.getRawData();
|
String rawData = playerData.getRawData();
|
||||||
|
@ -43,12 +49,19 @@ public class PlayerListener implements Listener {
|
||||||
long timeToResurrection = 0;
|
long timeToResurrection = 0;
|
||||||
for (String players : rawPlayers) {
|
for (String players : rawPlayers) {
|
||||||
if (players.startsWith(p.getDisplayName())) {
|
if (players.startsWith(p.getDisplayName())) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player " + p.getDisplayName() + " was found in the player data");
|
||||||
|
}
|
||||||
found = true;
|
found = true;
|
||||||
String[] playerSplit = players.split(",");
|
String[] playerSplit = players.split(",");
|
||||||
boolean dead = Boolean.parseBoolean(playerSplit[1]);
|
boolean dead = Boolean.parseBoolean(playerSplit[1]);
|
||||||
timeToResurrection = Long.parseLong(playerSplit[2]);
|
timeToResurrection = Long.parseLong(playerSplit[2]);
|
||||||
|
|
||||||
if (!dead) {
|
if (!dead) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player " + p.getDisplayName() + " is not dead; making sure they are in survival");
|
||||||
|
}
|
||||||
|
|
||||||
for (PotionEffect effect : p.getActivePotionEffects())
|
for (PotionEffect effect : p.getActivePotionEffects())
|
||||||
p.removePotionEffect(effect.getType());
|
p.removePotionEffect(effect.getType());
|
||||||
p.setGameMode(GameMode.SURVIVAL);
|
p.setGameMode(GameMode.SURVIVAL);
|
||||||
|
@ -65,9 +78,16 @@ public class PlayerListener implements Listener {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player " + p.getDisplayName() + " was not found in the player data; registering");
|
||||||
|
}
|
||||||
|
|
||||||
playerData.saveData(rawData + ";" + p.getDisplayName() + ",false,0");
|
playerData.saveData(rawData + ";" + p.getDisplayName() + ",false,0");
|
||||||
}
|
}
|
||||||
if (resumeDeath && !timerRunning) {
|
if (resumeDeath && !timerRunning) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player " + p.getDisplayName() + " is dead; pushing into dead state until resurrection");
|
||||||
|
}
|
||||||
// spawn = p.getLocation();
|
// spawn = p.getLocation();
|
||||||
p.sendMessage(ChatColor.RED + "You are still dead. To check how long you have left before you are resurrected, ");
|
p.sendMessage(ChatColor.RED + "You are still dead. To check how long you have left before you are resurrected, ");
|
||||||
p.sendMessage(ChatColor.RED + "run the \"/howlong\" command in chat.");
|
p.sendMessage(ChatColor.RED + "run the \"/howlong\" command in chat.");
|
||||||
|
@ -91,6 +111,21 @@ public class PlayerListener implements Listener {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
String rawData = playerData.getRawData();
|
||||||
|
int index = 0;
|
||||||
|
for (String players : rawPlayers) {
|
||||||
|
if (players.startsWith(p.getDisplayName())) {
|
||||||
|
String[] playerSplit = players.split(",");
|
||||||
|
playerSplit[1] = "false";
|
||||||
|
playerSplit[2] = "0";
|
||||||
|
|
||||||
|
rawPlayers[index] = String.join(",", playerSplit);
|
||||||
|
rawData = String.join(";", rawPlayers);
|
||||||
|
playerData.saveData(rawData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
stillDead = false;
|
stillDead = false;
|
||||||
for (PotionEffect effect : p.getActivePotionEffects())
|
for (PotionEffect effect : p.getActivePotionEffects())
|
||||||
p.removePotionEffect(effect.getType());
|
p.removePotionEffect(effect.getType());
|
||||||
|
@ -110,11 +145,16 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDeath(PlayerDeathEvent e) {
|
public void onDeath(PlayerDeathEvent e) {
|
||||||
System.out.println("[Resurrection] A player has died!");
|
|
||||||
Player p = e.getEntity();
|
Player p = e.getEntity();
|
||||||
stillDead = true;
|
stillDead = true;
|
||||||
|
if (DEBUG) {
|
||||||
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player " + p.getDisplayName() + " has died, reading resurrection_time in settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get human readable form of resurrection time
|
||||||
TimeCheck timeCheck = new TimeCheck(Long.parseLong(parseSettings.getSetting("resurrection_time")));
|
TimeCheck timeCheck = new TimeCheck(Long.parseLong(parseSettings.getSetting("resurrection_time")));
|
||||||
|
|
||||||
|
// calculate time that player will resurrect at
|
||||||
long resurrectionTime = System.currentTimeMillis() + Long.parseLong(parseSettings.getSetting("resurrection_time"));
|
long resurrectionTime = System.currentTimeMillis() + Long.parseLong(parseSettings.getSetting("resurrection_time"));
|
||||||
|
|
||||||
e.setDeathMessage(e.getDeathMessage() + " and will respawn in the next " + timeCheck.formatTime('f'));
|
e.setDeathMessage(e.getDeathMessage() + " and will respawn in the next " + timeCheck.formatTime('f'));
|
||||||
|
|
Loading…
Add table
Reference in a new issue