Jump to content

Why is the capability not present on playerclone event if it is present before the player dies?


Recommended Posts

Posted (edited)

Hello, I'm having trouble keeping player nbt data after death, this is my code currently:
 

@SubscribeEvent
    public static void onPlayerCloned(PlayerEvent.Clone event) {
        if(event.isWasDeath()) {
            System.out.println("Player died");
            System.out.println("Cloning wallet 0/2");
            System.out.println(event.getOriginal().getDisplayName().getString());
            System.out.println(event.getOriginal().getCapability(WalletProvider.WALLET_CAPABILITY).isPresent());
            event.getOriginal().getCapability(WalletProvider.WALLET_CAPABILITY).ifPresent(oldStore -> {
                System.out.println("Cloning wallet 1/2");
                event.getPlayer().getCapability(WalletProvider.WALLET_CAPABILITY).ifPresent(newStore -> {
                    System.out.println("Cloning wallet 2/2");
                    newStore.copyFrom(oldStore);
                });
            });
        }
    }

I have a /balance command, and when I give myself some money it displays the correct balance, but for some reason the capability is not present in the playerclone event, the

System.out.println(event.getOriginal().getCapability(WalletProvider.WALLET_CAPABILITY).isPresent());

prints "false".

I know that the capability is being attached properly and everything, this is my console:

Attached wallet to player
Player died
Cloning wallet 0/2
Dev
false
Attached wallet to player

Please anyone help

Edited by Anonomys
clarification

This is my signature. I don't really too much know about java but i try to help and i try to get help from others too. Thank you!

Posted (edited)
  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.