use of org.spongepowered.common.profile.SpongeGameProfile in project SpongeCommon by SpongePowered.
the class PlayerListMixin method impl$canPlayerLoginServer.
protected final CompletableFuture<net.minecraft.network.chat.Component> impl$canPlayerLoginServer(final SocketAddress param0, final com.mojang.authlib.GameProfile param1) {
final SpongeGameProfile profile = SpongeGameProfile.basicOf(param1);
return Sponge.server().serviceProvider().banService().find(profile).thenCompose(profileBanOpt -> {
if (profileBanOpt.isPresent()) {
final Ban.Profile var0 = profileBanOpt.get();
final MutableComponent var1 = new TranslatableComponent("multiplayer.disconnect.banned.reason", var0.reason().orElse(Component.empty()));
if (var0.expirationDate().isPresent()) {
var1.append(new TranslatableComponent("multiplayer.disconnect.banned.expiration", BAN_DATE_FORMAT.format(var0.expirationDate().get())));
}
return CompletableFuture.completedFuture(var1);
}
if (param0 instanceof LocalAddress) {
// don't bother looking up IP bans on local address
return CompletableFuture.completedFuture(null);
}
final InetAddress address;
try {
address = InetAddress.getByName(NetworkUtil.getHostString(param0));
} catch (final UnknownHostException ex) {
// no
return CompletableFuture.completedFuture(new TextComponent(ex.getMessage()));
}
return Sponge.server().serviceProvider().banService().find(address).thenCompose(ipBanOpt -> {
if (ipBanOpt.isPresent()) {
final Ban.IP var2 = ipBanOpt.get();
final MutableComponent var3 = new TranslatableComponent("multiplayer.disconnect.banned_ip.reason", var2.reason().orElse(Component.empty()));
if (var2.expirationDate().isPresent()) {
var3.append(new TranslatableComponent("multiplayer.disconnect.banned_ip.expiration", BAN_DATE_FORMAT.format(var2.expirationDate().get())));
}
return CompletableFuture.completedFuture(var3);
}
return CompletableFuture.supplyAsync(() -> {
if (!Sponge.server().isWhitelistEnabled()) {
return true;
}
final PermissionService permissionService = Sponge.server().serviceProvider().permissionService();
Subject subject = permissionService.userSubjects().subject(param1.getId().toString()).orElse(null);
if (subject == null) {
subject = permissionService.defaults();
}
return subject.hasPermission(LoginPermissions.BYPASS_WHITELIST_PERMISSION);
}, SpongeCommon.server()).thenCompose(w -> {
if (w) {
return CompletableFuture.completedFuture(null);
}
return Sponge.server().serviceProvider().whitelistService().isWhitelisted(profile).<net.minecraft.network.chat.Component>thenApply(whitelisted -> {
if (!whitelisted) {
return new TranslatableComponent("multiplayer.disconnect.not_whitelisted");
}
return null;
});
});
});
}).thenApplyAsync(component -> {
if (component != null) {
return component;
}
if (this.players.size() >= this.maxPlayers && !this.shadow$canBypassPlayerLimit(param1)) {
return new TranslatableComponent("multiplayer.disconnect.server_full");
}
return null;
}, SpongeCommon.server());
}
Aggregations