SBPrime / AsyncWorldEdit-Premium

Async WorldEdit - Edit millions of blocks without lag! (Premium version)
Other
19 stars 4 forks source link

How to get the number of blocks currently in the queue? #79

Closed kpalang closed 8 years ago

kpalang commented 8 years ago

Hello, I need to get current queue size to decide, if next job is allowed by my players. I have looked at several progress display extensions https://github.com/SBPrime/AsyncWorldEdit but I as I understand, they only work when pasting is in progress. I basically want to copy /awe jobs behavior, but instead of outputting the results to a string message, the variables would be available for separate use.

Thanks in advance, TCS

SBPrime commented 8 years ago

The progress display display runs for all jobs.

Currently there is no event for block queue change. There are events informing you of Job added/removed and job state changed (indicates that all blocks are placed). To get the exact number of queued blocks please do:

  1. Get AWE API
  2. Get PlayerManager
  3. Get the PlayerEntry (from PlayerManager)
  4. Get BlockPlacer
  5. Use getPlayerEvents to get the current BlockPlacer player queue (can be removed and recreated when operations are performed so do no cache)
  6. Finally use getQueue to get all operations queued for player

For API please go to: https://github.com/SBPrime/AsyncWorldEdit-API

kpalang commented 8 years ago

Alright, now I'm getting NPE, on the Queue declaration: IAsyncWorldEdit asyncWorldEdit = (IAsyncWorldEdit) Bukkit.getPluginManager().getPlugin("AsyncWorldEdit"); IPlayerEntry playerEntry = asyncWorldEdit.getPlayerManager().getConsolePlayer; IBlockPlacer iBlockPlacer = asyncWorldEdit.getBlockPlacer(); Queue<IBlockPlacerEntry> iBlockPlacerEntryQueue = iBlockPlacer.getPlayerEvents(playerEntry).getQueue();

Also, do i understand correctly that i need to get the size of the queue to get the number of blocks still to place?

TCS

SBPrime commented 8 years ago

You get NPE because the BlocksPlacer has the entry ONLY if the player has any operations queued. If the queue is empty the entry is null.

Yes to get the amount of blocks you need to get the size. I don't know what exactly are you planning to to bu I suggest using the progress display API.

kpalang commented 8 years ago

Alright, i got the first method working. How would I use the mentioned Progress Display API? I need the time left variable. I noticed a setMessage method in the IProrgressDisplay, but as far as I understand it's a setter, not getter.

TCS

kpalang commented 8 years ago

I think I got everything I need. I understood how interfaces work and I should manage on my own now. Thank you once again for answering just enough to lead me on the right track!

TCS

SBPrime commented 8 years ago

Ok,if you have more questions don't hesitate to ask.