Plugin config send me a message saying "null"

Discussion in 'Plugin Development' started by stantheman68, Jul 24, 2012.

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

    stantheman68

    Hey bukkit fourms, I recently made a small plugin when you do /staff it is suppose to get what is in the config and send it to you. But when I do the command instead of sending me the ranks that I put in it and also the players it will only send me "null" in all the ranks colors.

    Here is the code:
    Code:
    package me.stantheman68.staff;
     
     
    import java.util.logging.Logger;
     
    import me.stantheman68.staff.Staff;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Staff extends JavaPlugin{
    public final Logger logger = Logger.getLogger("Minecraft");
    public static Staff plugin;
     
    @Override
    public void onDisable() {
    PluginDescriptionFile pdfFile = this.getDescription();
      this.logger.info(pdfFile.getName() + " Has Been Disabled! Made By Stantheman68! ");
    }
     
    @Override
    public void onEnable() {
    PluginDescriptionFile pdfFile = this.getDescription();
      this.logger.info(pdfFile.getName() + "Version" + pdfFile.getVersion() + " Has Been Enabled! Made By Stantheman68");
      getConfig().options().copyDefaults(true);
    saveConfig();
     
    }
     
     
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
      Player player = (Player) sender;
     
      if(commandLabel.equalsIgnoreCase("staff")){
    player.sendMessage(ChatColor.DARK_AQUA + getConfig().getString("owner:"));
    player.sendMessage(ChatColor.DARK_RED + getConfig().getString("headadmin(s):"));
    player.sendMessage(ChatColor.AQUA + getConfig().getString("admin(s):"));
    player.sendMessage(ChatColor.LIGHT_PURPLE + getConfig().getString("headmod(s):"));
    player.sendMessage(ChatColor.LIGHT_PURPLE + getConfig().getString("mod(s):"));
    player.sendMessage(ChatColor.DARK_PURPLE + getConfig().getString("helper(s):"));
    player.sendMessage(ChatColor.GOLD + "[" + ChatColor.WHITE + "Tip" + ChatColor.GOLD + "]" + ChatColor.WHITE + "Ranks colors are not %100 right.");
        }
    return false;
    }
    } 
    
    Here is the config.yml and plugin.yml:
    Condig.yml:

    Owner: stantheman68,end.
    HeadAdmin(s): chamallama82,end.
    Admin(s): end.
    HeadMod(s): end.
    Mod(s): end.
    Helper(s): end.


    Plugin.yml:

    name: Staff
    main: me.stantheman68.staff.Staff
    version: 1.0
    description: >
    Shows all the staff!
    commands:
    staff:
    description: Shows all the staff!


    Please help.
     
  2. Offline

    chaseoes

    I think the ()'s in your config screw with YAML. Try removing them.
     
  3. Offline

    stantheman68

    It didnt seem to work
     
  4. Offline

    chaseoes

    Post everything you have now?
    Edit: When using .getString("string:");, don't include the :'s, so:
    Code:
    getConfig().getString("string");
     
  5. Offline

    sensus12

    Delete ("player.sendMessage(), use getConfig().getString("");
     
  6. Offline

    Haza2169

    Where you entered your string getConfig().getString("Owner");

    Remove the ':' after the String name NOT on the config.yml but on the code
     
  7. Offline

    chaseoes

    Thanks, it's not like anybody already said that.
     
  8. Offline

    Haza2169

    ohh, sorry, didnt see
     
  9. Offline

    stantheman68

    It didnt work...when i do the command /staff instead of all the ranks it will send me "null" in all the ranks places with there colors.
     
  10. Offline

    lololmaker

    Try working around this:
    Code:java
    1. Boolean sentRank = false;
    2. for(String rank : getConfig().getKeys(false)){
    3. sentRank = false;
    4. for(String player : getConfig.getStringList(rank){
    5. if(sentRank){
    6. sender.sendMessage(player);
    7. }else{
    8. sender.sendMessage(rank);
    9. sender.sendMessage(player);
    10. sentRank = true;
    11. }
    12. }


    I just looked into javadocs, not tested at all. Basically you *should* get all the ranks and all players in with that rank and than sending it. sentRank variable *should* prevent you from sending rank for every player, so output *should* be:

    Owner
    player
    Admin
    player2
    player3

    When without sentRank would *probably* be:

    Owner
    player
    Admin
    player2
    Admin
    player3


    Really, just some javadocs, it's not for copy paste, if this method works, it's flexible to all the possible ranks and users in file, not just some static ranks.
     
Thread Status:
Not open for further replies.

Share This Page