EnderPearl CoolDown with xp Bar

Discussion in 'Plugin Development' started by Samsoon, Jan 29, 2018.

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

    Samsoon

    Hey
    Recently I am trying to make a plugin for my Servers which is enderpearl cooldown with Xp bar
    I think most of you guys have heard some Famous practice PvP Server like arcane / mineman club / velt PvP
    I saw they have a xp bar count down after they have thrown an enderpearl
    like this
    And I want to make the same like them
    What I have now is

    https://pastebin.com/abKnLrnF

    This is the link of the code

    Download the txt :)

    Please someone help me :*(

    Code:
    package me.samsoon;
    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    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.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    public class cooldown implements Listener, CommandExecutor{
        int time;
        ArrayList<Player> cooldown = new ArrayList<Player>();
     
        @EventHandler
        public void EnderPearl(PlayerInteractEvent e) {
            final Player p = e.getPlayer();
            ItemStack pearl = new ItemStack(Material.ENDER_PEARL);
            if(p.getGameMode() == GameMode.SURVIVAL) {
                if(p.getInventory().getItemInHand() == pearl) {
                    if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                        p.performCommand("epearlcd");
                            }
                        }
                    }
                }
         
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            final Player p = (Player)sender;
            time = 16;
         
         
            if(label.equalsIgnoreCase("epearlcd")) {
                if(cooldown.contains(p)) {
                    p.sendMessage(ChatColor.RED + "You cannot throw an ender pearl yet");
                    return true;
                }
                if(p instanceof Player) {
                    time = time -1;
                    p.setLevel(time);
                    p.setExp(time / (float) 16);
                    cooldown.add(p);
                    Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) this, new Runnable() {
                        public void run() {
                            cooldown.remove(p);          
                        }
                 
                    }, 20 * 16);
                    return true;
                 
                }
             
            }
     
            return false;
        }
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Samsoon You can't cast that class to Plugin for the runnable, pass the main instance along using constructors instead.
    Make a hashmap<uuid,long> the long will represent the time when they can throw again using the current system time in milliseconds. No need for the cooldown runnable either that way.
     
  3. Offline

    Samsoon

    Can I have an example
    I have instance in my main class
     
Thread Status:
Not open for further replies.

Share This Page