finally figured out how to edit player data. now how to save it...
This commit is contained in:
parent
34e7a03d28
commit
fb22ed40df
6 changed files with 55 additions and 3 deletions
|
@ -1 +1 @@
|
||||||
username,false,0
|
username,false,0;bryzinga,false,0
|
Binary file not shown.
Binary file not shown.
|
@ -2,12 +2,15 @@ package net.brysonsteck.Resurrection;
|
||||||
|
|
||||||
import net.brysonsteck.Resurrection.commands.CommandAbout;
|
import net.brysonsteck.Resurrection.commands.CommandAbout;
|
||||||
import net.brysonsteck.Resurrection.commands.CommandResurrect;
|
import net.brysonsteck.Resurrection.commands.CommandResurrect;
|
||||||
|
import net.brysonsteck.Resurrection.player.PlayerData;
|
||||||
import net.brysonsteck.Resurrection.player.PlayerListener;
|
import net.brysonsteck.Resurrection.player.PlayerListener;
|
||||||
import net.brysonsteck.Resurrection.startup.CheckForUpdate;
|
import net.brysonsteck.Resurrection.startup.CheckForUpdate;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
public class Resurrection extends JavaPlugin implements Listener {
|
public class Resurrection extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
//spigot things
|
//spigot things
|
||||||
|
@ -62,6 +65,38 @@ public class Resurrection extends JavaPlugin implements Listener {
|
||||||
System.out.println("[Resurrection] Successfully Started!");
|
System.out.println("[Resurrection] Successfully Started!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) { }
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// DO THISgit
|
||||||
|
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");
|
||||||
|
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();
|
||||||
|
String[] rawPlayers = rawData.split(";");
|
||||||
|
String[] rawSinglePlayer = new String[3];
|
||||||
|
int index = 0;
|
||||||
|
for (String players : rawPlayers) {
|
||||||
|
if (players.startsWith("bryzinga")) {
|
||||||
|
String[] playerSplit = players.split(",");
|
||||||
|
playerSplit[1] = "true";
|
||||||
|
playerSplit[2] = "12345";
|
||||||
|
|
||||||
|
rawPlayers[index] = String.join(",", playerSplit);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
rawData = String.join(";", rawPlayers);
|
||||||
|
System.out.println(rawData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
7
src/net/brysonsteck/Resurrection/config.yml
Normal file
7
src/net/brysonsteck/Resurrection/config.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
resurrect:
|
||||||
|
bryzinga:
|
||||||
|
dead: false
|
||||||
|
resurrectTime: 0
|
||||||
|
jobuxx:
|
||||||
|
dead: true
|
||||||
|
resurrectTime: 8192734897563945
|
|
@ -1,16 +1,20 @@
|
||||||
package net.brysonsteck.Resurrection.player;
|
package net.brysonsteck.Resurrection.player;
|
||||||
|
|
||||||
|
import net.brysonsteck.Resurrection.Resurrection;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
public class PlayerData {
|
public class PlayerData {
|
||||||
Hashtable<String, Hashtable<String, String>> playerData = new Hashtable<>();
|
Hashtable<String, Hashtable<String, String>> playerData = new Hashtable<>();
|
||||||
|
String rawData;
|
||||||
|
|
||||||
public void saveData(String write) {
|
public void saveData(String write) {
|
||||||
try {
|
try {
|
||||||
FileWriter writer = new FileWriter("data/player.data");
|
FileWriter writer = new FileWriter("data/player.data");
|
||||||
writer.write(write);
|
writer.write(rawData + ";" + write);
|
||||||
writer.close();
|
writer.close();
|
||||||
readData();
|
readData();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -20,6 +24,7 @@ public class PlayerData {
|
||||||
|
|
||||||
public void readData() {
|
public void readData() {
|
||||||
try {
|
try {
|
||||||
|
rawData = "";
|
||||||
BufferedReader reader = new BufferedReader(new FileReader("data/player.data"));
|
BufferedReader reader = new BufferedReader(new FileReader("data/player.data"));
|
||||||
String line = "";
|
String line = "";
|
||||||
String[] playerData;
|
String[] playerData;
|
||||||
|
@ -29,6 +34,7 @@ public class PlayerData {
|
||||||
if (line == null) {
|
if (line == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
rawData = rawData + line;
|
||||||
playerData = line.split(",");
|
playerData = line.split(",");
|
||||||
Hashtable<String, String> playerHash = new Hashtable<>();
|
Hashtable<String, String> playerHash = new Hashtable<>();
|
||||||
playerHash.put("dead", playerData[1]);
|
playerHash.put("dead", playerData[1]);
|
||||||
|
@ -43,4 +49,8 @@ public class PlayerData {
|
||||||
public Hashtable<String, Hashtable<String, String>> getPlayers() {
|
public Hashtable<String, Hashtable<String, String>> getPlayers() {
|
||||||
return playerData;
|
return playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRawData() {
|
||||||
|
return rawData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue