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();
}
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;
}
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();
}
Aggregations