Add proper nullity checks for task name and location

This commit is contained in:
Davis Cook
2019-02-12 17:49:12 -05:00
parent cdfffd9780
commit b332e7ba97
2 changed files with 39 additions and 24 deletions

View File

@@ -242,8 +242,7 @@ public class SlayerPlugin extends Plugin
clientToolbar.addNavigation(navButton);
if (client.getGameState() == GameState.LOGGED_IN
&& config.amount() != -1
if (config.amount() != -1
&& !config.taskName().isEmpty())
{
points = config.points();
@@ -283,24 +282,8 @@ public class SlayerPlugin extends Plugin
{
case HOPPING:
case LOGGING_IN:
cachedXp = 0;
currentTask = new TaskData(0, 0, 0,0, 0, "", "", true);
loginFlag = true;
highlightedTargets.clear();
break;
case LOGGED_IN:
if (config.amount() != -1
&& !config.taskName().isEmpty()
&& loginFlag)
{
points = config.points();
streak = config.streak();
setExpeditiousChargeCount(config.expeditious());
setSlaughterChargeCount(config.slaughter());
setTask(config.taskName(), config.amount(), config.initialAmount(), true, config.taskLocation());
loginFlag = false;
}
break;
}
}
@@ -341,6 +324,11 @@ public class SlayerPlugin extends Plugin
// (and close npc dialog) or go into the rewards screen which also closes npc dialog
private boolean canMatchDialog = true;
// rising edge detection isn't enough for some reason (don't know why) so in addition to a rising edge rather than
// instantly allowing for another assignment we'll do a 2 tick refractory period
private static final int FORCED_WAIT = 2;
private int forcedWait = -1;
@Subscribe
public void onGameTick(GameTick tick)
{
@@ -360,12 +348,14 @@ public class SlayerPlugin extends Plugin
String location = mAssign.group("location");
setTask(name, amount, amount, true, location);
canMatchDialog = false;
forcedWait = FORCED_WAIT;
}
else if (mAssignFirst.find())
{
int amount = Integer.parseInt(mAssignFirst.group(2));
setTask(mAssignFirst.group(1), amount, amount, true);
canMatchDialog = false;
forcedWait = FORCED_WAIT;
}
else if (mAssignBoss.find())
{
@@ -373,6 +363,7 @@ public class SlayerPlugin extends Plugin
setTask(mAssignBoss.group(1), amount, amount, true);
points = Integer.parseInt(mAssignBoss.group(3).replaceAll(",", ""));
canMatchDialog = false;
forcedWait = FORCED_WAIT;
}
else if (mCurrent.find())
{
@@ -381,9 +372,16 @@ public class SlayerPlugin extends Plugin
String location = mCurrent.group("location");
setTask(name, amount, currentTask.getInitialAmount(), false, location);
canMatchDialog = false;
forcedWait = FORCED_WAIT;
}
} else if (npcDialog == null) {
canMatchDialog = true;
}
else if (npcDialog == null)
{
if (forcedWait <= 0)
{
canMatchDialog = true;
}
forcedWait--;
}
Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT);

View File

@@ -237,7 +237,7 @@ public class SlayerTaskPanel extends PluginPanel
private static boolean isEmptyTask(TaskData taskData)
{
return taskData.getTaskName().equals("") && taskData.getAmount() == 0 && taskData.getInitialAmount() == 0;
return (taskData.getTaskName() == null || taskData.getTaskName().equals("")) && taskData.getAmount() == 0 && taskData.getInitialAmount() == 0;
}
private void showMainView()
@@ -255,6 +255,23 @@ public class SlayerTaskPanel extends PluginPanel
return newBox;
}
private boolean stringsEqualIncludeNull(String str0, String str1)
{
if (str0 == null && str1 == null)
{
return true; // both are null
}
else if (str0 == null || str1 == null)
{
return false; // only 1 is null
}
else
{
// none are null so equals check is safe
return str0.equals(str1);
}
}
void updateCurrentTask(boolean updated, boolean paused, TaskData newData, boolean isNewAssignment)
{
// important case for if the current task is completed so the update will show the empty task
@@ -294,9 +311,9 @@ public class SlayerTaskPanel extends PluginPanel
// if here there is a current task so check if the current task matches
// the update being sent
TaskBox current = tasks.get(0);
if (!current.getTaskData().getTaskName().equals(newData.getTaskName()) ||
!current.getTaskData().getTaskLocation().equals(newData.getTaskLocation()) ||
current.getTaskData().getInitialAmount() != newData.getInitialAmount())
if (!stringsEqualIncludeNull(current.getTaskData().getTaskName(), newData.getTaskName()) ||
!stringsEqualIncludeNull(current.getTaskData().getTaskLocation(), newData.getTaskLocation()) ||
current.getTaskData().getInitialAmount() != newData.getInitialAmount())
{
// current task does not match the update being sent so the current task
// must have been outdated - this is necessarily true because if a true