resurrect command should remove death
This commit is contained in:
parent
bf005f030b
commit
98478964f2
8 changed files with 41 additions and 7 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -129,6 +129,8 @@ public class Resurrection extends JavaPlugin implements Listener {
|
||||||
// rawData = String.join(";", rawPlayers);
|
// rawData = String.join(";", rawPlayers);
|
||||||
// playerData.saveData(rawData);
|
// playerData.saveData(rawData);
|
||||||
// System.out.println(rawData);
|
// System.out.println(rawData);
|
||||||
|
// String[] array = ";bryzinga,false,0".split(";");
|
||||||
|
// System.out.println(array.length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.brysonsteck.Resurrection.commands;
|
package net.brysonsteck.Resurrection.commands;
|
||||||
|
|
||||||
|
import net.brysonsteck.Resurrection.player.PlayerData;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
@ -31,6 +32,7 @@ public class CommandResurrect implements CommandExecutor {
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1, 0);
|
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1, 0);
|
||||||
}
|
}
|
||||||
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);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(ChatColor.RED + strings[0] + " is not dead! Failed to resurrect.");
|
p.sendMessage(ChatColor.RED + strings[0] + " is not dead! Failed to resurrect.");
|
||||||
|
@ -56,6 +58,7 @@ public class CommandResurrect implements CommandExecutor {
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1, 0);
|
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1, 0);
|
||||||
}
|
}
|
||||||
Bukkit.broadcastMessage(strings[0] + " has been resurrected manually by an admin!");
|
Bukkit.broadcastMessage(strings[0] + " has been resurrected manually by an admin!");
|
||||||
|
removeDeath(resurrectPlayer);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
System.out.println(strings[0] + " is not dead! Failed to resurrect.");
|
System.out.println(strings[0] + " is not dead! Failed to resurrect.");
|
||||||
|
@ -68,4 +71,26 @@ public class CommandResurrect implements CommandExecutor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,11 @@ public class PlayerListener implements Listener {
|
||||||
boolean dead = Boolean.parseBoolean(playerSplit[1]);
|
boolean dead = Boolean.parseBoolean(playerSplit[1]);
|
||||||
resurrectTime = Long.parseLong(playerSplit[2]);
|
resurrectTime = Long.parseLong(playerSplit[2]);
|
||||||
|
|
||||||
if (p.getGameMode() == GameMode.SPECTATOR && !dead) {
|
if (!dead) {
|
||||||
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);
|
||||||
} else if (p.getGameMode() == GameMode.SPECTATOR && dead) {
|
} else {
|
||||||
resumeDeath = true;
|
resumeDeath = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,14 +57,21 @@ public class PlayerListener implements Listener {
|
||||||
playerData.saveData(rawData + ";" + p.getDisplayName() + ",false,0");
|
playerData.saveData(rawData + ";" + p.getDisplayName() + ",false,0");
|
||||||
}
|
}
|
||||||
if (resumeDeath) {
|
if (resumeDeath) {
|
||||||
PotionEffect blindness = new PotionEffect(PotionEffectType.BLINDNESS, 999999999, 10, false);
|
new BukkitRunnable() {
|
||||||
PotionEffect slowness = new PotionEffect(PotionEffectType.SLOW, 999999999, 10, false);
|
@Override
|
||||||
blindness.apply(p);
|
public void run() {
|
||||||
slowness.apply(p);
|
p.setGameMode(GameMode.SPECTATOR);
|
||||||
// convert to seconds and to ticks
|
PotionEffect blindness = new PotionEffect(PotionEffectType.BLINDNESS, 999999999, 10, false);
|
||||||
|
PotionEffect slowness = new PotionEffect(PotionEffectType.SLOW, 999999999, 10, false);
|
||||||
|
blindness.apply(p);
|
||||||
|
slowness.apply(p);
|
||||||
|
// convert to seconds and to ticks
|
||||||
|
}
|
||||||
|
}.runTaskLater(JavaPlugin.getProvidingPlugin(Resurrection.class), 1);
|
||||||
resurrectTime = resurrectTime - System.currentTimeMillis();
|
resurrectTime = resurrectTime - System.currentTimeMillis();
|
||||||
resurrectTime = resurrectTime / 1000;
|
resurrectTime = resurrectTime / 1000;
|
||||||
resurrectTime = resurrectTime * 20;
|
resurrectTime = resurrectTime * 20;
|
||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue