#Dev problem

1 messages · Page 1 of 1 (latest)

novel frost
#

I got a problem to make a DataSave system for my Java Minecraft Plugin. I try different method but it doesn't work. Can you help me ? I will create a .yml file with 3 infos per player inside; custom Exp, custom Job Level, and playername.

stone jewel
#

create a UserManager class

#

and a User class

novel frost
#

yes i've create playerData class

stone jewel
#

in your UserManager you want a Map<UUID, User>

novel frost
#

but to put new values or get that it doesn't work

#

do you have an example code ?

#

i quiet see what you're talking about

stone jewel
#

No but its very basic to do

novel frost
#

sorry ^^ i'm not very very good

stone jewel
#

show what you have tried

novel frost
stone jewel
#

use paste, its easier to read

novel frost
#

i do but it's too heavy for discord

shell patrol
hollow saffron
#

?paste

novel frost
#

oh sorry

hollow saffron
#

Sadge no bot

novel frost
#

i do

#

how can i send to you ? just need the link ?

stone jewel
#

click save then post the link it gives you in here

novel frost
stone jewel
#

line 126 is going to overwrite any changes you make

#

nm

#

its not

#

however, line 96, don;t store Player references. Only their UUID

novel frost
#

i don't understand

stone jewel
#

this.player = player; you are storing a Player object

novel frost
#

i want to overwrite new values of each players

stone jewel
#

Players go stale when they log out

#

it's a new object when they log back in

novel frost
#

ok

stone jewel
#

so only reference them by UUD

novel frost
#

ok

stone jewel
#

line 86

novel frost
#

how i do ?

stone jewel
#

PlayerData playerData = new PlayerData((Player) playerConfig);

#

you can't cast a YamlConfiguration to a Player

novel frost
#

wow i'm not sure to understand

stone jewel
#

Object casting is when you try to change the Object interface/class you want use to access underlying object

novel frost
#

ok

stone jewel
#

(Player) playerConfigIs trying to change the playerConfig into a Player

#

which it can not do

novel frost
#

oh ok

stone jewel
#

as there is no relation between the two

novel frost
#

and how i change that ?

#

i don't master HashMap fonctions ^^

stone jewel
#

your PlayerData Class needs two constructors. One that accepts a UUID and a second which takes a YamlConfigurations

novel frost
#

ok i understand but i don't know what i must modifiy

stone jewel
#

It seems you are very new to Java

novel frost
#

yes and i'm French so i understand but not all ^^

#

like constructors

#

you say i must use 2

stone jewel
#

each class has a constructor. You can have as many as you want, which is called overloading

novel frost
#

ok

stone jewel
#

