Help with String Lists and kits

Discussion in 'Plugin Development' started by BillyBobJoe168, Apr 5, 2014.

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

    BillyBobJoe168

    Hi guys! I am currently trying to make a plugin where is you type in /sm kit <kit name> it will give you certain items. I want to be able to edit these items in a config file. My config file used to be like this:
    Code:
    kits:
      archer:
        rank: default
        item1: 261 1
        item2: 262 64
    etc.
    Now, I want to use string lists so I want it to be like this:
    Code:
    kits:
      archer:
      - 261 1
      - 262 64
      - etc.
      archerrank: default
    My code for the default rank kits is:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. Player player = (Player) sender;
    3. if (cmd.getName().equalsIgnoreCase("sm")) {
    4. int length = args.length;
    5. if (length == 2) {
    6. if (args[0].equalsIgnoreCase("kit")) {
    7. if (args[1].equalsIgnoreCase(args[1])) {
    8. if (getConfig().getString("kits." + args[1] + "rank").equalsIgnoreCase("default")) {
    9. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "clear -a " + player.getName());
    10. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "give " + player.getName() + " " + getConfig().getString("kits." + args[1]));
    11. player.sendMessage(ChatColor.YELLOW + "You have chosen the " + ChatColor.GREEN + args[1] + ChatColor.YELLOW + " kit!");
    12. }
    13. }
    14. }
    15. }
    16. }
    17. return false;
    18. }

    Now, I am nooby and there fore do not know what to do with string lists because this is my first time using them. Could someone please tell me how to give players each of the items on a string list?
     
  2. Offline

    Gater12

    BillyBobJoe168
    Loop through the String lists.
    Example:
    Code:java
    1. for(String s : getConfig().getStringList("path.to.here")){
    2. /* Insert functions here */
    3. }
     
  3. Offline

    BillyBobJoe168

    Gater12 Oh so after that, I would put the /give <playername> s command to give the player all the items in the string?
     
  4. Offline

    Gater12

    BillyBobJoe168
    I'm sorry? Do you know the basics of Java and the Bukkit API?
     
  5. Offline

    Monkey_Swag

    Gater12 from what I can see, he probably copy/pasted some code from some tutorial. He is trying to use a /give command for some reason...
     
  6. Offline

    BillyBobJoe168

    Gater12 I'm sorry? did you not read the 2nd to last line of my first post?

    Monkey_Swag No I did not copy paste any code for any of my plugins. I always write my own code from scratch.

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

    Gater12

  8. Offline

    BillyBobJoe168

    Um actually if I put
    Code:
    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "give " + player.getName() + " " + s);
    
    inside a for loop it works...not sure why you decided to ask if I new the basics of Java and the Bukkit API...
     
  9. BillyBobJoe168
    May I ask why you're dispatching a command instead of simply adding it to the player's inventory?
     
  10. Offline

    BillyBobJoe168

    The Gaming Grunts Not sure how. I'm trying to figure that out. That is just temporary. My config file is like this:
    Code:
    kits:
      archer:
      - 261 1
      - 262 64
      - 298 1
      - 299 1
      - 300 1
      - 301 1
      archerrank: default
    the player.getInventory().addItem() thing isn't really working for me because I get a string list but this requires and Integer. Do you know how I could do this?

    Is there a way to use splits to separate the item and the amount and then do the player.getInventory().addItem(first half of the split, second half of the split)? Never used splits before but I'm thinking there should be a way to separate them with commas and then be able to get both halves separately right?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page