Search in sources :

Example 16 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project Nucleus by NucleusPowered.

the class UnbanCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    GameProfile gp;
    if (args.hasAny(key)) {
        gp = args.<GameProfile>getOne(key).get();
    } else {
        gp = args.<GameProfile>getOne(key2).get();
    }
    BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
    Optional<Ban.Profile> obp = service.getBanFor(gp);
    if (!obp.isPresent()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkban.notset", gp.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown"))));
        return CommandResult.empty();
    }
    service.removeBan(obp.get());
    MutableMessageChannel notify = new PermissionMessageChannel(BanCommand.notifyPermission).asMutable();
    notify.addMember(src);
    notify.send(plugin.getMessageProvider().getTextMessageWithFormat("command.unban.success", obp.get().getProfile().getName().orElse("standard.unknown"), src.getName()));
    return CommandResult.success();
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) GameProfile(org.spongepowered.api.profile.GameProfile) BanService(org.spongepowered.api.service.ban.BanService) GameProfile(org.spongepowered.api.profile.GameProfile) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 17 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class MixinPlayerProfileCache method lookupByNames.

@Override
public Map<String, Optional<GameProfile>> lookupByNames(Iterable<String> names) {
    checkNotNull(names, "names");
    Map<String, Optional<GameProfile>> result = Maps.newHashMap();
    SpongeImpl.getServer().getGameProfileRepository().findProfilesByNames(Iterables.toArray(names, String.class), Agent.MINECRAFT, new MapProfileLookupCallback(result));
    if (!result.isEmpty()) {
        for (Optional<GameProfile> entry : result.values()) {
            if (entry.isPresent()) {
                this.addEntry((com.mojang.authlib.GameProfile) entry.get(), null);
            }
        }
        return ImmutableMap.copyOf(result);
    }
    return ImmutableMap.of();
}
Also used : Optional(java.util.Optional) GameProfile(org.spongepowered.api.profile.GameProfile) MapProfileLookupCallback(org.spongepowered.common.profile.callback.MapProfileLookupCallback)

Example 18 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class MixinPlayerProfileCache method lookupByName.

@Override
public Optional<GameProfile> lookupByName(String name) {
    SingleProfileLookupCallback callback = new SingleProfileLookupCallback();
    SpongeImpl.getServer().getGameProfileRepository().findProfilesByNames(new String[] { name }, Agent.MINECRAFT, callback);
    Optional<GameProfile> profile = callback.getResult();
    if (profile.isPresent()) {
        this.addEntry((com.mojang.authlib.GameProfile) profile.get(), null);
    }
    return profile;
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) SingleProfileLookupCallback(org.spongepowered.common.profile.callback.SingleProfileLookupCallback)

Example 19 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class MixinPlayerProfileCache method getByIds.

@Override
public Map<UUID, Optional<GameProfile>> getByIds(Iterable<UUID> uniqueIds) {
    checkNotNull(uniqueIds, "unique ids");
    Map<UUID, Optional<GameProfile>> result = Maps.newHashMap();
    for (UUID uniqueId : uniqueIds) {
        result.put(uniqueId, Optional.ofNullable((GameProfile) this.getProfileByUUID(uniqueId)));
    }
    return result.isEmpty() ? ImmutableMap.of() : ImmutableMap.copyOf(result);
}
Also used : Optional(java.util.Optional) GameProfile(org.spongepowered.api.profile.GameProfile) UUID(java.util.UUID)

Example 20 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class SkullUtils method updatePlayerProfile.

public static void updatePlayerProfile(IMixinTileEntitySkull skull) {
    GameProfile profile = (GameProfile) skull.getPlayerProfile();
    if (profile != null && profile.getName().isPresent() && !profile.getName().get().isEmpty()) {
        if (profile.isFilled() && profile.getPropertyMap().containsKey("textures")) {
            skull.markDirty();
        } else {
            Sponge.getServer().getGameProfileManager().get(profile.getName().get()).handle((newProfile, thrown) -> {
                if (newProfile != null) {
                    skull.setPlayerProfile((com.mojang.authlib.GameProfile) newProfile, false);
                    skull.markDirty();
                } else {
                    SpongeImpl.getLogger().warn("Could not update player GameProfile for Skull: ", thrown.getMessage());
                }
                return newProfile;
            });
        }
    } else {
        skull.markDirty();
    }
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile)

Aggregations

GameProfile (org.spongepowered.api.profile.GameProfile)44 Optional (java.util.Optional)12 UUID (java.util.UUID)12 Text (org.spongepowered.api.text.Text)9 User (org.spongepowered.api.entity.living.player.User)8 IOException (java.io.IOException)7 List (java.util.List)6 Sponge (org.spongepowered.api.Sponge)6 Cause (org.spongepowered.api.event.cause.Cause)6 World (org.spongepowered.api.world.World)6 Vector3d (com.flowpowered.math.vector.Vector3d)5 Collectors (java.util.stream.Collectors)5 Keys (org.spongepowered.api.data.key.Keys)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)4 ImmutableList (com.google.common.collect.ImmutableList)4 Lists (com.google.common.collect.Lists)4 Collection (java.util.Collection)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4