Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added the option to use all the stats in the conditions #357

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@ValueData(name = "stat-type", description = "Gets a certain Stat type from a bot", example = "stat-type(experience, earned)")
public class StatTypeValue implements Value<Number>, Parser {
private Stats.General key;
private StatsAPI.Key key;
private StatsAPI.Stat stat;
private StatData dataType;

Expand All @@ -35,10 +35,22 @@ public class StatTypeValue implements Value<Number>, Parser {
}
}

private Stats.General getKeyFromString(String key) {
for (Stats.General stat : Stats.General.values()) {
if (stat.name().equalsIgnoreCase(key)) return stat;
private StatsAPI.Key getKeyFromString(String key) {
for (Stats.General statGeneral : Stats.General.values()) {
if (statGeneral.name().equalsIgnoreCase(key))
return statGeneral;
}

for (Stats.Bot statBot : Stats.Bot.values()) {
if (statBot.name().equalsIgnoreCase(key))
return statBot;
}

for (Stats.BootyKey statKey : Stats.BootyKey.values()) {
if (statKey.name().equalsIgnoreCase(key))
return statKey;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of hard-coding the bot's stats, you should be using the stat API to grab any of the registered stats. The point here is that 3rd party plugins can register their own stats and with a custom tracker update the values, and they should be possible to use here too!

Consider having a syntax for namespaced keys, so you can have:
experience: namespace -> null (the bot's namespace), category -> any, name -> experience
dmplugin:experience: namespace -> dmplugin, category -> any, name -> experience
dmplugin:general:experience: namespace -> dmplugin, category -> general, name -> experience

To implement this matching logic you can probably expose in StatsManager and StatsAPI a:

public Collection<? extends StatsAPI.Key> getStatKeys() {
  return Collections.unmodifiableSet(statistics.keySet());
}

and use that to search for the category for the namespace/key given, if none is found defer the operation to later as the stat could've not been registered yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation done, I'm not very proud of this implementation but I can't think of any other way right now.


return null;
}

Expand Down
Loading