Closed Sfiguz7 closed 3 years ago
we should probably add removeUuid too since there's no way to remove it properly.
Thinking more:
The entire persistent thing is meant to handle more complex types like this. We should follow the correct way to add new types by making our own PersistentDataType for UUID. We can store it as an int array which is how MC is now storing all their UUIDs too. I have the code for this already so I'll post it below. This would make the code cleaner and not require ANOTHER method just for removal.
Code I wrote in the past for this:
public static UUID fromIntArray(@Nonnull int[] ints) {
return new UUID(ints[0] << 32L | ints[1] & 0xFFFFFFFFL, ints[2] << 32L | ints[3] & 0xFFFFFFFFL);
}
public static int[] toIntArray(@Nonnull UUID uuid) {
final long mostSig = uuid.getMostSignificantBits();
final long leastSig = uuid.getLeastSignificantBits();
return new int[] {(int) (mostSig >> 32L), (int) mostSig, (int) (leastSig >> 32L), (int) leastSig};
}
There's a copy paste mistake in one of the docs, I'll fix it in a few
Added the three methods to deal with UUIDs. Parameters differ from the default as it's easier to just ask for plugin and key to make manipulations and avoid deprecated methods. I've followed existing standards other than that, added documentation to hasUuid and getUuid, kept formatting the same, broke nothing (hopefully). Lmk if anything needs changes