Hi, i would like to do a /help command. The player will get a return from config file within the list "HelpMessages". All the "Messages" in the list will be send to the player. I would also like to implement color codes. My current code looks like this: Code: public class Help implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(args.length == 0){ @SuppressWarnings("unchecked") List<String> helpmessages = (List<String>)Main.plugin.getConfig().getList("HelpMessages"); sender.sendMessage(helpmessages); } sender.sendMessage("Will be added soon"); return false; } } And o would like to have my config like this: PHP: HelpMessages:- 'Line1'- 'Line2'- 'Should be avalible'- 'to add how many'- 'lines you want' Thank you so much is this how i should do it? Code: @SuppressWarnings("unchecked") List<String> helpmessages = (List<String>)Main.plugin.getConfig().getList("HelpMessages"); String Message = helpmessages.toString(); sender.sendMessage(Message); merged
all of the content in the list are added into one line i minecraft. I want it to be seperated lines i minecraft too... yes, everything is comming out in one line. What i wanted was on seperated lines EDIT by Timtower: merged posts, please use the edit button instead of double posting.
1. Don't cast to List<String>. You can use .getStringList("path") instead of .getList("path") 2. Loop through the list and send the player the message of the current String you are iterating over
@stamline There are two ways you can do this. 1: Loop through all the strings, use the methods listed above for color codes, and send each one individually. Create a String field and create a loop for all the strings. Inside that loop you would take the string field, add "\n" (\n means new line) and then the next String.
@teej107 but if i have 1000 messages i will send, do i have to make a new "player.sendMessage();" every time?
@stamline If you use the first way that I mentioned, yes. If you use the second way I mentioned (using \n), then you would only need to use the .sendmessage once.
There is .sendMessage(String str) and .sendMessage(String[] str)... so you could just turn that list into an array: Code: .sendMessage((String[]) list.toArray()); I think this would be the easiest solution but it won't support color codes. If you want color codes you need to use @Zombie_Striker's or @teej107's answers