Add getter for skill experience (#76)
This commit is contained in:
@@ -354,4 +354,39 @@ public class Client
|
||||
{
|
||||
return client.getClanChatCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local player's current experience in the specified {@link Skill}.
|
||||
*
|
||||
* @param skill the {@link Skill} to retrieve the experience for
|
||||
* @return the local player's current experience in the specified {@link Skill}, or -1 if the {@link Skill} isn't
|
||||
* valid
|
||||
*/
|
||||
public int getSkillExperience(Skill skill)
|
||||
{
|
||||
int[] experiences = client.getSkillExperiences();
|
||||
|
||||
if (skill == Skill.OVERALL)
|
||||
{
|
||||
int totalExperience = 0;
|
||||
|
||||
for (int experience : experiences)
|
||||
{
|
||||
totalExperience += experience;
|
||||
}
|
||||
|
||||
return totalExperience;
|
||||
}
|
||||
|
||||
int idx = skill.ordinal();
|
||||
|
||||
// I'm not certain exactly how needed this is, but if the Skill enum is updated in the future
|
||||
// to hold something else that's not reported it'll save us from an ArrayIndexOutOfBoundsException.
|
||||
if (idx >= experiences.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return experiences[idx];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,18 +25,30 @@
|
||||
|
||||
package net.runelite.client.events;
|
||||
|
||||
import net.runelite.api.Skill;
|
||||
|
||||
public class ExperienceChanged
|
||||
{
|
||||
/** the index in the array which changed */
|
||||
private int index;
|
||||
/**
|
||||
* The {@link Skill} that had its experience changed.
|
||||
*/
|
||||
private Skill skill;
|
||||
|
||||
public int getIndex()
|
||||
/**
|
||||
* Returns the {@link Skill} that had its experience changed
|
||||
* @return the {@link Skill} that had its experience changed
|
||||
*/
|
||||
public Skill getSkill()
|
||||
{
|
||||
return index;
|
||||
return skill;
|
||||
}
|
||||
|
||||
public void setIndex(int index)
|
||||
/**
|
||||
* Sets the changed {@link Skill} to the specified {@link Skill}.
|
||||
* @param skill the {@link Skill} that had its experience changed
|
||||
*/
|
||||
public void setSkill(Skill skill)
|
||||
{
|
||||
this.index = index;
|
||||
this.skill = skill;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package net.runelite.inject.callbacks;
|
||||
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.events.ExperienceChanged;
|
||||
import net.runelite.client.events.MapRegionChanged;
|
||||
@@ -52,8 +53,15 @@ public class Hooks
|
||||
case "experienceChanged":
|
||||
{
|
||||
ExperienceChanged experienceChanged = new ExperienceChanged();
|
||||
experienceChanged.setIndex(idx);
|
||||
runelite.getEventBus().post(experienceChanged);
|
||||
Skill[] possibleSkills = Skill.values();
|
||||
|
||||
// We subtract one here because 'Overall' isn't considered a skill that's updated.
|
||||
if (idx < possibleSkills.length - 1)
|
||||
{
|
||||
Skill updatedSkill = possibleSkills[idx];
|
||||
experienceChanged.setSkill(updatedSkill);
|
||||
runelite.getEventBus().post(experienceChanged);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "mapRegionsChanged":
|
||||
|
||||
Reference in New Issue
Block a user