/*
 * Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package net.runelite.client.plugins.boosts;

import com.google.common.collect.ObjectArrays;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Binder;
import com.google.inject.Provides;
import javax.inject.Inject;
import lombok.Getter;
import net.runelite.api.Skill;
import net.runelite.api.events.ConfigChanged;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;

@PluginDescriptor(
	name = "Boosts plugin"
)
public class BoostsPlugin extends Plugin
{
	private static final Skill[] COMBAT = new Skill[]
	{
		Skill.ATTACK, Skill.STRENGTH, Skill.DEFENCE, Skill.RANGED, Skill.MAGIC
	};
	private static final Skill[] SKILLING = new Skill[]
	{
		Skill.MINING, Skill.AGILITY, Skill.SMITHING, Skill.HERBLORE, Skill.FISHING, Skill.THIEVING,
		Skill.COOKING, Skill.CRAFTING, Skill.FIREMAKING, Skill.FLETCHING, Skill.WOODCUTTING, Skill.RUNECRAFT,
		Skill.SLAYER, Skill.FARMING, Skill.CONSTRUCTION, Skill.HUNTER
	};

	@Inject
	InfoBoxManager infoBoxManager;

	@Inject
	BoostsOverlay boostsOverlay;

	@Inject
	BoostsConfig config;

	@Getter
	private Skill[] shownSkills;

	@Override
	public void configure(Binder binder)
	{
		binder.bind(BoostsOverlay.class);
	}

	@Provides
	BoostsConfig provideConfig(ConfigManager configManager)
	{
		return configManager.getConfig(BoostsConfig.class);
	}

	@Override
	public Overlay getOverlay()
	{
		return boostsOverlay;
	}

	@Subscribe
	public void onConfigChanged(ConfigChanged event)
	{
		if (!config.enabled())
		{
			return;
		}

		if (config.enableSkill())
		{
			shownSkills = ObjectArrays.concat(COMBAT, SKILLING, Skill.class);
		}
		else
		{
			shownSkills = COMBAT;
		}

		if (event.getKey().equals("displayIndicators"))
		{
			for (BoostIndicator indicator : boostsOverlay.getIndicators())
			{
				if (indicator == null)
				{
					continue;
				}

				if (config.displayIndicators())
				{
					infoBoxManager.addInfoBox(indicator);
				}
				else
				{
					infoBoxManager.removeInfoBox(indicator);
				}
			}
		}
	}
}

@@ -2959,260 +2959,278 @@
 %0A%0A%09@
-Subscribe%0A%09public void onConfigChanged(ConfigChanged event)%0A%09%7B%0A%09%09if (!config.enabled())%0A%09%09%7B%0A%09%09%09return;%0A%09%09%7D%0A%0A%09%09if (config.enableSkill())%0A%09%09%7B%0A%09%09%09shownSkills = ObjectArrays.concat(COMBAT, SKILLING, Skill.class);%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09shownSkills = COMBAT;%0A%09%09%7D
+Override%0A%09protected void startUp()%0A%09%7B%0A%09%09if (config.enabled())%0A%09%09%7B%0A%09%09%09updateShownSkills(config.enableSkill());%0A%09%09%7D%0A%09%7D%0A%0A%09@Subscribe%0A%09public void onConfigChanged(ConfigChanged event)%0A%09%7B%0A%09%09if (!config.enabled())%0A%09%09%7B%0A%09%09%09return;%0A%09%09%7D%0A%0A%09%09updateShownSkills(config.enableSkill());
 %0A%0A%09%09
@@ -3576,11 +3576,221 @@
 %7D%0A%09%09%7D%0A%09%7D
+%0A%0A%09private void updateShownSkills(boolean showSkillingSkills)%0A%09%7B%0A%09%09if (showSkillingSkills)%0A%09%09%7B%0A%09%09%09shownSkills = ObjectArrays.concat(COMBAT, SKILLING, Skill.class);%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09shownSkills = COMBAT;%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

Fix NPEs from BoostsPlugin at startup