aboutsummaryrefslogtreecommitdiff
path: root/src/net/brysonsteck/Resurrection/player
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/brysonsteck/Resurrection/player')
-rw-r--r--src/net/brysonsteck/Resurrection/player/PlayerData.java46
-rw-r--r--src/net/brysonsteck/Resurrection/player/PlayerListener.java76
-rw-r--r--src/net/brysonsteck/Resurrection/player/ResurrectPlayer.java16
-rw-r--r--src/net/brysonsteck/Resurrection/player/TimeCheck.java20
4 files changed, 158 insertions, 0 deletions
diff --git a/src/net/brysonsteck/Resurrection/player/PlayerData.java b/src/net/brysonsteck/Resurrection/player/PlayerData.java
new file mode 100644
index 0000000..a8a1192
--- /dev/null
+++ b/src/net/brysonsteck/Resurrection/player/PlayerData.java
@@ -0,0 +1,46 @@
+package net.brysonsteck.Resurrection.player;
+
+import java.io.*;
+import java.util.Arrays;
+import java.util.Hashtable;
+
+public class PlayerData {
+ Hashtable<String, Hashtable<String, String>> playerData = new Hashtable<>();
+
+ public void saveData(String write) {
+ try {
+ FileWriter writer = new FileWriter("data/player.data");
+ writer.write(write);
+ writer.close();
+ readData();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void readData() {
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader("data/player.data"));
+ String line = "";
+ String[] playerData;
+ while (true) {
+ playerData = new String[3];
+ line = reader.readLine();
+ if (line == null) {
+ break;
+ }
+ playerData = line.split(",");
+ Hashtable<String, String> playerHash = new Hashtable<>();
+ playerHash.put("dead", playerData[1]);
+ playerHash.put("timeLeft", playerData[2]);
+ this.playerData.put(playerData[0], playerHash);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Hashtable<String, Hashtable<String, String>> getPlayers() {
+ return playerData;
+ }
+}
diff --git a/src/net/brysonsteck/Resurrection/player/PlayerListener.java b/src/net/brysonsteck/Resurrection/player/PlayerListener.java
new file mode 100644
index 0000000..bec8abb
--- /dev/null
+++ b/src/net/brysonsteck/Resurrection/player/PlayerListener.java
@@ -0,0 +1,76 @@
+package net.brysonsteck.Resurrection.player;
+
+import net.brysonsteck.Resurrection.Resurrection;
+import org.bukkit.ChatColor;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+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.PlayerMoveEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class PlayerListener implements Listener {
+
+ Location spawn;
+
+ @EventHandler
+ public void onDeath(PlayerDeathEvent e) {
+ System.out.println("Resurrection: A player has died!");
+ Player p = e.getEntity();
+ Long timeOfDeath = System.currentTimeMillis();
+ Long resurrectionTime = timeOfDeath + 86400000;
+//
+// TimeCheck death = new TimeCheck(timeOfDeath);
+// TimeCheck resurrect = new TimeCheck((timeOfDeath + 86400000) - timeOfDeath);
+//
+// String deathFormatted = death.formatTime();
+// String resurrectFormatted = resurrect.formatTime();
+
+ p.sendMessage("You have died!! You will be able to respawn in the next 24 hours.");
+
+ new Thread (() -> {
+ try {
+ Thread.sleep(86400000);
+ } catch (InterruptedException interruptedException) {
+ interruptedException.printStackTrace();
+ p.sendMessage("Failed to make the thread sleep!");
+ }
+ ResurrectPlayer resurrectPlayer = new ResurrectPlayer(p);
+ }).start();
+ }
+
+ @EventHandler
+ public void onPlayerRespawn(PlayerRespawnEvent e) {
+ final Player p = e.getPlayer();
+ p.setGameMode(GameMode.SPECTATOR);
+ spawn = p.getLocation();
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ PotionEffect invisibility = new PotionEffect(PotionEffectType.INVISIBILITY, 200, 10, false);
+ PotionEffect blindness = new PotionEffect(PotionEffectType.BLINDNESS, 200, 10, false);
+ PotionEffect slowness = new PotionEffect(PotionEffectType.SLOW, 200, 10, false);
+ invisibility.apply(p);
+ blindness.apply(p);
+ slowness.apply(p);
+ }
+ }.runTaskLater(JavaPlugin.getProvidingPlugin(Resurrection.class), 20);
+
+
+ }
+
+ @EventHandler
+ public void onPlayerMove(PlayerMoveEvent e) {
+ Player p = e.getPlayer();
+ Location location = p.getLocation();
+ if (p.getGameMode() == GameMode.SPECTATOR) {
+ p.teleport(spawn);
+ }
+ }
+}
diff --git a/src/net/brysonsteck/Resurrection/player/ResurrectPlayer.java b/src/net/brysonsteck/Resurrection/player/ResurrectPlayer.java
new file mode 100644
index 0000000..971ada3
--- /dev/null
+++ b/src/net/brysonsteck/Resurrection/player/ResurrectPlayer.java
@@ -0,0 +1,16 @@
+package net.brysonsteck.Resurrection.player;
+
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.entity.Player;
+import org.bukkit.potion.PotionEffect;
+
+public class ResurrectPlayer {
+
+ public ResurrectPlayer(Player p) {
+ for (PotionEffect effect : p.getActivePotionEffects())
+ p.removePotionEffect(effect.getType());
+ p.setGameMode(GameMode.SURVIVAL);
+ Bukkit.broadcastMessage(p.getDisplayName() + " has resurrected!");
+ }
+}
diff --git a/src/net/brysonsteck/Resurrection/player/TimeCheck.java b/src/net/brysonsteck/Resurrection/player/TimeCheck.java
new file mode 100644
index 0000000..f1cf004
--- /dev/null
+++ b/src/net/brysonsteck/Resurrection/player/TimeCheck.java
@@ -0,0 +1,20 @@
+package net.brysonsteck.Resurrection.player;
+
+import java.util.concurrent.TimeUnit;
+
+public class TimeCheck {
+ long millis;
+
+ public TimeCheck(long millis) {
+ this.millis = millis;
+ }
+
+ public String formatTime() {
+ String formattedTime = String.format("%d hrs, %d min, %d sec",
+ TimeUnit.MILLISECONDS.toHours(millis),
+ TimeUnit.MILLISECONDS.toMinutes(millis),
+ TimeUnit.MILLISECONDS.toSeconds(millis) -
+ TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
+ return formattedTime;
+ }
+}