use of org.spongepowered.api.service.whitelist.WhitelistService in project LanternServer by LanternPowered.
the class CommandWhitelist method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.child(CommandSpec.builder().arguments(GenericArguments.string(Text.of("player"))).executor((src, args) -> {
final String playerName = args.<String>getOne("player").get();
final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
Lantern.getGame().getGameProfileManager().get(playerName).whenComplete((profile, error) -> {
if (error != null) {
src.sendMessage(t("commands.whitelist.add.failed", playerName));
} else {
src.sendMessage(t("commands.whitelist.add.success", playerName));
service.addProfile(((LanternGameProfile) profile).withoutProperties());
}
});
return CommandResult.success();
}).build(), "add").child(CommandSpec.builder().arguments(GenericArguments.string(Text.of("player"))).executor((src, args) -> {
final String playerName = args.<String>getOne("player").get();
final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
Lantern.getGame().getGameProfileManager().get(playerName).whenComplete((profile, error) -> {
if (error != null || !service.isWhitelisted(profile = ((LanternGameProfile) profile).withoutProperties())) {
src.sendMessage(t("commands.whitelist.remove.failed", playerName));
} else {
src.sendMessage(t("commands.whitelist.remove.success", playerName));
service.removeProfile(profile);
}
});
return CommandResult.success();
}).build(), "remove").child(CommandSpec.builder().executor((src, args) -> {
final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
final List<String> whitelisted = service.getWhitelistedProfiles().stream().map(p -> p.getName().get()).collect(Collectors.toList());
src.sendMessage(t("commands.whitelist.list", whitelisted.size(), Sponge.getServer().getOnlinePlayers().size()));
src.sendMessage(Text.of(Joiner.on(", ").join(whitelisted)));
return CommandResult.success();
}).build(), "list").child(CommandSpec.builder().executor((src, args) -> {
Lantern.getGame().getGlobalConfig().setWhitelistEnabled(true);
src.sendMessage(t("commands.whitelist.enabled"));
return CommandResult.success();
}).build(), "on").child(CommandSpec.builder().executor((src, args) -> {
Lantern.getGame().getGlobalConfig().setWhitelistEnabled(false);
src.sendMessage(t("commands.whitelist.disabled"));
return CommandResult.success();
}).build(), "off").child(CommandSpec.builder().executor((src, args) -> {
final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
if (service instanceof Reloadable) {
try {
((Reloadable) service).reload();
} catch (Exception e) {
throw new CommandException(t("commands.whitelist.reload.failed", e.getMessage()), e);
}
} else {
src.sendMessage(t("commands.whitelist.reload.not_supported"));
return CommandResult.empty();
}
return CommandResult.success();
}).build(), "reload");
}
use of org.spongepowered.api.service.whitelist.WhitelistService in project LanternServer by LanternPowered.
the class NetworkSession method isWhitelisted.
private static boolean isWhitelisted(GameProfile gameProfile) {
if (!Lantern.getGame().getGlobalConfig().isWhitelistEnabled()) {
return true;
}
final WhitelistService whitelistService = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
if (whitelistService.isWhitelisted(gameProfile)) {
return true;
}
final PermissionService permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
return permissionService.getUserSubjects().getSubject(gameProfile.getUniqueId().toString()).map(subject -> subject.hasPermission(Permissions.Login.BYPASS_WHITELIST_PERMISSION)).orElse(false);
}
use of org.spongepowered.api.service.whitelist.WhitelistService in project LanternServer by LanternPowered.
the class LanternUserStorageService method getFromWhitelistService.
/**
* Attempts to get a {@link User} from the {@link WhitelistService}.
*
* @param uniqueId The unique id
* @return The user
*/
@Nullable
private ProxyUser getFromWhitelistService(UUID uniqueId) {
final LanternGameProfile gameProfile;
final WhitelistService whitelistService = this.whitelistService.get();
if (whitelistService instanceof WhitelistConfig) {
gameProfile = ((WhitelistConfig) whitelistService).getEntryByUUID(uniqueId).map(UserEntry::getProfile).orElse(null);
} else {
gameProfile = (LanternGameProfile) whitelistService.getWhitelistedProfiles().stream().filter(profile -> profile.getUniqueId().equals(uniqueId)).findFirst().orElse(null);
}
return gameProfile == null ? null : new ProxyUser(gameProfile);
}
Aggregations