aboutsummaryrefslogtreecommitdiff
path: root/src/net/brysonsteck/Resurrection/player
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2021-06-16 16:50:42 -0600
committerBryson Steck <steck.bryson@gmail.com>2021-06-16 16:50:42 -0600
commitc1aae0979096944fa86b41495f39a7085497bb7e (patch)
tree65a825f6746d01f0493883101929317a59cbb846 /src/net/brysonsteck/Resurrection/player
parentfb22ed40df5b1599aefce668e8ce6e1c43643544 (diff)
downloadresurrection-c1aae0979096944fa86b41495f39a7085497bb7e.tar
resurrection-c1aae0979096944fa86b41495f39a7085497bb7e.tar.gz
resurrection-c1aae0979096944fa86b41495f39a7085497bb7e.tar.bz2
implemented playerdata
Diffstat (limited to 'src/net/brysonsteck/Resurrection/player')
-rw-r--r--src/net/brysonsteck/Resurrection/player/PlayerData.java2
-rw-r--r--src/net/brysonsteck/Resurrection/player/PlayerListener.java106
2 files changed, 107 insertions, 1 deletions
diff --git a/src/net/brysonsteck/Resurrection/player/PlayerData.java b/src/net/brysonsteck/Resurrection/player/PlayerData.java
index cc82952..44dddb5 100644
--- a/src/net/brysonsteck/Resurrection/player/PlayerData.java
+++ b/src/net/brysonsteck/Resurrection/player/PlayerData.java
@@ -14,7 +14,7 @@ public class PlayerData {
public void saveData(String write) {
try {
FileWriter writer = new FileWriter("data/player.data");
- writer.write(rawData + ";" + write);
+ writer.write(write);
writer.close();
readData();
} catch (IOException e) {
diff --git a/src/net/brysonsteck/Resurrection/player/PlayerListener.java b/src/net/brysonsteck/Resurrection/player/PlayerListener.java
index c7ca2dc..026cf03 100644
--- a/src/net/brysonsteck/Resurrection/player/PlayerListener.java
+++ b/src/net/brysonsteck/Resurrection/player/PlayerListener.java
@@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.java.JavaPlugin;
@@ -19,6 +20,69 @@ public class PlayerListener implements Listener {
Location spawn;
@EventHandler
+ public void onJoin(PlayerJoinEvent e) {
+ Player p = e.getPlayer();
+ PlayerData playerData = new PlayerData();
+ playerData.readData();
+ String rawData = playerData.getRawData();
+ String[] rawPlayers = rawData.split(";");
+ int index = 0;
+ boolean found = false;
+ boolean resumeDeath = false;
+ long resurrectTime = 0;
+ for (String players : rawPlayers) {
+ if (players.startsWith(p.getDisplayName())) {
+ found = true;
+ String[] playerSplit = players.split(",");
+ boolean dead = Boolean.parseBoolean(playerSplit[1]);
+ resurrectTime = Long.parseLong(playerSplit[2]);
+
+ if (p.getGameMode() == GameMode.SPECTATOR && !dead) {
+ for (PotionEffect effect : p.getActivePotionEffects())
+ p.removePotionEffect(effect.getType());
+ p.setGameMode(GameMode.SURVIVAL);
+ } else if (p.getGameMode() == GameMode.SPECTATOR && dead) {
+ resumeDeath = true;
+ }
+
+ // save data
+ rawPlayers[index] = String.join(",", playerSplit);
+ rawData = String.join(";", rawPlayers);
+ playerData.saveData(rawData);
+ break;
+ }
+ index++;
+ }
+ if (!found) {
+ playerData.saveData(rawData + ";" + p.getDisplayName() + ",false,0");
+ }
+ if (resumeDeath) {
+ 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
+ resurrectTime = resurrectTime - System.currentTimeMillis();
+ resurrectTime = resurrectTime / 1000;
+ resurrectTime = resurrectTime * 20;
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ stillDead = false;
+ for (PotionEffect effect : p.getActivePotionEffects())
+ p.removePotionEffect(effect.getType());
+ p.setGameMode(GameMode.SURVIVAL);
+ for(Player p : Bukkit.getOnlinePlayers()){
+ p.playSound(p.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1, 0);
+ }
+ Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + p.getDisplayName() + " has resurrected!");
+ }
+ }.runTaskLater(JavaPlugin.getProvidingPlugin(Resurrection.class), resurrectTime);
+ }
+
+ }
+
+ @EventHandler
public void onDeath(PlayerDeathEvent e) {
System.out.println("Resurrection: A player has died!");
Player p = e.getEntity();
@@ -29,13 +93,55 @@ public class PlayerListener implements Listener {
//
// String deathFormatted = death.formatTime();
// String resurrectFormatted = resurrect.formatTime();
+ long timeOfDeath = System.currentTimeMillis();
+ long resurrectionTime = System.currentTimeMillis() + 86400000;
p.sendMessage("You have died!! You will be able to respawn in the next 24 hours.");
+ // save death state
+ PlayerData playerData = new PlayerData();
+ playerData.readData();
+ String rawData = playerData.getRawData();
+ String[] rawPlayers = rawData.split(";");
+ int index = 0;
+ boolean found = false;
+ for (String players : rawPlayers) {
+ if (players.startsWith(p.getDisplayName())) {
+ found = true;
+ String[] playerSplit = players.split(",");
+ playerSplit[1] = "true";
+ playerSplit[2] = String.valueOf(resurrectionTime);
+
+ // save data
+ rawPlayers[index] = String.join(",", playerSplit);
+ rawData = String.join(";", rawPlayers);
+ playerData.saveData(rawData);
+ break;
+ }
+ index++;
+ }
+
+
new BukkitRunnable() {
// save death information to player file
@Override
public void run() {
+ // save death to false
+ 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;
for (PotionEffect effect : p.getActivePotionEffects())
p.removePotionEffect(effect.getType());