Skip to content

Commit

Permalink
[feature] Adicionado alternativas de nomes em GameMode
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian-Sknz committed Feb 6, 2021
1 parent 565a770 commit e25da27
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/main/java/me/skiincraft/api/osu/object/game/GameMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,39 @@

public enum GameMode {

Osu(0, "osu!standard"),
Taiko(1, "osu!taiko"),
Mania(2, "osu!mania"),
Fruits(3, "osu!catch");
Osu(0, "standard", "default", "osu!"),
Taiko(1, "taiko", "osu!taiko"),
Mania(2, "mania", "osu!mania"),
Fruits(3, "catch", "osu!catch", "osu!fruits");

private final int id;
private final String description;
private final String[] alternate;

GameMode(int id, String description) {
GameMode(int id, String... alternate) {
this.id = id;
this.description = description;
this.alternate = alternate;
}

@Nullable
public static GameMode byInt(int id) {
return Arrays.stream(values()).filter(gm -> gm.getId() == id).findFirst().orElse(null);
return Arrays.stream(values()).filter(gm -> gm.getId() == id)
.findFirst()
.orElse(null);
}

@Nullable
public static GameMode byName(String name) {
if (name.length() == name.replaceAll("\\D+", "").length()) {
return byInt(Integer.parseInt(name));
}
return Arrays.stream(values()).filter(gm -> gm.name().equalsIgnoreCase(name)).findFirst().orElse(null);
return Arrays.stream(values()).filter(gm -> gm.name().equalsIgnoreCase(name) ||
Arrays.stream(gm.alternate).anyMatch(alt -> alt.equalsIgnoreCase(name)))
.findFirst()
.orElse(null);
}

public String getDescription() {
return description;
public String[] getAlternate() {
return alternate;
}

public int getId() {
Expand Down

0 comments on commit e25da27

Please sign in to comment.