starting to test timer
This commit is contained in:
parent
7d5f60d921
commit
8db9ccdf64
15 changed files with 54 additions and 26 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.brysonsteck.Resurrection;
|
||||
package net.brysonsteck.Resurrection.player;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
|
@ -1,6 +1,7 @@
|
|||
package net.brysonsteck.Resurrection;
|
||||
package net.brysonsteck.Resurrection.player;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import net.brysonsteck.Resurrection.Resurrection;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -14,30 +15,41 @@ 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 {
|
||||
|
||||
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();
|
||||
//
|
||||
// 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.ADVENTURE);
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
spawn = p.getLocation();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -57,8 +69,8 @@ public class PlayerListener implements Listener {
|
|||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
Location location = p.getLocation();
|
||||
if (p.getGameMode() == GameMode.ADVENTURE) {
|
||||
p.teleport(location);
|
||||
if (p.getGameMode() == GameMode.SPECTATOR) {
|
||||
p.teleport(spawn);
|
||||
}
|
||||
}
|
||||
}
|
16
src/net/brysonsteck/Resurrection/player/ResurrectPlayer.java
Normal file
16
src/net/brysonsteck/Resurrection/player/ResurrectPlayer.java
Normal file
|
@ -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!");
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package net.brysonsteck.Resurrection;
|
||||
package net.brysonsteck.Resurrection.player;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
class TimeCheck {
|
||||
public class TimeCheck {
|
||||
long millis;
|
||||
|
||||
public TimeCheck(long millis) {
|
|
@ -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.
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue