package core.entities.menus;

import java.util.ArrayList;
import java.util.List;

import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;

public class Menu {
	
	private List<MenuItem> menuItemList = new ArrayList<MenuItem>();
	private MessageChannel channel;
	private Message statusMessage;
	
	
	public Menu(MessageChannel c){
		this.channel = c;
	}
	
	public MenuItem getMenuItem(String id){
		for(MenuItem m : menuItemList){
			if (m.getId().equals(id)){
				return m;
			}
		}
		return null;
	}
	
	public MenuItem getMenuItemByText(String text){
		for(MenuItem m : menuItemList){
			if (m.getText().equals(text)){
				return m;
			}
		}
		return null;
	}
	
	public void createMenuItem(String text, String[] buttons){
		menuItemList.add(new MenuItem(channel, text, buttons));
	}
	
	public void createMenuItem(String text, String button){
		menuItemList.add(new MenuItem(channel, text, button));
	}
	
	public void createStatusMessage(String text){
		statusMessage = channel.sendMessage(text).complete();
	}
	
	public void editStatusMessage(String text){
		statusMessage.editMessage(text).complete();
	}
	
	public MessageChannel getChannel(){
		return channel;
	}
	
	public void deleteMenuItems(){
		menuItemList.forEach((mi) -> mi.remove());
		menuItemList.clear();
	}
	
	public void deleteMenuItem(MenuItem mi){
		mi.remove();
		menuItemList.remove(mi);
	}
	
	public void deleteStatusMessage(){
		statusMessage.delete().complete();
	}
}

@@ -326,16 +326,23 @@
 sMessage
+ = null
 ;%0A%09%0A%09%0A%09p
@@ -1441,16 +1441,46 @@
 sage()%7B%0A
+%09%09if(statusMessage != null)%7B%0A%09
 %09%09status
@@ -1508,13 +1508,17 @@
 lete();%0A
+%09%09%7D%0A
 %09%7D%0A%7D%0A

Add null check to statusMessage