Some help.

Discussion in 'Plugin Development' started by JHA™, Jan 17, 2013.

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

    JHA™

    Hey guys. I am making a KitPVP plugin and was wondering one thing. How do I add enchantments to armor. I know how to add enchantments to items like sword but since I am setting the item into the armor sport I am unsure of how to do this. Here is some code:
    Code:
                inventory.setHelmet(new ItemStack(Material.DIAMOND_HELMET, 1));
                inventory.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE, 1));
                inventory.setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS, 1));
                inventory.setBoots(new ItemStack(Material.DIAMOND_BOOTS, 1));
                ItemStack item2 = new ItemStack(Material.DIAMOND_SWORD, 1);
                item2.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1);
    Another thing. I also was wondering how to make a tagging system. So when the event EntityDamageByEntityEvent the damagee and the damager are tagged for 10 seconds and added to a list. But I would like the delay on the messages so when you hit someone you both ar tagged and then after 10 seconds you can log out.
    Thanks for the help!
    ~JHA™
     
  2. Offline

    fireblast709

    Code:java
    1. ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
    2. item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1);
    3. inventory.setHelmet(item);
    The same as all items
     
  3. Offline

    JHA™

    Ill try it thanks.
     
  4. Offline

    Gungsu

    Guys,
    I need transform the itemsStack in String and inverse, I try this:

    This work, but when item is a Wood:2, for example, he transform in Wood:0
    and remove enchants and remove others specifics.
     
  5. Offline

    fireblast709

    thread hijacking much? Anyway why do you need to make a String out of an ItemStack?
     
  6. Offline

    Gungsu

    I need organize itens for select buy position in chest:
    Code:
    if (event.getClickedBlock().getType() == Material.CHEST){
                if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.getPlayer().isSneaking() && event.getPlayer().hasPermission("chestOrg.organize")){
                    Block bau = (Block) event.getClickedBlock();
                    Chest chesclick = (Chest) bau.getState();
                    ItemStack itensds[] = chesclick.getBlockInventory().getContents();
                    String IdQuant[] = new String[itensds.length];
                    ItemStack itenscomench[] = new ItemStack[itensds.length];
                    int n = 0;
                    for (int i = 0; i<itensds.length;i++ ){
                        if (itensds[i] != null){
                            if (itensds[i].getItemMeta().hasEnchants()){
                                itenscomench[n] = itensds[i];
                                IdQuant[i] = "0,0";
                                n++;
                            } else {
                                IdQuant[i] = itensds[i].getTypeId()+","+itensds[i].getAmount();
                            }
                        } else {
                            IdQuant[i] = "0,0";
                        }
                    }
                    Arrays.sort(IdQuant);
                    ItemStack novo[] = new ItemStack[IdQuant.length];
                    for (int i=0; i<IdQuant.length;i++){
                        if (IdQuant[i] != null){
                        String idQuaType[] = IdQuant[i].split(",");
                        int amon = new Integer (idQuaType[1]);
                        int matt = new Integer (idQuaType[0]);
                        novo[i] = new ItemStack(matt,amon);
                        }
                    }
                    int f = 0;
                    for (int i=0;i<itenscomench.length;i++){
                        if (itenscomench[i] != null){
                            novo[f] = itenscomench[i];
                            f++;
                        }
                    }
                    chesclick.getBlockInventory().setContents(novo);
                }
            } else {
                return;
            }
    My solution for enchants item is: remove for other var and replace in end, but the itens when typeid is genereric I don't
     
  7. Offline

    Gungsu

    I resolved,
    Code:
        if (event.getClickedBlock().getType() == Material.CHEST && event.getPlayer().getGameMode() == GameMode.SURVIVAL){
                if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.getPlayer().isSneaking() && event.getPlayer().hasPermission("chestOrg.organize")){
                    Block bau = (Block) event.getClickedBlock();
                    Chest chesclick = (Chest) bau.getState();
                    ItemStack itensds[] = chesclick.getBlockInventory().getContents();
                    String IdQuant[] = new String[itensds.length];
                    for (int i = 0; i<itensds.length;i++ ){
                        if (itensds[i] != null){
                            IdQuant[i] = itensds[i].getTypeId()+","+i;
                        } else {
                            IdQuant[i] = "0,N";
                        }
                    }
                    Arrays.sort(IdQuant);
                    ItemStack novo[] = new ItemStack[IdQuant.length];
                    for (int i=0; i<IdQuant.length;i++){
                        if (IdQuant[i] != null){
                            String ItemDiv[] = IdQuant[i].split(",");
                            if (!ItemDiv[1].equals("N")){
                            int parS = new Integer (ItemDiv[1]);
                            novo[i] = itensds[parS];
                            }
                        }
                    }
                    chesclick.getBlockInventory().setContents(novo);
                }
     
Thread Status:
Not open for further replies.

Share This Page