#(czybinkie) Weird issue with Persistence API

33 messages · Page 1 of 1 (latest)

pale wing
#

I'm trying to save some data using the Persistence API, I've done it before and it was saving, but now I'm getting that weird bug that I can't seem to fix.

Code:

package me.abdelaziz.practice.object.trait;

import me.abdelaziz.practice.Practice;
import me.abdelaziz.practice.object.player.PracticePlayer;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import org.bukkit.event.EventHandler;

public final class NPCKitTrait extends Trait {

    @Persist private String kitName;
    @Persist private boolean ranked;

    public NPCKitTrait() {
        super("npc_kit_trait");
    }

    public NPCKitTrait(final String kitName, final boolean ranked) {
        this();

        this.ranked = ranked;
        this.kitName = kitName;
    }

    @EventHandler
    public void onNPCRightClick(final NPCRightClickEvent event) {
        if (event.getNPC() != this.getNPC() || kitName == null) return;

        final PracticePlayer practicePlayer = Practice.getInstance().getManager().getPlayerHandler().getPlayer(event.getClicker());
        if (practicePlayer == null) return;

        Practice.getInstance().getManager().getQueueHandler().addQueue(practicePlayer, kitName, ranked);
    }
}

Issue:

  • The only thing being saved is the kitName, but not the ranked boolean variable
# Snippet from saves.yml
npc_kit_trait:
  kitName: smp
misty surgeBOT
#

(czybinkie) Weird issue with Persistence API

misty surgeBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.

pale wing
#

Should I override the save(DataKey) method?

pale wing
#

Debug:

[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=smp, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=uhc, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=Sword, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=pot, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=nethop, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=mace, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=crystal, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=axe, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=axe, ranked=false
[07:27:55 INFO]: [Practice] Saving NPCKitTrait: kitName=diamond, ranked=false

Code:

@Override
public void save(final DataKey key) {
  Practice.getInstance().getLogger().info("Saving NPCKitTrait: kitName=" + kitName + ", ranked=" + ranked);
  key.setBoolean("ranked", ranked);
  key.setString("kitName", kitName);
}
#

overriding load is pretty much useless, as the ranked key is not even there

pale cove
#

!logs

agile pewterBOT
# pale cove !logs
Info: logs

Please post your full latest log file.

Background Info: One of the most helpful tools to identifying the source of a problem is your server logs file! Logs contain all sorts of important information like server and plugin versions, any error messages, and a lot more important information (More Info).

How To: Your log can be found in the logs folder within your server folder. The most recent log is a text file labeled latest.log. To get help using these logs, please open that file in a text editor and copy all of the text, then open https://paste.denizenscript.com/New/Log and paste the text into the box on the page. Then click "Submit" and copy the URL and paste that back into this channel.

Please do not upload the file to Discord or to other pastebin services, use the log pastebin linked above.

pale cove
#

include shutdown component as well @pale wing

#

@pale wing remember that if the value is the default value (false) it won't be saved as that's already the default value in java

pale wing
#

Give me a minute to investigate this

#

Then why when I manually set the "ranked" value to false in the saves.yml it works and when it's not there it doesn't?

#

@pale cove

#

Startup + shutdown

pale cove
agile pewterBOT
# pale cove !logcheck https://paste.denizenscript.com/View/136329
Server Version

AdvancedSlimePaper version 1.21.8-16775-paper_upstream@5a75226 (2025-09-06T21:43:46Z)

Plugin Version(s)

Citizens v2.0.39-SNAPSHOT (build 3929) -- (Outdated build, behind by 10)

Checked For

@pale cove

Online/Offline

Offline (proxy status unknown).

Suspicious Plugin(s)

SkinsRestorer v15.8.0 :triangular_flag_on_post: (Offline skins fixer plugin)

Problematic Plugin(s)

PlugManX v3.0.2 - :warning: Plugin Managers are dangerous and will cause unpredictable issues. Remove it.
Geyser-Spigot v2.8.3-SNAPSHOT - Bedrock clients are unsupportable. Please do all testing with a Java Edition client.
floodgate v2.2.4-SNAPSHOT (b118-40d320a)

Possibly Relevant Plugin(s)

TAB v5.2.5 - This plugin adds Below_Name scoreboards to NPCs.
ViaVersion v5.4.2 - Mixed client vs server versions can sometimes cause packet-related issues.
FastAsyncWorldEdit v2.13.3-SNAPSHOT-1174;d83f24a - This plugin has been known to break the plugin load order on many servers, due to usage of the 'loadbefore' directive in its 'plugin.yml'.

Potentially Bad Line(s)

Starting Minecraft server on 0.0.0.0:25587 - server is offline but has no address bind. This might mean you're using a system level firewall, but if not, it means your proxy is bypassable by hackers. Either enable a system level firewall, or bind your server to localhost in server.properties via server-ip=127.0.0.1.

pale cove
#

Yes there is no issue here

simple torrentBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@pale wing

pale wing
pale cove
#

There is no problem ?

#

What is the problem

pale wing
#

The trait doesn't get loaded on my plugin to handle the click events

#

It only does so if I manually added the "ranked" key in the "saves.yml"

pale cove
#

Can you add some debug to confirm? There is on spawn and on attach methods to help

pale wing
#
@Override
public void onAttach() {
  logger.info("NPC " + getNPC().getId() + " attached with kit: " + kitName + " ranked: " + ranked);
}
#

Hold on

#

Never mind, solved!