So nothing is coming up in my config, I think im talking to it wrong. I want all players to get put into the "player-data" Section if they aren't already on join. Code: public class Join implements Listener { public Main pl; public Join(Main ins) { pl = ins; } @EventHandler public void onJoin(PlayerJoinEvent e) { e.setJoinMessage(null); Player p = (Player)e.getPlayer(); String uuid = p.getUniqueId().toString(); String name = p.getName().toLowerCase(); int kills = 0; int deaths = 0; int streak = 0; int bal = 0; if (pl.getConfig().getString("player-data").contains(".uuid" + uuid)) { p.sendMessage("welcome back!"); } else { pl.getConfig().set("player-data", ".name" + name); pl.getConfig().set("player-data", ".uuid" + uuid); pl.getConfig().set("player-data", ".kills" + kills); pl.getConfig().set("player-data", ".deaths" + deaths); pl.getConfig().set("player-data", ".streak" + streak); pl.getConfig().set("player-data", ".balance" + bal); pl.saveConfig(); return; } return; }
@TerroDoor You're using the ConfigurationSection#set() & Configuration#get() methods wrong. Code:Java // It should be#set("player-data.name", name) // Instead of#set("player-data", ".name" + name) // Also, the get method should be#getString("player-data.uuid." + uuid) != null // Instead of#getString("player-data").contains(".uuid" + uuid) Please do try to understand how they work, instead of just copying what i wrote here.
@KarimAKL what is the null check doing? if I have another player join the server with a different ID will it check if it's their's that's null?
@TerroDoor ConfigurationSection#get() will return null if nothing was found at the path so, yes, it checks if their UUID is at that path. Also, i just noticed i made a mistake on that part, i've edited it now.
@KarimAKL Thanks for the help, im understanding more. Why wouldn't the .contains method work in this case? Also, here's the updated code, It won't send the player his welcome message.. Code: @EventHandler public void onJoin(PlayerJoinEvent e) { e.setJoinMessage(null); Player p = (Player)e.getPlayer(); String uuid = p.getUniqueId().toString(); String name = p.getName().toLowerCase(); int kills = 0; int deaths = 0; int streak = 0; int bal = 0; if (pl.getConfig().getString("player-data.uuid" + uuid) != null) { p.sendMessage("welcome back!"); } else { pl.getConfig().set("player-data" + ".uuid", uuid); pl.saveConfig(); return; } It saves correctly into the config tho EDIT; I just switched my code around and implemented the .contains method, the welcome message is firing. Here's the update: Code: if (pl.getConfig().getString("player-data.uuid").contains(uuid)) { p.sendMessage("welcome back!"); } else {
@TerroDoor It appears as if you are trying to get the string from the config and add the player's UUID on the end of it. I think what you would have to do is: Code: if (pl.getConfig().getString("player-data." + uuid != null) { p.sendMessage("welcome back!") }
@FreakyPear5 It's not saving every player its overriding them in the existing section, "player-data". I want to put every player that joins into this config section
Because what you were doing was getting the string from the path "player-data", without even checking if it exists, then checking if the string (".uuid" + uuid) is inside of the string gotten. Example: Code:Java // If the path "player-data" doesn't exist#getString("player-data").contains(".uuid" + uuid) // Would throw a NullPointerException // If the path "player-data" does existString uuid = "SomeUUID"; // Just an example in this case#getString("player-data").contains(".uuid" + uuid) // Would return true if the string at the path was ".uuidSomeUUID", not "SomeUUID" Give me an example of how you want the file to look and how it does look, then i can understand it better.
Thanks for this I’m starting to understand. Basically every player that joins I want to be put into a “player-data” list with their name uuid etc. Example config : player-data: name: name UUID: uuid And so on for every player that joins. If the config is empty when I first start up the server and the first player joins how can I create the “player-data” string and also add the player into it. When the second player joins they will also be checked if they are in. That list and if not be placed in there too Example Player-data: Name: p1 UUID: uuid Name: p2 UUID: uuid Sent from my iPhone using Tapatalk
@TerroDoor The way you're doing it is wrong, you can't have multiple keys with the same name in the same section. You should change it from: Code:YAML player-data: name: playerName1 uuid: uuid1 name: playerName2 uuid: uuid2 To: Code:YAML player-data: uuid1: name: playerName1 uuid2: name: playerName2 If you're still having trouble, let me know.
I wrote this off my phone how it looks on my computer is: Player-data: Uuid Name Sent from my iPhone using Tapatalk
Well basically it puts player1 into the config like shown above BUT when player 2 joins, player 1 gets overwritten instead of being placed underneath player1s data Sent from my iPhone using Tapatalk
@KarimAKL it still overrides and only puts one player in at a time, tips? Sorry im really bad and I always get myself confused but im ambitious to learn this. Code: @EventHandler public void onJoin(PlayerJoinEvent e) { e.setJoinMessage(null); Player p = (Player)e.getPlayer(); String uuid = p.getUniqueId().toString(); if (pl.getConfig().getString("player-data.uuid" + uuid) != null) { p.sendMessage("welcome back"); } else { pl.getConfig().set("player-data.name", p.getName().toLowerCase()); pl.getConfig().set("player-data.uuid", uuid); pl.saveConfig(); return; } return; } } Config.yml Code: player-data: name: soaker uuid: 98b3475b-4e76-3008-b046-d448eaf4
@TerroDoor When you use this: Code:Java #set("player-data.name", p.getName().toLowerCase()) You're setting the key as "player-data.name", then it overwrites it the second time you use it, you need to include the player's UUID in that key. This also means that you won't have to set the UUID as a value.
So Config.set(“player-data.name” + p.getNane().toLowerCase(), p.getName.Tolowercase(); Wait so what will the value be? Sent from my iPhone using Tapatalk
@TerroDoor 1. Use the player's UUID as part of the key, not their name. 2. You need a section separator between "name" and the UUID. 3. I'd make the "name" key a sub-section of the UUID section.
Thankyou so much I got it working wen you mentioned sub-key, I realised I couldn’t have every path inside player-data starting with “name” as that pathwould already be existing with another player. Instead the key the player name and the uuid is now a sub key using “player-data.” + p.getname() + “.uuid”, uuid; I’ll post my code when I’m home, Thankyou again for your help and patience as I’m a slow learner.. Sent from my iPhone using Tapatalk
As i said before: So that would be: Code:Java ("player-data." + uuid + ".name", p.getName()) No problem, i especially enjoy helping people that ask questions like you did:
Oh how it all makes sense now, finally Thankyou @KarimAKL you’ve been a great help Sent from my iPhone using Tapatalk