TheBusyBiscuit / CS-CoreLib2

This is an updated (LITE) Version of CS-CoreLib. Instead of being a hard dependency, it should be shaded instead.
MIT License
19 stars 18 forks source link

Added UUID util #157

Closed Sfiguz7 closed 3 years ago

Sfiguz7 commented 3 years ago

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

WalshyDev commented 3 years ago

we should probably add removeUuid too since there's no way to remove it properly.

WalshyDev commented 3 years ago

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};
    }
Sfiguz7 commented 3 years ago

There's a copy paste mistake in one of the docs, I'll fix it in a few