public PlayerData(Player player) { is your current constructor

novel frost
#

ok i understand

stone jewel
#

that needs to change to public PlayerData(UUID playerID) {

novel frost
#

ok

#

line 90 ?

#

95*

stone jewel
#

then you add a second public PlayerData(YamlConfiguration config) {

#

yes

novel frost
#

i modify

stone jewel
#

show that class

novel frost
stone jewel
#

you changed to the second constructor. You still need the first.

#

two constructors

novel frost
#

where ?

stone jewel
#

and change private final Player player; to private final UUID playerID;

novel frost
#

ok

#

i do

#

i got some errors

stone jewel
#

you will have

#

you still need to add another constructor that takes a UUID

novel frost
#

can you modify and explain me ? i don't understand how to do it

stone jewel
#

one sec, let me open my IDE

novel frost
#

yes no problem

stone jewel
#

um odd question, why are you storing the players exp and level to a file?

novel frost
#

because i make a job plugin

#

so i save xp of each job and level too

stone jewel
wooden moon
#

why is the uuid a string

stone jewel
#

you only ever use it as a String so there no point in converting it every time

wooden moon
#

ok

novel frost
#

it works ? or i test it ?

stone jewel
#

No clue, you need to test it

novel frost
#

ok

#

it works !!!!

stone jewel
#

theres many things in there which are wrong but it's clear you are very new so lots to learn.

novel frost
#

ty very very very much

stone jewel
#

But play with it and you'll see where you made mistakes.

novel frost
stone jewel
#

eg, in onPlayerJoin you overwrite the saved data and then do nothing with it

novel frost
#

oh ok

#

because i want to get the amount of exp and level of the other class to overwrites the new values in the file

stone jewel
#

currently all you are doing is reading the players exp and level. nothing to do with any jobs

novel frost
#

ok

stone jewel
#

But

#

your next job is to cache the player data

novel frost
#

ok

stone jewel
#

so you are not loading it every time you need it

novel frost
#

ok and i must ?

stone jewel
#

you must cache it or you will lag your server out

#

file access is VERY slow

novel frost
#

ok

#

i don't know we can cache data ^^

stone jewel
#

so in your LegendJobs class add a Field Map<UUID, PlayerData> playerCache = new HashMap<>();

novel frost
#

before onEnable ?

stone jewel
#

at the very top, below public final class LegendJobs

novel frost
#

ok

#

i do

stone jewel
#

then in your getPlayerData method addjava private PlayerData getPlayerData(UUID playerId) { if (playerCache.containsKey(playerId)) return playerCache.get(playerId);

novel frost
#

ok

stone jewel
#

now there are two places you need to modify and you need to do this yourself... I'll tell you where and you work out what you need to change.

#

return new PlayerData(playerId);andreturn new PlayerData(playerConfig);

#

both those lines in getPlayerData instead of returning that new Object first need to add it to the playerCache, then return it.

novel frost
#

wow

#

my brain get out 🙂

#

i try

stone jewel
#

its quite simple, create the object, put in map, then return the object

#

currently it just returns a new object

novel frost
#

return new PlayerData(playerId);
is just one part ? i must create the function right ?

stone jewel
#

no

novel frost
#

just modify ?

#

i must found where right ?

stone jewel
#

data = new PlayerData(playerId);

#

then put data in the map

#

then return data

novel frost
#

i'm not sure to understand i'm very sorry

stone jewel
novel frost
#

Yes i want but i don't find a good site or support

#

and i speak english but not very well

stone jewel
novel frost
#

oh ty for sites

#

^^

#

ty

#

i got 2 errors

stone jewel
#

I used playerData instead of playerCache

novel frost
#

ok

#

i got no one

#

And with that i put to cache exp and level and it's write in file after?

stone jewel
#

?

novel frost
#

the code

stone jewel
#

that current code saves the player data when they disconnect

novel frost
#

ok

#

he take values at join ?

stone jewel
#

at the moment your code takes the players current exp and level

novel frost
#

ok

#

from the file

stone jewel
#

currently whatever is saved in the file gets ignored when they log in

novel frost
#

so i can do that but getting exp and level amount from lumberjack or miner class ?

stone jewel
#

Well now you are moving into things you REALLY need to learn the basics of Java for

#

at the moment you have a data cache, loading and saving.

novel frost
#

ok

#

i can learn writting

#

from another class

stone jewel
#

but you are overwriting anything your jobs would do when the player quits

novel frost
#

ok

stone jewel
#

you need to pass an instance of your main class to your Listner so you can get access to the playerCahe

#

well just to the getPlayerData method

novel frost
#

ok

stone jewel
#

in the main channel I linked to Dependency Injection

novel frost
#

ty

#

what is the function of di

#

?

stone jewel
#

are you planning on just giving the player exp when they do a job?

#

Do jobs have levels?

novel frost
#

yes like when player break wood it gives him exp and when he has a some exp he get a level

#

and exp reset

stone jewel
#

in that case there seems no point in saving any data

#

all you want to do is give exp

novel frost
#

yes but i must keep data to save their job level

stone jewel
#

no need for any data, saving nor loading

novel frost
#

like on a Skyblock

stone jewel
#

oh

#

so jobs have levels

novel frost
#

yes

#

sorry

stone jewel
#

ok

#

last time I played any skyblock was 7+ years ago and there were no jobs

novel frost
#

oh ok ^^

#

now Jobs has level ^^

#

and Skyblocks has jobs ^^

stone jewel
#

what does a job level mean? more exp?

novel frost
#

per example, to get the level 1 you need to break 10 logs (1.0 exp each), and when you reach the level one you can win a diamond axe

stone jewel
#

ok

novel frost
#

i've made some plugins but they were not enough difficult ^^

stone jewel
#

None of this is difficult, if you know Java

novel frost
#

yes...

#

you may have right

#

codecademy is a good website ? I think i'll learn java with this

stone jewel
#

they all have their good and bad, but all are worth trying

novel frost
#

or you have a better site ^^

#

ok

stone jewel
#

just don't pay anything to anyone to learn

novel frost
#

ok

#

ty