Search in sources :

Example 6 with Command

use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.

the class PlayerCommands method lightning.

@Command(alias = "strike", desc = "Throws a lightning bolt at a player or where you're looking")
public void lightning(CommandSource context, @Optional Integer damage, @Named({ "player", "p" }) Player player, @Named({ "fireticks", "f" }) Integer seconds, @Flag boolean unsafe) {
    damage = damage == null ? -1 : damage;
    if (damage != -1 && !context.hasPermission(module.perms().COMMAND_LIGHTNING_PLAYER_DAMAGE.getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to specify the damage!");
        return;
    }
    if ((damage != -1 && damage < 0) || damage > 20) {
        i18n.send(context, NEGATIVE, "The damage value has to be a number from 1 to 20");
        return;
    }
    if (unsafe && !context.hasPermission(module.perms().COMMAND_LIGHTNING_UNSAFE.getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to use the unsafe flag");
        return;
    }
    Location<World> location;
    if (player != null) {
        location = player.getLocation();
        player.offer(Keys.FIRE_TICKS, 20 * (seconds == null ? 0 : seconds));
        if (damage != -1) {
            // TODO better source
            player.damage(damage, DamageSource.builder().type(DamageTypes.CONTACT).build());
        }
    } else {
        if (!(context instanceof Player)) {
            i18n.send(context, NEGATIVE, "This command can only be used by a player!");
            return;
        }
        java.util.Optional<BlockRayHit<World>> end = BlockRay.from(((Player) context)).distanceLimit(module.getConfig().command.lightning.distance).stopFilter(BlockRay.onlyAirFilter()).build().end();
        if (end.isPresent()) {
            location = end.get().getLocation();
        } else {
            throw new IllegalStateException();
        }
    }
    Entity entity = location.getExtent().createEntity(EntityTypes.LIGHTNING, location.getPosition());
    if (!unsafe) {
        ((Lightning) entity).setEffect(true);
    }
    Sponge.getCauseStackManager().pushCause(context);
    location.getExtent().spawnEntity(entity);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Lightning(org.spongepowered.api.entity.weather.Lightning) World(org.spongepowered.api.world.World) BlockRayHit(org.spongepowered.api.util.blockray.BlockRayHit) Command(org.cubeengine.butler.parametric.Command)

Example 7 with Command

use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.

the class PlayerCommands method slap.

@Command(desc = "Slaps a player")
public void slap(CommandSource context, Player player, @Optional Integer damage) {
    damage = damage == null ? 3 : damage;
    if (damage < 1 || damage > 20) {
        i18n.send(context, NEGATIVE, "Only damage values from 1 to 20 are allowed!");
        return;
    }
    final Vector3d userDirection = player.getTransform().getRotationAsQuaternion().getDirection().mul(-1);
    Sponge.getCauseStackManager().pushCause(context);
    player.damage(damage, DamageSource.builder().type(DamageTypes.ATTACK).absolute().build());
    player.setVelocity(new Vector3d(userDirection.getX() * damage / 2, userDirection.getY() * damage / 20, userDirection.getZ() * damage / 2));
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) Command(org.cubeengine.butler.parametric.Command)

Example 8 with Command

use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.

the class ThrowCommands method throwCommand.

@Command(name = "throw", desc = "Throw something!")
@Restricted(value = Player.class, msg = "This command can only be used by a player!")
public void throwCommand(Player context, String material, @Optional Integer amount, @Named({ "delay", "d" }) Integer delay, @Flag boolean unsafe) {
    EntityType type = null;
    boolean showNotification = true;
    ThrowTask task = this.thrownItems.remove(context.getUniqueId());
    if (task != null) {
        int aDelay = delay == null ? task.getInterval() : delay;
        if (material == null || (type = entityMatcher.any(material, context.getLocale())) == task.getType() && task.getInterval() == aDelay && task.getPreventDamage() != unsafe && delay == null) {
            task.stop(true);
            return;
        }
        task.stop(showNotification = false);
    }
    amount = amount == null ? -1 : 1;
    if ((amount > this.module.getConfig().command.throwSection.maxAmount || amount < 1) && amount != -1) {
        i18n.send(context, NEGATIVE, "The amount must be a number from 1 to {integer}", this.module.getConfig().command.throwSection.maxAmount);
        return;
    }
    delay = delay == null ? 3 : delay;
    if (delay > this.module.getConfig().command.throwSection.maxDelay || delay < 0) {
        i18n.send(context, NEGATIVE, "The delay must be a number from 0 to {integer}", this.module.getConfig().command.throwSection.maxDelay);
        return;
    }
    if (unsafe && !context.hasPermission(module.perms().COMMAND_THROW_UNSAFE.getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to execute this command in unsafe mode.");
        return;
    }
    if (type == null) {
        type = entityMatcher.any(material, context.getLocale());
    }
    if (type == null) {
        i18n.send(context, NEGATIVE, "The given object was not found!");
        return;
    }
    if (!context.hasPermission(perms.get(type).getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to throw this.");
        return;
    }
    if ((BUGGED_ENTITIES.contains(type) || entityMatcher.isMonster(type)) && !unsafe) {
        i18n.send(context, NEUTRAL, "This object can only be thrown in unsafe mode. Add -u to enable the unsafe mode.");
        return;
    }
    task = new ThrowTask(context, type, amount, delay, !unsafe);
    if (task.start(showNotification)) {
        this.thrownItems.put(context.getUniqueId(), task);
    } else {
        i18n.send(context, NEGATIVE, "Failed to throw this!");
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Command(org.cubeengine.butler.parametric.Command) Restricted(org.cubeengine.butler.filter.Restricted)

Example 9 with Command

use of org.cubeengine.butler.parametric.Command 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)

Example 10 with Command

use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.

the class AuthCommands method clearPassword.

@Command(alias = "clearpw", desc = "Clears your password.")
public void clearPassword(CommandSource context, @Optional @Desc("* or a list of Players delimited by ,") PlayerList players) {
    if (players == null) {
        if (!(context instanceof Player)) {
            throw new TooFewArgumentsException();
        }
        module.resetPassword(((Player) context).getUniqueId());
        i18n.send(context, POSITIVE, "Your password has been reset!");
        return;
    }
    if (players.isAll()) {
        if (!context.hasPermission(module.perms().COMMAND_CLEARPASSWORD_ALL.getId())) {
            throw new PermissionDeniedException(module.perms().COMMAND_CLEARPASSWORD_ALL);
        }
        module.resetAllPasswords();
        i18n.send(context, POSITIVE, "All passwords reset!");
        return;
    }
    if (!context.hasPermission(module.perms().COMMAND_CLEARPASSWORD_OTHER.getId())) {
        throw new PermissionDeniedException(module.perms().COMMAND_CLEARPASSWORD_OTHER);
    }
    for (Player user : players.list()) {
        module.resetPassword(user.getUniqueId());
        i18n.send(context, POSITIVE, "{user}'s password has been reset!", user.getName());
    }
}
Also used : TooFewArgumentsException(org.cubeengine.butler.parameter.TooFewArgumentsException) Player(org.spongepowered.api.entity.living.player.Player) PermissionDeniedException(org.cubeengine.libcube.service.command.exception.PermissionDeniedException) Command(org.cubeengine.butler.parametric.Command)

Aggregations

Command (org.cubeengine.butler.parametric.Command)46 World (org.spongepowered.api.world.World)18 ContainerCommand (org.cubeengine.libcube.service.command.ContainerCommand)14 ConversationCommand (org.cubeengine.libcube.service.command.conversation.ConversationCommand)14 IMarketSignData (org.cubeengine.module.signmarket.data.IMarketSignData)14 ImmutableMarketSignData (org.cubeengine.module.signmarket.data.ImmutableMarketSignData)14 MarketSignData (org.cubeengine.module.signmarket.data.MarketSignData)14 Player (org.spongepowered.api.entity.living.player.Player)11 Alias (org.cubeengine.butler.alias.Alias)10 Restricted (org.cubeengine.butler.filter.Restricted)9 PermissionDeniedException (org.cubeengine.libcube.service.command.exception.PermissionDeniedException)5 ItemStack (org.spongepowered.api.item.inventory.ItemStack)5 Language (de.cubeisland.engine.i18n.language.Language)4 Inventory (org.spongepowered.api.item.inventory.Inventory)4 BlockRayHit (org.spongepowered.api.util.blockray.BlockRayHit)4 ArrayList (java.util.ArrayList)3 Locale (java.util.Locale)3 Text (org.spongepowered.api.text.Text)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 IOException (java.io.IOException)2