-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added game time
- Loading branch information
Showing
17 changed files
with
303 additions
and
108 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
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
71 changes: 71 additions & 0 deletions
71
...ction-core/src/main/java/dev/piotrulla/newbieprotection/NewbieProtectionDataInMemory.java
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,71 @@ | ||
package dev.piotrulla.newbieprotection; | ||
|
||
import eu.okaeri.configs.OkaeriConfig; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
public class NewbieProtectionDataInMemory extends OkaeriConfig implements NewbieProtectionDataRepository { | ||
|
||
private Set<Entry> entries = new HashSet<>(); | ||
|
||
@Override | ||
public boolean isExists(UUID uniqueId) { | ||
return this.entries.stream().anyMatch(entry -> entry.uniqueId().equals(uniqueId)); | ||
} | ||
|
||
@Override | ||
public void save(Newbie newbie) { | ||
this.entries.add(new Entry(newbie.uniqueId(), newbie.issuedAt(), newbie.protectionTime())); | ||
this.save(); | ||
} | ||
|
||
@Override | ||
public void remove(Newbie newbie) { | ||
this.entries.removeIf(entry -> entry.uniqueId().equals(newbie.uniqueId())); | ||
this.save(); | ||
} | ||
|
||
@Override | ||
public void update(Newbie newbie) { | ||
this.entries.removeIf(entry -> entry.uniqueId().equals(newbie.uniqueId())); | ||
this.save(newbie); | ||
} | ||
|
||
@Override | ||
public Newbie load(UUID uniqueId) { | ||
return this.entries.stream() | ||
.filter(entry -> entry.uniqueId().equals(uniqueId)) | ||
.findFirst() | ||
.map(entry -> new NewbieProtectionUser(uniqueId, entry.issuedAt(), entry.protectionTime())) | ||
.orElse(null); | ||
} | ||
|
||
public static class Entry extends OkaeriConfig { | ||
|
||
private UUID uniqueId; | ||
private Instant issuedAt; | ||
private Duration protectionTime; | ||
|
||
public Entry(UUID uniqueId, Instant issuedAt, Duration protectionTime) { | ||
this.uniqueId = uniqueId; | ||
this.issuedAt = issuedAt; | ||
this.protectionTime = protectionTime; | ||
} | ||
|
||
UUID uniqueId() { | ||
return this.uniqueId; | ||
} | ||
|
||
Instant issuedAt() { | ||
return this.issuedAt; | ||
} | ||
|
||
Duration protectionTime() { | ||
return this.protectionTime; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ion-core/src/main/java/dev/piotrulla/newbieprotection/NewbieProtectionDataRepository.java
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,16 @@ | ||
package dev.piotrulla.newbieprotection; | ||
|
||
import java.util.UUID; | ||
|
||
public interface NewbieProtectionDataRepository { | ||
|
||
boolean isExists(UUID uniqueId); | ||
|
||
void save(Newbie newbie); | ||
|
||
void remove(Newbie newbie); | ||
|
||
void update(Newbie newbie); | ||
|
||
Newbie load(UUID uniqueId); | ||
} |
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
Oops, something went wrong.