Ender Pearl Cooldown

Discussion in 'Plugin Development' started by JoelyBob, Apr 25, 2015.

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

    JoelyBob

    Hey!

    I am having trouble with this, I want to know how to cancel an Enderpearl from being thrown if they are in the cooldown array? I have tried a few different things, but nothing works.

    Code:

    Code:
    public void onEnable() {
    Bukkit.getPluginManager().registerEvents(this, this);
    getLogger().info(ChatColor.GREEN + "Pearls Enabled");
    }
    public void onDisable() {
    getLogger().info(ChatColor.RED + "Pearls Disabled");
    }
    ArrayList<String> cooldown = new ArrayList<String>();
    @EventHandler
    public void onInteract(final PlayerInteractEvent e)
    {
    if(e.getAction() == Action.RIGHT_CLICK_AIR)
    {
    Player p = e.getPlayer();
    ItemStack item = p.getItemInHand();
    if(item.getType() == Material.ENDER_PEARL)
    {
    if (!cooldown.contains(e.getPlayer().getName()))
    {
            e.getPlayer().launchProjectile(EnderPearl.class);
       
    p.sendMessage(ChatColor.GRAY + "You must wait " + ChatColor.YELLOW + "4 seconds" + ChatColor.GRAY + " before using another enderpearl.");
    cooldown.add(e.getPlayer().getName());
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    {
    @Override
    public void run()
    {
    cooldown.remove(e.getPlayer().getName());
    }
    }, 80L); // 20L = 1 Second & 30L = 1.5 Seconds
    }else
    I want the enderpearl to be cancelled if they try to throw one in that cooldown.
     
  2. Offline

    vhbob

    @JoelyBob please go into your ide || your coding enviorment click on your code and co ctrl + shit + f... it makes your code much easier to debug
     
  3. Offline

    JoelyBob

    Done:

    Code:
        public void onEnable() {
    
            Bukkit.getPluginManager().registerEvents(this, this);
    
            getLogger().info(ChatColor.GREEN + "PvPBoxPearls Enabled");
    
        }
    
        public void onDisable() {
    
            getLogger().info(ChatColor.RED + "PvPBoxPearls Disabled");
    
        }
    
        ArrayList<String> cooldown = new ArrayList<String>();
    
        @EventHandler
        public void onInteract(final PlayerInteractEvent e) {
            if (e.getAction() == Action.RIGHT_CLICK_AIR) {
                Player p = e.getPlayer();
                ItemStack item = p.getItemInHand();
                if (item.getType() == Material.ENDER_PEARL) {
                    if (!cooldown.contains(e.getPlayer().getName())) {
                        // Delete the slashes below this line if it doesn't work
    
                        e.getPlayer().launchProjectile(EnderPearl.class);
    
                        p.sendMessage(ChatColor.GRAY + "You must wait "
                                + ChatColor.YELLOW + "4 seconds" + ChatColor.GRAY
                                + " before using another enderpearl.");
                        cooldown.add(e.getPlayer().getName());
    
                        Bukkit.getServer().getScheduler()
                                .scheduleSyncDelayedTask(this, new Runnable() {
                                    @Override
                                    public void run() {
                                        cooldown.remove(e.getPlayer().getName());
                                    }
                                }, 80L); // 20L = 1 Second & 30L = 1.5 Seconds
                    } else {
    Anything I can do?
     
  4. Offline

    vhbob

    @JoelyBob no idea..... im terrible with cooldowns myself ;)
     
  5. Offline

    Zombie_Striker

    Did you debug? do you no nothing is null? is the player still in the map after your 4 seconds?
     
  6. Offline

    Vamure

    e.setCancelled(true); ?
     
Thread Status:
Not open for further replies.

Share This Page