Search in sources :

Example 1 with Restricted

use of org.cubeengine.butler.filter.Restricted 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 2 with Restricted

use of org.cubeengine.butler.filter.Restricted 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 3 with Restricted

use of org.cubeengine.butler.filter.Restricted in project modules-extra by CubeEngine.

the class KitCommand method create.

@Command(alias = "open", desc = "Opens the configured kit if the kit does not exists a new is created")
@Restricted(value = Player.class, msg = "Just log in or use the config!")
public void create(Player context, String kitname) {
    if (!FileUtil.isValidFileName(kitname)) {
        i18n.send(context, NEGATIVE, "{name#kit} is is not a valid name! Do not use characters like *, | or ?", kitname);
        return;
    }
    Inventory inventory = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(i18n.getTranslation(context, "Kit Contents: "), kitname))).build(module.getPlugin());
    List<ItemStack> itemList = new ArrayList<>();
    Kit kit = manager.getKit(kitname);
    if (kit == null) {
        kit = new Kit(module, kitname, false, 0, -1, true, "", new ArrayList<>(), itemList);
    } else {
        itemList = kit.getItems();
    }
    showKit(context, inventory, itemList, kit);
}
Also used : ArrayList(java.util.ArrayList) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Command(org.cubeengine.butler.parametric.Command) Restricted(org.cubeengine.butler.filter.Restricted)

Example 4 with Restricted

use of org.cubeengine.butler.filter.Restricted in project modules-extra by CubeEngine.

the class IgnoreCommands method unignore.

@Command(desc = "Stops ignoring all messages from a player")
@Restricted(value = Player.class, msg = "Congratulations! You are now looking at this text!")
public void unignore(Player context, List<User> players) {
    List<String> added = new ArrayList<>();
    for (User user : players) {
        if (!this.removeIgnore(context, user)) {
            i18n.send(context, NEGATIVE, "You haven't ignored {user}!", user);
        } else {
            added.add(user.getName());
        }
    }
    if (added.isEmpty()) {
        return;
    }
    i18n.send(context, POSITIVE, "You removed {user#list} from your ignore list!", StringUtils.implode(ChatFormat.WHITE + ", " + ChatFormat.DARK_GREEN, added));
}
Also used : User(org.spongepowered.api.entity.living.player.User) ArrayList(java.util.ArrayList) Command(org.cubeengine.butler.parametric.Command) Restricted(org.cubeengine.butler.filter.Restricted)

Example 5 with Restricted

use of org.cubeengine.butler.filter.Restricted in project modules-extra by CubeEngine.

the class EditModeCommand method copy.

@Restricted(Player.class)
@Command(desc = "Copies the settings from the previous sign")
public void copy(Player context) {
    ImmutableMarketSignData data = manager.getPreviousData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No previous market sign");
        return;
    }
    if (data.getOwner().equals(IMarketSignData.ADMIN_SIGN)) {
        if (!context.hasPermission(module.perms().EDIT_ADMIN.getId())) {
            throw new PermissionDeniedException(module.perms().EDIT_ADMIN);
        }
    } else {
        if (!context.hasPermission(module.perms().EDIT_USE.getId())) {
            throw new PermissionDeniedException(module.perms().EDIT_USE);
        }
    }
    MarketSignData copy = data.asMutable();
    if (!copy.isAdminOwner()) {
        copy.setStock(0);
    }
    Location<World> loc = manager.updateData(copy, context);
    manager.executeShowInfo(copy, context, loc);
}
Also used : ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) IMarketSignData(org.cubeengine.module.signmarket.data.IMarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) PermissionDeniedException(org.cubeengine.libcube.service.command.exception.PermissionDeniedException) World(org.spongepowered.api.world.World) Restricted(org.cubeengine.butler.filter.Restricted) Command(org.cubeengine.butler.parametric.Command) ConversationCommand(org.cubeengine.libcube.service.command.conversation.ConversationCommand)

Aggregations

Restricted (org.cubeengine.butler.filter.Restricted)9 Command (org.cubeengine.butler.parametric.Command)9 ContainerCommand (org.cubeengine.libcube.service.command.ContainerCommand)5 Alias (org.cubeengine.butler.alias.Alias)4 Inventory (org.spongepowered.api.item.inventory.Inventory)3 ArrayList (java.util.ArrayList)2 Material (org.bukkit.Material)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 Instant (java.time.Instant)1 CommandPermission (org.cubeengine.libcube.service.command.annotation.CommandPermission)1 Unloggable (org.cubeengine.libcube.service.command.annotation.Unloggable)1 ConversationCommand (org.cubeengine.libcube.service.command.conversation.ConversationCommand)1 PermissionDeniedException (org.cubeengine.libcube.service.command.exception.PermissionDeniedException)1 IPowertoolData (org.cubeengine.module.powertools.data.IPowertoolData)1 PowertoolData (org.cubeengine.module.powertools.data.PowertoolData)1 IMarketSignData (org.cubeengine.module.signmarket.data.IMarketSignData)1 ImmutableMarketSignData (org.cubeengine.module.signmarket.data.ImmutableMarketSignData)1 MarketSignData (org.cubeengine.module.signmarket.data.MarketSignData)1 EntityType (org.spongepowered.api.entity.EntityType)1 User (org.spongepowered.api.entity.living.player.User)1