Help Kit on signs

Discussion in 'Spigot Plugin Development' started by Kozuko, Jun 21, 2016.

  1. Code (Text):
      @EventHandler
      public void onInteract(PlayerInteractEvent e) {
          Player p = e.getPlayer();
          Action action = e.getAction();
          Block clickedBlock = e.getClickedBlock();
          if (action == Action.RIGHT_CLICK_BLOCK) {
              if(!(clickedBlock.getType()==Material.SIGN || clickedBlock.getType()==Material.SIGN_POST || clickedBlock.getType()==Material.WALL_SIGN)) return;
              Sign sign = (Sign) clickedBlock.getState();
              String line1 = sign.getLine(0);
              if (line1.contains("[Tank]"))
          {
        p.getInventory().clear();
        p.sendMessage(ChatColor.GREEN+"Kit Tank Selected");
       
        ItemStack helm = new ItemStack(Material.DIAMOND_HELMET);
        helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
        helm.addUnsafeEnchantment(Enchantment.DURABILITY, 3);
       
        ItemStack chest = new ItemStack(Material.DIAMOND_CHESTPLATE);
        chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
        chest.addUnsafeEnchantment(Enchantment.DURABILITY, 3);
       
        ItemStack legs = new ItemStack(Material.DIAMOND_LEGGINGS);
        legs.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
        legs.addUnsafeEnchantment(Enchantment.DURABILITY, 3);
       
        ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS);
        boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
        boots.addUnsafeEnchantment(Enchantment.DURABILITY, 3);
        boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 4);
       
        ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1);
        sword.addUnsafeEnchantment(Enchantment.DURABILITY, 3);
        sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 2);
        sword.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 1);
       
        ItemStack pearl = new ItemStack(Material.ENDER_PEARL, 16);
        ItemStack steak = new ItemStack(Material.COOKED_BEEF,64);
        ItemStack speed =  new ItemStack(Material.POTION,1, (short) 8226);
        ItemStack fireres =  new ItemStack(Material.POTION,1, (short) 8259);
        ItemStack heal =  new ItemStack(Material.POTION,1, (short) 16421);
       
        p.getInventory().setItem(0,sword);
        p.getInventory().setItem(1, pearl);
        p.getInventory().setItem(2,speed);
        p.getInventory().setItem(3,fireres);
        p.getInventory().setItem(4,heal);
        p.getInventory().setItem(5,heal);
        p.getInventory().setItem(6,heal);
        p.getInventory().setItem(7,heal);
        p.getInventory().setItem(8, steak);
        p.getInventory().setItem(9,heal);
        p.getInventory().setItem(10,heal);
        p.getInventory().setItem(11,heal);
        p.getInventory().setItem(12,heal);
        p.getInventory().setItem(13,heal);
        p.getInventory().setItem(14,heal);
        p.getInventory().setItem(15,heal);
        p.getInventory().setItem(16,heal);
        p.getInventory().setItem(17,speed);
        p.getInventory().setItem(18,heal);
        p.getInventory().setItem(19,heal);
        p.getInventory().setItem(20,heal);
        p.getInventory().setItem(21,heal);
        p.getInventory().setItem(22,heal);
        p.getInventory().setItem(23,heal);
        p.getInventory().setItem(24,heal);
        p.getInventory().setItem(25,heal);
        p.getInventory().setItem(26,speed);
        p.getInventory().setItem(27,heal);
        p.getInventory().setItem(28,heal);
        p.getInventory().setItem(29,heal);
        p.getInventory().setItem(30,heal);
        p.getInventory().setItem(31,heal);
        p.getInventory().setItem(32,heal);
        p.getInventory().setItem(33,heal);
        p.getInventory().setItem(34,heal);
        p.getInventory().setItem(35,speed);
       
        p.getInventory().setHelmet(helm);
        p.getInventory().setChestplate(chest);
        p.getInventory().setLeggings(legs);
        p.getInventory().setBoots(boots);
       
        for (PotionEffect effect : p.getActivePotionEffects())
            p.removePotionEffect(effect.getType());
       
        p.updateInventory();


    my code works very well i had multiple kits in signs such like (Bard, Tank, Archer)
    but theres a problem when i left click with a item the item doesnt replace! example
    when i left click with the bow the bow still there and doesnt put the thing that i want thats has supposed to be a potion!
     
  2. And then I puked all over myself. With a new shirt on, too! :(

    But anyway, I don't understand your problem. That code contains nothing about doing something when the player left clicks
     
  3. want the full code?
     
  4. Code (Java):

    for(int slot : Arrays.asList(1, 2, 3, 4)) {
     setItem(slot, item);
    }
     
    Also :
    if (action == Action.RIGHT_CLICK_BLOCK) {
     
  5. sorry for the stupid question but im new in this thing of java where i put that?
     
  6. an even simpler approach, at least for the potions, would be just a standard for loop