Add some more UUIDUtil methods

This commit is contained in:
Vankka 2024-08-03 17:27:03 +03:00
parent 53ced9be86
commit 8058d6a3ff
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB
3 changed files with 19 additions and 4 deletions

View File

@ -28,6 +28,7 @@ import com.discordsrv.common.config.main.AvatarProviderConfig;
import com.discordsrv.common.feature.profile.Profile; import com.discordsrv.common.feature.profile.Profile;
import com.discordsrv.common.util.ComponentUtil; import com.discordsrv.common.util.ComponentUtil;
import com.discordsrv.common.util.GamePermissionUtil; import com.discordsrv.common.util.GamePermissionUtil;
import com.discordsrv.common.util.UUIDUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -82,9 +83,9 @@ public interface IPlayer extends DiscordSRVPlayer, IOfflinePlayer, ICommandSende
if (avatarConfig.autoDecideAvatarUrl) { if (avatarConfig.autoDecideAvatarUrl) {
// Offline mode // Offline mode
if (uniqueId().version() == 3) avatarUrlTemplate = "https://cravatar.eu/helmavatar/%player_name%/128.png#%player_skin_texture_id%"; if (UUIDUtil.isOffline(uniqueId())) avatarUrlTemplate = "https://cravatar.eu/helmavatar/%player_name%/128.png#%player_skin_texture_id%";
// Bedrock // Bedrock
else if (uniqueId().getLeastSignificantBits() == 0) avatarUrlTemplate = "https://api.tydiumcraft.net/skin?uuid=%player_uuid_short%&type=avatar&size=128"; else if (UUIDUtil.isGeyser(uniqueId())) avatarUrlTemplate = "https://api.tydiumcraft.net/skin?uuid=%player_uuid_short%&type=avatar&size=128";
} }
if (avatarUrlTemplate == null) { if (avatarUrlTemplate == null) {

View File

@ -69,8 +69,7 @@ public abstract class AbstractPlayerProvider<T extends IPlayer, DT extends Disco
this.allPlayers.add(player); this.allPlayers.add(player);
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(new PlayerConnectedEvent(player, initial))); discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(new PlayerConnectedEvent(player, initial)));
if (uuid.getLeastSignificantBits() != 0 /* Not Geyser */ if (UUIDUtil.isOffline(uuid) /* Offline */) {
&& uuid.version() == 3 /* Offline */) {
anyOffline.set(true); anyOffline.set(true);
} }
} }

View File

@ -56,4 +56,19 @@ public final class UUIDUtil {
public static String toShort(@NotNull UUID uuid) { public static String toShort(@NotNull UUID uuid) {
return uuid.toString().replace("-", ""); return uuid.toString().replace("-", "");
} }
@Placeholder("version")
public static int getVersion(@NotNull UUID uuid) {
return uuid.version();
}
@Placeholder("isgeyser")
public static boolean isGeyser(@NotNull UUID uuid) {
return uuid.getLeastSignificantBits() == 0;
}
@Placeholder("isoffline")
public static boolean isOffline(@NotNull UUID uuid) {
return !isGeyser(uuid) && uuid.version() == 3;
}
} }