Skip to content

Commit

Permalink
fix: FIx for the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dm94 committed Jun 23, 2024
1 parent 19010cd commit 0a19b7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public class StatTypeValue implements Value<Number>, Parser {
}

private StatsAPI.Key getKeyFromString(String token) {
String[] tokenParts = token.split(":", 3);
String[] tokenParts = token.split(":");

String statNamespace = tokenParts.length >= 2 ? tokenParts[0] : null;
String statCategory = tokenParts.length == 3 ? tokenParts[1] : null;
String statNamespace = tokenParts.length == 3 ? tokenParts[0] : null;
String statCategory = tokenParts.length >= 2 ? tokenParts[tokenParts.length - 2] : null;
String statKey = tokenParts[tokenParts.length - 1];

return StatsManager.getStatKeys().stream()
.filter(s -> statNamespace == null || s.namespace().equals(statNamespace))
.filter(s -> statCategory == null || s.category().equals(statCategory))
.filter(s -> statKey == null || s.name().equals(statKey))
.filter(s -> statNamespace == null || s.namespace().equalsIgnoreCase(statNamespace))
.filter(s -> statCategory == null || s.category().equalsIgnoreCase(statCategory))
.filter(s -> s.name().equalsIgnoreCase(statKey))
.findFirst().orElse(null);
}

Expand Down Expand Up @@ -77,12 +77,12 @@ public static StatData of(String sd) {

@Override
public String toString() {
return "stat-type(" + key.name().toLowerCase(Locale.ROOT) + "," + dataType + ")";
return "stat-type(" + getKeyFormatted(key) + "," + dataType + ")";
}

private String getKeyFormatted(Key keyToFormat) {
return (keyToFormat.namespace() != null ? keyToFormat.namespace() + ":" : "") + keyToFormat.category() + ":"
+ keyToFormat.name();
return ((keyToFormat.namespace() != null ? keyToFormat.namespace() + ":" : "") + keyToFormat.category() + ":"
+ keyToFormat.name()).toLowerCase(Locale.ROOT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public class StatsManager implements Manager, StatsAPI, NativeUpdatable {
private final Main main;
private final EventBrokerAPI eventBroker;

private static StatsManager INSTANCE;

private long address;

public int userId;
Expand All @@ -53,7 +51,6 @@ public class StatsManager implements Manager, StatsAPI, NativeUpdatable {
public StatsManager(Main main, EventBrokerAPI eventBroker) {
this.main = main;
this.eventBroker = eventBroker;
INSTANCE = this;

registerImpl(Stats.Bot.RUNTIME, runtime = createStat());

Expand Down Expand Up @@ -129,11 +126,7 @@ private void registerImpl(Key key, StatImpl stat) {
}

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

public static StatsManager getInstance() {
return INSTANCE;
return Collections.unmodifiableSet(Main.INSTANCE.statsManager.statistics.keySet());
}

@Override
Expand Down

0 comments on commit 0a19b7b

Please sign in to comment.