use of org.cubeengine.libcube.service.command.annotation.CommandPermission in project modules-extra by CubeEngine.
the class AuthCommands method login.
@Unloggable
@Command(desc = "Logs you in with your password!")
// TODO assign by default
@CommandPermission(checkPermission = false)
@Restricted(value = Player.class, msg = "Only players can log in!")
public void login(Player context, String password) throws InterruptedException, ExecutionException {
if (module.isLoggedIn(context.getUniqueId())) {
i18n.send(context, POSITIVE, "You are already logged in!");
return;
}
boolean isLoggedIn = module.login(context, password).get();
if (isLoggedIn) {
i18n.send(context, POSITIVE, "You logged in successfully!");
return;
}
i18n.send(context, NEGATIVE, "Wrong password!");
if (module.getConfig().fail2ban) {
if (fails.get(context.getUniqueId()) != null) {
if (fails.get(context.getUniqueId()) + SECONDS.toMillis(10) > currentTimeMillis()) {
Text msg = Text.of(i18n.translate(context, NEGATIVE, "Too many wrong passwords!") + "\n" + i18n.translate(context, NEUTRAL, "For your security you were banned 10 seconds."));
Instant expires = Instant.now().plus(module.getConfig().banDuration, ChronoUnit.SECONDS);
module.getBanService().addBan(Ban.builder().profile(context.getProfile()).reason(msg).expirationDate(expires).source(context).build());
if (!Sponge.getServer().getOnlineMode()) {
module.getBanService().addBan(Ban.builder().address(context.getConnection().getAddress().getAddress()).reason(msg).expirationDate(expires).source(context).build());
}
context.kick(msg);
}
}
fails.put(context.getUniqueId(), currentTimeMillis());
}
}
Aggregations