Search in sources :

Example 6 with Region

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 "";
}
Also used : Limit(dev.frankheijden.insights.api.config.limits.Limit) PlaceholderExpansion(me.clip.placeholderapi.expansion.PlaceholderExpansion) StringUtils(dev.frankheijden.insights.api.utils.StringUtils) 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) UUID(java.util.UUID) Region(dev.frankheijden.insights.api.addons.Region) Location(org.bukkit.Location) World(org.bukkit.World) Locale(java.util.Locale) LimitEnvironment(dev.frankheijden.insights.api.config.LimitEnvironment) Optional(java.util.Optional) InsightsPlugin(dev.frankheijden.insights.api.InsightsPlugin) World(org.bukkit.World) Storage(dev.frankheijden.insights.api.concurrent.storage.Storage) Region(dev.frankheijden.insights.api.addons.Region) LimitEnvironment(dev.frankheijden.insights.api.config.LimitEnvironment) Limit(dev.frankheijden.insights.api.config.limits.Limit) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 7 with Region

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

Example 8 with Region

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);
}
Also used : LimitInfo(dev.frankheijden.insights.api.config.limits.LimitInfo) StringUtils(dev.frankheijden.insights.api.utils.StringUtils) ScanTask(dev.frankheijden.insights.api.tasks.ScanTask) Storage(dev.frankheijden.insights.api.concurrent.storage.Storage) ScanObject(dev.frankheijden.insights.api.objects.wrappers.ScanObject) Player(org.bukkit.entity.Player) Level(java.util.logging.Level) ChunkStorage(dev.frankheijden.insights.api.concurrent.storage.ChunkStorage) Messages(dev.frankheijden.insights.api.config.Messages) ScanOptions(dev.frankheijden.insights.api.concurrent.ScanOptions) ChunkPart(dev.frankheijden.insights.api.objects.chunk.ChunkPart) Block(org.bukkit.block.Block) Location(org.bukkit.Location) World(org.bukkit.World) Chunk(org.bukkit.Chunk) InsightsPlugin(dev.frankheijden.insights.api.InsightsPlugin) TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Material(org.bukkit.Material) Listener(org.bukkit.event.Listener) Limit(dev.frankheijden.insights.api.config.limits.Limit) WorldStorage(dev.frankheijden.insights.api.concurrent.storage.WorldStorage) BlockState(org.bukkit.block.BlockState) InsightsBase(dev.frankheijden.insights.api.objects.InsightsBase) ChunkUtils(dev.frankheijden.insights.api.utils.ChunkUtils) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) Consumer(java.util.function.Consumer) List(java.util.List) Region(dev.frankheijden.insights.api.addons.Region) LimitEnvironment(dev.frankheijden.insights.api.config.LimitEnvironment) Optional(java.util.Optional) AddonStorage(dev.frankheijden.insights.api.concurrent.storage.AddonStorage) DistributionStorage(dev.frankheijden.insights.api.concurrent.storage.DistributionStorage) UUID(java.util.UUID)

Aggregations

Region (dev.frankheijden.insights.api.addons.Region)8 Storage (dev.frankheijden.insights.api.concurrent.storage.Storage)8 Limit (dev.frankheijden.insights.api.config.limits.Limit)8 InsightsPlugin (dev.frankheijden.insights.api.InsightsPlugin)6 ScanObject (dev.frankheijden.insights.api.objects.wrappers.ScanObject)6 ChunkUtils (dev.frankheijden.insights.api.utils.ChunkUtils)6 Optional (java.util.Optional)6 UUID (java.util.UUID)6 Location (org.bukkit.Location)6 Player (org.bukkit.entity.Player)6 LimitEnvironment (dev.frankheijden.insights.api.config.LimitEnvironment)5 Messages (dev.frankheijden.insights.api.config.Messages)5 LimitInfo (dev.frankheijden.insights.api.config.limits.LimitInfo)5 World (org.bukkit.World)5 AddonStorage (dev.frankheijden.insights.api.concurrent.storage.AddonStorage)4 ChunkStorage (dev.frankheijden.insights.api.concurrent.storage.ChunkStorage)4 DistributionStorage (dev.frankheijden.insights.api.concurrent.storage.DistributionStorage)4 WorldStorage (dev.frankheijden.insights.api.concurrent.storage.WorldStorage)4 ChunkPart (dev.frankheijden.insights.api.objects.chunk.ChunkPart)4 StringUtils (dev.frankheijden.insights.api.utils.StringUtils)4