Event calling multiple at the same time or not?

Discussion in 'Plugin Development' started by bars96, Jun 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    bars96

    For example I have that code:
    Code:java
    1. public class MyListener implements Listener {
    2. public MyPlugin plugin;
    3. Block block;
    4.  
    5. public MyListener(MyPlugin instance) {
    6. plugin = instance;
    7. }
    8.  
    9. @EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
    10. private void onPlayerInteract(PlayerInteractEvent e) {
    11. initBlock(e.getBlock());
    12. block.setTypeId(0);
    13. }
    14.  
    15. private void initBlock(Block b) {
    16. block = b;
    17. }
    18. }

    If it turns out that the two players SIMULTANEOUSLY clicked on different blocks, they are deleted ALL (one by one) or just ONE of these blocks? In other words, the body of the event (function "onPlayerInteract") is executed exactly one after the other or Bukkit simultaneously execute them for multiple blocks?

    Is it safe? (global variable "block")
     
  2. Offline

    rfsantos1996

    Well, it'll execute the onPlayerInteract (create event -> initBlock -> set block -> and i'll only run when another event is created)... Since Bukkit/Minecraft is basicly one-threated, it is safe, everything is syncronized (well, this is a good point about using the same thread for everything - they could seperate threads for other things though, Mojang should've thougth about that when programming Minecraft, servers could be even on different computers - like a server for login and storage, other for world and block manipulation and other for population - entities, etc but of course this is hard to do and this doesn't exist on indie games, this is something exremely hard to do/syncronize)
     
    bars96 likes this.
Thread Status:
Not open for further replies.

Share This Page