Splitting Config Help

Discussion in 'Spigot Plugin Development' started by Haydenman2, May 19, 2016.

  1. I'm trying to create a relatively complicated kit plugin that allows people to create kits in game. So far, I've gotten to the point that my config that stores the kit info looks like this:
    Code (Text):
        created: true
          STONE_AXE: STONE_AXE,1, 0
          STONE_HOE: STONE_HOE,1, 0
    My question is how I would go about splitting all the entries individually under items into strings that I could then use to hand out said items. Basically, I want people to be able to type /kit Stone and receive all five of those items. The only problem is, I have no clue how to do that. I also want it to be versatile so that I can add in a kit with any items and varying amount of items and spit out the correct items.

    Any help is appreciated, I've been sat here for an hour scratching my head trying to solve this problem.
  2. Use StringUtils
  3. I'm not sure I know what or where to use StringUtils, so can I get a code example?
  4. Use this and if that doesnt work search it up
  5. well you can use this information to help you saving with sorty config you want
    Code (Java):
    String MyName = "MadMax-Cookie";
    String[] parts = MyName.split("-");
    String part 1 = part[0]; // MadMax
    String part 2 = part[1]; // Cookie
    Code (Java):
    // If you'd like to retain the split character in the resulting parts, then make use of [URL='http://www.regular-expressions.info/lookaround.html']positive lookaround[/URL]. In case you want to have the split character to end up in left hand side, use positive lookbehind by prefixing ?<= group on the pattern.

    String MyName ="MadMax-Cookie";
    String[] parts = MyName.split("(?<=-)");
    String part1 = parts[0];// MadMax-
    String part2 = parts[1];// Cookie;
    Code (Java):
    // In case you want to have the split character to end up in right hand side, use positive lookahead by prefixing ?= group on the pattern.

    String MyName ="MadMax-Cookie";
    String[] parts = MyName.split("(?=-)");
    String part1 = parts[0];// MadMax
    String part2 = parts[1];// -Cookie
    Code (Java):
    // If you'd like to limit the number of resulting parts, then you can supply the desired number as 2nd argument of split() method.

    String MyName = "MadMax-Cookie-Cool";
    String[] parts = MyName.split("-", 2);
    String part1 = parts[0];// MadMax
    String part2 = parts[1];// Cookie-Cool
    #5 MadMaxCookie, May 19, 2016
    Last edited: May 19, 2016
  6. If you want to go all out, use JSON and read/write the kits when edited and when the server starts up.
    Using gson, you can easily convert an object into text and vice versa.

    before gson

    Code (Text):
    package com.xilixir.test;

    import java.util.List;

    public class YourClass {
        private String random;
        private long words;
        private List<String> ftw;

        public YourClass(String random, long words, List<String> ftw) {
            this.random = random;
            this.words = words;
            this.ftw = ftw;
    after gson

    Code (Text):
      "random": "test1",
      "words": 1337,
      "ftw": [
    If you know how to write/read files already, this should help you.
  7. This, or if you want to use YAML make your class implement ConfigurationSerializable