(Help) Giving players more than 1 item in config!

Discussion in 'Plugin Development' started by Jetsinsu, Feb 23, 2014.

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

    Jetsinsu

    Hello. I have used config for one item but I don't know how to add more than one item or give an enchantment from the config file :(. Here are the codes I used.

    Main Class:
    Code:
    String[] array = new String[3];
    array[0] = "262"; //Want to be able to change this in config
    array[1] = "64";  //Want to be able to change this in config
    pi.addItem(new ItemStack(Material.matchMaterial(array[0]), Integer.parseInt(array[1])));
    Config:
    Code:
    kits:
      archer:
        armor:
          helmet: 306
          chestplate: 307
          leggings: 308
          boots: 309
        weapon:
          0: 261
          1: 262, 64
     
  2. Offline

    Brendyn Todd

    Jetsinsu More code please. It's awfully hard to help with nothing to look at.
     
  3. Offline

    Jetsinsu

    Hopefully this will help? I mean it's not much.
    Code:java
    1. if (args.length == 1){
    2. if (args[0].equalsIgnoreCase("Archer")){
    3. if (getConfig().getConfigurationSection("spawn") == null){
    4. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.YELLOW + " ====================");
    5. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.RED + " Spawn has not been set!");
    6. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.YELLOW + " ====================");
    7. return true;
    8. }
    9. if (getConfig().getConfigurationSection("leave") == null){
    10. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.YELLOW + " ====================");
    11. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.RED + " Leave has not been set!");
    12. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.YELLOW + " ====================");
    13. return true;
    14. }
    15.  
    16. World w = Bukkit.getServer().getWorld(getConfig().getString("spawn.world"));
    17. double x = getConfig().getDouble("spawn.x");
    18. double y = getConfig().getDouble("spawn.y");
    19. double z = getConfig().getDouble("spawn.z");
    20. p.teleport(new Location(w, x, y, z));
    21. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.YELLOW + " =============================");
    22. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.YELLOW + " You have recieved Archer kit!");
    23. p.sendMessage(ChatColor.RED + "[" + ChatColor.BLUE + "HorsePvp" + ChatColor.RED + "]" + ChatColor.YELLOW + " =============================");
    24. p.setFoodLevel(20);
    25. pi.clear();
    26. String[] array = new String[3];
    27. array[0] = "262";
    28. array[1] = "64";
    29. pi.addItem(new ItemStack(Material.matchMaterial(array[0]), Integer.parseInt(array[1])));
    30. pi.setHelmet(new ItemStack(Material.matchMaterial(getConfig().getString("kits.archer.armor.helmet"))));
    31. pi.setChestplate(new ItemStack(Material.matchMaterial(getConfig().getString("kits.archer.armor.chestplate"))));
    32. pi.setLeggings(new ItemStack(Material.matchMaterial(getConfig().getString("kits.archer.armor.leggings"))));
    33. pi.setBoots(new ItemStack(Material.matchMaterial(getConfig().getString("kits.archer.armor.boots"))));
    34. if (!(h1 instanceof Horse)){
    35. @SuppressWarnings("deprecation")
    36. Horse h = (Horse) p.getWorld().spawnCreature(p.getLocation(), EntityType.HORSE);
    37. h.setTamed(true);
    38. h.setOwner(p);
    39. h.getInventory().setSaddle(new ItemStack(Material.SADDLE, 1));
    40. h.setPassenger(p);
    41.  
    42. }
    43. }
     
  4. Offline

    Brendyn Todd

    Jetsinsu
    So basically your wanting to give the player items using the ID's from the config, Correct?
     
  5. Offline

    Jetsinsu

    Brendyn Todd
    Well I can do that but I wan to give players "more" than 1 item in the config. So yes. (You reply fast o.o)
     
  6. Offline

    Brendyn Todd

    Jetsinsu
    You mean instead of one helm multiple helms? Or more items than just the helm? Or am I just an idiot?
     
  7. Offline

    Jetsinsu

    No, you're right. :)
     
  8. Offline

    Brendyn Todd

    Jetsinsu
    Why not just use a HashSet and temporarily store a id to add to the player?
     
  9. Offline

    Jetsinsu

    I would like to start off with the basics xD
     
  10. Offline

    Brendyn Todd

    Jetsinsu
    HashSet is really the only way I see to do that. Just look them up, they aren't THAT complicated.
     
  11. Offline

    Jetsinsu

    I'm looking for one right now. If you can find a tutorial for "Dummies" please send me the link :D(Never learned HashSet before :\
     
Thread Status:
Not open for further replies.

Share This Page