1 kit per Life Issue

Discussion in 'Plugin Development' started by looparound, Aug 24, 2013.

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

    looparound

    This is The Code for 1 Of My Kits. Not Sure y but in game once choosing a kit and trying to choose another it sends the message. You Allready have a kit. But It still gives you the kits. So say i Pick PvP First it gives me. Than I try Archer It sends me the msg but still gives me the archer kit.Also When I try to Pick a kit Once Joining my Test Server For The First Time It doesnt Give a kit. If you Know how to fix Id Greatly appreciate it!! Thanks :D

    if(cmd.getName().equalsIgnoreCase("caveman")) {
    if(Kits.HasKit.containsKey(p)) {
    p.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.GOLD + "RoyalPvP" +
    ChatColor.DARK_RED + "] " + ChatColor.RED + "You already got a kit!");
    }else{
    Kits.HasKit.put(p, null);
    return true;
    }
    if(!p.hasPermission("caveman.use")) {
    p.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.GOLD + "RoyalPvP" + ChatColor.DARK_RED + "] "
    + ChatColor.GRAY + "You Dont Have Permission To This Kit!");
    return true;
    }

    p.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.GOLD + "RoyalPvP" + ChatColor.DARK_RED + "] "
    + ChatColor.GRAY + "You Have Chosen The 'Caveman' Kit!");
    p.removePotionEffect(PotionEffectType.SPEED);
    p.removePotionEffect(PotionEffectType.POISON);
    p.removePotionEffect(PotionEffectType.JUMP);
    p.removePotionEffect(PotionEffectType.FIRE_RESISTANCE);
    p.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
    p.removePotionEffect(PotionEffectType.INVISIBILITY);
    p.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
    p.removePotionEffect(PotionEffectType.SLOW);
    p.removePotionEffect(PotionEffectType.REGENERATION);
    p.removePotionEffect(PotionEffectType.WEAKNESS);
    pi.clear();
    pi.setHelmet(null);
    pi.setChestplate(null);
    pi.setLeggings(null);
    pi.setBoots(null);

    ItemStack leg = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    ItemStack boots = new ItemStack(Material.GOLD_BOOTS, 1);
    ItemStack stick = new ItemStack(Material.STICK, 1);

    LeatherArmorMeta meta = (LeatherArmorMeta) leg.getItemMeta();
    meta.setColor(Color.ORANGE);
    leg.setItemMeta(meta);
    ItemMeta meta2 = (ItemMeta) stick.getItemMeta();
    meta2.setDisplayName(ChatColor.RED + "Club");
    stick.setItemMeta(meta2);

    leg.addUnsafeEnchantment(Enchantment.DURABILITY, 5);
    leg.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    boots.addUnsafeEnchantment(Enchantment.DURABILITY, 5);
    boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    stick.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 5);

    pi.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
    pi.setLeggings(leg);
    pi.setBoots(boots);

    pi.addItem(stick);
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    return true;

    P.S This Is The HashMaps i used For This Kit:
    public static final HashMap<Player, ArrayList<Block>> CavemanKit = new HashMap<Player, ArrayList<Block>>();
    public static final HashMap<Player, ArrayList<Block>> HasKit = new HashMap<Player, ArrayList<Block>>();
     
  2. Offline

    naorpeled

    First , do [ Syntax = Java ] [ /Syntax ] no spaces.
    second, its very simple.
    Code:Java
    1.  
    2. Set<String> hasKit = new HashSet<String>();
    3. if(hasKit.contains(player.getName()){
    4. // What it does
    5. }else{
    6. // You already chose a kit.
    7. }
    8.  

    looparound
    Edit: You should check for perms before checking the hasKit
     
  3. Offline

    Squid_Boss

    Yeah, like SkillSam suggested, I'd use an arraylist. And then use the PlayerDeathEvent and check if the player is int the arraylist, and if they are, remove them from it. :)
     
    Th3Br1x likes this.
Thread Status:
Not open for further replies.

Share This Page