From 8db9ccdf642ed81f585e900a843c411b973ce6da Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Tue, 15 Jun 2021 18:43:25 -0600 Subject: starting to test timer --- src/net/brysonsteck/Resurrection/PlayerData.java | 46 ------------- .../brysonsteck/Resurrection/PlayerListener.java | 64 ------------------ src/net/brysonsteck/Resurrection/Resurrection.java | 7 +- src/net/brysonsteck/Resurrection/TimeCheck.java | 20 ------ .../Resurrection/commands/CommandResurrect.java | 2 +- .../Resurrection/player/PlayerData.java | 46 +++++++++++++ .../Resurrection/player/PlayerListener.java | 76 ++++++++++++++++++++++ .../Resurrection/player/ResurrectPlayer.java | 16 +++++ .../brysonsteck/Resurrection/player/TimeCheck.java | 20 ++++++ src/net/brysonsteck/Resurrection/plugin.yml | 2 +- .../Resurrection/startup/CheckForUpdate.java | 9 ++- 11 files changed, 168 insertions(+), 140 deletions(-) delete mode 100644 src/net/brysonsteck/Resurrection/PlayerData.java delete mode 100644 src/net/brysonsteck/Resurrection/PlayerListener.java delete mode 100644 src/net/brysonsteck/Resurrection/TimeCheck.java create mode 100644 src/net/brysonsteck/Resurrection/player/PlayerData.java create mode 100644 src/net/brysonsteck/Resurrection/player/PlayerListener.java create mode 100644 src/net/brysonsteck/Resurrection/player/ResurrectPlayer.java create mode 100644 src/net/brysonsteck/Resurrection/player/TimeCheck.java (limited to 'src/net') diff --git a/src/net/brysonsteck/Resurrection/PlayerData.java b/src/net/brysonsteck/Resurrection/PlayerData.java deleted file mode 100644 index f63a359..0000000 --- a/src/net/brysonsteck/Resurrection/PlayerData.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.brysonsteck.Resurrection; - -import java.io.*; -import java.util.Arrays; -import java.util.Hashtable; - -public class PlayerData { - Hashtable> 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 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> getPlayers() { - return playerData; - } -} diff --git a/src/net/brysonsteck/Resurrection/PlayerListener.java b/src/net/brysonsteck/Resurrection/PlayerListener.java deleted file mode 100644 index e922a06..0000000 --- a/src/net/brysonsteck/Resurrection/PlayerListener.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.brysonsteck.Resurrection; - -import org.bukkit.Bukkit; -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; - -import static org.bukkit.Bukkit.getServer; - -public class PlayerListener implements Listener { - - @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."); - } - - @EventHandler - public void onPlayerRespawn(PlayerRespawnEvent e) { - final Player p = e.getPlayer(); - p.setGameMode(GameMode.ADVENTURE); - 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.ADVENTURE) { - p.teleport(location); - } - } -} diff --git a/src/net/brysonsteck/Resurrection/Resurrection.java b/src/net/brysonsteck/Resurrection/Resurrection.java index cfd196d..7a7e949 100644 --- a/src/net/brysonsteck/Resurrection/Resurrection.java +++ b/src/net/brysonsteck/Resurrection/Resurrection.java @@ -2,15 +2,11 @@ package net.brysonsteck.Resurrection; import net.brysonsteck.Resurrection.commands.CommandAbout; import net.brysonsteck.Resurrection.commands.CommandResurrect; +import net.brysonsteck.Resurrection.player.PlayerListener; import net.brysonsteck.Resurrection.startup.CheckForUpdate; -import org.bukkit.command.CommandExecutor; import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; -import org.w3c.dom.stylesheets.LinkStyle; - -import static org.bukkit.Bukkit.getServer; public class Resurrection extends JavaPlugin implements Listener { // public Plugin plugin = getPlugin(Resurrection.class); @@ -52,6 +48,7 @@ public class Resurrection extends JavaPlugin implements Listener { // end of spigot things public static void main(String[] args) { + CheckForUpdate check = new CheckForUpdate(); // PlayerData playerData = new PlayerData(); // playerData.saveData("This is the first line\nthis is the second line"); // System.out.println(playerData.getPlayers()); diff --git a/src/net/brysonsteck/Resurrection/TimeCheck.java b/src/net/brysonsteck/Resurrection/TimeCheck.java deleted file mode 100644 index a7ea06c..0000000 --- a/src/net/brysonsteck/Resurrection/TimeCheck.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.brysonsteck.Resurrection; - -import java.util.concurrent.TimeUnit; - -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; - } -} diff --git a/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java b/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java index 8d5c4b5..f05de5d 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java @@ -44,7 +44,7 @@ public class CommandResurrect implements CommandExecutor { System.out.println("That player does not exist! Failed to resurrect."); return false; } - if (resurrectPlayer.getGameMode() == GameMode.ADVENTURE) { + if (resurrectPlayer.getGameMode() == GameMode.SPECTATOR) { for (PotionEffect effect : resurrectPlayer.getActivePotionEffects()) resurrectPlayer.removePotionEffect(effect.getType()); resurrectPlayer.setGameMode(GameMode.SURVIVAL); 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> 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 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> 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; + } +} diff --git a/src/net/brysonsteck/Resurrection/plugin.yml b/src/net/brysonsteck/Resurrection/plugin.yml index 2a0f9a5..08a62bf 100644 --- a/src/net/brysonsteck/Resurrection/plugin.yml +++ b/src/net/brysonsteck/Resurrection/plugin.yml @@ -1,7 +1,7 @@ main: net.brysonsteck.Resurrection.Resurrection name: Resurrection author: 'Bryson Steck' -version: '0.0.1 alpha' +version: '0.1 beta' commands: about: description: Displays information about Resurrection. diff --git a/src/net/brysonsteck/Resurrection/startup/CheckForUpdate.java b/src/net/brysonsteck/Resurrection/startup/CheckForUpdate.java index 1507480..be30844 100644 --- a/src/net/brysonsteck/Resurrection/startup/CheckForUpdate.java +++ b/src/net/brysonsteck/Resurrection/startup/CheckForUpdate.java @@ -20,8 +20,11 @@ public class CheckForUpdate { String json = urlReader(); JsonElement root = new JsonParser().parse(json); JsonObject rootobj = root.getAsJsonObject(); - version = rootobj.get("current-version").getAsString(); - versionURL = rootobj.get("release-url").getAsString(); + JsonElement softwareElement = rootobj.get("resurrection"); + JsonObject softwareObj = softwareElement.getAsJsonObject(); + version = softwareObj.get("current-release").toString(); +// version = rootobj.get("current-version").getAsString(); +// versionURL = rootobj.get("release-url").getAsString(); } catch (IOException e) { System.out.println("[Resurrection] An error has occurred while attempting to check for updates."); e.printStackTrace(); @@ -29,7 +32,7 @@ public class CheckForUpdate { } public String urlReader() throws IOException { - URL website = new URL("https://brysonsteck.net/resurrect.json"); + URL website = new URL("https://brysonsteck.net/updates.json"); URLConnection connection = website.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( -- cgit v1.2.3