Search in sources :

Example 1 with CommandMethod

use of cloud.commandframework.annotations.CommandMethod in project Insights by InsightsPlugin.

the class CommandScanHistory method handleScanHistory.

@CommandMethod("scanhistory <page>")
@CommandPermission("insights.scanregion.tile")
private void handleScanHistory(Player player, @Argument("page") Page page) {
    UUID uuid = player.getUniqueId();
    Optional<Messages.PaginatedMessage<?>> historyOptional = plugin.getScanHistory().getHistory(uuid);
    if (historyOptional.isPresent()) {
        historyOptional.get().sendTo(player, page.page);
    } else {
        plugin.getMessages().getMessage(Messages.Key.SCANHISTORY_NO_HISTORY).sendTo(player);
    }
}
Also used : UUID(java.util.UUID) CommandMethod(cloud.commandframework.annotations.CommandMethod) CommandPermission(cloud.commandframework.annotations.CommandPermission)

Example 2 with CommandMethod

use of cloud.commandframework.annotations.CommandMethod in project Insights by InsightsPlugin.

the class CommandScan method handleCustomScan.

@CommandMethod("custom <items>")
@CommandPermission("insights.scan.custom")
private void handleCustomScan(Player player, @Argument("radius") @Range(min = "0", max = "256") int radius, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk, @Argument("items") ScanObject<?>[] items) {
    List<ScanObject<?>> scanObjects = Arrays.asList(items);
    boolean hasOnlyEntities = scanObjects.stream().allMatch(s -> s.getType() == ScanObject.Type.ENTITY);
    boolean hasOnlyMaterials = scanObjects.stream().allMatch(s -> s.getType() == ScanObject.Type.MATERIAL);
    ScanOptions options;
    if (hasOnlyEntities) {
        options = ScanOptions.entitiesOnly();
    } else if (hasOnlyMaterials) {
        options = ScanOptions.materialsOnly();
    } else {
        options = ScanOptions.scanOnly();
    }
    handleScan(player, radius, new HashSet<>(scanObjects), options, true, groupByChunk);
}
Also used : ScanObject(dev.frankheijden.insights.api.objects.wrappers.ScanObject) ScanOptions(dev.frankheijden.insights.api.concurrent.ScanOptions) CommandMethod(cloud.commandframework.annotations.CommandMethod) CommandPermission(cloud.commandframework.annotations.CommandPermission)

Example 3 with CommandMethod

use of cloud.commandframework.annotations.CommandMethod in project Insights by InsightsPlugin.

the class CommandInsights method displayStatistics.

@CommandMethod("stats")
@CommandPermission("insights.stats")
private void displayStatistics(CommandSender sender) {
    ContainerExecutorService executor = ((Insights) plugin).getExecutor();
    plugin.getMessages().getMessage(Messages.Key.STATS).addTemplates(Messages.tagOf("chunks_scanned", StringUtils.pretty(executor.getCompletedTaskCount())), Messages.tagOf("blocks_scanned", StringUtils.pretty(plugin.getMetricsManager().getTotalBlocksScanned().sum())), Messages.tagOf("queue_size", StringUtils.pretty(executor.getQueueSize()))).sendTo(sender);
}
Also used : Insights(dev.frankheijden.insights.Insights) ContainerExecutorService(dev.frankheijden.insights.concurrent.ContainerExecutorService) CommandMethod(cloud.commandframework.annotations.CommandMethod) CommandPermission(cloud.commandframework.annotations.CommandPermission)

Example 4 with CommandMethod

use of cloud.commandframework.annotations.CommandMethod in project Insights by InsightsPlugin.

the class CommandScanCache method handleCacheClear.

@CommandMethod("clear")
@CommandPermission("insights.scancache.clear")
private void handleCacheClear(Player player) {
    Location loc = player.getLocation();
    Optional<Region> optionalRegion = plugin.getAddonManager().getRegion(loc);
    // If a region is present, try to delete cache of the region.
    if (optionalRegion.isPresent()) {
        plugin.getAddonStorage().remove(optionalRegion.get().getKey());
    } else {
        plugin.getWorldStorage().getWorld(loc.getWorld().getUID()).remove(ChunkUtils.getKey(loc.getChunk()));
    }
    String areaName = optionalRegion.map(r -> plugin.getAddonManager().getAddon(r.getAddon()).getAreaName()).orElse("chunk");
    plugin.getMessages().getMessage(Messages.Key.SCANCACHE_CLEARED).addTemplates(Messages.tagOf("area", areaName)).sendTo(player);
}
Also used : Arrays(java.util.Arrays) CommandPermission(cloud.commandframework.annotations.CommandPermission) EnumUtils(dev.frankheijden.insights.api.utils.EnumUtils) CommandMethod(cloud.commandframework.annotations.CommandMethod) Limit(dev.frankheijden.insights.api.config.limits.Limit) Set(java.util.Set) ChunkUtils(dev.frankheijden.insights.api.utils.ChunkUtils) Storage(dev.frankheijden.insights.api.concurrent.storage.Storage) ScanObject(dev.frankheijden.insights.api.objects.wrappers.ScanObject) Player(org.bukkit.entity.Player) HashSet(java.util.HashSet) Messages(dev.frankheijden.insights.api.config.Messages) InsightsCommand(dev.frankheijden.insights.api.commands.InsightsCommand) Region(dev.frankheijden.insights.api.addons.Region) Location(org.bukkit.Location) Component(net.kyori.adventure.text.Component) Optional(java.util.Optional) RTileEntityTypes(dev.frankheijden.insights.api.reflection.RTileEntityTypes) Constants(dev.frankheijden.insights.api.utils.Constants) Comparator(java.util.Comparator) Argument(cloud.commandframework.annotations.Argument) InsightsPlugin(dev.frankheijden.insights.api.InsightsPlugin) Region(dev.frankheijden.insights.api.addons.Region) Location(org.bukkit.Location) CommandMethod(cloud.commandframework.annotations.CommandMethod) CommandPermission(cloud.commandframework.annotations.CommandPermission)

Aggregations

CommandMethod (cloud.commandframework.annotations.CommandMethod)4 CommandPermission (cloud.commandframework.annotations.CommandPermission)4 ScanObject (dev.frankheijden.insights.api.objects.wrappers.ScanObject)2 Argument (cloud.commandframework.annotations.Argument)1 Insights (dev.frankheijden.insights.Insights)1 InsightsPlugin (dev.frankheijden.insights.api.InsightsPlugin)1 Region (dev.frankheijden.insights.api.addons.Region)1 InsightsCommand (dev.frankheijden.insights.api.commands.InsightsCommand)1 ScanOptions (dev.frankheijden.insights.api.concurrent.ScanOptions)1 Storage (dev.frankheijden.insights.api.concurrent.storage.Storage)1 Messages (dev.frankheijden.insights.api.config.Messages)1 Limit (dev.frankheijden.insights.api.config.limits.Limit)1 RTileEntityTypes (dev.frankheijden.insights.api.reflection.RTileEntityTypes)1 ChunkUtils (dev.frankheijden.insights.api.utils.ChunkUtils)1 Constants (dev.frankheijden.insights.api.utils.Constants)1 EnumUtils (dev.frankheijden.insights.api.utils.EnumUtils)1 ContainerExecutorService (dev.frankheijden.insights.concurrent.ContainerExecutorService)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1