use of dev.frankheijden.insights.api.addons.Region in project Insights by InsightsPlugin.
the class InsightsPlaceholderExpansion method onPlaceholderRequest.
@Override
public String onPlaceholderRequest(Player player, String identifier) {
if (identifier == null)
return "";
String[] args = identifier.split("_");
switch(args[0].toLowerCase(Locale.ENGLISH)) {
case "limits":
if (args.length < 3)
break;
String itemString = StringUtils.join(args, "_", 2).toUpperCase(Locale.ENGLISH);
final ScanObject<?> item;
try {
item = ScanObject.parse(itemString);
} catch (IllegalArgumentException ex) {
return "";
}
Location location = player.getLocation();
World world = location.getWorld();
UUID worldUid = world.getUID();
LimitEnvironment env = new LimitEnvironment(player, world.getName());
Optional<Limit> limitOptional = plugin.getLimits().getFirstLimit(item, env);
if (!limitOptional.isPresent())
break;
Limit limit = limitOptional.get();
switch(args[1].toLowerCase(Locale.ENGLISH)) {
case "name":
return limit.getLimit(item).getName();
case "max":
return String.valueOf(limit.getLimit(item).getLimit());
case "count":
Optional<Region> regionOptional = plugin.getAddonManager().getRegion(location);
Optional<Storage> storageOptional;
if (regionOptional.isPresent()) {
Region region = regionOptional.get();
storageOptional = plugin.getAddonStorage().get(region.getKey());
} else {
long chunkKey = ChunkUtils.getKey(location);
storageOptional = plugin.getWorldStorage().getWorld(worldUid).get(chunkKey);
}
return storageOptional.map(storage -> String.valueOf(storage.count(limit, item))).orElse("");
default:
break;
}
break;
default:
break;
}
return "";
}
use of dev.frankheijden.insights.api.addons.Region 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);
}
use of dev.frankheijden.insights.api.addons.Region in project Insights by InsightsPlugin.
the class InsightsListener method handleModification.
protected void handleModification(Location location, Consumer<Storage> storageConsumer) {
UUID worldUid = location.getWorld().getUID();
long chunkKey = ChunkUtils.getKey(location);
plugin.getWorldStorage().getWorld(worldUid).get(chunkKey).ifPresent(storageConsumer);
plugin.getAddonManager().getRegion(location).flatMap(region -> plugin.getAddonStorage().get(region.getKey())).ifPresent(storageConsumer);
}
Aggregations