Search in sources :

Example 11 with UserStorageService

use of org.spongepowered.api.service.user.UserStorageService in project Nucleus by NucleusPowered.

the class BanCommand method executeBan.

private CommandResult executeBan(CommandSource src, GameProfile u, String r) {
    BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
    UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
    User user = uss.get(u).get();
    if (!user.isOnline() && !permissions.testSuffix(src, "offline")) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
        return CommandResult.empty();
    }
    if (service.isBanned(u)) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.alreadyset", u.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown"))));
        return CommandResult.empty();
    }
    // Create the ban.
    Ban bp = Ban.builder().type(BanTypes.PROFILE).profile(u).source(src).reason(TextSerializers.FORMATTING_CODE.deserialize(r)).build();
    service.addBan(bp);
    // Get the permission, "quickstart.ban.notify"
    MutableMessageChannel send = new PermissionMessageChannel(notifyPermission).asMutable();
    send.addMember(src);
    send.send(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.applied", u.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown")), src.getName()));
    send.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", r));
    if (Sponge.getServer().getPlayer(u.getUniqueId()).isPresent()) {
        Sponge.getServer().getPlayer(u.getUniqueId()).get().kick(TextSerializers.FORMATTING_CODE.deserialize(r));
    }
    return CommandResult.success();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) User(org.spongepowered.api.entity.living.player.User) BanService(org.spongepowered.api.service.ban.BanService) Ban(org.spongepowered.api.util.ban.Ban) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 12 with UserStorageService

use of org.spongepowered.api.service.user.UserStorageService in project Nucleus by NucleusPowered.

the class NicknameArgumentTests method getMockUserStorageService.

private UserStorageService getMockUserStorageService() {
    GameProfile gp1 = Mockito.mock(GameProfile.class);
    GameProfile gp2 = Mockito.mock(GameProfile.class);
    Mockito.when(gp1.getName()).thenReturn(Optional.of("test"));
    Mockito.when(gp2.getName()).thenReturn(Optional.of("testtest"));
    UserStorageService mockUss = Mockito.mock(UserStorageService.class);
    Mockito.when(mockUss.getAll()).thenReturn(Lists.newArrayList(gp1, gp2));
    User u1 = Mockito.mock(User.class);
    Mockito.when(u1.getName()).thenAnswer(g -> gp1.getName().get());
    Mockito.when(u1.getPlayer()).thenAnswer(g -> Optional.empty());
    User u2 = Mockito.mock(User.class);
    Mockito.when(u2.getName()).thenAnswer(g -> gp2.getName().get());
    Mockito.when(u2.getPlayer()).thenAnswer(g -> Optional.empty());
    Mockito.when(mockUss.get(gp1)).thenReturn(Optional.of(u1));
    Mockito.when(mockUss.get(gp2)).thenReturn(Optional.of(u2));
    return mockUss;
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) User(org.spongepowered.api.entity.living.player.User) GameProfile(org.spongepowered.api.profile.GameProfile)

Example 13 with UserStorageService

use of org.spongepowered.api.service.user.UserStorageService in project Nucleus by NucleusPowered.

the class GetFromIpCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    String ip = args.<String>getOne(ipKey).get();
    if (Arrays.stream(ip.split("\\.")).anyMatch(x -> Integer.parseInt(x) > 255)) {
        throw ReturnMessageException.fromKey("command.getfromip.notvalid");
    }
    UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
    List<User> users = plugin.getUserCacheService().getForIp(ip).stream().map(uss::get).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    if (users.isEmpty()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.getfromip.nousers"));
        return CommandResult.success();
    }
    NameUtil name = plugin.getNameUtil();
    Util.getPaginationBuilder(src).title(plugin.getMessageProvider().getTextMessageWithFormat("command.getfromip.title", ip)).contents(users.stream().map(y -> {
        Text n = name.getName(y);
        return n.toBuilder().onClick(TextActions.runCommand("/nucleus:seen " + y.getName())).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithTextFormat("command.getfromip.hover", n))).build();
    }).collect(Collectors.toList())).sendTo(src);
    return CommandResult.success();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Arrays(java.util.Arrays) NameUtil(io.github.nucleuspowered.nucleus.NameUtil) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) UserStorageService(org.spongepowered.api.service.user.UserStorageService) RegexArgument(io.github.nucleuspowered.nucleus.argumentparsers.RegexArgument) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Optional(java.util.Optional) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) User(org.spongepowered.api.entity.living.player.User) Optional(java.util.Optional) Text(org.spongepowered.api.text.Text) NameUtil(io.github.nucleuspowered.nucleus.NameUtil)

Aggregations

UserStorageService (org.spongepowered.api.service.user.UserStorageService)13 User (org.spongepowered.api.entity.living.player.User)10 Text (org.spongepowered.api.text.Text)5 Optional (java.util.Optional)4 Player (org.spongepowered.api.entity.living.player.Player)4 GameProfile (org.spongepowered.api.profile.GameProfile)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Sponge (org.spongepowered.api.Sponge)3 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 CommandResult (org.spongepowered.api.command.CommandResult)2 CommandSource (org.spongepowered.api.command.CommandSource)2 CommandContext (org.spongepowered.api.command.args.CommandContext)2 PaginationService (org.spongepowered.api.service.pagination.PaginationService)2 TextColors (org.spongepowered.api.text.format.TextColors)2 RPLang (br.net.fabiozumbi12.RedProtect.Sponge.config.RPLang)1 WEListener (br.net.fabiozumbi12.RedProtect.Sponge.hooks.WEListener)1