Search in sources :

Example 1 with ConfigWorld

use of org.cubeengine.libcube.service.config.ConfigWorld in project modules-extra by CubeEngine.

the class VigilConfig method getDisabledReports.

public List<Class<? extends Report>> getDisabledReports(World world) {
    List<Class<? extends Report>> reports = disabledReportsMap.get(world.getUniqueId());
    if (reports == null) {
        reports = new ArrayList<>();
        disabledReportsMap.put(world.getUniqueId(), reports);
        ConfigWorld cWorld = new ConfigWorld(world);
        for (String name : disabledReports.getOrDefault(cWorld, Collections.emptyList())) {
            if ("*".equals(name)) {
                name = "Report";
            }
            Report.getReport(name).ifPresent(reports::add);
        }
        if (!reports.isEmpty()) {
            List<String> list = new ArrayList<>();
            disabledReports.put(cWorld, list);
            // Save long names
            reports.forEach(c -> list.add(c.getClass().getName()));
            this.save();
        }
    }
    return reports;
}
Also used : ConfigWorld(org.cubeengine.libcube.service.config.ConfigWorld) Report(org.cubeengine.module.vigil.report.Report) ArrayList(java.util.ArrayList)

Example 2 with ConfigWorld

use of org.cubeengine.libcube.service.config.ConfigWorld in project modules-extra by CubeEngine.

the class VigilAdminCommands method setReportActive.

@Command(desc = "enables or disables reports in a world")
public // TODO completer
void setReportActive(// TODO completer
CommandSource ctx, // TODO completer
World world, // TODO completer
String name, // TODO completer
@Default boolean enable) {
    Class<? extends Report> report = "*".equals(name) ? Report.class : Report.getReport(name).orElse(null);
    if (report == null) {
        // TODO suggest?
        i18n.send(ctx, NEGATIVE, "Unknown Report: {name}", name);
        return;
    }
    List<String> list = module.getConfig().disabledReports.computeIfAbsent(new ConfigWorld(world), w -> new ArrayList<>());
    if (enable) {
        i18n.send(ctx, POSITIVE, "Report {name} is now enabled in {world}", name, world);
        list.remove(name);
    } else {
        i18n.send(ctx, POSITIVE, "Report {name} is now disabled in {world}", name, world);
        list.add(name);
    }
    module.getConfig().markDirty(world);
    module.getConfig().save();
}
Also used : ConfigWorld(org.cubeengine.libcube.service.config.ConfigWorld) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Command(org.cubeengine.butler.parametric.Command)

Aggregations

ConfigWorld (org.cubeengine.libcube.service.config.ConfigWorld)2 ArrayList (java.util.ArrayList)1 Command (org.cubeengine.butler.parametric.Command)1 ContainerCommand (org.cubeengine.libcube.service.command.ContainerCommand)1 Report (org.cubeengine.module.vigil.report.Report)1