Particle not removing on death?

Discussion in 'Plugin Development' started by Treeline1, Jan 23, 2015.

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

    Treeline1

    ATM I am making a plugin where the player chooses a particle per life and keeps it until death. ATM the particle doesnt get removed on death and i am not sure why :/ Anyone know?

    Code:
    package me.liam.commands;
    
    import me.liam.main.Kitpvp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class Flames implements CommandExecutor {
    
        private Kitpvp plugin;
        public Flames(Kitpvp instance){
            this.plugin = instance;
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
            if(!(sender instanceof Player)){
                return false;
            }
    
            final Player player = (Player)sender;
    
    
            if(cmd.getName().equalsIgnoreCase("flames")){
                if(!sender.hasPermission("flames.set")){
                    sender.sendMessage(ChatColor.RED + "You do not have permission to use this particle!");
                    return true;
                }else if(!(this.plugin.Flames.contains(player.getName()))){
                    if(!(this.plugin.particleused.contains(player.getName()))){
                        this.plugin.Flames.add(player.getName());
                        this.plugin.particleused.add(player.getName());
    
                        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                            public void run() {
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.2, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0.5), 10);
                                ParticleEffect.LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                                ParticleEffect.DRIP_LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                            }
                        }, 2, 20);
    
                    }
                }
            }
    
            return true;
        }
    
    }
    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            Player player = event.getEntity().getPlayer();
            String msg = event.getDeathMessage();
            msg = ChatColor.RED + msg;
            if(this.plugin.kitused.contains(player.getName())){
                this.plugin.kitused.remove(player.getName());
                if(this.plugin.KitCommand.contains(player.getName())){
                    this.plugin.KitCommand.remove(player.getName());
                }else if(this.plugin.ArcherCommand.contains(player.getName())){
                    this.plugin.ArcherCommand.remove(player.getName());
                }else if(this.plugin.ScoutCommand.contains(player.getName())){
                    this.plugin.ScoutCommand.remove(player.getName());
                }else if(this.plugin.SquashCommand.contains(player.getName())){
                    this.plugin.SquashCommand.remove(player.getName());
                }else if(this.plugin.HopperCommand.contains(player.getName())){
                    this.plugin.HopperCommand.remove(player.getName());
                }else if(this.plugin.MarioCommand.contains(player.getName())){
                    this.plugin.MarioCommand.remove(player.getName());
                }else if(this.plugin.RageCommand.contains(player.getName())){
                    this.plugin.RageCommand.remove(player.getName());
                }else if(this.plugin.FishermanCommand.contains(player.getName())){
                    this.plugin.FishermanCommand.remove(player.getName());
                }else if(this.plugin.PilotCommand.contains(player.getName())){
                    this.plugin.PilotCommand.remove(player.getName());
                }else if(this.plugin.JuggernautCommand.contains(player.getName())){
                    this.plugin.JuggernautCommand.remove(player.getName());
                }else if(this.plugin.SniperCommand.contains(player.getName())){
                    this.plugin.SniperCommand.remove(player.getName());
                }else if(this.plugin.SquidCommand.contains(player.getName())){
                    this.plugin.SquidCommand.remove(player.getName());
                }else if(this.plugin.GravitatorCommand.contains(player.getName())){
                    this.plugin.GravitatorCommand.remove(player.getName());
                }else if(this.plugin.RemoverCommand.contains(player.getName())){
                    this.plugin.RemoverCommand.remove(player.getName());
                }
            }
            if(this.plugin.particleused.contains(player.getName())){
                this.plugin.particleused.remove(player.getName());
                if(this.plugin.Hearts.contains(player.getName())){
                    this.plugin.Hearts.remove(player.getName());
                }else if(this.plugin.Smoke.contains(player.getName())){
                    this.plugin.Smoke.remove(player.getName());
                }else if(this.plugin.Flames.contains(player.getName())){
                    this.plugin.Flames.remove(player.getName());
                }
            }
        }
      
      
    
    Its removing them from the list, but just not getting rid of the particles.
     
  2. Offline

    Skionz

    @Treeline1 Use Java naming conventions. The reason the particles continue is because you never cancel the Scheduler.
     
    mine-care likes this.
  3. Offline

    Treeline1

    Wait so how do I cancel it?
     
  4. Offline

    Skionz

  5. Offline

    Treeline1

    Ok, but if I put that in there it stops the particles after 1 use... To do it on the if statement?
     
  6. Offline

    Skionz

    @Treeline1 Use it whenever you wish to stop the effect.
     
  7. Offline

    Treeline1

    Ok, so atm I have this:
    Code:
    package me.liam.commands;
    
    import me.liam.main.Kitpvp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.PlayerDeathEvent;
    
    public class Smoke implements CommandExecutor {
    
        private Kitpvp plugin;
        public Smoke(Kitpvp instance){
            this.plugin = instance;
        }
        static int task;
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            Bukkit.getScheduler().cancelTask(task);
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
            if(!(sender instanceof Player)){
                return false;
            }
    
            final Player player = (Player)sender;
    
    
            if(cmd.getName().equalsIgnoreCase("smoke")){
                if(!sender.hasPermission("smoke.set")){
                    sender.sendMessage(ChatColor.RED + "You do not have permission to use this particle!");
                    return true;
                }else if(!(this.plugin.Smoke.contains(player.getName()))){
                    if(!(this.plugin.particleused.contains(player.getName()))){
                        this.plugin.Smoke.add(player.getName());
                        this.plugin.particleused.add(player.getName());
                        task = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                            public void run() {
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.3, 0), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 2.3, 0), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 2.3, 0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.3, 0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 2.3, 0), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 2.3, -0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.3, -0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 2.3, -0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 2.3, 0.5), 3);
    
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0, 0), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0, 0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0, 0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0, 0), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0, -0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0, -0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0, -0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0, 0.5), 2);
    
                            }
                        }, 2, 20);
                    }
    
                }
            }
    
            return true;
        }
    
    }
    Still doesn't get rid... What do I need here? I assume I actually need to define the player on the death event, how do I define him just here?? Because everything I try it doesnt work xD
     
  8. Offline

    Skionz

    @Treeline1 The task's id is player specific due to the way you using it, but you are storing it completely wrong. Store it along with the Player in a Map, but make sure to clean it up when necessary.
     
  9. Offline

    Treeline1

    Soo something like this? It isnt right... But Is this what your talking about?
    Code:
    package me.liam.commands;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import me.liam.main.Kitpvp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.PlayerDeathEvent;
    
    public class Smoke implements CommandExecutor {
        private static List<String> smokerunner = new ArrayList<String>();
        private Kitpvp plugin;
        public Smoke(Kitpvp instance){
            this.plugin = instance;
        }
        static int task;
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            if(event.getEntity() instanceof Player){
                Player p = (Player) event.getEntity();
                Smoke.smokerunner.remove(p.getName());
            }
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
            if(!(sender instanceof Player)){
                return false;
            }
    
            final Player player = (Player)sender;
    
    
            if(cmd.getName().equalsIgnoreCase("smoke")){
                if(!sender.hasPermission("smoke.set")){
                    sender.sendMessage(ChatColor.RED + "You do not have permission to use this particle!");
                    return true;
                }else if(!(this.plugin.Smoke.contains(player.getName()))){
                    if(!(this.plugin.particleused.contains(player.getName()))){
                        this.plugin.Smoke.add(player.getName());
                        this.plugin.particleused.add(player.getName());
                        Smoke.smokerunner.add(sender.getName());
                        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                           
                            public void run() {
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.3, 0), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 2.3, 0), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 2.3, 0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.3, 0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 2.3, 0), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 2.3, -0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.3, -0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 2.3, -0.5), 3);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 2.3, 0.5), 3);
    
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0, 0), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0, 0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0, 0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0, 0), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0, -0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0, -0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0, -0.5), 2);
                                ParticleEffect.SMOKE_LARGE.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0, 0.5), 2);
    
                            }
                        }, 2, 20);
                    }
    
                }
            }
    
            return true;
        }
    
    }
     
  10. Offline

    Skionz

  11. Offline

    Treeline1

    :/ ?? How am I suppose to story a Schedular in an array?
     
  12. Offline

    WinX64

    Store the id of the task you got, after calling scheduleSyncDelayedTask. Like you were doing earlier.
    Code:
    int task = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plu...
    Now that you have the id of the task, all you have to do is store it for later use. Like Skionz told you, you can easily do this with a map, not a list.
     
  13. Offline

    Treeline1

    Ahh ok... So I have
    Code:
    package me.liam.commands;
    
    import java.util.HashMap;
    
    import me.liam.main.Kitpvp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.PlayerDeathEvent;
    
    public class Flames implements CommandExecutor {
    
        private Kitpvp plugin;
        public Flames(Kitpvp instance){
            this.plugin = instance;
        }
        HashMap<String, Integer> ca = new HashMap<String, Integer>();
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            Player player = event.getEntity().getPlayer();
            Bukkit.getServer().getScheduler().cancelTask(ca);
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
            if(!(sender instanceof Player)){
                return false;
            }
    
            final Player player = (Player)sender;
    
    
            if(cmd.getName().equalsIgnoreCase("flames")){
                if(!sender.hasPermission("flames.set")){
                    sender.sendMessage(ChatColor.RED + "You do not have permission to use this particle!");
                    return true;
                }else if(!(this.plugin.Flames.contains(player.getName()))){
                    if(!(this.plugin.particleused.contains(player.getName()))){
                        this.plugin.Flames.add(player.getName());
                        this.plugin.particleused.add(player.getName());
    
                        int ca = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                            public void run() {
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.2, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0.5), 10);
                                ParticleEffect.LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                                ParticleEffect.DRIP_LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                            }
                        }, 2, 20);
    
                    }
                }
            }
    
            return true;
        }
    
    }
    Is that kinda what it means now?
     
  14. Offline

    WinX64

    Almost! Once you retrieve your task id, add your player to the map along side with the task id with the put method.
    Once the player dies, retrieve the task id with with the get method. To do that, you need to specify the key, which in this case is your player.
     
  15. Offline

    Treeline1

    Closer? xD
    Code:
    package me.liam.commands;
    
    import java.util.HashMap;
    
    import me.liam.main.Kitpvp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.PlayerDeathEvent;
    
    public class Flames implements CommandExecutor {
    
        private Kitpvp plugin;
        public Flames(Kitpvp instance){
            this.plugin = instance;
        }
        HashMap<String, Integer> can = new HashMap<String, Integer>();
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            Player player = event.getEntity().getPlayer();
            can.remove(player);
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
            if(!(sender instanceof Player)){
                return false;
            }
    
            final Player player = (Player)sender;
    
    
            if(cmd.getName().equalsIgnoreCase("flames")){
                if(!sender.hasPermission("flames.set")){
                    sender.sendMessage(ChatColor.RED + "You do not have permission to use this particle!");
                    return true;
                }else if(!(this.plugin.Flames.contains(player.getName()))){
                    if(!(this.plugin.particleused.contains(player.getName()))){
                        this.plugin.Flames.add(player.getName());
                        this.plugin.particleused.add(player.getName());
    
                        final int ca = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                            public void run() {
                                can.put(player.getName(), ca));
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.2, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0.5), 10);
                                ParticleEffect.LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                                ParticleEffect.DRIP_LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                            }
                        }, 2, 20);
    
                    }
                }
            }
    
            return true;
        }
    
    }
     
  16. Offline

    WinX64

    Very close! You got it right when adding it to the map, but put it outside the task. Now for the other part, you're simply removing it from the map, and this does not automatically cancel the task, you have to do it manually.
     
  17. Offline

    Treeline1

    This is what I have now
    Code:
    package me.liam.commands;
    
    import java.util.HashMap;
    
    import me.liam.main.Kitpvp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.PlayerDeathEvent;
    
    public class Flames implements CommandExecutor {
    
        private Kitpvp plugin;
        public Flames(Kitpvp instance){
            this.plugin = instance;
        }
       
        int ca;
       
        HashMap<String, Integer> can = new HashMap<String, Integer>();
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            Player player = event.getEntity().getPlayer();
            can.remove(player);
            Bukkit.getScheduler().cancelTask(ca);
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
            if(!(sender instanceof Player)){
                return false;
            }
    
            final Player player = (Player)sender;
    
    
            if(cmd.getName().equalsIgnoreCase("flames")){
                if(!sender.hasPermission("flames.set")){
                    sender.sendMessage(ChatColor.RED + "You do not have permission to use this particle!");
                    return true;
                }else if(!(this.plugin.Flames.contains(player.getName()))){
                    if(!(this.plugin.particleused.contains(player.getName()))){
                        this.plugin.Flames.add(player.getName());
                        this.plugin.particleused.add(player.getName());
                        can.put(player.getName(), ca);
                         int ca = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                            public void run() {
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.2, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0.5), 10);
                                ParticleEffect.LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                                ParticleEffect.DRIP_LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                            }
                        }, 2, 20);
    
                    }
                }
            }
    
            return true;
        }
    
    }
    Still not 100% sure on how to go with this though

    @WinX64
    There still is a few errors etc...So i dont quite know

    Bump.... Anyone? D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  18. Offline

    mythbusterma

    @Treeline1

    You haven't defined "a few errors."
     
  19. Offline

    Treeline1

    I messed around a bit and now theres no errors, but of course still doesnt get rid of the particles...
    Code:
    package me.liam.commands;
    
    import java.util.HashMap;
    
    import me.liam.main.Kitpvp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.PlayerDeathEvent;
    
    public class Flames implements CommandExecutor {
    
        private Kitpvp plugin;
        public Flames(Kitpvp instance){
            this.plugin = instance;
        }
       
        int ca;
       
        HashMap<String, Integer> can = new HashMap<String, Integer>();
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            Player player = event.getEntity().getPlayer();
            can.remove(player);
            Bukkit.getScheduler().cancelTask(ca);
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
            if(!(sender instanceof Player)){
                return false;
            }
    
            final Player player = (Player)sender;
    
    
            if(cmd.getName().equalsIgnoreCase("flames")){
                if(!sender.hasPermission("flames.set")){
                    sender.sendMessage(ChatColor.RED + "You do not have permission to use this particle!");
                    return true;
                }else if(!(this.plugin.Flames.contains(player.getName()))){
                    if(!(this.plugin.particleused.contains(player.getName()))){
                        this.plugin.Flames.add(player.getName());
                        this.plugin.particleused.add(player.getName());
                        can.put(player.getName(), ca);
                         int ca = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                            public void run() {
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2.2, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, 0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(0.5, 0.5, -0.5), 10);
                                ParticleEffect.FLAME.display(10, 15, 0, 0, 0, player.getLocation().add(-0.5, 0.5, 0.5), 10);
                                ParticleEffect.LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                                ParticleEffect.DRIP_LAVA.display(10, 15, 0, 0, 0, player.getLocation().add(0, 2, 0), 10);
                            }
                        }, 2, 20);
    
                    }
                }
            }
    
            return true;
        }
    
    }
    Thats what I've got so far

    @mythbusterma
     
    Last edited by a moderator: Jan 26, 2015
  20. Offline

    mythbusterma

    @Treeline1

    Because I don't see a remove or cancel anywhere in that code?
     
  21. Offline

    Treeline1

    Code:
    @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            Player player = event.getEntity().getPlayer();
            can.remove(player);
            Bukkit.getScheduler().cancelTask(ca);
        }
    I was trying that but it didnt work...
     
  22. Offline

    mythbusterma

    @Treeline1

    You're removing a Player from a HashMap that relates a String to an Integer. Also, "ca" is not defined in that context? Are you sure you're not looking for this: The Java™ Tutorials?
     
  23. Offline

    Treeline1

    I was just trying to follow what Winx64 was telling me...
    Basically I was trying to define the GetScheduler... Then I could cancel it on the death event
     
  24. Offline

    mythbusterma

    @Treeline1

    Alright, doesn't change the fact that the type you provided to the Map#remove(...) is incompatible with the type it expects. When is a Player EVER equal to a String?
     
  25. Offline

    Treeline1

    Ok I did wrong, I understand. Can you help me/walk me through?
     
  26. Offline

    mythbusterma

    @Treeline1

    I told you exactly what to do: provide the correct argument to Map#remove(...), i.e. a String.
     
  27. Offline

    Treeline1

    I am trying to figure this out.... I understand you don't like people on here ask stupid questions as I've seen in other posts... But where am I saying that Player is a string??
     
  28. Offline

    mythbusterma

    @Treeline1

    Let's take a look at a Map. It associates a Value of type V with a Key of type K. You declare a Map here:

    HashMap<String, Integer> can = new HashMap<String, Integer>();

    And then try to do remove a value (keep in mind, the argument of Map#remove(..) takes an argument of type K) here:

    can.remove(player);

    Do you see the type mismatch?
     
  29. Offline

    Treeline1

    So will can.remove(player.getName()); work any better then?
     
  30. Offline

    mythbusterma

Thread Status:
Not open for further replies.

Share This Page