Async Event

Discussion in 'Spigot Plugin Development' started by minecraftkeba, Jun 2, 2017.

  1. Hello,

    whenever a player breaks a block, i need to check if this player owns the chuck which the block is in. So I do that with a Mysql db and get a boolean from the db. Whenever the event runs I open a Thread, but I'm not able to cancel the event using e.setCancelled in the Thread, is there a way to run a spigot event async?

    Thanks
     
  2. You should not access any of the Spigot API in a different thread or any async manner. Also, it is generally a better option to cache all the required data from a database upon starting the server rather than making queries and database connections constantly; this will take up more system memory, but will greatly increase run-time performance (in most cases).

    Back to your question though, it is hard to say exactly what your issue could be without seeing the code you are using. If you could show the code in question that is not working, we will have a much easier time helping you.
     
  3. Its probably better to cache data per chunk than per World, especially if there's a lot of data in a world (chunks are loaded before a player gets near it anyway, unless they're actually going faster than normally possible - during load, just deny it by default)
     
  4. @EventHandler
    public void onEvent(PlayerInteractEvent e)
    {
    e.setCancelled(true);
    Thread t = new Thread(new Runnable()
    {

    @Override
    public void run()
    {
    e.setCancelled(false);
    }
    });
    t.setPriority(Thread.MAX_PRIORITY);
    t.start();
    }
     
  5. @DarkSeraphim great idea if there is no better idea, i will do that. Thank you <3