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