Solved Retreiving Config String and Returning value on /command

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

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

    14manj01

    Hello, I am confused on how to get my command to reply with a string the player set in the plugin config. My config consists of one string called newjoinmessage. This string will be updated time to time to give various information to the player etc.

    My issue is how do I configure the plugin to reply with the string from the config, when a user types /njm or newjoinmessage (note ill clean up the command later to add the other abbreviation). Below is where I am having the issue setting up the command return.

    public boolean onCommand(CommandSender sender, Command command, String label, String[] arguments){
    // /help label would - help argument would be empty list
    if (cmd.getName().equalsIgnoreCase("NewJoinMessage")){
    sender.sendMessage(newjoinmessage);
    getConfig().getString(newjoinmessage);



    Full plugin class below...

    Code:
    package me.myip.newjoinmessage;
    //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.Event;
    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 = "";
          
            //creates a config file, sets a default line of text for the config file.
            config.set(newjoinmessage, "Configure this");
            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 command, String label, String[] arguments){
            // /help label would - help argument would be empty list
            if (cmd.getName().equalsIgnoreCase("NewJoinMessage")){
                sender.sendMessage(newjoinmessage); <=== doesnt work
                getConfig().getString(newjoinmessage); <=== doesn't work either
                //below may need to be returned false as it will send a player a default message, stating cmd
                return true;
            }
          
            return false;
        }
    }
    //:
    //;
    Thank you for reading
     
  2. Offline

    yPedx

    @14manj01
    Put the getConfig above the sendMessage. You have to specify where to get the string from, example:
    Code:
    String newJoinMessage = getConfig().getString("path.to.string");
    // then
    sender.sendMessage(newJoinMessage);
    Also, do not log your own plugins, Bukkit does this by itself.
     
  3. Offline

    14manj01


    Thank you,
     
Thread Status:
Not open for further replies.

Share This Page