Particles around the player

Discussion in 'Plugin Development' started by Smartloser, Jan 17, 2014.

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

    Smartloser



    I am trying to make something like that. Now, I have this code:

    Code:java
    1.  
    2. for(Player player : Bukkit.getServer().getOnlinePlayers()) {
    3.  
    4. Handler h = new Handler();
    5. try
    6. {
    7. h.getLocation(player);
    8. Thread.sleep(150);
    9. }
    10. catch(Exception e)
    11. {
    12. System.out.print(e);
    13. }
    14.  
    15.  
    16.  
    17.  


    h.getLocation bascially spawns the hearts (7 hearts) next to the player. Now, when I use this code the server is lagging badly, as MoveEvent is checking every tick or mouse move, which is causing massive spawn. Now, I was wondering how should I spawn the hearts without making the server lag? thank you.

    Regards,
    Smartloser.
     
  2. Offline

    Niknea

    Smartloser correct me if I'm wrong, however isint that the effects you get when you right click a note block or juke box?
     
  3. Offline

    Blingdaddy1

  4. Offline

    Smartloser

    Niknea I actually have no idea haha, I am more interested in the hearts effect than the other one :p
     
  5. Offline

    ShearsSheep

  6. Offline

    xTrollxDudex

    Smartloser
    I think you can construct this by sending one particle (yes, there is a parameter for that) with an offset per each position on a circle over the player's head.
     
    Garris0n likes this.
  7. Offline

    DarkBladee12

    Smartloser You'd have to get the locations of a circle with the center of a block that is above the players head and then just play a particle effect at each location with my library with amount set to 1 and every offset set to 0, this will the particle cause to be spawned exactly at a location ;)
     
  8. Offline

    Garris0n

  9. Offline

    Smartloser

    Updated with a new problem, any suggestions?
     
  10. Offline

    LCastr0

    Niknea yes, it is, but at the server he showed (I don't know if I can say the name here, so I'll say Hy, pixel.), there's a special command for MVP+, Youtubers, Helpers, Mods and Admins, where you do /pp, and then select a particle to spawn above your head
     
  11. Offline

    xTigerRebornx

    Smartloser Unless you are using this on a different thread, the source of your lag is this
    Code:
    Thread.sleep(150);
    You are making the entire server sleep with this, locking it up
     
  12. Offline

    saturnine_nl

    there is a way to make (ab)use of the onplayerMove event without lagging.
    This code can excute as a very accurate timer without causing any lag on the server.
    Make sure you set the interval bigger than the time it takes to excute your code.

    Greets Sat

    Code:java
    1. private HashMap<UUID,Long> playerLocation =new HashMap<UUID,Location>();
    2. private HashMap<UUID,Long> movingTimer =new HashMap<UUID,Long>();
    3.  
    4. private Long movingInterval=1000L;
    5.  
    6. private UUID playerID;
    7.  
    8. @EventHandler(priority=EventPriority.NORMAL)
    9. public void onPlayerMove(PlayerMoveEvent event)
    10. {
    11.  
    12. player=event.getPlayer();
    13. playerID=player.getUniqueId();
    14.  
    15. // initialize hashmaps
    16.  
    17. if(movingTimer.get(playerID)==null){movingTimer.put(playerID, System.currentTimeMillis());}
    18. if(playerLocation.get(playerID)==null){playerLocation.put(playerID,player.getLocation());}
    19.  
    20. // run code every movingInterval milliseconds
    21.  
    22. if(System.currentTimeMillis()-movingTimer.get(playerID)>=movingInterval)
    23. {
    24.  
    25. // store new time
    26.  
    27. movingTimer.put(playerID, System.currentTimeMillis());
    28.  
    29. // get stored location
    30.  
    31. playerLoc=plugin.playerLocation.get(playerID);
    32.  
    33. // get current location
    34.  
    35. playerX=player.getLocation().getBlockX();
    36. playerY=player.getLocation().getBlockY();
    37. playerZ=player.getLocation().getBlockZ();
    38.  
    39. // player has moved after last check
    40.  
    41. if(playerLoc.getBlockX()!=playerX || playerLoc.getBlockY()!=playerY || playerLoc.getBlockZ()!=playerZ)
    42. {
    43. // your code comes here
    44. }
    45. }
    46. }
     
Thread Status:
Not open for further replies.

Share This Page