#Save player in persistant data
23 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
what is your end goal here?
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.
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
just store the uuid
there is probably also a lifespan id you can use which resets on object creation
How can I get the player from the uuid?
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
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
yes. At least I dont remember a method to directly grab the player by uuid
Ok, thanks
Ticket closed!
@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
Funfact, probe shows this option
e.level.getPlayerByUUID()
server.getPlayerList().getPlayer(uuid) seems to exist
^ thats a direct map access instead of list iteration