-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement persisted map scores & cooldowns (#1470)
Signed-off-by: Pablo Herrera <[email protected]>
- Loading branch information
1 parent
df8e82e
commit 003a76e
Showing
11 changed files
with
428 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package tc.oc.pgm.api.map; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import tc.oc.pgm.api.match.Match; | ||
|
||
public interface MapData { | ||
|
||
String getId(); | ||
|
||
Instant lastPlayed(); | ||
|
||
Duration lastDuration(); | ||
|
||
double score(); | ||
|
||
void setScore(double score, boolean update); | ||
|
||
void saveMatch(Match match, double score); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package tc.oc.pgm.db; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import tc.oc.pgm.api.map.MapData; | ||
|
||
abstract class MapDataImpl implements MapData { | ||
protected final String id; | ||
protected Instant lastPlayed = Instant.EPOCH; | ||
protected Duration lastDuration = Duration.ZERO; | ||
protected double score; | ||
|
||
public MapDataImpl(String id, double defaultScore) { | ||
this.id = id; | ||
this.score = defaultScore; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public Instant lastPlayed() { | ||
return lastPlayed; | ||
} | ||
|
||
@Override | ||
public Duration lastDuration() { | ||
return lastDuration; | ||
} | ||
|
||
@Override | ||
public double score() { | ||
return score; | ||
} | ||
|
||
@Override | ||
public void setScore(double score, boolean update) { | ||
this.score = score; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return id.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof MapData mapData)) return false; | ||
return getId().equals(mapData.getId()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MapDataImpl{" + "id='" | ||
+ id + '\'' + ", lastPlayed=" | ||
+ lastPlayed + ", lastDuration=" | ||
+ lastDuration + ", score=" | ||
+ score + '}'; | ||
} | ||
} |
Oops, something went wrong.