aboutsummaryrefslogtreecommitdiff
path: root/src/net/brysonsteck/Resurrection
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/brysonsteck/Resurrection')
-rw-r--r--src/net/brysonsteck/Resurrection/Resurrection.java9
-rw-r--r--src/net/brysonsteck/Resurrection/config.yml7
-rw-r--r--src/net/brysonsteck/Resurrection/player/PlayerData.java2
-rw-r--r--src/net/brysonsteck/Resurrection/player/PlayerListener.java106
4 files changed, 113 insertions, 11 deletions
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());