diff options
-rw-r--r-- | data/player.data | 2 | ||||
-rw-r--r-- | out/artifacts/Resurrection_jar/Resurrection.jar | bin | 1339140 -> 1343846 bytes | |||
-rw-r--r-- | out/production/Resurrection/net/brysonsteck/Resurrection/Resurrection.class | bin | 5262 -> 5303 bytes | |||
-rw-r--r-- | out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerData.class | bin | 2671 -> 2642 bytes | |||
-rw-r--r-- | out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener$1.class | bin | 2628 -> 2626 bytes | |||
-rw-r--r-- | out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener.class | bin | 2771 -> 6486 bytes | |||
-rw-r--r-- | src/net/brysonsteck/Resurrection/Resurrection.java | 9 | ||||
-rw-r--r-- | src/net/brysonsteck/Resurrection/config.yml | 7 | ||||
-rw-r--r-- | src/net/brysonsteck/Resurrection/player/PlayerData.java | 2 | ||||
-rw-r--r-- | src/net/brysonsteck/Resurrection/player/PlayerListener.java | 106 |
10 files changed, 114 insertions, 12 deletions
diff --git a/data/player.data b/data/player.data index 453a62d..d5d4ef7 100644 --- a/data/player.data +++ b/data/player.data @@ -1 +1 @@ -username,false,0;bryzinga,false,0
\ No newline at end of file +username,false,0
\ No newline at end of file diff --git a/out/artifacts/Resurrection_jar/Resurrection.jar b/out/artifacts/Resurrection_jar/Resurrection.jar Binary files differindex 1c9de1f..873cff4 100644 --- a/out/artifacts/Resurrection_jar/Resurrection.jar +++ b/out/artifacts/Resurrection_jar/Resurrection.jar diff --git a/out/production/Resurrection/net/brysonsteck/Resurrection/Resurrection.class b/out/production/Resurrection/net/brysonsteck/Resurrection/Resurrection.class Binary files differindex 8e06fe9..4ca7e8f 100644 --- a/out/production/Resurrection/net/brysonsteck/Resurrection/Resurrection.class +++ b/out/production/Resurrection/net/brysonsteck/Resurrection/Resurrection.class diff --git a/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerData.class b/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerData.class Binary files differindex b61bdaa..51cc93f 100644 --- a/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerData.class +++ b/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerData.class diff --git a/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener$1.class b/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener$1.class Binary files differindex ad295f0..47363a5 100644 --- a/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener$1.class +++ b/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener$1.class diff --git a/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener.class b/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener.class Binary files differindex 38ae1d0..4aedb1b 100644 --- a/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener.class +++ b/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerListener.class diff --git a/src/net/brysonsteck/Resurrection/Resurrection.java b/src/net/brysonsteck/Resurrection/Resurrection.java index 52e910b..5bb2683 100644 --- a/src/net/brysonsteck/Resurrection/Resurrection.java +++ b/src/net/brysonsteck/Resurrection/Resurrection.java @@ -67,18 +67,20 @@ public class Resurrection extends JavaPlugin implements Listener { public static void main(String[] args) { - // DO THISgit + // DO THIS PlayerData playerData = new PlayerData(); System.out.println("--- Reading Player data file ---"); playerData.readData(); System.out.println(playerData.getPlayers()); System.out.println(playerData.getRawData()); System.out.println("--- Oh look! A new player joined. Adding them. ---"); - playerData.saveData("bryzinga,false,0"); + String rawData = playerData.getRawData(); + rawData = rawData + ";bryzinga,false,0"; + playerData.saveData(rawData); System.out.println(playerData.getPlayers()); System.out.println(playerData.getRawData()); System.out.println("--- A player has died! Update the data file! ---"); - String rawData = playerData.getRawData(); + rawData = playerData.getRawData(); String[] rawPlayers = rawData.split(";"); String[] rawSinglePlayer = new String[3]; int index = 0; @@ -95,6 +97,7 @@ public class Resurrection extends JavaPlugin implements Listener { index++; } rawData = String.join(";", rawPlayers); + playerData.saveData(rawData); System.out.println(rawData); } diff --git a/src/net/brysonsteck/Resurrection/config.yml b/src/net/brysonsteck/Resurrection/config.yml deleted file mode 100644 index 825512d..0000000 --- a/src/net/brysonsteck/Resurrection/config.yml +++ /dev/null @@ -1,7 +0,0 @@ -resurrect: - bryzinga: - dead: false - resurrectTime: 0 - jobuxx: - dead: true - resurrectTime: 8192734897563945
\ No newline at end of file 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()); |