#config file manager

1 messages · Page 1 of 1 (latest)

leaden knoll
#

btw it creates the folder and the yml file, but it does not set anything inside it

leaden knoll
#

i still need help btw

#

ok so i switched joins.set("test", "hello"); with joins = YamlConfiguration.loadConfiguration(joinsFile); in the try thingie, and it makes the file, reloads it and saves it and everything is fine, but then when i stop the server and start it again, it sends an error

fluid escarp
#

You need to call reloadJoins() once before you can do anything else.

acoustic shadow
#

I think its because you never initialized this.joins before using it

#

cant save something thats not there

fluid escarp
#

The error is pretty self explanatory

leaden knoll
#

oh so i need to switch the save and reload in loadConfigManager in the main class?

acoustic shadow
#

you can try it

leaden knoll
#

alr 1 sec

acoustic shadow
#

or at least put it in the onEnable at the start once

fluid escarp
#

What you need to do is initialize the joins field before you call methods on it. Thats the core problem.

leaden knoll
#

i'm already doing that

acoustic shadow
#

Nullpointer exceptions are relatively easy to fix imo

fluid escarp
#

How you manage that is up to you

leaden knoll
#

in ConfigManager() (method, not class)

fluid escarp
#

Oh i see the problem

                joins.set("test", "hello");
                joins = YamlConfiguration.loadConfiguration(joinsFile);
fluid escarp
#

joins is null.
Then you call joins.set()
which results in a NullPointer

#

Switch those two lines

leaden knoll
fluid escarp
#

You need to first initialize a variable or else its null.
And if you call a method on a variable thats null you just get a Nullpointer

acoustic shadow
#

the reload method initializes the join variable which basically just goes around the error of putting joins.set before joins = ...

#

thats why its not giving an error

leaden knoll
#

i don't really understand, sorry

#

everything seems to be working fine though

acoustic shadow
#

if you put the reloadJoins method before the other one you have joins = YamlConfiguration.loadConfiguration(joinsFile);

leaden knoll
#

i take that back, no errors but the file doesn't have anything in it

acoustic shadow
#

not seeing what you want it to put in

leaden knoll
#

just the test: hello for testing

acoustic shadow
#

oh that

#

not sure on that. maybe try putting an extra method to put those test values in and call it after youre done creating the file

leaden knoll
#

alr

#

somethin like this and then call it in the main class after the reload and save?

    public void testingJoins() {
        System.out.println(joins.get("test"));
    }```
acoustic shadow
#

I meant something like put the joins.set() into an extra method to call after youre done making the file

leaden knoll
#

but the set thing is already after i made the file

leaden knoll
#

lemme try ur thing

acoustic shadow
#

yeah if theres nothing to get from that path its gonna return null

leaden knoll
#

makes sense

#

honestly idk why i was expecting anything else

#

alr ur thing works

acoustic shadow
#

tbh wasnt expecting it to

leaden knoll
#

nope nvm

#

it's just weird

acoustic shadow
#

ok you might have to repaste the things you have now

leaden knoll
#
    public void testingJoins() {
        joins.set("test", "hello");
        System.out.println(joins.get("test"));
    }```sends `hello` to console, and yet when i check the file it's empty
#

do i need to add a reload in the middle?

acoustic shadow
#

close and open the file

leaden knoll
#

it's empty

acoustic shadow
#

I think you might need to add a section?

leaden knoll
#

like a label or whatever it's called?

#

i honestly forgot how these things work

acoustic shadow
#

if you add the path "test" by default it will set that path to "hello"

leaden knoll
#

(not that i knew much in the first place)

acoustic shadow
#

createSection()

#

not sure on that tho

leaden knoll
#

how do i use that

acoustic shadow
#

joins.createSection()

leaden knoll
#

???
i just added the reload line in the middle and now it's sending null to console

#

huh

acoustic shadow
#

maybe try this?

leaden knoll
#

what that do

acoustic shadow
#

read

leaden knoll
#

oh ok

acoustic shadow
#

I found something else aswell

#

but thats like 3 years old

leaden knoll
#

the tutorial i used for this is also very old

acoustic shadow
leaden knoll
acoustic shadow
# leaden knoll didn't work

