mesenhanced: add config caching.
This commit is contained in:
@@ -39,6 +39,7 @@ import net.runelite.api.ItemID;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.MenuOpcode;
|
||||
import net.runelite.api.events.AnimationChanged;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
@@ -60,7 +61,9 @@ public class MesEnhanced extends Plugin
|
||||
private static final int GOBLIN_SALUTE = 2128;
|
||||
private static final String LIGHT = "Light";
|
||||
private static final String QUICK_BONE = "Quick Bone";
|
||||
private static final Set<Integer> TINDER = ImmutableSet.of(ItemID.TINDERBOX, ItemID.GOLDEN_TINDERBOX);
|
||||
private static final Set<Integer> TINDER = ImmutableSet.of(
|
||||
ItemID.TINDERBOX, ItemID.GOLDEN_TINDERBOX
|
||||
);
|
||||
private static final Set<Integer> LIGHTABLE_LOGS = ImmutableSet.of(
|
||||
ItemID.LOGS, ItemID.ACHEY_TREE_LOGS, ItemID.OAK_LOGS,
|
||||
ItemID.WILLOW_LOGS, ItemID.TEAK_LOGS, ItemID.ARCTIC_PINE_LOGS, ItemID.MAPLE_LOGS,
|
||||
@@ -80,14 +83,15 @@ public class MesEnhanced extends Plugin
|
||||
private EventBus eventBus;
|
||||
@Inject
|
||||
private MesEnhancedConfig config;
|
||||
|
||||
private boolean tinder;
|
||||
private boolean bones;
|
||||
private boolean leftClickLog;
|
||||
private boolean quickBone;
|
||||
private boolean tick;
|
||||
private int tinderIdx;
|
||||
private int tinderId;
|
||||
private int bonesIdx;
|
||||
private boolean tinder;
|
||||
private int bonesId;
|
||||
private int bonesIdx;
|
||||
private int tinderId;
|
||||
private int tinderIdx;
|
||||
|
||||
@Provides
|
||||
MesEnhancedConfig getConfig(ConfigManager configManager)
|
||||
@@ -98,11 +102,12 @@ public class MesEnhanced extends Plugin
|
||||
@Override
|
||||
public void startUp()
|
||||
{
|
||||
eventBus.subscribe(AnimationChanged.class, this, this::onAnimationChanged);
|
||||
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
|
||||
eventBus.subscribe(GameTick.class, this, this::onGameTick);
|
||||
eventBus.subscribe(ItemContainerChanged.class, this, this::onItemContainerChanged);
|
||||
eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded);
|
||||
eventBus.subscribe(MenuOptionClicked.class, this, this::onMenuOptionClicked);
|
||||
eventBus.subscribe(AnimationChanged.class, this, this::onAnimationChanged);
|
||||
eventBus.subscribe(GameTick.class, this, this::onGameTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,6 +116,17 @@ public class MesEnhanced extends Plugin
|
||||
eventBus.unregister(this);
|
||||
}
|
||||
|
||||
private void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (!event.getGroup().equals("mesEnhanced"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.quickBone = config.quickBones();
|
||||
this.leftClickLog = config.leftClickLog();
|
||||
}
|
||||
|
||||
private void onGameTick(GameTick event)
|
||||
{
|
||||
if (tick)
|
||||
@@ -132,20 +148,20 @@ public class MesEnhanced extends Plugin
|
||||
|
||||
private void onMenuEntryAdded(MenuEntryAdded event)
|
||||
{
|
||||
if (!config.leftClickLog() && !config.quickBones())
|
||||
if (!this.leftClickLog && !this.quickBone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final int id = event.getIdentifier();
|
||||
|
||||
if (config.leftClickLog() && tinder && event.getType() == MenuOpcode.ITEM_USE.getId()
|
||||
if (this.leftClickLog && tinder && event.getType() == MenuOpcode.ITEM_USE.getId()
|
||||
&& LIGHTABLE_LOGS.contains(id))
|
||||
{
|
||||
event.getMenuEntry().setOption(LIGHT);
|
||||
event.setWasModified(true);
|
||||
}
|
||||
else if (config.quickBones() && bones && event.getType() == MenuOpcode.GAME_OBJECT_FIRST_OPTION.getId()
|
||||
else if (this.quickBone && bones && event.getType() == MenuOpcode.GAME_OBJECT_FIRST_OPTION.getId()
|
||||
&& event.getTarget().toLowerCase().contains("altar"))
|
||||
{
|
||||
event.getMenuEntry().setOption(QUICK_BONE);
|
||||
@@ -155,14 +171,14 @@ public class MesEnhanced extends Plugin
|
||||
|
||||
private void onMenuOptionClicked(MenuOptionClicked event)
|
||||
{
|
||||
if (!config.leftClickLog() && !config.quickBones())
|
||||
if (!this.leftClickLog && !this.quickBone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final MenuEntry entry = event.getMenuEntry();
|
||||
|
||||
if (config.leftClickLog() && tinder && event.getOpcode() == MenuOpcode.ITEM_USE.getId()
|
||||
if (this.leftClickLog && tinder && event.getOpcode() == MenuOpcode.ITEM_USE.getId()
|
||||
&& event.getOption().equals(LIGHT))
|
||||
{
|
||||
entry.setOpcode(MenuOpcode.ITEM_USE_ON_WIDGET_ITEM.getId());
|
||||
@@ -170,11 +186,11 @@ public class MesEnhanced extends Plugin
|
||||
client.setSelectedItemSlot(tinderIdx);
|
||||
client.setSelectedItemID(tinderId);
|
||||
}
|
||||
else if (config.quickBones() && bones && event.getOption().equals(QUICK_BONE) && tick)
|
||||
else if (this.quickBone && bones && event.getOption().equals(QUICK_BONE) && tick)
|
||||
{
|
||||
event.consume();
|
||||
}
|
||||
else if (config.quickBones() && bones && event.getOpcode() == MenuOpcode.GAME_OBJECT_FIRST_OPTION.getId()
|
||||
else if (this.quickBone && bones && event.getOpcode() == MenuOpcode.GAME_OBJECT_FIRST_OPTION.getId()
|
||||
&& event.getOption().equals(QUICK_BONE))
|
||||
{
|
||||
entry.setOpcode(MenuOpcode.ITEM_USE_ON_GAME_OBJECT.getId());
|
||||
@@ -187,6 +203,11 @@ public class MesEnhanced extends Plugin
|
||||
|
||||
private void onItemContainerChanged(ItemContainerChanged event)
|
||||
{
|
||||
if (!this.leftClickLog && !this.quickBone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemContainer itemContainer = event.getItemContainer();
|
||||
final List<Item> items = Arrays.asList(itemContainer.getItems());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user