Search in sources :

Example 6 with PermissionDeniedException

use of org.cubeengine.libcube.service.command.exception.PermissionDeniedException in project modules-extra by CubeEngine.

the class EditModeCommand method admin.

@Command(desc = "Changes the sign to an admin-sign")
public void admin(Player context) {
    if (!context.hasPermission(module.perms().EDIT_ADMIN.getId())) {
        throw new PermissionDeniedException(module.perms().EDIT_ADMIN);
    }
    MarketSignData data = manager.getCurrentData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No active sign!");
        return;
    }
    data.setOwner(IMarketSignData.ADMIN_SIGN);
    Location<World> loc = manager.updateData(data, context);
    manager.executeShowInfo(data, context, loc);
}
Also used : 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) Command(org.cubeengine.butler.parametric.Command) ConversationCommand(org.cubeengine.libcube.service.command.conversation.ConversationCommand)

Example 7 with PermissionDeniedException

use of org.cubeengine.libcube.service.command.exception.PermissionDeniedException in project modules-extra by CubeEngine.

the class Kit method give.

public boolean give(CommandSource sender, Player player, boolean force) {
    if (!force && this.getPermission() != null) {
        if (!sender.hasPermission(getPermission().getId())) {
            throw new PermissionDeniedException(getPermission());
        }
    }
    if (!force) {
        if (limitUsagePerPlayer > 0) {
            boolean reached = false;
            Optional<KitData> kitData = player.get(KitData.class);
            if (kitData.isPresent()) {
                reached = limitUsagePerPlayer <= kitData.get().getTimes().getOrDefault(this.name, 0);
            }
            if (reached) {
                // TODO this messages are not displayed & translated
                throw new IncorrectUsageException(false, "Kit-limit reached.");
            }
        }
        if (limitUsageDelay > 0) {
            boolean inDelay = false;
            // System.currentTimeMillis() - lastUsage < limitUsageDelay)
            Optional<KitData> kitData = player.get(KitData.class);
            if (kitData.isPresent()) {
                inDelay = limitUsageDelay <= System.currentTimeMillis() - kitData.get().getTime().getOrDefault(this.name, System.currentTimeMillis());
            }
            if (inDelay) {
                throw new IncorrectUsageException(false, "This kit isn't available at the moment. Try again later!");
            }
        }
    }
    // TODO what if not enough place
    items.forEach(i -> player.getInventory().offer(i.copy()));
    KitData kitData = player.get(KitData.class).orElse(null);
    if (kitData == null) {
        kitData = new KitData();
    }
    kitData.getTime().put(name, System.currentTimeMillis());
    kitData.getTimes().put(name, kitData.getTimes().getOrDefault(name, 0) + 1);
    player.offer(kitData);
    this.executeCommands(player);
    return true;
}
Also used : KitData(org.cubeengine.module.module.kits.data.KitData) PermissionDeniedException(org.cubeengine.libcube.service.command.exception.PermissionDeniedException) IncorrectUsageException(org.cubeengine.butler.parameter.IncorrectUsageException)

Aggregations

PermissionDeniedException (org.cubeengine.libcube.service.command.exception.PermissionDeniedException)7 Command (org.cubeengine.butler.parametric.Command)5 IMarketSignData (org.cubeengine.module.signmarket.data.IMarketSignData)5 ImmutableMarketSignData (org.cubeengine.module.signmarket.data.ImmutableMarketSignData)5 MarketSignData (org.cubeengine.module.signmarket.data.MarketSignData)5 World (org.spongepowered.api.world.World)5 ConversationCommand (org.cubeengine.libcube.service.command.conversation.ConversationCommand)4 Restricted (org.cubeengine.butler.filter.Restricted)1 IncorrectUsageException (org.cubeengine.butler.parameter.IncorrectUsageException)1 TooFewArgumentsException (org.cubeengine.butler.parameter.TooFewArgumentsException)1 KitData (org.cubeengine.module.module.kits.data.KitData)1 Player (org.spongepowered.api.entity.living.player.Player)1