2021-06-06 12:18:29 -06:00
|
|
|
package net.brysonsteck.Resurrection.commands;
|
|
|
|
|
2021-06-16 18:02:05 -06:00
|
|
|
import net.brysonsteck.Resurrection.player.PlayerData;
|
2021-06-06 12:18:29 -06:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.GameMode;
|
2021-06-15 20:23:28 -06:00
|
|
|
import org.bukkit.Sound;
|
2021-06-06 12:18:29 -06:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
|
|
|
|
public class CommandResurrect implements CommandExecutor {
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
2021-06-06 12:22:07 -06:00
|
|
|
boolean valid = (strings.length == 1);
|
2021-06-06 12:18:29 -06:00
|
|
|
|
|
|
|
if (commandSender instanceof Player) {
|
|
|
|
Player p = (Player) commandSender;
|
|
|
|
if (valid) {
|
|
|
|
Player resurrectPlayer = Bukkit.getPlayer(strings[0]);
|
|
|
|
if (resurrectPlayer == null) {
|
2021-06-15 20:15:51 -06:00
|
|
|
p.sendMessage(ChatColor.RED + "That player does not exist! Failed to resurrect.");
|
2021-06-06 12:18:29 -06:00
|
|
|
return false;
|
|
|
|
}
|
2021-06-15 18:49:36 -06:00
|
|
|
if (resurrectPlayer.getGameMode() == GameMode.SPECTATOR) {
|
2021-06-06 12:18:29 -06:00
|
|
|
for (PotionEffect effect : resurrectPlayer.getActivePotionEffects())
|
|
|
|
resurrectPlayer.removePotionEffect(effect.getType());
|
|
|
|
resurrectPlayer.setGameMode(GameMode.SURVIVAL);
|
2021-06-15 20:23:28 -06:00
|
|
|
for(Player player : Bukkit.getOnlinePlayers()){
|
|
|
|
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1, 0);
|
|
|
|
}
|
2021-06-15 20:15:51 -06:00
|
|
|
Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + strings[0] + " has been resurrected manually by an admin!");
|
2021-06-16 18:02:05 -06:00
|
|
|
removeDeath(resurrectPlayer);
|
2021-07-21 21:48:54 -06:00
|
|
|
if (p.getBedSpawnLocation() != null) {
|
|
|
|
p.teleport(p.getBedSpawnLocation());
|
|
|
|
}
|
2021-06-06 12:18:29 -06:00
|
|
|
return true;
|
|
|
|
} else {
|
2021-06-15 20:15:51 -06:00
|
|
|
p.sendMessage(ChatColor.RED + strings[0] + " is not dead! Failed to resurrect.");
|
2021-06-06 12:18:29 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2021-06-15 20:15:51 -06:00
|
|
|
System.out.println(ChatColor.RED + "Too few arguments!");
|
|
|
|
System.out.println(ChatColor.RED + "Usage: /resurrect PLAYER");
|
2021-06-06 12:18:29 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (valid) {
|
|
|
|
Player resurrectPlayer = Bukkit.getPlayer(strings[0]);
|
|
|
|
if (resurrectPlayer == null) {
|
|
|
|
System.out.println("That player does not exist! Failed to resurrect.");
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-15 18:43:25 -06:00
|
|
|
if (resurrectPlayer.getGameMode() == GameMode.SPECTATOR) {
|
2021-06-06 12:18:29 -06:00
|
|
|
for (PotionEffect effect : resurrectPlayer.getActivePotionEffects())
|
|
|
|
resurrectPlayer.removePotionEffect(effect.getType());
|
|
|
|
resurrectPlayer.setGameMode(GameMode.SURVIVAL);
|
2021-06-15 20:23:28 -06:00
|
|
|
for(Player player : Bukkit.getOnlinePlayers()){
|
|
|
|
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1, 0);
|
|
|
|
}
|
2021-06-06 12:18:29 -06:00
|
|
|
Bukkit.broadcastMessage(strings[0] + " has been resurrected manually by an admin!");
|
2021-06-16 18:02:05 -06:00
|
|
|
removeDeath(resurrectPlayer);
|
2021-07-21 21:48:54 -06:00
|
|
|
if (resurrectPlayer.getBedSpawnLocation() != null) {
|
|
|
|
resurrectPlayer.teleport(resurrectPlayer.getBedSpawnLocation());
|
|
|
|
}
|
2021-06-06 12:18:29 -06:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
System.out.println(strings[0] + " is not dead! Failed to resurrect.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
System.out.println("Too few arguments!");
|
|
|
|
System.out.println("Usage: /resurrect PLAYER");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-16 18:02:05 -06:00
|
|
|
|
|
|
|
public void removeDeath(Player p) {
|
|
|
|
PlayerData playerData = new PlayerData();
|
|
|
|
playerData.readData();
|
|
|
|
String rawData = playerData.getRawData();
|
|
|
|
String[] rawPlayers = rawData.split(";");
|
|
|
|
int index = 0;
|
|
|
|
for (String players : rawPlayers) {
|
|
|
|
if (players.startsWith(p.getDisplayName())) {
|
|
|
|
String[] playerSplit = players.split(",");
|
|
|
|
playerSplit[1] = "false";
|
|
|
|
playerSplit[2] = "0";
|
|
|
|
|
|
|
|
// save data
|
|
|
|
rawPlayers[index] = String.join(",", playerSplit);
|
|
|
|
rawData = String.join(";", rawPlayers);
|
|
|
|
playerData.saveData(rawData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
2021-06-06 12:18:29 -06:00
|
|
|
}
|