Search in sources :

Example 1 with PermissionDeniedException

use of org.cubeengine.libcube.service.command.exception.PermissionDeniedException 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)

Example 2 with PermissionDeniedException

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

the class MarketSignManager method setSign.

public void setSign(Location<World> loc, Player player) {
    if (activeSigns.values().contains(loc)) {
        i18n.send(ACTION_BAR, player, NEGATIVE, "Someone else is editing this sign!");
        return;
    }
    MarketSignData data = loc.get(MarketSignData.class).get();
    if (data.isAdminOwner()) {
        if (!player.hasPermission(module.perms().EDIT_ADMIN.getId())) {
            throw new PermissionDeniedException(module.perms().EDIT_ADMIN);
        }
    } else {
        if (data.isOwner(player.getUniqueId())) {
            if (!player.hasPermission(module.perms().EDIT_PLAYER_SELF.getId())) {
                throw new PermissionDeniedException(module.perms().EDIT_PLAYER_SELF);
            }
        } else {
            if (!player.hasPermission(module.perms().EDIT_PLAYER_OTHER.getId())) {
                throw new PermissionDeniedException(module.perms().EDIT_PLAYER_OTHER);
            }
        }
    }
    Location<World> last = activeSigns.put(player.getUniqueId(), loc);
    if (last != null) {
        ImmutableMarketSignData prevData = last.get(MarketSignData.class).map(MarketSignData::asImmutable).orElse(previousSign.get(player.getUniqueId()));
        previousSign.put(player.getUniqueId(), prevData);
        updateSignText(prevData.asMutable(), last);
    }
    updateSignText(loc.get(MarketSignData.class).get(), loc);
    i18n.send(ACTION_BAR, player, POSITIVE, "Changed active sign!");
}
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)

Example 3 with PermissionDeniedException

use of org.cubeengine.libcube.service.command.exception.PermissionDeniedException 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)

Example 4 with PermissionDeniedException

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

the class EditModeCommand method player.

@Command(desc = "Changes the sign to an player-sign")
public void player(Player context) {
    if (!context.hasPermission(module.perms().EDIT_PLAYER_SELF.getId())) {
        throw new PermissionDeniedException(module.perms().EDIT_PLAYER_SELF);
    }
    MarketSignData data = manager.getCurrentData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No active sign!");
        return;
    }
    if (data.isAdminOwner()) {
        data.setSize(6);
    }
    data.setOwner(context.getUniqueId());
    data.setStock(0);
    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 5 with PermissionDeniedException

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

the class EditModeCommand method owner.

@Command(desc = "Changes the signs owner")
public void owner(Player context, User owner) {
    if (!context.equals(owner)) {
        if (!context.hasPermission(module.perms().EDIT_PLAYER_OTHER.getId())) {
            throw new PermissionDeniedException(module.perms().EDIT_PLAYER_OTHER);
        }
    } else {
        if (!context.hasPermission(module.perms().EDIT_PLAYER_SELF.getId())) {
            throw new PermissionDeniedException(module.perms().EDIT_PLAYER_SELF);
        }
    }
    MarketSignData data = manager.getCurrentData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No active sign!");
        return;
    }
    data.setOwner(owner.getUniqueId());
    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)

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