Particles

Discussion in 'Plugin Development' started by DaanSander, Jan 19, 2015.

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

    DaanSander

    Hello can someone please explain me how to make particles that swing around my head?
     
  2. Offline

    InkzzzMC

  3. Offline

    Zandor300

    Just setup a repeating task and do some math. Just get the players eye location. Add 1 to the y so they don't go in front of the player's screen (which is irritating). Then just add values to the x and z to make a circle add all those locations in an ArrayList. Then everytime the repeating task executes, just play the particle effect on the next location.
     
  4. Offline

    DaanSander

    i get a error when i play effects in the editor: the method playEffect(Location, Effect, int ) from the type player is deprecated

    code:
    Code:
    package me.daansander.particle;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Effect;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Particle extends JavaPlugin {
       
        public void onEnable() {
            Bukkit.getLogger().info("Particles has been set");
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                        p.playEffect(p.getLocation().add(0, 2, 0) , Effect.HEART, 2003);
                    }
                }
               
            }, 0, 5);
        }
    }
    
     
  5. Offline

    Zandor300

    It will still work. But this will only spawn a particle above your head and not around like you described in the main post. If you want that just ask and i'll explain :)
     
  6. Offline

    DaanSander

    i meant it doesnt play the effect
     
  7. Offline

    Zandor300

  8. Offline

    DaanSander

    Last edited: Jan 21, 2015
  9. Offline

    Zandor300

    1. Create a new class called "ParticleEffect" and put https://github.com/DarkBlade12/Part...arkblade12/particleeffect/ParticleEffect.java in it.
    2. Create another class called "ReflectionUtils" and put https://github.com/DarkBlade12/Part...rkblade12/particleeffect/ReflectionUtils.java in it.
    3. Replace in your repeating task
    Code:
    p.playEffect(p.getLocation().add(0, 2, 0) , Effect.HEART, 2003);
    with
    Code:
    ParticleEffect.NAME.display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, double range);
    4. Compile + test.
     
  10. Offline

    DaanSander

    WOW thx man maybe can you explain to me how to make them swing around my head so i have a base for another particles?
     
  11. Offline

    Zandor300

    Create a HashMap<String(playername), Integer(number of location)> for storing the player's animation frame (how i will call it in this example).

    Then in the repeating task:
    Code:
    if(hashmap.get(player.getName()) == null) // Nullchecking because you get a NPE otherwise.
        hashmap.put(player.getName(), 0);
    
    ArrayList<Location> locations = new ArrayList<Location>(); // We store the locations here.
    int radius = 3; // Your circle radius.
    
    // We have to redo this calculation everytime because the player moves and the particles have to move with him.
    for(int x = player.getLocation().getBlockX() - radius ; x <= player.getLocation().getBlockX() + radius ; x++)
      for(int z = player.getLocation().getBlockZ() - radius ; x <= player.getLocation().getBlockZ() + radius ; z++)
        if(Math.round(Math.sqrt(Math.pow(player.getLocation().getBlockX() - x, 2) + Math.pow(player.getLocation().getBlockZ() - z, 2))) == radius)
            locations.add(new Location(Bukkit.getWorld("world"), x, player.getLocation().getY() + 2, z));
    
    ParticleEffect.NAME.display(float offsetX, float offsetY, float offsetZ, float speed, int amount, locations.get(hashmap.get(player.getName())), double range); // Spawn the particle.
    
    hashmap.put(player.getName(), hashmap.get(player.getName() + 1); // Setting the integer to the next frame.
    if(hashmap.get(player.getName() >= locations.size()) // We have to check that the player's frame int isn't outside the size of locations. We get an OOB otherwise.
        hashmap.put(player.getName(), 0);
    player = the player you want the particles to spawn on.
    radius = the radius of the circle.
    hashmap = the hashmap you've created earlier in this post.
    you have to change the ParticleEffect.name.display() to what you want.

    I hope this helped :)

    P.S. Gister was ik op je server en sprak ik HELEMAAL_NIETS. :)
     
  12. Offline

    DaanSander

    ben je nederlands(Are you dutch)?
     
  13. Offline

    Zandor300

    Inderdaad ik ben Nederlands :p Ik heb HELEMAAL_NIETS trouwens nu op Skype.
     
  14. Offline

    DaanSander

    Wat is jouw skype?
    die van mij is DaanSander1
     
  15. Offline

    Zandor300

    But we are getting off-topic here... Did it work?

    (Check je Skype)
     
    Last edited: Jan 22, 2015
  16. Offline

    DaanSander

    it is giving errors:
    The operator >= is undifened for the type(s) string, int
    The method scheduleSyncRepeatingTask(Plugin, Runnable, long, long) in the type BukkitScheduler is not applicable for the arguments (Particle, new Runnable(){})
     
  17. Offline

    Zandor300

    My mistake...

    Code:
    if(hashmap.get(player.getName()) >= locations.size())
     
  18. Offline

    CraftCreeper6

  19. Offline

    Zandor300

    It doesn't care if you just use usernames in this example. Only when things are saved between sessions...
     
  20. Offline

    CraftCreeper6

    @Zandor300
    Unless a player changes their name during their current session. Better safe than sorry.
     
  21. Offline

    Zandor300

    They have to relog before their name changes in the server so when you remove them from your ArrayList when they leave, then it'll be fine.
     
  22. Offline

    CraftCreeper6

    @Zandor300
    Depends, if you are using configs then it's a completely different story.
     
Thread Status:
Not open for further replies.

Share This Page