Config help request

Hi, I have a problem with configuration and my plugin.
What I really want is help with creation small library what contains:

  • function getUserIdByDiscord(discordid)
  • function getUserIdByNickname(nickname)
  • function getUserClasses(userid)
  • function getUserCode(userid)
  • function getLastId()
  • function createUser(discordid, username, code, id)
  • function addClass(userid, classname)
  • function deleteClass(userid, classname)
  • function deleteUser(userid)
  • function hasUserClass(userid, classname) : bool

Config Code: #### USERS.CONF ####users{ 1{ nickname: "Nick" discordid: 328932049328 - Pastebin.com

(Yes, i was looking and copy-pasting from web (and didnt work), yes, I i fight with that 4 days, yes, I know thats much work).

If someone will create it, Ill add his nickname, YT channel etc to /credits cmd.

Im more then happy to make a config class that does all that, but can i ask, what was your original code?

There is not original code

Here you go, remember to save after you change the file.

Config - Config - Pastebin.com

UserConfig - UserConfig - Pastebin.com

The normal config is required, i seperated them so if you choose to have another config you can still use the same functions.

Did that help you? Do you have any questions?

Can you add function ifPlayerExist(userid), and how to modify, for example classes using functions getUserIdByDiscord/Name?

I can add the first function. I dont understand what you mean by the second. Could you rephrase it?

I have function for example getUserIdByDiscord - and how to use it for changing add user class (Discord sync)

Ok. I think i get it.

Ill make the changes when i get back from work. As for updating a players class from there discord id.

UserConfig config;
String classToAdd;
String discordId;
Optional<GameProfile> opProfile = config.getUserByDiscord(discordId);
if(!opProfile.isPresent()){
    //No user found
}
config.addClass(opProfile.get().getUnquieId(), classToAdd);
config.save();

Config not working,

@Inject
@ConfigDir(sharedRoot = false)
private File configDir;

private File userConfigFile = new File(configDir + "/users.conf");

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join e)
{
    Player p = e.getTargetEntity();
    UserConfig cfg = new UserConfig(userConfigFile);
    cfg.registerUser(p.getUniqueId(), p.getName(), "CODE", "classd");

}

Config is not being created, and if manualy created - same result

Btw can you make that UserConfig with default, users.conf test in sharedroot false?

So i made Config class for myself and then others wanted similar things. The config class was designed for the manual way of config handling, as in you create a file and then give config that file.

The default config sponge gives you in main wasnt designed to be supported, but its a simple change

So this is how it would be registered.

public static final UserConfig USER_CONFIG;

static {
    File file = new File("configuration/" + PLUGIN_ID + "/UserConfig.conf");
    if(!file.exists()){
        try{
            file.mkdirs();
            file.createNewFile();
        }catch(IOException e){
            e.printStackTrace();
        }
    }
    USER_CONFIG = new UserConfig(file);
    
}

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    USER_CONFIG.registerUser(p.getUniquieId(), p.getName(), "discord id", "code", "classd");
    USER_CONFIG.save();
}

Updated UserConfig - Updated UserConfig - Pastebin.com
Updated Config - Updated Config - Pastebin.com

Trouble, when User A is registered and then User B join - it overrides User A

Well thats impossible unless your passing the same uuid in, or the config is completely overriding itself, for that to happen the Config instance needs to be created more then once.

Whats your code?

Before:

After

I meant your java code. Not your config

yours, copy-paste Config help request - #13 by MoseMister

If thats the case then the reading of the values is going wrong.

If you go into the Config class and go to line 33. That is the line to use if the reading fails. It currently just uses a blank config, just incase it is a new config.

If you use e.printStackTrace() you should be able to find out whats going wrong