implemented playerdata
This commit is contained in:
parent
fb22ed40df
commit
c1aae09790
10 changed files with 114 additions and 12 deletions
|
@ -1 +1 @@
|
|||
username,false,0;bryzinga,false,0
|
||||
username,false,0
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
resurrect:
|
||||
bryzinga:
|
||||
dead: false
|
||||
resurrectTime: 0
|
||||
jobuxx:
|
||||
dead: true
|
||||
resurrectTime: 8192734897563945
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
@ -18,6 +19,69 @@ public class PlayerListener implements Listener {
|
|||
boolean stillDead;
|
||||
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!");
|
||||
|
@ -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());
|
||||
|
|
Loading…
Add table
Reference in a new issue