Fixes a bug causing duplicate records to be stored

This commit is contained in:
Kristian Knarvik 2023-04-07 18:51:07 +02:00
parent b95cc294ab
commit cd7d8eded0
3 changed files with 18 additions and 2 deletions

View File

@ -77,7 +77,10 @@ public class DropperArenaRecordsRegistry implements ConfigurationSerializable {
* @return <p>The result explaining what type of record was achieved</p>
*/
public @NotNull RecordResult registerDeathRecord(@NotNull UUID playerId, int deaths) {
Consumer<Integer> consumer = (value) -> leastDeaths.add(new IntegerRecord(playerId, value));
Consumer<Integer> consumer = (value) -> {
leastDeaths.removeIf((item) -> item.getUserId().equals(playerId));
leastDeaths.add(new IntegerRecord(playerId, value));
};
Set<ArenaRecord<Integer>> asInt = new HashSet<>(leastDeaths);
return registerRecord(asInt, consumer, playerId, deaths);
}
@ -90,7 +93,10 @@ public class DropperArenaRecordsRegistry implements ConfigurationSerializable {
* @return <p>The result explaining what type of record was achieved</p>
*/
public @NotNull RecordResult registerTimeRecord(@NotNull UUID playerId, long milliseconds) {
Consumer<Long> consumer = (value) -> shortestTimeMilliSeconds.add(new LongRecord(playerId, value));
Consumer<Long> consumer = (value) -> {
shortestTimeMilliSeconds.removeIf((item) -> item.getUserId().equals(playerId));
shortestTimeMilliSeconds.add(new LongRecord(playerId, value));
};
Set<ArenaRecord<Long>> asLong = new HashSet<>(shortestTimeMilliSeconds);
return registerRecord(asLong, consumer, playerId, milliseconds);
}

View File

@ -24,6 +24,11 @@ public class IntegerRecord extends SummableArenaRecord<Integer> {
return new IntegerRecord(this.getUserId(), this.getRecord() + value);
}
@Override
public boolean equals(Object other) {
return other instanceof IntegerRecord && this.getUserId().equals(((IntegerRecord) other).getUserId());
}
/**
* Deserializes the saved arena record
*

View File

@ -19,6 +19,11 @@ public class LongRecord extends SummableArenaRecord<Long> {
super(userId, record);
}
@Override
public boolean equals(Object other) {
return other instanceof LongRecord && this.getUserId().equals(((LongRecord) other).getUserId());
}
@Override
public SummableArenaRecord<Long> sum(Long value) {
return new LongRecord(this.getUserId(), this.getRecord() + value);