From fb22ed40df5b1599aefce668e8ce6e1c43643544 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Tue, 15 Jun 2021 22:01:12 -0600 Subject: [PATCH] finally figured out how to edit player data. now how to save it... --- data/player.data | 2 +- .../Resurrection/Resurrection.class | Bin 4067 -> 5262 bytes .../Resurrection/player/PlayerData.class | Bin 2046 -> 2671 bytes .../Resurrection/Resurrection.java | 37 +++++++++++++++++- src/net/brysonsteck/Resurrection/config.yml | 7 ++++ .../Resurrection/player/PlayerData.java | 12 +++++- 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/net/brysonsteck/Resurrection/config.yml diff --git a/data/player.data b/data/player.data index d5d4ef7..453a62d 100644 --- a/data/player.data +++ b/data/player.data @@ -1 +1 @@ -username,false,0 \ No newline at end of file +username,false,0;bryzinga,false,0 \ No newline at end of file diff --git a/out/production/Resurrection/net/brysonsteck/Resurrection/Resurrection.class b/out/production/Resurrection/net/brysonsteck/Resurrection/Resurrection.class index 3157aa41ddf6eeea2e147836c1afa94bc7a83118..8e06fe9a73abccd206e02e0443f26bc469bbe371 100644 GIT binary patch delta 1601 zcmZ`&X;f5Y7=AuxyK}j?3{0LerArwCF>E1q082VrY9PcU9Q9~jnkx(q17~K?^wgPt zNQ;Ig*Gk&lDq6GzYH&%c#3I{mv24$_KmF`qM|$quC{N3u?|r}beV=!E-tRkm(bjzV zjQP+Z@NUPcq);8!-HOL5cZ78gp zPBV0ig8SeUkfIEn#BWt_KOPW}TlKgFj0w!h%dc(M)@jAv@ld#Uu@-BKYb{~DN=7F7 z6kGr!A>hrkV!~RawYa{eUB4w>mEU9*dQibbxYEkmsI50kN!TG!W_DTMriME^Z_QC_ z)QG-b?XsF}?+iusV3ArAOpOq4(>sdHz9l>&Fs&uJVIwEg3fF4km|j>SL+`<33LeJ{ zjuX??=~j)M0wrdRn#r_nT1*Xw^k9y6nEa+Wb&4kJ@}(j77Kv zb(n+YxD>0A3mtROfjo30A9paa2Sw=R1bryM4wPaq$}og-yv__K`FT&H62CIjZ@5Z0 zaJBHFM$E=F)u|54NdiRnpB+vY890hjPS=ZVIEGirLm&U{YfNTi^1E=HnjK@t>Z!95 zC-4R%NuM}FTRI0haRfapMsRoS5M<9iNq8GrujPbcwAKXR$< zBdAjL$#%~R0iW#f90>Tm4$nTHd=Nu{0VtasVv{5WCXRV_`Dv>L# zE#Q3-I4v9}R zBZ7D7PGiYdyhpcjpkT+fwUSbOUN;C;jUIv5D_(k42c=oWf6ocE4x_w zcE6X}#cH8aK~O=o@*nUIXx*}ng!Fu4OhJqHdEe)p^E~H0XLQr|T5o>o<7Z$OZ)d!g zlDX;9qgEZs4(3i8D-Z4M%bv-m`?CYNboZ&jV*|N1_s(w(9(X+DQH;lB^zg(j`rquC z`x0bq()|h!*mKuiULSd7G`J%{rE3p@;ux=uRGxk+PYw;MV+12gvG9UeTDR$rHhsWm z^jN_~VVH(eMucU{1zh5?m{C#?cc?n7^CgbW;w9qmN&GblC{i-6jukRVFj7@;^9ycO z%WiWg;%OTSTc0H*Tq9MbRBNS8vVm&0P{U5;+Nq_B_3Tr0KN~qr9lg|ZoCZ$Q$T^xA zrkSg3W?ZT}Y-K`o&a#cKY-gSwEYQjicJq@qi;}U`?6Dd;GWmI1v>q(==Z6*Mb46yR zGsY;_H1oJ3*TsrteqL-$pLOnFVqM=2ZmKd|Y_m?doBx*D`Oi{~TijMrXcVsgF86e= Y62C9;(>zY(af%npc#6Jcnl~hW11v*evj6}9 diff --git a/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerData.class b/out/production/Resurrection/net/brysonsteck/Resurrection/player/PlayerData.class index 6d05fc95e6d2e2e355a42c6bca1e8da69f29df7b..b61bdaa7bf230585453af24ad8279f411ea81537 100644 GIT binary patch literal 2671 zcmb_eT~icC6g|y;%({+(i?~9J8bM{3g;kRHwS*Y(3$u#~1SH0oVYh*iVP-Qki||kK zoEP6xu_{6pRPvgt{GvSM>-5Z!?8;UuR^@@-?mOM*-gEA~-Td;$?oR-&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P|Z8u@L8S!4^} z6AgU6Mt69KG(^)K#7V1-rv#QV~4yHS8R-$KzR*lfu9-zT-Oe?(}WIgMG#>=P?V<` z6uT+32b)Z9V}KBS*yZM>G3c5xO+`_3;~w2o2)Bq8B&pHQ>MAXe2_2)GYjkS>{!3x)3Esy(OA{R6t;*fUfbeLfu;)OZy3m~I$<)X T;oqvL)p3<2+h+Z~+x_4V1}&9V diff --git a/src/net/brysonsteck/Resurrection/Resurrection.java b/src/net/brysonsteck/Resurrection/Resurrection.java index aa357aa..52e910b 100644 --- a/src/net/brysonsteck/Resurrection/Resurrection.java +++ b/src/net/brysonsteck/Resurrection/Resurrection.java @@ -2,12 +2,15 @@ package net.brysonsteck.Resurrection; import net.brysonsteck.Resurrection.commands.CommandAbout; import net.brysonsteck.Resurrection.commands.CommandResurrect; +import net.brysonsteck.Resurrection.player.PlayerData; import net.brysonsteck.Resurrection.player.PlayerListener; import net.brysonsteck.Resurrection.startup.CheckForUpdate; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; +import java.util.Hashtable; + public class Resurrection extends JavaPlugin implements Listener { //spigot things @@ -62,6 +65,38 @@ public class Resurrection extends JavaPlugin implements Listener { 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); + + } } diff --git a/src/net/brysonsteck/Resurrection/config.yml b/src/net/brysonsteck/Resurrection/config.yml new file mode 100644 index 0000000..825512d --- /dev/null +++ b/src/net/brysonsteck/Resurrection/config.yml @@ -0,0 +1,7 @@ +resurrect: + bryzinga: + dead: false + resurrectTime: 0 + jobuxx: + dead: true + resurrectTime: 8192734897563945 \ No newline at end of file diff --git a/src/net/brysonsteck/Resurrection/player/PlayerData.java b/src/net/brysonsteck/Resurrection/player/PlayerData.java index a8a1192..cc82952 100644 --- a/src/net/brysonsteck/Resurrection/player/PlayerData.java +++ b/src/net/brysonsteck/Resurrection/player/PlayerData.java @@ -1,16 +1,20 @@ package net.brysonsteck.Resurrection.player; +import net.brysonsteck.Resurrection.Resurrection; +import org.bukkit.plugin.java.JavaPlugin; + import java.io.*; import java.util.Arrays; import java.util.Hashtable; public class PlayerData { Hashtable> playerData = new Hashtable<>(); + String rawData; public void saveData(String write) { try { FileWriter writer = new FileWriter("data/player.data"); - writer.write(write); + writer.write(rawData + ";" + write); writer.close(); readData(); } catch (IOException e) { @@ -20,6 +24,7 @@ public class PlayerData { public void readData() { try { + rawData = ""; BufferedReader reader = new BufferedReader(new FileReader("data/player.data")); String line = ""; String[] playerData; @@ -29,6 +34,7 @@ public class PlayerData { if (line == null) { break; } + rawData = rawData + line; playerData = line.split(","); Hashtable playerHash = new Hashtable<>(); playerHash.put("dead", playerData[1]); @@ -43,4 +49,8 @@ public class PlayerData { public Hashtable> getPlayers() { return playerData; } + + public String getRawData() { + return rawData; + } }