Search in sources :

Example 1 with SpongeProfileManager

use of org.spongepowered.common.profile.SpongeProfileManager in project SpongeCommon by SpongePowered.

the class MixinEntity_Tracker method getUserForUuid.

private Optional<User> getUserForUuid(UUID uuid) {
    // get player if online
    Player player = Sponge.getServer().getPlayer(uuid).orElse(null);
    if (player != null) {
        return Optional.of(player);
    }
    // player is not online, get user from storage if one exists
    if (this.spongeProfileManager == null) {
        this.spongeProfileManager = ((SpongeProfileManager) Sponge.getServer().getGameProfileManager());
    }
    if (this.userStorageService == null) {
        this.userStorageService = SpongeImpl.getGame().getServiceManager().provide(UserStorageService.class).get();
    }
    // check username cache
    String username = SpongeUsernameCache.getLastKnownUsername(uuid);
    if (username != null) {
        return this.userStorageService.get(GameProfile.of(uuid, username));
    }
    // check mojang cache
    GameProfile profile = this.spongeProfileManager.getCache().getById(uuid).orElse(null);
    if (profile != null) {
        return this.userStorageService.get(profile);
    }
    // If we reach this point, queue UUID for async lookup and return empty
    this.spongeProfileManager.lookupUserAsync(uuid);
    return Optional.empty();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) GameProfile(org.spongepowered.api.profile.GameProfile) SpongeProfileManager(org.spongepowered.common.profile.SpongeProfileManager)

Example 2 with SpongeProfileManager

use of org.spongepowered.common.profile.SpongeProfileManager in project SpongeCommon by SpongePowered.

the class MixinEntity method onConstruction.

@Inject(method = "<init>", at = @At("RETURN"))
public void onConstruction(net.minecraft.world.World worldIn, CallbackInfo ci) {
    if (this.entityType instanceof SpongeEntityType) {
        SpongeEntityType spongeEntityType = (SpongeEntityType) this.entityType;
        if (spongeEntityType.getEnumCreatureType() == null) {
            for (EnumCreatureType type : EnumCreatureType.values()) {
                if (SpongeImplHooks.isCreatureOfType((net.minecraft.entity.Entity) (Object) this, type)) {
                    spongeEntityType.setEnumCreatureType(type);
                    break;
                }
            }
        }
    }
    if (worldIn != null && !worldIn.isRemote) {
        this.spongeProfileManager = ((SpongeProfileManager) Sponge.getServer().getGameProfileManager());
        this.userStorageService = SpongeImpl.getGame().getServiceManager().provide(UserStorageService.class).get();
    }
}
Also used : EnumCreatureType(net.minecraft.entity.EnumCreatureType) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) SpongeProfileManager(org.spongepowered.common.profile.SpongeProfileManager) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

SpongeProfileManager (org.spongepowered.common.profile.SpongeProfileManager)2 EnumCreatureType (net.minecraft.entity.EnumCreatureType)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Player (org.spongepowered.api.entity.living.player.Player)1 GameProfile (org.spongepowered.api.profile.GameProfile)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 SpongeEntityType (org.spongepowered.common.entity.SpongeEntityType)1