Search in sources :

Example 1 with GameProfileManager

use of org.spongepowered.api.profile.GameProfileManager in project ChangeSkin by games647.

the class SpongeSkinAPI method applyProperties.

@Override
public void applyProperties(GameProfile profile, SkinModel targetSkin) {
    // remove existing skins
    profile.getPropertyMap().clear();
    if (targetSkin != null) {
        GameProfileManager profileManager = Sponge.getServer().getGameProfileManager();
        ProfileProperty profileProperty = profileManager.createProfileProperty(SkinProperty.SKIN_KEY, targetSkin.getEncodedValue(), targetSkin.getSignature());
        profile.getPropertyMap().put(SkinProperty.SKIN_KEY, profileProperty);
    }
}
Also used : ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty) GameProfileManager(org.spongepowered.api.profile.GameProfileManager)

Example 2 with GameProfileManager

use of org.spongepowered.api.profile.GameProfileManager in project modules-extra by CubeEngine.

the class HideListener method onServerPingList.

@Listener
public void onServerPingList(ClientPingServerEvent event) {
    GameProfileManager gpm = Sponge.getServer().getGameProfileManager();
    event.getResponse().getPlayers().ifPresent(l -> {
        for (UUID uuid : module.getHiddenUsers()) {
            GameProfile gp = gpm.get(uuid).join();
            l.getProfiles().remove(gp);
        }
    });
}
Also used : GameProfileManager(org.spongepowered.api.profile.GameProfileManager) GameProfile(org.spongepowered.api.profile.GameProfile) UUID(java.util.UUID) Listener(org.spongepowered.api.event.Listener)

Example 3 with GameProfileManager

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

the class GetUserCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    CompletableFuture<GameProfile> profile;
    final String toGet;
    final GameProfileManager manager = Sponge.getServer().getGameProfileManager();
    if (args.hasAny(uuidKey)) {
        UUID u = args.<UUID>getOne(uuidKey).get();
        toGet = u.toString();
        profile = manager.get(u, false);
    } else {
        toGet = args.<String>getOne(playerKey).get();
        profile = manager.get(toGet, false);
    }
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.getuser.starting", toGet));
    profile.handle((gp, th) -> {
        if (th != null || gp == null) {
            if (th != null && Nucleus.getNucleus().isDebugMode()) {
                th.printStackTrace();
            }
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.getuser.failed", toGet));
            // I have to return something, even though I don't care about it.
            return 0;
        }
        // We have a game profile, it's been added to the cache. Create the user too, just in case.
        Sponge.getServiceManager().provideUnchecked(UserStorageService.class).getOrCreate(gp);
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.getuser.success", gp.getUniqueId().toString(), gp.getName().orElse("unknown")));
        return 0;
    });
    return CommandResult.success();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) GameProfile(org.spongepowered.api.profile.GameProfile) GameProfileManager(org.spongepowered.api.profile.GameProfileManager) UUID(java.util.UUID)

Example 4 with GameProfileManager

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

the class BanCommand method executeCommand.

@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
    final String r = args.<String>getOne(reason).orElse(plugin.getMessageProvider().getMessageWithFormat("ban.defaultreason"));
    Optional<GameProfile> ou = Optional.ofNullable(args.<GameProfile>getOne(uuid).orElseGet(() -> args.<GameProfile>getOne(user).orElse(null)));
    if (ou.isPresent()) {
        Optional<User> optionalUser = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(ou.get());
        if ((!optionalUser.isPresent() || !optionalUser.get().isOnline()) && !permissions.testSuffix(src, "offline")) {
            throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
        }
        if (optionalUser.isPresent() && permissions.testSuffix(optionalUser.get(), "exempt.target", src, false)) {
            throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.exempt", optionalUser.get().getName()));
        }
        return executeBan(src, ou.get(), r);
    }
    if (!permissions.testSuffix(src, "offline")) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
    }
    final String userToFind = args.<String>getOne(name).get();
    // Get the profile async.
    Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
        GameProfileManager gpm = Sponge.getServer().getGameProfileManager();
        try {
            GameProfile gp = gpm.get(userToFind).get();
            // Ban the user sync.
            Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
                // Create the user.
                UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
                User user = uss.getOrCreate(gp);
                src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("gameprofile.new", user.getName()));
                try {
                    executeBan(src, gp, r);
                } catch (Exception e) {
                    Nucleus.getNucleus().printStackTraceIfDebugMode(e);
                }
            });
        } catch (Exception e) {
            Nucleus.getNucleus().printStackTraceIfDebugMode(e);
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.profileerror", userToFind));
        }
    });
    return CommandResult.empty();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) User(org.spongepowered.api.entity.living.player.User) GameProfile(org.spongepowered.api.profile.GameProfile) GameProfileManager(org.spongepowered.api.profile.GameProfileManager) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Aggregations

GameProfileManager (org.spongepowered.api.profile.GameProfileManager)4 GameProfile (org.spongepowered.api.profile.GameProfile)3 UUID (java.util.UUID)2 UserStorageService (org.spongepowered.api.service.user.UserStorageService)2 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)1 User (org.spongepowered.api.entity.living.player.User)1 Listener (org.spongepowered.api.event.Listener)1 ProfileProperty (org.spongepowered.api.profile.property.ProfileProperty)1