help with my code?

Discussion in 'Plugin Development' started by zack6849, Jul 4, 2012.

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


    essentially, the idea for this plugin is to make it to where you type ./serverinfo it will print everything thats placed under serverinfo: in the yml.

    so instead of having to add more code for each and every line under that i wanted to make it to where annybody using the plugin can add custom lines.
    example config:
    i want it to load all this stuff without requiring modification to the plugins code.
    now for some reason, the plugin when i enter the command sends me no errors, gives no errors in the server prompt, and no errors in essentials. here is the coding for my plugin.
    =================================================== - changed to a pastie link. (indents didn't work in this)
    so if anyone has any idea why this isn't working it would be appreciated.
  2. Offline


    Most likely, you will get a NPE.

    1. for (String serverinfo : getConfig().getStringList("serverinfo")){
    2. Player player = (Player) sender;
    3. sender.sendMessage(serverinfo);
    4. return true;
    5. }

    I will recommend that you create a config like this :
      - server: TystoCraft
      - owner: Tystom3
      - host: Tystom3
      - admins: JMarkus
      - creeper: TNTUP
    In which serverinfo is a List and the strings on the lists are in the format blahblah:value

    Then when you are getting the values do this :

    1. List<String> serverinfo = getConfig().getStringList("serverinfo");
    2. try{
    3. for (String string : serverinfo) {
    4. player.sendMessage(string);
    5. }
    6. }catch (Exception x) {
    7. //error
    8. }
    9. return true;
  3. Offline


    You could create a list like this:
        - Server-TystoCraft
        - Owner-Tystom3
        - Host-Tystom3
    and then read string list and split like this:
    List<String> items = this.plugin.getConfig().getStringList("serverinfo");
                for (String s : items) {
                    String temp[] = s.split("-");
                    player.sendMessage(temp[0] + ": " + temp[1]);
    this will split the string in 2:
    using the server name:
    temp[0] will contain the server title (Server) and temp [1] will contain the the server name (TystoCraft). this will repeat for everything in the list printing it in the chat for the player
  4. Offline


    We both said the exact same thing xD
  5. Offline


    haha :p this is exactly what i implemented in my plugin for the rules and giving items to players
Thread Status:
Not open for further replies.

Share This Page