Help With Checking "If the player already did the command!"

Discussion in 'Plugin Development' started by SirLittlemonster7, Sep 8, 2012.

Thread Status:
Not open for further replies.
  1. Hey Guys I was just wondering if I could get some help on this, Im not good at hash maps and it would be awesome if someone could help me!
     
  2. Offline

    The_Coder

    Map <String> playername = new HashMap <String>;

    OnCommand(){

    Player player = (Player) sender;
    //Command
    If(!playername.contain(player.getName()){
    //do things
    playername.put(player.getName())
    }
    }
     
  3. Offline

    Infamous Jeezy

    The previous post will help if you're trying to make it a one time use command that will need a manual reset via a command or a called event.
    Although, if you're trying to make cooldowns on your events, this way may be of use.
    This may not be the best way of handling it, but it works, you could also replace the scheduler and use the server time to compare when the command was used last, but I use this method since I use the scheduler for broadcasts.
    Declarations:
    Code:
    public Map<String, Integer> commandCooldown = new HashMap<String, Integer>();
    public int serverMinutes = 0;
    
    Scheduler(mine is placed in onEnable, runs every one minute):
    Code:
            Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
            {
                public void run()
                    {
                    serverMinutes++;
                    }
            }, 0L, 1200L);
    
    Cooldown Initiation/Remove(place inside desired command):
    Code:
                if((plugin.commandCooldown.containsKey(playername)) == false)
                {
                //if the cooldown is not present
                Integer delay = 1; //how long the cooldown is, in minutes
                Integer timecheck = plugin.serverMinutes + delay;
                plugin.commandCooldown.put(sPlr, timecheck);
                }
                else
                {
                Integer timeGoal = plugin.commandCooldown.get(playername);
                Integer serverTime = plugin.serverMinutes;
                Integer remainingSeconds = 0;
                if(timeGoal>=serverTime)
                {
                remainingSeconds = timeGoal - serverTime;
                String seconds = remainingSeconds.toString();
                    player.sendMessage(ChatColor.DARK_RED + "That ability is on cooldown for another " + seconds + " minutes.");
                }
                if(timeGoal<serverTime)
                {
                    plugin.commandCooldown.remove(playername);
                    player.sendMessage(ChatColor.DARK_GREEN + "The cooldown has finished please retype the command.");
                }
                }
    
    If you have any issues or questions with this feel free to let me know.
     
  4. Thanks! now.... Where would I put it in this code?!?! Its pretty complicated... well thats what I would say :p
    Code:
    package me.littlemonster7.happy;
     
     
    import org.bukkit.inventory.ItemStack;
     
    import org.bukkit.inventory.PlayerInventory;
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    public class little extends JavaPlugin{
       
        public final Logger logger = Logger.getLogger("Minecraft");
        public static little plugin;
       
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "Kits, Has Been Disabled!");
        }
       
       
        @Override   
        public void onEnable() {PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName() + "Version" + pdfFile.getVersion() + "Kits, Has Been Enabled!");
       
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[]args){
            Player player = (Player) sender;
            PlayerInventory inventory = player.getInventory();
            if(player.hasPermission("happy.pvp")) {
            if(commandLabel.equalsIgnoreCase("PvP") || commandLabel.equalsIgnoreCase("pvp")){
                player.sendMessage(ChatColor.GREEN + "Giving The Little PvP Kit!");
                player.sendMessage(ChatColor.GRAY + "Has Set Health To: Full!");
                if(args.length == 0){
                    inventory.clear();
                    inventory.setHelmet(new ItemStack(Material.IRON_HELMET, 1));
                    inventory.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
                    inventory.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
                    inventory.setBoots(new ItemStack(Material.IRON_BOOTS, 1));
                    ItemStack item = new ItemStack(Material.DIAMOND_SWORD,1);
                    item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1);
                    player.getInventory().addItem(item);
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    player.setHealth(20);
                    player.setSaturation(20);
                    player.setFoodLevel(20);
     
                    }
                }
            if(player.hasPermission("happy.knight")) {
            if(commandLabel.equalsIgnoreCase("knight") || commandLabel.equalsIgnoreCase("knight")){
                player.sendMessage(ChatColor.GREEN + "Knight Kit!");
                player.sendMessage(ChatColor.GRAY + "Has Set Food Level to full!");
                if(args.length == 0){
                    inventory.clear();
                    inventory.setHelmet(new ItemStack(Material.CHAINMAIL_HELMET, 1));
                    inventory.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
                    inventory.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
                    inventory.setBoots(new ItemStack(Material.CHAINMAIL_BOOTS, 1));
                    ItemStack item = new ItemStack(Material.IRON_SWORD,1);
                    item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1);
                    player.getInventory().addItem(item);
                    ItemStack item1 = new ItemStack(Material.BOW,1);
                    item1.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 1);
                    player.getInventory().addItem(item1);
                    inventory.addItem(new ItemStack(Material.ARROW, 15));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    player.setHealth(20);
                    player.setSaturation(20);
                    player.setFoodLevel(20);
                    }
                }
            if(player.hasPermission("happy.archer")) {
            if(commandLabel.equalsIgnoreCase("Archer") || commandLabel.equalsIgnoreCase("archer")){
                player.sendMessage(ChatColor.GREEN + "Archer Kit!");
                player.sendMessage(ChatColor.GRAY + "Has Set Food Level to full!");
                if(args.length == 0){
                    inventory.clear();
                    inventory.setHelmet(new ItemStack(Material.GOLD_HELMET));
                    inventory.setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
                    inventory.setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
                    inventory.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
                    ItemStack item1 = new ItemStack(Material.BOW, 1);
                    item1.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 6);
                    player.getInventory().addItem(item1);
                    inventory.addItem(new ItemStack(Material.ENDER_PEARL, 6));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.ARROW, 128));
                    player.setHealth(20);
                    player.setSaturation(20);
                    player.setFoodLevel(20);
                }
            }
            if(player.hasPermission("happy.fireman")) {
        if(commandLabel.equalsIgnoreCase("FireMan") || commandLabel.equalsIgnoreCase("fireman")){
            player.sendMessage(ChatColor.GREEN + "FireMan Kit!");
            player.sendMessage(ChatColor.GRAY + "Has Set Food Level to full!");
            if(args.length == 0){
                inventory.clear();
                ItemStack item1 = new ItemStack(Material.GOLD_HELMET,1);
                item1.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                inventory.setHelmet(item1);
                ItemStack item2 = new ItemStack(Material.GOLD_CHESTPLATE,1);
                item2.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
                inventory.setChestplate(item2);
                ItemStack item3 = new ItemStack(Material.GOLD_LEGGINGS,1);
                item3.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                inventory.setLeggings(item3);
                ItemStack item4 = new ItemStack(Material.GOLD_BOOTS,1);
                item4.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                inventory.setBoots(item4);
                ItemStack item5 = new ItemStack(Material.IRON_SWORD,1);
                item5.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 1);
                player.getInventory().addItem(item5);
                inventory.addItem(new ItemStack(Material.BOW, 1));
                inventory.addItem(new ItemStack(Material.ARROW, 32));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                player.setHealth(20);
                player.setSaturation(20);
                player.setFoodLevel(20);
            }
        }
        if(player.hasPermission("happy.scout")) {
    if(commandLabel.equalsIgnoreCase("Scout") || commandLabel.equalsIgnoreCase("scout")){
        player.sendMessage(ChatColor.GREEN + "Scout Kit!");
        player.sendMessage(ChatColor.GRAY + "Has Set Food Level to full!");
        if(args.length == 0){
            inventory.clear();
            ItemStack item = new ItemStack(Material.IRON_BOOTS, 1);
            item.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 6);
            inventory.setBoots(item);
            ItemStack item1 = new ItemStack(Material.WOOD_SWORD,1);
            item1.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 6);
            player.getInventory().addItem(item1);
            ItemStack item2 = new ItemStack(Material.BOW, 1);
            item2.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 2);
            player.getInventory().addItem(item2);
            inventory.addItem(new ItemStack(Material.ARROW, 128));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            player.setSaturation(20);
            player.setFoodLevel(20);
        }
    }
            }
            }
            }
            return false;
        }
    }
            return false;
        }
    }
     
  5. Offline

    Infamous Jeezy

    Code:
    package me.littlemonster7.happy;
     
     
    import org.bukkit.inventory.ItemStack;
     
    import org.bukkit.inventory.PlayerInventory;
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    public class little extends JavaPlugin{
     
        public final Logger logger = Logger.getLogger("Minecraft");
        public static little plugin;
        public Map<String, Integer> happypvpCooldown = new HashMap<String, Integer>();
        public int serverMinutes = 0;
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "Kits, Has Been Disabled!");
        }
     
     
        @Override 
        public void onEnable() {PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName() + "Version" + pdfFile.getVersion() + "Kits, Has Been Enabled!");
                Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
            {
                public void run()
                    {
                    serverMinutes++;
                    }
            }, 0L, 1200L);
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[]args){
            Player player = (Player) sender;
            PlayerInventory inventory = player.getInventory();
            if(player.hasPermission("happy.pvp")) {
            if(commandLabel.equalsIgnoreCase("PvP") || commandLabel.equalsIgnoreCase("pvp")){
                            if((plugin.happypvpCooldown.containsKey(playername)) == false)
                {
                player.sendMessage(ChatColor.GREEN + "Giving The Little PvP Kit!");
                player.sendMessage(ChatColor.GRAY + "Has Set Health To: Full!");
                if(args.length == 0){
                    inventory.clear();
                    inventory.setHelmet(new ItemStack(Material.IRON_HELMET, 1));
                    inventory.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
                    inventory.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
                    inventory.setBoots(new ItemStack(Material.IRON_BOOTS, 1));
                    ItemStack item = new ItemStack(Material.DIAMOND_SWORD,1);
                    item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1);
                    player.getInventory().addItem(item);
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    player.setHealth(20);
                    player.setSaturation(20);
                    player.setFoodLevel(20);
                Integer delay = 1; //how long the cooldown is, in minutes
                Integer timecheck = plugin.serverMinutes + delay;
                plugin.happypvpCooldown.put(sPlr, timecheck);
                }
                else
                {
                Integer timeGoal = plugin.happypvpCooldown.get(playername);
                Integer serverTime = plugin.serverMinutes;
                Integer remainingSeconds = 0;
                if(timeGoal>=serverTime)
                {
                remainingSeconds = timeGoal - serverTime;
                String seconds = remainingSeconds.toString();
                    player.sendMessage(ChatColor.DARK_RED + "That ability is on cooldown for another " + seconds + " minutes.");
                }
                if(timeGoal<serverTime)
                {
                    plugin.happypvpCooldown.remove(playername);
                    player.sendMessage(ChatColor.DARK_GREEN + "The cooldown has finished please retype the command.");
                }
                }
     
              }
          }
            if(player.hasPermission("happy.knight")) {
            if(commandLabel.equalsIgnoreCase("knight") || commandLabel.equalsIgnoreCase("knight")){
                player.sendMessage(ChatColor.GREEN + "Knight Kit!");
                player.sendMessage(ChatColor.GRAY + "Has Set Food Level to full!");
                if(args.length == 0){
                    inventory.clear();
                    inventory.setHelmet(new ItemStack(Material.CHAINMAIL_HELMET, 1));
                    inventory.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
                    inventory.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
                    inventory.setBoots(new ItemStack(Material.CHAINMAIL_BOOTS, 1));
                    ItemStack item = new ItemStack(Material.IRON_SWORD,1);
                    item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1);
                    player.getInventory().addItem(item);
                    ItemStack item1 = new ItemStack(Material.BOW,1);
                    item1.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 1);
                    player.getInventory().addItem(item1);
                    inventory.addItem(new ItemStack(Material.ARROW, 15));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    player.setHealth(20);
                    player.setSaturation(20);
                    player.setFoodLevel(20);
                    }
                }
            if(player.hasPermission("happy.archer")) {
            if(commandLabel.equalsIgnoreCase("Archer") || commandLabel.equalsIgnoreCase("archer")){
                player.sendMessage(ChatColor.GREEN + "Archer Kit!");
                player.sendMessage(ChatColor.GRAY + "Has Set Food Level to full!");
                if(args.length == 0){
                    inventory.clear();
                    inventory.setHelmet(new ItemStack(Material.GOLD_HELMET));
                    inventory.setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
                    inventory.setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
                    inventory.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
                    ItemStack item1 = new ItemStack(Material.BOW, 1);
                    item1.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 6);
                    player.getInventory().addItem(item1);
                    inventory.addItem(new ItemStack(Material.ENDER_PEARL, 6));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                    inventory.addItem(new ItemStack(Material.ARROW, 128));
                    player.setHealth(20);
                    player.setSaturation(20);
                    player.setFoodLevel(20);
                }
            }
            if(player.hasPermission("happy.fireman")) {
        if(commandLabel.equalsIgnoreCase("FireMan") || commandLabel.equalsIgnoreCase("fireman")){
            player.sendMessage(ChatColor.GREEN + "FireMan Kit!");
            player.sendMessage(ChatColor.GRAY + "Has Set Food Level to full!");
            if(args.length == 0){
                inventory.clear();
                ItemStack item1 = new ItemStack(Material.GOLD_HELMET,1);
                item1.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                inventory.setHelmet(item1);
                ItemStack item2 = new ItemStack(Material.GOLD_CHESTPLATE,1);
                item2.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
                inventory.setChestplate(item2);
                ItemStack item3 = new ItemStack(Material.GOLD_LEGGINGS,1);
                item3.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                inventory.setLeggings(item3);
                ItemStack item4 = new ItemStack(Material.GOLD_BOOTS,1);
                item4.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                inventory.setBoots(item4);
                ItemStack item5 = new ItemStack(Material.IRON_SWORD,1);
                item5.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 1);
                player.getInventory().addItem(item5);
                inventory.addItem(new ItemStack(Material.BOW, 1));
                inventory.addItem(new ItemStack(Material.ARROW, 32));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
                player.setHealth(20);
                player.setSaturation(20);
                player.setFoodLevel(20);
            }
        }
        if(player.hasPermission("happy.scout")) {
    if(commandLabel.equalsIgnoreCase("Scout") || commandLabel.equalsIgnoreCase("scout")){
        player.sendMessage(ChatColor.GREEN + "Scout Kit!");
        player.sendMessage(ChatColor.GRAY + "Has Set Food Level to full!");
        if(args.length == 0){
            inventory.clear();
            ItemStack item = new ItemStack(Material.IRON_BOOTS, 1);
            item.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 6);
            inventory.setBoots(item);
            ItemStack item1 = new ItemStack(Material.WOOD_SWORD,1);
            item1.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 6);
            player.getInventory().addItem(item1);
            ItemStack item2 = new ItemStack(Material.BOW, 1);
            item2.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 2);
            player.getInventory().addItem(item2);
            inventory.addItem(new ItemStack(Material.ARROW, 128));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
            player.setSaturation(20);
            player.setFoodLevel(20);
        }
    }
            }
            }
            }
            return false;
        }
    }
            return false;
        }
    }
    
    Okay, I implemented it into the happypvp command.
    I'll leave the rest of the commands up to you, you won't learn if I do it all for you. :p
    Basically, just create a hashmap for each command that you want to have a cooldown and then change the syntax of the other commands like what I did for the happypvp command.
     
  6. Thanks! Your the best :) Ill try to learn off of this code and being to help other people on the map :)

    Ok, I imported everything but I get the red line of death at this:

    Code:
                          if((plugin.happypvpCooldown.containsKey(playername)) == false)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  7. Offline

    Infamous Jeezy

    SirLittlemonster7
    What do you mean by the red line of death?
    Can you post the error you get? It'll be easier for me to figure out what you did wrong if it wasn't my own error.
     
  8. Offline

    QuantumDev

    Change

    if((plugin.happypvpCooldown.containsKey(playername)) == false)

    to

    if(plugin.happypvpCooldown.containsKey(playername) == false)
     
  9. Code:
    plugin.happypvpCooldown.put(sPlr, timecheck);//sPlr is the error
    Hey guys I just have 1 more error, right here:
     
  10. Offline

    StevasaurousREX

    @SirLittlemonster7 add
    Code:
    String sPlr = player.getName();
    under
    Code:
    Player player = (Player) sender;
     

  11. Could I possibly make a:
    Code line where if they have any armour contents on it doesn't do the command? like a get Boots().getKind == Material.IRON_BOOTS != null) {

    Would that work at all? I need help ;( and how would I make it actully WORK​

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  12. Offline

    Infamous Jeezy

    SirLittlemonster7
    I believe it's more along the lines of this, where air means a blank slot,
    since I'm pretty sure an ItemStack cannot be null.
    This is assuming for your onCommand method that your CommandSender value is labeled sender.
    Code:
    if(sender instanceof Player)
    {
    Player target = (Player) sender;
            if(target!=null)
            {
                      Player tar = plugin.getServer().getPlayer(args[0]);
                      PlayerInventory inv = tar.getInventory();
                        if(inv.getBoots()==Material.AIR==true)
                               {
                                //do stuff
                               }
            }
            if(target==null)
            System.out.println("Only players can execute this command!");
            return true; //I always return true. This is optional where you wanna place this.
    }
    
    Good luck!
    Let me know if you have any issues, sorry for the late response.
     
Thread Status:
Not open for further replies.

Share This Page