Remove particles FROM player without stopping whole tread

Discussion in 'Spigot Plugin Development' started by Surprisejedi, Apr 13, 2017.

  1. My title might be confusing, but it will make sense when I explain it. Basically, I want to emit particles when a player hits another player, then THE first attacker LOSES their current particles. So basically when a player is punched their particles are transferred!

    Here is my code:

    Code (Java):

    package me.surprisejedi;
    import org.bukkit.Effect;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.scheduler.BukkitRunnable;
    public class PlayerListener implements Listener {
        private final EventHandle plugin;
        public PlayerListener (EventHandle plugin) {
            this.plugin = plugin;
            this.plugin.getServer().getPluginManager().registerEvents(this,  plugin);

        }

        @SuppressWarnings({ "deprecation" })
        @EventHandler

        public void onPlayerHitEvent(final EntityDamageByEntityEvent e) {

            new BukkitRunnable() {
                    public void run() {
         
                    final Entity attacker = e.getEntity();

                    if (attacker instanceof Player) {
                        final Player p = (Player) e.getEntity();
                        p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
                    }

                    }
                }.runTaskTimer(this.plugin, 0, 40);
         
            }
    }

     
    Is there a way to do this?
     
  2. FrostedSnowman

    Resource Staff

    store the bukkit task in a map, and when u need to cancel it, call BukkitRunnable#cancel
     
  3. Wouldn't it make more sense to have a single runnable, which renders all particles for every player (or whatever particles the player even has), and let the hits transfer 'particles' through a simple 'registry' (f.e. decrease the int value of the damaged player by one, and increase the int value of the attacker by one, simply tracked in a Map<Player, Integer>)
     
    • Agree Agree x 2