then you should try creating a section with the intended path, then setting the value of that path to the intended value

leaden knoll
#

sorry again but i don't understand

acoustic shadow
#

sorry if Im feeding you a little more code than you would want in the next message

#

joins.createSection("test");
joins.set("test", "hello");

#

Im also not very good at YML files so this might just be wrong tbh

leaden knoll
#

didn't work for me in the main class

#

no errors

acoustic shadow
#

Ive gotta head out. sorry, maybe ask someone else in the help development channel

leaden knoll
#

alright, thanks

split kiln
#

Custom config files! Woo, save that data!

P.S I always pronounce "parser" wrong :(

------ Links ------

Download Eclipse: https://www.eclipse.org/downloads/packages/release/2019-03/r/eclipse-ide-java-developers

Download Spigot: https://getbukkit.org/download/spigot

Build Spigot: https://www.spigotmc.org/wiki/buildtools/

Starting Server up: ...

▶ Play video
leaden knoll
#

this is from a tutorial tho

#

not the same one but i just want to get this one working

split kiln
#

Well you said that one was 3 years old anyways, and I know for a fact that tutorial works

#

Why are you trying to create config sections anyways? You can just do config.set(path, object)

#

Also from the errors it says joins is null

#

Did you set joins to an instance of your config class onEnable?

leaden knoll
#

i'm not trying to create sections, we were just trying stuff
and the error is long gone, it just doesn't set the text in the file anymore

grand sequoia
#

Hi yes what were you asking for help with

#

I sat with configs for a while myself

#

@leaden knoll

leaden knoll
#

okie, do you know what i can do to fix this issue?

#

lemme get the code and stuff

#

it creates the file but nothing in it

grand sequoia
#

Yeah do you have a config.yml?

leaden knoll
#

i have joins.yml

grand sequoia
#

It creates the config from a base file, or whatever you've added to it through that

#

The plugin generates joins.yml but it's empty, yeah?

leaden knoll
#

yes

grand sequoia
#

The way I've come to understand how it works is that the config it generates is blank unless you yourself have made a default one

leaden knoll
#

what's that mean

grand sequoia
#

Basically it means if you don't want a blank default config, you have to create the stuff you want in your config

#

Like if you want the default config to contain something like

leaden knoll
#

wdym by default config

grand sequoia
#

Let me backtrack a bit, what do you want that config to have in it?

#

The one that's automatically generated

leaden knoll
#

in joins.yml i want to add all uuids that have joined the server

#

brb tho, i need to eat

grand sequoia
#

And did you add code to do that? Like code that will save the UUID's ?

#

I see there's "getJoins" but it returns "joins"... what is "joins"?

#

Unless I'm mistaken, what you want is an event listener that checks for PlayerJoinEvent, then grabs the UUID and saves it to your file

#

I'll try write up something and see if it works then I'll send it here

leaden knoll
#

back

#

doing it on join isn't the problem, as you can see in the main class, it's supposed to get the config file and then set something in it, but that doesn't work for some reason

grand sequoia
#

Oh

#

So adding stuff to the config is where you have an issue?

#

Okay that helps a bit, where is it you're trying to do that?

#

Like what line in what file

leaden knoll
#

last line in loadConfigManager in main class

grand sequoia
#

Yes ofc but where in there are you trying to save the info

#

oh woops

#

Missed your message before that

leaden knoll
#

oh and before this, i put the set thing in the config manager class in the try thingie and it set it but had an error

#

like it would create and set and whatnot, but then when i restart it would send an error

grand sequoia
#

Yeah I am pretty sure there error here is that there is no config

#

Like

#

There is but there isn't

#

create a file in your resources, where the plugin.yml is, and call that whatever you want it to be called, same as you're calling it in the code

#

Then add "Test:" to it, save that. Run your code

leaden knoll
#

i don't understand, sorry

grand sequoia
#

Do you have something like this, with the plugin.yml?

#

You should make another file there, call it "joins.yml" or whatever it is you assigned the config to be named, then add "test:" as the first line and save it

leaden knoll
#

ok i figured it out i think

grand sequoia
#

Your code is trying to save "Hello" to a section of the config that doesn't exist

leaden knoll
#

i just needed to add the save method after i set it