Search in sources :

Example 1 with Permission

use of org.cubeengine.libcube.service.permission.Permission in project core by CubeEngine.

the class ContainerCommand method addCommand.

@Override
public boolean addCommand(CommandBase command) {
    if (!(command instanceof AliasCommand) && command.getDescriptor() instanceof CubeDescriptor) {
        PermissionManager pm = manager.getPermissionManager();
        Class owner = getDescriptor().getOwner();
        Permission basePerm = pm.getBasePermission(owner);
        Permission cmdPerm = pm.getPermission(basePerm.getId() + ".command");
        if (cmdPerm == null) {
            // TODO Description for BaseCommand Permission
            cmdPerm = pm.register(owner, "command", "Allows using all commands for this module", null);
        }
        // gets the container permission
        Permission thisPerm = getDescriptor().registerPermission(pm, cmdPerm);
        // register the added cmd permission
        ((CubeDescriptor) command.getDescriptor()).registerPermission(pm, thisPerm);
    }
    return super.addCommand(command);
}
Also used : AliasCommand(org.cubeengine.butler.alias.AliasCommand) PermissionManager(org.cubeengine.libcube.service.permission.PermissionManager) CommandPermission(org.cubeengine.libcube.service.command.annotation.CommandPermission) Permission(org.cubeengine.libcube.service.permission.Permission) RawPermission(org.cubeengine.libcube.service.command.property.RawPermission)

Example 2 with Permission

use of org.cubeengine.libcube.service.permission.Permission in project core by CubeEngine.

the class CubeCommandDescriptor method registerPermission.

@Override
public Permission registerPermission(PermissionManager pm, Permission parent) {
    if (!getPermission().isRegistered()) {
        Permission thisPerm = getPermission().fallbackDescription("Allows using the command " + getName()).registerPermission(getOwner(), pm, parent);
        registerParameterPermissions(pm, thisPerm, getParameters());
    }
    return getPermission().getRegistered();
}
Also used : Permission(org.cubeengine.libcube.service.permission.Permission) RawPermission(org.cubeengine.libcube.service.command.property.RawPermission)

Example 3 with Permission

use of org.cubeengine.libcube.service.permission.Permission in project core by CubeEngine.

the class CubeCommandManager method addCommand.

@Override
public boolean addCommand(CommandBase command) {
    if (command instanceof AliasCommand) {
        Set<CommandBase> cmds = commands.computeIfAbsent(((AliasCommand) command).getTarget(), k -> new HashSet<>());
        cmds.add(command);
    }
    if (command.getDescriptor() instanceof CubeDescriptor) {
        CubeDescriptor descriptor = (CubeDescriptor) command.getDescriptor();
        String name = mm.getModuleName(descriptor.getOwner()).orElse(descriptor.getOwner().getSimpleName());
        Permission parent = pm.register(descriptor.getOwner(), "command", "Allows using all commands of " + name, null);
        descriptor.registerPermission(pm, parent);
    }
    boolean b = super.addCommand(command);
    if (!(command instanceof AliasCommand) || ((AliasDescriptor) command.getDescriptor()).mainDescriptor().getDispatcher() != this) {
        Optional<CommandMapping> mapping = registerSpongeCommand(command.getDescriptor());
        if (mapping.isPresent()) {
            mappings.put(command, mapping.get());
            commandLogger.debug("Registered command: " + mapping.get().getPrimaryAlias());
            return b;
        }
        commandLogger.warn("Command was not registered successfully!");
    }
    return b;
}
Also used : AliasCommand(org.cubeengine.butler.alias.AliasCommand) CommandBase(org.cubeengine.butler.CommandBase) CommandMapping(org.spongepowered.api.command.CommandMapping) Permission(org.cubeengine.libcube.service.permission.Permission)

Example 4 with Permission

use of org.cubeengine.libcube.service.permission.Permission in project modules-extra by CubeEngine.

the class Spawner method onInteract.

@Listener(order = POST)
public void onInteract(InteractBlockEvent.Secondary event, @First Player player) {
    if (!event.getTargetBlock().getLocation().isPresent()) {
        return;
    }
    Location<World> block = event.getTargetBlock().getLocation().get();
    if (block.getBlockType().equals(MOB_SPAWNER) && player.getItemInHand(MAIN_HAND).map(i -> i.getType().equals(ItemTypes.SPAWN_EGG)).orElse(false)) {
        event.setCancelled(true);
        if (block.get(SPAWNER_ENTITIES).map(RandomObjectTable::isEmpty).orElse(false)) {
            ItemStack itemInHand = player.getItemInHand(MAIN_HAND).get();
            EntityType type = itemInHand.get(Keys.SPAWNABLE_ENTITY_TYPE).get();
            Permission perm = this.perms.get(type);
            if (perm == null) {
                this.initPerm(type);
                perm = this.perms.get(type);
            }
            if (perm == null && !player.hasPermission(eggPerms.getId())) {
                i18n.send(ACTION_BAR, player, NEGATIVE, "Invalid SpawnEgg!");
                return;
            }
            if (perm != null && !player.hasPermission(perm.getId())) {
                i18n.send(ACTION_BAR, player, NEGATIVE, "You are not allowed to change Monster Spawner to this EntityType!");
                return;
            }
            WeightedTable<EntityArchetype> spawns = new WeightedTable<>();
            EntityArchetype nextSpawn = EntityArchetype.builder().type(type).build();
            spawns.add(nextSpawn, 1);
            block.offer(SPAWNER_ENTITIES, spawns);
            block.offer(SPAWNER_NEXT_ENTITY_TO_SPAWN, new WeightedSerializableObject<>(nextSpawn, 1));
            if (!player.gameMode().get().equals(CREATIVE)) {
                itemInHand.setQuantity(itemInHand.getQuantity() - 1);
                player.setItemInHand(MAIN_HAND, itemInHand);
            }
            i18n.send(ACTION_BAR, player, POSITIVE, "Monster Spawner activated!");
            return;
        }
        i18n.send(ACTION_BAR, player, NEGATIVE, "You can only change inactive Monster Spawner!");
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) Permission(org.cubeengine.libcube.service.permission.Permission) World(org.spongepowered.api.world.World) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 5 with Permission

use of org.cubeengine.libcube.service.permission.Permission in project modules-extra by CubeEngine.

the class Spawner method initPerm.

private void initPerm(EntityType... types) {
    for (EntityType type : types) {
        Permission child = pm.register(Spawner.class, type.getName(), "Allows creating " + type.getName() + " spawners", eggPerms);
        this.perms.put(type, child);
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Permission(org.cubeengine.libcube.service.permission.Permission)

Aggregations

Permission (org.cubeengine.libcube.service.permission.Permission)6 AliasCommand (org.cubeengine.butler.alias.AliasCommand)2 RawPermission (org.cubeengine.libcube.service.command.property.RawPermission)2 EntityType (org.spongepowered.api.entity.EntityType)2 Listener (org.spongepowered.api.event.Listener)2 CommandBase (org.cubeengine.butler.CommandBase)1 CommandPermission (org.cubeengine.libcube.service.command.annotation.CommandPermission)1 PermissionManager (org.cubeengine.libcube.service.permission.PermissionManager)1 RulebookCommands (org.cubeengine.module.rulebook.bookManagement.RulebookCommands)1 RulebookManager (org.cubeengine.module.rulebook.bookManagement.RulebookManager)1 CommandMapping (org.spongepowered.api.command.CommandMapping)1 EntityArchetype (org.spongepowered.api.entity.EntityArchetype)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 WeightedTable (org.spongepowered.api.util.weighted.WeightedTable)1 World (org.spongepowered.api.world.World)1