MysticCity / Ancient

http://dev.bukkit.org/bukkit-plugins/ancient-rpg/
4 stars 6 forks source link

Relog = Full HP | Player data storing incomplete #180

Open MysticCity opened 9 years ago

MysticCity commented 9 years ago

If you make an relog you got Full HP

matcracker commented 9 years ago

Because in PlayerQuitEvent you use "p.setHealth(hp.health / hp.maxhp * 20);", if you remove that I think the bug is fixed ;)

FroznMine commented 9 years ago

I don't know what's around that code, but I think I originally added this and some other lines to reset the life to the normal representation, because like said in #57 there will be many many hearts if you just remove Ancient...

Anyway thanks for the help, we appreciate it. Going to have a look at this.

matcracker commented 9 years ago

It's normal! If you create a class with 200 hearths,with any editing, Minecraft add many hearths but, if you want to maintain only one line of hearths and save the last health, you should create a paramater to save the last health of player, for example: Ancient.plugin.getConfig...;//Choose the config where the health wil be saved Double or float lasthealth = p.getHealth(); //Take health of player plugin.set("LastHeal" + lasthealth);

FroznMine commented 9 years ago

I know it's the expected behaviour that you get more hearts. For that there is the p.setHealthScaled(true) somewhere when the player joins. On leave this scaling is disabled and the player should only have 20 hearts again. At least that was my plan ^^

What I don't understand is: Why should I make an additional config just for storing the players health while I'm indirectly storing it through scaling it down. Because when I remove the line you mentioned above the player would have way too much health in almost any cases.

FroznMine commented 9 years ago

Just looked at the code, I think the error comes from not storing and loading the full player data:

Around https://github.com/MysticCity/Ancient/blob/66d7be12b78d49541ab51eca510a87aaad80f474/src/main/java/com/ancientshores/Ancient/Listeners/AncientPlayerListener.java#L235 the player data is stored and deleted when the player leaves the server. When the player joins the data will be loaded from the file again around https://github.com/MysticCity/Ancient/blob/66d7be12b78d49541ab51eca510a87aaad80f474/src/main/java/com/ancientshores/Ancient/Listeners/AncientPlayerListener.java#L176 Because the player data isn't loaded but it has one on the file system it will be loaded https://github.com/MysticCity/Ancient/blob/66d7be12b78d49541ab51eca510a87aaad80f474/src/main/java/com/ancientshores/Ancient/PlayerData.java#L269 loading "everything" important that is stored and then creating missing things here: https://github.com/MysticCity/Ancient/blob/66d7be12b78d49541ab51eca510a87aaad80f474/src/main/java/com/ancientshores/Ancient/PlayerData.java#L318 This leads to creation of a new hpsystem instance over here https://github.com/MysticCity/Ancient/blob/66d7be12b78d49541ab51eca510a87aaad80f474/src/main/java/com/ancientshores/Ancient/PlayerData.java#L162 with the max hp set to the standard hp which is the maximum hp available for a player. The constructor of the Hpsystem then sets health and max hp to the maximum, thus resulting in the player having full hp.

So: It looks like there isn't enough player data stored... As it is a file written/read with ObjectStreams the data isn't human readable. I think I have to go through everything that may be stored in player data and add this to the in and out streams. For that also compatibility to the current serialization has to be given... Looks like something a bit more complicated to do :/ I will rename the ticket so I know what has to be done^^

Thanks for your help anyway. If you think you find a solution for another problem that works feel free to create a pull request so we can check the code and then may merge it.

matcracker commented 9 years ago

Yes, you are quite right! Get the data is not saved properly, in fact in my server sometimes (and often), it happens that the players lose the class but, trying to remove this -> https://github.com/MysticCity/Ancient/blob/66d7be12b78d49541ab51eca510a87aaad80f474/src/main/java/com/ancientshores/Ancient/Listeners/AncientPlayerListener.java#L235 , the class is successfully saved but the regeneration of hearts no longer works. Obviously the class is reset because the players crashed and therefore does not save.

No problem! It 'a pleasure to discuss and maybe solve problems together :)

FroznMine commented 9 years ago

What happens if you remove the line and then restart the server? Does the player still has his class? I would expect that he doesn't store the class at all but that would be fatal :D The regeneration doesn't work because of https://github.com/MysticCity/Ancient/blob/66d7be12b78d49541ab51eca510a87aaad80f474/src/main/java/com/ancientshores/Ancient/Listeners/AncientPlayerListener.java#L236 there he cancels the regeneration task. When the player relogs he will continue using his old playerdata object which has the regeneration task cancelled, thus resulting in no regeneration^^

If there is the problem that he doesn't store the full data with the latest official release then that would be a HUGE bug, but I don't think thats the case^^

Teamwork^^ Maybe, if you want to, you can help coding Ancient. I'm very busy at the moment and as far as I know I'm the only one coding here. So @MysticCity (:P) may give you a chance if you want to^^ Just talk to him if you are interested. I would appreciate any help I could get :D

matcracker commented 9 years ago

I tried to remove pd.dispose() but the regeneration doesn't work anyway xD but how you said, it's a problem of save playerdata.

Thanks a lot for the oppurtunity! But unfortunately they are very busy and do not think I can devote time to the plugin but sometimes if I have problems, I create a pull request or gladly help you find the problem are available here :D Thanks again!