MrBumtart
MrBumtart

Reputation: 481

How do i add a message through a config in bukkit?

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if(sender instanceof Player) {
        Player  player = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("member")) {
            String member = "member " + player.getName();
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), member);
            player.sendMessage(getConfig().getStringList("MemberText"));

How do i make the player.sendMessage(getConfig().getStringList("MemberText")); work? An error message pops up when i try to post it.

Error: The method sendMessage(String) in the type CommandSender is not applicable for the arguments (List)

Upvotes: 1

Views: 1203

Answers (3)

Jojodmo
Jojodmo

Reputation: 23616

You could loop threw all of the values in the config for MemberText, then send those, or one of those, to the player. for example:

List<String> memberTextMessage = new ArrayList<String>();
memberTextMessage = this.getConfig.getStringList("MemberText");
//we now have all of the strings under "MemberText"

for(int i = 0; i < memberTextMessage.size(); i++){
    //loop threw all the messages
    String s = memberTextMessage.get(i);

    player.sendMessage(s); //send the player the string
    //This will send them all of the messages under "MemberText" in the config
}

Just make sure to have a null check right before you assign memberTextMessage to what's in the config, just incase there's nothing under MemberText in the config, otherwise, you will get a NullPointerException:

if(this.getConfig.contains("MemberText"){

else, send the player a message saying there is nothing under MemberText, or, don't send them anything.

Upvotes: 1

BadSkillz
BadSkillz

Reputation: 2003

Either loop through the list and send every line, or if there is only one line of text in the config change getConfig().getStringList("MemberText") to getConfig().getString("MemberText")

More on how to use the config here

Upvotes: 1

Matt Clark
Matt Clark

Reputation: 28619

I am not a Minecraft Modder, however, it appears as if player.sendMessage() expects a string, but the return type of getConfig().getStringList("MemberText") is that of type List.

Try converting your results to a string, or loop through, and sendMessage on each one of the items in the list.

Upvotes: 1

Related Questions