Solved getconfig().getstring() not printing string issue.

Discussion in 'Plugin Development' started by 14manj01, May 30, 2017.

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

    14manj01

    So what I am trying to do is get the config file and a string from the config that a user is able to set, and from that print whatever the user has configured it to. However, when pulling the string it doesn't print anything. I tested that everything else works by making a default message when the command is ran to ensure there wasn't any other unforeseen issues.



    Plugin Class (Only one class ATM)
    Code:
    package me.myip.newjoinmessage;
    import org.bukkit.ChatColor;
    //imports craftbukkit for usage, this will allways be needed
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class newjoinmessage extends JavaPlugin implements Listener {
    
    //All stuff I forgot
    FileConfiguration config = getConfig();
      
        public void onEnable(){
            //getServer().getLogger().info("New Join MSG: Visit mc.beyondhorizonmc.net for support");
          
            //default string for new join message
            String newjoinmessage = "NewJoinText";
            //creates a config file, sets a default line of text for the config file.
            config.set(newjoinmessage, "Configure");
            config.options().copyDefaults(true);
            saveConfig();
            //checking for new people
            getServer().getPluginManager().registerEvents(this, this);
        }
        public void onDisable(){
            //getServer().getLogger().info("New Join MSG Disabled");
        }
    //MAIN BODY OF PLUGIN  
      
        @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
        if (config.getBoolean("Welcome to the Server, visit mc.beyondhorizonmc.net for help")){
                player.sendMessage("Welcome to the Server, visit mc.beyondhorizonmc.net for help ");
      
        }else {
          
        }
      
      
      
        }
      
      
      
      
      
      
      
        //@EventHandler
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arguments){
            // /help label would - help argument would be empty list
            if (cmd.getName().equalsIgnoreCase("newjoinmessage")){
            String newjoinmessage = getConfig().getString("newjoinmessage");
            sender.sendMessage(ChatColor.RED + "It should be printing  below  this");
            sender.sendMessage(newjoinmessage);   //<--- this should print that right???
                //below may need to be returned false as it will send a player a default message, stating cmd
                return true;
            }
          
            return false;
        }
    }
    //:
    //;



    config.yml is simply, the string name and the configure which is created by the class.




    However, the error is that it doesn't pring the config string just It should be printing below this. Thank you for any insight you guys may provide!
     
  2. Offline

    YoloSanta

    So your problem is the string is not showing up? When u issue the command /newjoinmessage ?
     
  3. Offline

    14manj01

    Yes Sir. I need to ensure that this works so when I create the new join message for players and set it to show on first join.
     
  4. Offline

    YoloSanta

    So basically like a motd plugin? When a player joins a message is shown to them, for example "You are now playing on the <server name> Network!"
     
  5. Offline

    14manj01

    No, its for new players only. I fixed it.
     
Thread Status:
Not open for further replies.

Share This Page