#Save player in persistant data

23 messages · Page 1 of 1 (latest)

loud aspen
#

Can I just store a player in persistant data?
Or if not, is there any data of the player that I can stored(maybe username or uuid) and get the player from easily later?

viscid flaxBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

hollow axle
#

what is your end goal here?

dusky grailBOT
#

The XY problem is when you really want to do X, and you think that Y can achieve X. However, you can't get Y to work, and so ask for help exclusively about Y.

This can lead to a lot of confusion from the people trying to help you, as Y can seem like a very random thing to want to do, and a lot of the time isn't the best way to achieve X anyway.

Its fine to ask about Y, just always include some context about X so you can be put on the right track if Y won't do X well, or there is an easier way to do X.

loud aspen
#

Still working on my projectile system, and when a projectile hits an enemy, I want to read and change stuff in the player persistant data, so I need the player object

#

For that I want to store the player in the projectile, which is stored in the server persistant data

tiny harness
#

just store the uuid

#

there is probably also a lifespan id you can use which resets on object creation

loud aspen
#

How can I get the player from the uuid?

tiny harness
#

levels are entity getters, you can get a list of players there and check

#

server does have a list too, but I don't now the method exactly

loud aspen
#

So, in the end I'll have to loop over every player and test if their uuid is the one stored in the projectile?

#

Because thats what I thought of myself, but I hoped there was a more performant option

tiny harness
#

yes. At least I dont remember a method to directly grab the player by uuid

loud aspen
#

Ok, thanks

viscid flaxBOT
#

Ticket closed!

tiny harness
#
    @Nullable
    default Player getPlayerByUUID(UUID uUID) {
        for(int i = 0; i < this.players().size(); ++i) {
            Player player = (Player)this.players().get(i);
            if (uUID.equals(player.getUUID())) {
                return player;
            }
        }

        return null;
    }
#

in server level. But it just does a loop too

loud aspen
#

Funfact, probe shows this option
e.level.getPlayerByUUID()

tiny harness
#

^ thats a direct map access instead of list iteration

loud aspen
#

Also, why are you doing a for loop and not a forEach there?

#

Anyways, thanks a lot