Search in sources :

Example 1 with Messages

use of dev.frankheijden.insights.api.config.Messages in project Insights by InsightsPlugin.

the class CommandScanCache method handleScan.

/**
 * Checks the player's location for a cache and displays the distribution of items.
 */
public void handleScan(Player player, Set<? extends ScanObject<?>> items, boolean displayZeros) {
    Location loc = player.getLocation();
    Optional<Region> optionalRegion = plugin.getAddonManager().getRegion(loc);
    Optional<Storage> optionalStorage;
    // If a region is present, try to fetch cache of the region.
    if (optionalRegion.isPresent()) {
        optionalStorage = plugin.getAddonStorage().get(optionalRegion.get().getKey());
    } else {
        optionalStorage = plugin.getWorldStorage().getWorld(loc.getWorld().getUID()).get(ChunkUtils.getKey(loc.getChunk()));
    }
    if (optionalStorage.isPresent()) {
        var storage = optionalStorage.get();
        var messages = plugin.getMessages();
        // Check which items we need to display & sort them based on their name.
        ScanObject<?>[] displayItems = (items == null ? storage.keys() : items).stream().filter(item -> storage.count(item) != 0 || displayZeros).sorted(Comparator.comparing(ScanObject::name)).toArray(ScanObject[]::new);
        var footer = messages.getMessage(Messages.Key.SCANCACHE_RESULT_FOOTER).addTemplates(Messages.tagOf("area", optionalRegion.map(r -> plugin.getAddonManager().getAddon(r.getAddon()).getAreaName()).orElse("chunk")));
        var message = messages.createPaginatedMessage(messages.getMessage(Messages.Key.SCANCACHE_RESULT_HEADER), Messages.Key.SCANCACHE_RESULT_FORMAT, footer, displayItems, storage::count, item -> Component.text(EnumUtils.pretty(item.getObject())));
        plugin.getScanHistory().setHistory(player.getUniqueId(), message);
        message.sendTo(player, 0);
    } else {
        plugin.getMessages().getMessage(Messages.Key.SCANCACHE_NO_CACHE).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) Storage(dev.frankheijden.insights.api.concurrent.storage.Storage) ScanObject(dev.frankheijden.insights.api.objects.wrappers.ScanObject) Region(dev.frankheijden.insights.api.addons.Region) Location(org.bukkit.Location)

Aggregations

Argument (cloud.commandframework.annotations.Argument)1 CommandMethod (cloud.commandframework.annotations.CommandMethod)1 CommandPermission (cloud.commandframework.annotations.CommandPermission)1 InsightsPlugin (dev.frankheijden.insights.api.InsightsPlugin)1 Region (dev.frankheijden.insights.api.addons.Region)1 InsightsCommand (dev.frankheijden.insights.api.commands.InsightsCommand)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 ScanObject (dev.frankheijden.insights.api.objects.wrappers.ScanObject)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 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Component (net.kyori.adventure.text.Component)1