Wintertodt selective eventbus listening
This commit is contained in:
@@ -37,6 +37,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import static net.runelite.api.AnimationID.*;
|
import static net.runelite.api.AnimationID.*;
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import static net.runelite.api.GameState.LOADING;
|
||||||
import net.runelite.api.InventoryID;
|
import net.runelite.api.InventoryID;
|
||||||
import net.runelite.api.Item;
|
import net.runelite.api.Item;
|
||||||
import net.runelite.api.ItemContainer;
|
import net.runelite.api.ItemContainer;
|
||||||
@@ -49,6 +50,7 @@ import net.runelite.api.events.AnimationChanged;
|
|||||||
import net.runelite.api.events.ChatMessage;
|
import net.runelite.api.events.ChatMessage;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.ItemContainerChanged;
|
import net.runelite.api.events.ItemContainerChanged;
|
||||||
import net.runelite.api.events.VarbitChanged;
|
import net.runelite.api.events.VarbitChanged;
|
||||||
import net.runelite.client.Notifier;
|
import net.runelite.client.Notifier;
|
||||||
@@ -114,6 +116,8 @@ public class WintertodtPlugin extends Plugin
|
|||||||
private WintertodtNotifyMode notifyCondition;
|
private WintertodtNotifyMode notifyCondition;
|
||||||
private Color damageNotificationColor;
|
private Color damageNotificationColor;
|
||||||
|
|
||||||
|
private boolean subscribed;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
WintertodtConfig getConfig(ConfigManager configManager)
|
WintertodtConfig getConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
@@ -130,12 +134,15 @@ public class WintertodtPlugin extends Plugin
|
|||||||
|
|
||||||
reset();
|
reset();
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
|
|
||||||
|
handleWintertodtRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
super.shutDown();
|
eventBus.unregister(this);
|
||||||
|
eventBus.unregister("inside-wintertodt");
|
||||||
|
|
||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
reset();
|
reset();
|
||||||
@@ -144,11 +151,23 @@ public class WintertodtPlugin extends Plugin
|
|||||||
private void addSubscriptions()
|
private void addSubscriptions()
|
||||||
{
|
{
|
||||||
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
|
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
|
||||||
eventBus.subscribe(GameTick.class, this, this::onGameTick);
|
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
|
||||||
eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged);
|
eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged);
|
||||||
eventBus.subscribe(ChatMessage.class, this, this::onChatMessage);
|
}
|
||||||
eventBus.subscribe(AnimationChanged.class, this, this::onAnimationChanged);
|
|
||||||
eventBus.subscribe(ItemContainerChanged.class, this, this::onItemContainerChanged);
|
private void wintertodtSubscriptions(boolean subscribe)
|
||||||
|
{
|
||||||
|
if (subscribe)
|
||||||
|
{
|
||||||
|
eventBus.subscribe(GameTick.class, "inside-wintertodt", this::onGameTick);
|
||||||
|
eventBus.subscribe(ChatMessage.class, "inside-wintertodt", this::onChatMessage);
|
||||||
|
eventBus.subscribe(AnimationChanged.class, "inside-wintertodt", this::onAnimationChanged);
|
||||||
|
eventBus.subscribe(ItemContainerChanged.class, "inside-wintertodt", this::onItemContainerChanged);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eventBus.unregister("inside-wintertodt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onConfigChanged(ConfigChanged event)
|
private void onConfigChanged(ConfigChanged event)
|
||||||
@@ -180,9 +199,24 @@ public class WintertodtPlugin extends Plugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onGameTick(GameTick gameTick)
|
private void handleWintertodtRegion()
|
||||||
{
|
{
|
||||||
if (!isInWintertodtRegion())
|
if (isInWintertodtRegion())
|
||||||
|
{
|
||||||
|
if (!isInWintertodt)
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
log.debug("Entered Wintertodt!");
|
||||||
|
}
|
||||||
|
isInWintertodt = true;
|
||||||
|
|
||||||
|
if (!subscribed)
|
||||||
|
{
|
||||||
|
wintertodtSubscriptions(true);
|
||||||
|
subscribed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (isInWintertodt)
|
if (isInWintertodt)
|
||||||
{
|
{
|
||||||
@@ -191,16 +225,25 @@ public class WintertodtPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
isInWintertodt = false;
|
isInWintertodt = false;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isInWintertodt)
|
if (subscribed)
|
||||||
|
{
|
||||||
|
wintertodtSubscriptions(false);
|
||||||
|
subscribed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onGameStateChanged(GameStateChanged event)
|
||||||
|
{
|
||||||
|
if (event.getGameState() == LOADING)
|
||||||
{
|
{
|
||||||
reset();
|
handleWintertodtRegion();
|
||||||
log.debug("Entered Wintertodt!");
|
|
||||||
}
|
}
|
||||||
isInWintertodt = true;
|
}
|
||||||
|
|
||||||
|
private void onGameTick(GameTick gameTick)
|
||||||
|
{
|
||||||
checkActionTimeout();
|
checkActionTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,11 +295,6 @@ public class WintertodtPlugin extends Plugin
|
|||||||
|
|
||||||
private void onChatMessage(ChatMessage chatMessage)
|
private void onChatMessage(ChatMessage chatMessage)
|
||||||
{
|
{
|
||||||
if (!isInWintertodt)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatMessageType chatMessageType = chatMessage.getType();
|
ChatMessageType chatMessageType = chatMessage.getType();
|
||||||
|
|
||||||
if (chatMessageType != ChatMessageType.GAMEMESSAGE && chatMessageType != ChatMessageType.SPAM)
|
if (chatMessageType != ChatMessageType.GAMEMESSAGE && chatMessageType != ChatMessageType.SPAM)
|
||||||
@@ -395,11 +433,6 @@ public class WintertodtPlugin extends Plugin
|
|||||||
|
|
||||||
private void onAnimationChanged(final AnimationChanged event)
|
private void onAnimationChanged(final AnimationChanged event)
|
||||||
{
|
{
|
||||||
if (!isInWintertodt)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Player local = client.getLocalPlayer();
|
final Player local = client.getLocalPlayer();
|
||||||
|
|
||||||
if (event.getActor() != local)
|
if (event.getActor() != local)
|
||||||
@@ -445,7 +478,7 @@ public class WintertodtPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
final ItemContainer container = event.getItemContainer();
|
final ItemContainer container = event.getItemContainer();
|
||||||
|
|
||||||
if (!isInWintertodt || container != client.getItemContainer(InventoryID.INVENTORY))
|
if (container != client.getItemContainer(InventoryID.INVENTORY))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user