Properly check for changing values in raids plugin

- Determine if we are in raid on startup
- Properly reset state on shutdown
- Do not reset raid state when not necessary

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-07-19 21:16:11 +02:00
parent 6cd71a9a34
commit 2d4c895e5e

View File

@@ -85,11 +85,6 @@ public class RaidsPlugin extends Plugin
private static final String SPLIT_REGEX = "\\s*,\\s*"; private static final String SPLIT_REGEX = "\\s*,\\s*";
private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)]"); private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)]");
private RaidsTimer timer;
@Getter
private boolean inRaidChambers;
@Inject @Inject
private ChatMessageManager chatMessageManager; private ChatMessageManager chatMessageManager;
@@ -117,20 +112,25 @@ public class RaidsPlugin extends Plugin
@Inject @Inject
private SpriteManager spriteManager; private SpriteManager spriteManager;
@Getter
private final ArrayList<String> roomWhitelist = new ArrayList<>();
@Getter
private final ArrayList<String> roomBlacklist = new ArrayList<>();
@Getter
private final ArrayList<String> rotationWhitelist = new ArrayList<>();
@Getter
private final ArrayList<String> layoutWhitelist = new ArrayList<>();
@Getter @Getter
private Raid raid; private Raid raid;
@Getter @Getter
private ArrayList<String> roomWhitelist = new ArrayList<>(); private boolean inRaidChambers;
@Getter private RaidsTimer timer;
private ArrayList<String> roomBlacklist = new ArrayList<>();
@Getter
private ArrayList<String> rotationWhitelist = new ArrayList<>();
@Getter
private ArrayList<String> layoutWhitelist = new ArrayList<>();
@Provides @Provides
RaidsConfig provideConfig(ConfigManager configManager) RaidsConfig provideConfig(ConfigManager configManager)
@@ -149,14 +149,8 @@ public class RaidsPlugin extends Plugin
{ {
overlayManager.add(overlay); overlayManager.add(overlay);
overlayManager.add(pointsOverlay); overlayManager.add(pointsOverlay);
if (client.getGameState() == GameState.LOGGED_IN)
{
inRaidChambers = client.getVar(Varbits.IN_RAID) == 1;
updateInfoBoxState();
}
updateLists(); updateLists();
checkRaidPresence(true);
} }
@Override @Override
@@ -164,40 +158,28 @@ public class RaidsPlugin extends Plugin
{ {
overlayManager.remove(overlay); overlayManager.remove(overlay);
overlayManager.remove(pointsOverlay); overlayManager.remove(pointsOverlay);
infoBoxManager.removeInfoBox(timer);
if (timer != null) inRaidChambers = false;
{ raid = null;
infoBoxManager.removeInfoBox(timer); timer = null;
}
} }
@Subscribe @Subscribe
public void onConfigChanged(ConfigChanged event) public void onConfigChanged(ConfigChanged event)
{ {
if (!event.getGroup().equals("raids"))
{
return;
}
if (event.getKey().equals("raidsTimer")) if (event.getKey().equals("raidsTimer"))
{ {
updateInfoBoxState(); updateInfoBoxState();
return;
} }
if (event.getKey().equals("whitelistedRooms")) updateLists();
{ checkRaidPresence(true);
updateList(roomWhitelist, config.whitelistedRooms());
}
if (event.getKey().equals("blacklistedRooms"))
{
updateList(roomBlacklist, config.blacklistedRooms());
}
if (event.getKey().equals("whitelistedRotations"))
{
updateList(rotationWhitelist, config.whitelistedRotations());
}
if (event.getKey().equals("whitelistedLayouts"))
{
updateList(layoutWhitelist, config.whitelistedLayouts());
}
} }
@Subscribe @Subscribe
@@ -219,47 +201,7 @@ public class RaidsPlugin extends Plugin
@Subscribe @Subscribe
public void onVarbitChange(VarbitChanged event) public void onVarbitChange(VarbitChanged event)
{ {
boolean setting = client.getVar(Varbits.IN_RAID) == 1; checkRaidPresence(false);
if (inRaidChambers != setting)
{
inRaidChambers = setting;
updateInfoBoxState();
if (inRaidChambers)
{
raid = buildRaid();
if (raid == null)
{
log.debug("Failed to build raid");
return;
}
Layout layout = layoutSolver.findLayout(raid.toCode());
if (layout == null)
{
log.debug("Could not find layout match");
return;
}
raid.updateLayout(layout);
RotationSolver.solve(raid.getCombatRooms());
overlay.setScoutOverlayShown(true);
}
else if (!config.scoutOverlayAtBank())
{
overlay.setScoutOverlayShown(false);
raid = null;
}
}
if (client.getVar(VarPlayer.IN_RAID_PARTY) == -1)
{
overlay.setScoutOverlayShown(false);
raid = null;
}
} }
@Subscribe @Subscribe
@@ -321,23 +263,73 @@ public class RaidsPlugin extends Plugin
} }
} }
private void checkRaidPresence(boolean force)
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return;
}
boolean setting = client.getVar(Varbits.IN_RAID) == 1;
if (force || inRaidChambers != setting)
{
inRaidChambers = setting;
updateInfoBoxState();
if (inRaidChambers)
{
raid = buildRaid();
if (raid == null)
{
log.debug("Failed to build raid");
return;
}
Layout layout = layoutSolver.findLayout(raid.toCode());
if (layout == null)
{
log.debug("Could not find layout match");
return;
}
raid.updateLayout(layout);
RotationSolver.solve(raid.getCombatRooms());
overlay.setScoutOverlayShown(true);
}
else if (!config.scoutOverlayAtBank())
{
overlay.setScoutOverlayShown(false);
}
}
if (client.getVar(VarPlayer.IN_RAID_PARTY) == -1)
{
overlay.setScoutOverlayShown(false);
}
}
private void updateInfoBoxState() private void updateInfoBoxState()
{ {
if (timer != null) if (timer == null)
{ {
if (inRaidChambers && config.raidsTimer()) return;
{ }
infoBoxManager.addInfoBox(timer);
}
else
{
infoBoxManager.removeInfoBox(timer);
}
if (!inRaidChambers) if (inRaidChambers && config.raidsTimer())
{ {
timer = null; infoBoxManager.addInfoBox(timer);
} }
else
{
infoBoxManager.removeInfoBox(timer);
}
if (!inRaidChambers)
{
timer = null;
} }
} }
@@ -372,7 +364,7 @@ public class RaidsPlugin extends Plugin
} }
} }
public int getRotationMatches() int getRotationMatches()
{ {
String rotation = raid.getRotationString().toLowerCase(); String rotation = raid.getRotationString().toLowerCase();
String[] bosses = rotation.split(SPLIT_REGEX); String[] bosses = rotation.split(SPLIT_REGEX);