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);
}
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();
}
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;
}
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!");
}
}
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);
}
}
Aggregations