Search in sources :

Example 1 with CommandPermission

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());
    }
}
Also used : Instant(java.time.Instant) Text(org.spongepowered.api.text.Text) Command(org.cubeengine.butler.parametric.Command) Restricted(org.cubeengine.butler.filter.Restricted) CommandPermission(org.cubeengine.libcube.service.command.annotation.CommandPermission) Unloggable(org.cubeengine.libcube.service.command.annotation.Unloggable)

Aggregations

Instant (java.time.Instant)1 Restricted (org.cubeengine.butler.filter.Restricted)1 Command (org.cubeengine.butler.parametric.Command)1 CommandPermission (org.cubeengine.libcube.service.command.annotation.CommandPermission)1 Unloggable (org.cubeengine.libcube.service.command.annotation.Unloggable)1 Text (org.spongepowered.api.text.Text)1