Search in sources :

Example 1 with Lookup

use of org.cubeengine.module.vigil.Lookup in project modules-extra by CubeEngine.

the class VigilLookupCommands method lookup.

@Alias(value = "lookup")
@Command(desc = "Performs a lookup.")
public void lookup(Player context, @Named("radius") int radius) {
    LookupData ld = new LookupData();
    Lookup lookup = new Lookup(ld).with(context.getLocation()).withRadius(radius);
    this.qm.queryAndShow(lookup, context);
}
Also used : Lookup(org.cubeengine.module.vigil.Lookup) LookupData(org.cubeengine.module.vigil.data.LookupData) Command(org.cubeengine.butler.parametric.Command) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Alias(org.cubeengine.butler.alias.Alias)

Example 2 with Lookup

use of org.cubeengine.module.vigil.Lookup in project modules-extra by CubeEngine.

the class QueryManager method queryAndShow.

public // TODO lookup object
void queryAndShow(// TODO lookup object
Lookup lookup, // TODO lookup object
Player player) {
    // TODO lookup cancel previous?
    Future future = queryFuture.get(player.getUniqueId());
    if (future != null && !future.isDone()) {
        i18n.send(ChatTypes.ACTION_BAR, player, MessageType.NEGATIVE, "There is another lookup active!");
        return;
    }
    Query query = buildQuery(lookup);
    future = // Async MongoDB Lookup
    CompletableFuture.supplyAsync(() -> lookup(lookup, query)).thenApply(// Still Async Prepare Reports
    result -> this.prepareReports(lookup, player, result)).thenAcceptAsync(r -> this.show(lookup, player, r), // Resync to show information
    queryShowExecutor);
    queryFuture.put(player.getUniqueId(), future);
}
Also used : Document(org.bson.Document) ChatTypes(org.spongepowered.api.text.chat.ChatTypes) MongoCollection(com.mongodb.client.MongoCollection) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ReportManager(org.cubeengine.module.vigil.report.ReportManager) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Lookup(org.cubeengine.module.vigil.Lookup) Report(org.cubeengine.module.vigil.report.Report) Map(java.util.Map) LinkedList(java.util.LinkedList) ThreadFactory(java.util.concurrent.ThreadFactory) PluginContainer(org.spongepowered.api.plugin.PluginContainer) ExecutorService(java.util.concurrent.ExecutorService) ReportActions(org.cubeengine.module.vigil.report.ReportActions) I18n(org.cubeengine.libcube.service.i18n.I18n) Semaphore(java.util.concurrent.Semaphore) MessageType(org.cubeengine.libcube.service.i18n.formatter.MessageType) SpongeExecutorService(org.spongepowered.api.scheduler.SpongeExecutorService) Sponge(org.spongepowered.api.Sponge) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) UUID(java.util.UUID) Consumer(java.util.function.Consumer) MongoTimeoutException(com.mongodb.MongoTimeoutException) Indexes(com.mongodb.client.model.Indexes) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Receiver(org.cubeengine.module.vigil.Receiver) FindIterable(com.mongodb.client.FindIterable) Queue(java.util.Queue) Player(org.spongepowered.api.entity.living.player.Player) Action(org.cubeengine.module.vigil.report.Action) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future)

Aggregations

Lookup (org.cubeengine.module.vigil.Lookup)2 MongoTimeoutException (com.mongodb.MongoTimeoutException)1 FindIterable (com.mongodb.client.FindIterable)1 MongoCollection (com.mongodb.client.MongoCollection)1 Indexes (com.mongodb.client.model.Indexes)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Queue (java.util.Queue)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)1 Future (java.util.concurrent.Future)1 Semaphore (java.util.concurrent.Semaphore)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 Consumer (java.util.function.Consumer)1