From db5c24bc26e4d6a34ecd1ab9118f0f098eee3581 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Sun, 6 Jun 2021 11:49:01 -0600 Subject: death event works, working on commands --- src/net/brysonsteck/PlayerData.java | 46 --------------------- src/net/brysonsteck/PlayerListener.java | 19 --------- src/net/brysonsteck/Resurrection.java | 46 --------------------- .../brysonsteck/Resurrection/CheckForUpdate.java | 4 ++ src/net/brysonsteck/Resurrection/PlayerData.java | 46 +++++++++++++++++++++ .../brysonsteck/Resurrection/PlayerListener.java | 37 +++++++++++++++++ src/net/brysonsteck/Resurrection/Resurrection.java | 48 ++++++++++++++++++++++ src/net/brysonsteck/Resurrection/TImeCheck.java | 20 +++++++++ .../Resurrection/commands/CommandAbout.java | 20 +++++++++ src/net/brysonsteck/Resurrection/plugin.yml | 13 ++++++ src/net/brysonsteck/plugin.yml | 3 -- 11 files changed, 188 insertions(+), 114 deletions(-) delete mode 100644 src/net/brysonsteck/PlayerData.java delete mode 100644 src/net/brysonsteck/PlayerListener.java delete mode 100644 src/net/brysonsteck/Resurrection.java create mode 100644 src/net/brysonsteck/Resurrection/CheckForUpdate.java create mode 100644 src/net/brysonsteck/Resurrection/PlayerData.java create mode 100644 src/net/brysonsteck/Resurrection/PlayerListener.java create mode 100644 src/net/brysonsteck/Resurrection/Resurrection.java create mode 100644 src/net/brysonsteck/Resurrection/TImeCheck.java create mode 100644 src/net/brysonsteck/Resurrection/commands/CommandAbout.java create mode 100644 src/net/brysonsteck/Resurrection/plugin.yml delete mode 100644 src/net/brysonsteck/plugin.yml (limited to 'src/net') diff --git a/src/net/brysonsteck/PlayerData.java b/src/net/brysonsteck/PlayerData.java deleted file mode 100644 index 556c147..0000000 --- a/src/net/brysonsteck/PlayerData.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.brysonsteck; - -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/PlayerListener.java b/src/net/brysonsteck/PlayerListener.java deleted file mode 100644 index a586d31..0000000 --- a/src/net/brysonsteck/PlayerListener.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.brysonsteck; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.plugin.java.JavaPlugin; - -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; - - p.sendMessage("You have died at " + timeOfDeath + ". You will respawn at " + resurrectionTime); - } -} diff --git a/src/net/brysonsteck/Resurrection.java b/src/net/brysonsteck/Resurrection.java deleted file mode 100644 index d0925cd..0000000 --- a/src/net/brysonsteck/Resurrection.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.brysonsteck; - -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.*; -import java.nio.Buffer; - -public class Resurrection extends JavaPlugin { -// public Plugin plugin = getPlugin(Resurrection.class); - - //spigot things - @Override - public void onDisable() { - super.onDisable(); - } - - @Override - public void onEnable() { - super.onEnable(); - this.getServer().getPluginManager().registerEvents(new PlayerListener(), this); - System.out.println("Resurrection: I'm alive!"); - PlayerListener playerListener = new PlayerListener(); - } - - // end of spigot things - public static void main(String[] args) { -// PlayerData playerData = new PlayerData(); -// playerData.saveData("This is the first line\nthis is the second line"); -// System.out.println(playerData.getPlayers()); -// playerData.readData(); - -// playerData.saveData("username,false,0"); -// System.out.println("now adding two more lines"); -// playerData.saveData(playerData.getPlayers() + "this is the third line\nthis is the fourth line\nthe thread is now sleeping\nonce more\nand again"); -// System.out.println(playerData.getPlayers()); -// try { -// Thread.sleep(100000); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } - - } - -} diff --git a/src/net/brysonsteck/Resurrection/CheckForUpdate.java b/src/net/brysonsteck/Resurrection/CheckForUpdate.java new file mode 100644 index 0000000..68cab70 --- /dev/null +++ b/src/net/brysonsteck/Resurrection/CheckForUpdate.java @@ -0,0 +1,4 @@ +package net.brysonsteck.Resurrection; + +public class CheckForUpdate { +} diff --git a/src/net/brysonsteck/Resurrection/PlayerData.java b/src/net/brysonsteck/Resurrection/PlayerData.java new file mode 100644 index 0000000..f63a359 --- /dev/null +++ b/src/net/brysonsteck/Resurrection/PlayerData.java @@ -0,0 +1,46 @@ +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 new file mode 100644 index 0000000..a12ec52 --- /dev/null +++ b/src/net/brysonsteck/Resurrection/PlayerListener.java @@ -0,0 +1,37 @@ +package net.brysonsteck.Resurrection; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class PlayerListener implements Listener { + + @EventHandler + public void onJoin() { + + } + + @EventHandler + public void onDeath(PlayerDeathEvent e) { + System.out.println("Resurrection: A player has died!"); + Player p = e.getEntity(); + p.setGameMode(GameMode.SPECTATOR); + p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000000, 500)); + p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1000000000, 500)); + Long timeOfDeath = System.currentTimeMillis(); + Long resurrectionTime = timeOfDeath + 86400000; + + TimeCheck death = new TimeCheck(timeOfDeath); + TimeCheck resurrect = new TimeCheck(timeOfDeath + 86400000); + + String deathFormatted = death.formatTime(); + String resurrectFormatted = resurrect.formatTime(); + + + p.sendMessage("You have died! You will be able to respawn in 24 hours."); + } +} diff --git a/src/net/brysonsteck/Resurrection/Resurrection.java b/src/net/brysonsteck/Resurrection/Resurrection.java new file mode 100644 index 0000000..2547e6c --- /dev/null +++ b/src/net/brysonsteck/Resurrection/Resurrection.java @@ -0,0 +1,48 @@ +package net.brysonsteck.Resurrection; + +import net.brysonsteck.Resurrection.commands.CommandAbout; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +public class Resurrection extends JavaPlugin { + public Plugin plugin = getPlugin(Resurrection.class); + + //spigot things + @Override + public void onDisable() { + super.onDisable(); + } + + @Override + public void onEnable() { + super.onEnable(); + + // register listener + this.getServer().getPluginManager().registerEvents(new PlayerListener(), this); + + // register commands + this.getCommand("about").setExecutor(new CommandAbout()); + + System.out.println("Resurrection: I'm alive!"); + } + + // end of spigot things + public static void main(String[] args) { +// PlayerData playerData = new PlayerData(); +// playerData.saveData("This is the first line\nthis is the second line"); +// System.out.println(playerData.getPlayers()); +// playerData.readData(); + +// playerData.saveData("username,false,0"); +// System.out.println("now adding two more lines"); +// playerData.saveData(playerData.getPlayers() + "this is the third line\nthis is the fourth line\nthe thread is now sleeping\nonce more\nand again"); +// System.out.println(playerData.getPlayers()); +// try { +// Thread.sleep(100000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } + + } + +} diff --git a/src/net/brysonsteck/Resurrection/TImeCheck.java b/src/net/brysonsteck/Resurrection/TImeCheck.java new file mode 100644 index 0000000..a7ea06c --- /dev/null +++ b/src/net/brysonsteck/Resurrection/TImeCheck.java @@ -0,0 +1,20 @@ +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/CommandAbout.java b/src/net/brysonsteck/Resurrection/commands/CommandAbout.java new file mode 100644 index 0000000..ac95f20 --- /dev/null +++ b/src/net/brysonsteck/Resurrection/commands/CommandAbout.java @@ -0,0 +1,20 @@ +package net.brysonsteck.Resurrection.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandAbout implements CommandExecutor { + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + String aboutMessage = "This is the about message for Resurrection."; + if (commandSender instanceof Player) { + Player p = (Player) commandSender; + p.sendMessage(aboutMessage); + } else { + System.out.println(aboutMessage); + } + return true; + } +} diff --git a/src/net/brysonsteck/Resurrection/plugin.yml b/src/net/brysonsteck/Resurrection/plugin.yml new file mode 100644 index 0000000..a253795 --- /dev/null +++ b/src/net/brysonsteck/Resurrection/plugin.yml @@ -0,0 +1,13 @@ +main: net.brysonsteck.Resurrection.Resurrection +name: Resurrection +author: 'Bryson Steck' +version: '0.0.1 alpha' +commands: + about: + description: Displays information about Resurrection. + permission: op + usage: /about + + timecheck: + description: Displays the remaining time before the player (or specified player) is resurrected. + usage: /timecheck [PLAYER NAME] \ No newline at end of file diff --git a/src/net/brysonsteck/plugin.yml b/src/net/brysonsteck/plugin.yml deleted file mode 100644 index 36632da..0000000 --- a/src/net/brysonsteck/plugin.yml +++ /dev/null @@ -1,3 +0,0 @@ -main: net.brysonsteck.Resurrection -name: Resurrection -version: alpha 0.0.1 \ No newline at end of file -- cgit v1.2.3