Add proper nullity checks for task name and location
This commit is contained in:
@@ -242,8 +242,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
|
|
||||||
clientToolbar.addNavigation(navButton);
|
clientToolbar.addNavigation(navButton);
|
||||||
|
|
||||||
if (client.getGameState() == GameState.LOGGED_IN
|
if (config.amount() != -1
|
||||||
&& config.amount() != -1
|
|
||||||
&& !config.taskName().isEmpty())
|
&& !config.taskName().isEmpty())
|
||||||
{
|
{
|
||||||
points = config.points();
|
points = config.points();
|
||||||
@@ -283,24 +282,8 @@ public class SlayerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
case HOPPING:
|
case HOPPING:
|
||||||
case LOGGING_IN:
|
case LOGGING_IN:
|
||||||
cachedXp = 0;
|
|
||||||
currentTask = new TaskData(0, 0, 0,0, 0, "", "", true);
|
|
||||||
loginFlag = true;
|
|
||||||
highlightedTargets.clear();
|
highlightedTargets.clear();
|
||||||
break;
|
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
|
// (and close npc dialog) or go into the rewards screen which also closes npc dialog
|
||||||
private boolean canMatchDialog = true;
|
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
|
@Subscribe
|
||||||
public void onGameTick(GameTick tick)
|
public void onGameTick(GameTick tick)
|
||||||
{
|
{
|
||||||
@@ -360,12 +348,14 @@ public class SlayerPlugin extends Plugin
|
|||||||
String location = mAssign.group("location");
|
String location = mAssign.group("location");
|
||||||
setTask(name, amount, amount, true, location);
|
setTask(name, amount, amount, true, location);
|
||||||
canMatchDialog = false;
|
canMatchDialog = false;
|
||||||
|
forcedWait = FORCED_WAIT;
|
||||||
}
|
}
|
||||||
else if (mAssignFirst.find())
|
else if (mAssignFirst.find())
|
||||||
{
|
{
|
||||||
int amount = Integer.parseInt(mAssignFirst.group(2));
|
int amount = Integer.parseInt(mAssignFirst.group(2));
|
||||||
setTask(mAssignFirst.group(1), amount, amount, true);
|
setTask(mAssignFirst.group(1), amount, amount, true);
|
||||||
canMatchDialog = false;
|
canMatchDialog = false;
|
||||||
|
forcedWait = FORCED_WAIT;
|
||||||
}
|
}
|
||||||
else if (mAssignBoss.find())
|
else if (mAssignBoss.find())
|
||||||
{
|
{
|
||||||
@@ -373,6 +363,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
setTask(mAssignBoss.group(1), amount, amount, true);
|
setTask(mAssignBoss.group(1), amount, amount, true);
|
||||||
points = Integer.parseInt(mAssignBoss.group(3).replaceAll(",", ""));
|
points = Integer.parseInt(mAssignBoss.group(3).replaceAll(",", ""));
|
||||||
canMatchDialog = false;
|
canMatchDialog = false;
|
||||||
|
forcedWait = FORCED_WAIT;
|
||||||
}
|
}
|
||||||
else if (mCurrent.find())
|
else if (mCurrent.find())
|
||||||
{
|
{
|
||||||
@@ -381,9 +372,16 @@ public class SlayerPlugin extends Plugin
|
|||||||
String location = mCurrent.group("location");
|
String location = mCurrent.group("location");
|
||||||
setTask(name, amount, currentTask.getInitialAmount(), false, location);
|
setTask(name, amount, currentTask.getInitialAmount(), false, location);
|
||||||
canMatchDialog = false;
|
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);
|
Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT);
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
|
|
||||||
private static boolean isEmptyTask(TaskData taskData)
|
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()
|
private void showMainView()
|
||||||
@@ -255,6 +255,23 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
return newBox;
|
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)
|
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
|
// 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
|
// if here there is a current task so check if the current task matches
|
||||||
// the update being sent
|
// the update being sent
|
||||||
TaskBox current = tasks.get(0);
|
TaskBox current = tasks.get(0);
|
||||||
if (!current.getTaskData().getTaskName().equals(newData.getTaskName()) ||
|
if (!stringsEqualIncludeNull(current.getTaskData().getTaskName(), newData.getTaskName()) ||
|
||||||
!current.getTaskData().getTaskLocation().equals(newData.getTaskLocation()) ||
|
!stringsEqualIncludeNull(current.getTaskData().getTaskLocation(), newData.getTaskLocation()) ||
|
||||||
current.getTaskData().getInitialAmount() != newData.getInitialAmount())
|
current.getTaskData().getInitialAmount() != newData.getInitialAmount())
|
||||||
{
|
{
|
||||||
// current task does not match the update being sent so the current task
|
// 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
|
// must have been outdated - this is necessarily true because if a true
|
||||||
|
|||||||
Reference in New Issue
Block a user