-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa94f44
commit 63bf99f
Showing
22 changed files
with
520 additions
and
255 deletions.
There are no files selected for viewing
42 changes: 30 additions & 12 deletions
42
api/src/main/java/com/guflimc/brick/stats/api/StatsManager.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
76 changes: 76 additions & 0 deletions
76
api/src/main/java/com/guflimc/brick/stats/api/actor/Actor.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,76 @@ | ||
package com.guflimc.brick.stats.api.actor; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.*; | ||
import java.util.stream.Stream; | ||
|
||
public interface Actor { | ||
|
||
UUID id(); | ||
|
||
String type(); | ||
|
||
// | ||
|
||
static Actor player(@NotNull UUID id) { | ||
return new TempActor(id, "PLAYER"); | ||
} | ||
|
||
record TempActor(@NotNull UUID id, @NotNull String type) implements Actor { | ||
} | ||
|
||
// | ||
|
||
class ActorSet implements Iterable<Actor> { | ||
|
||
private final Set<Actor> actors; | ||
|
||
public ActorSet(@NotNull Collection<? extends Actor> c) { | ||
if ( c.isEmpty() ) { | ||
throw new IllegalArgumentException("ActorSet must contain at least one actor."); | ||
} | ||
this.actors = Set.copyOf(c); | ||
} | ||
|
||
public <T extends Actor> ActorSet(@NotNull T... actors) { | ||
this(Set.of(actors)); | ||
} | ||
|
||
public int size() { | ||
return actors.size(); | ||
} | ||
|
||
public Actor first() { | ||
return iterator().next(); | ||
} | ||
|
||
public Stream<Actor> stream() { | ||
return actors.stream(); | ||
} | ||
|
||
public Set<Actor> copySet() { | ||
return new HashSet<>(actors); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Iterator<Actor> iterator() { | ||
return actors.iterator(); | ||
} | ||
|
||
// | ||
|
||
|
||
@Override | ||
public int hashCode() { | ||
return actors.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return obj instanceof ActorSet as && actors.equals(as.actors); | ||
} | ||
} | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
api/src/main/java/com/guflimc/brick/stats/api/container/Container.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,31 @@ | ||
package com.guflimc.brick.stats.api.container; | ||
|
||
import com.guflimc.brick.stats.api.actor.Actor; | ||
import com.guflimc.brick.stats.api.key.StatsKey; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.function.IntFunction; | ||
|
||
public interface Container { | ||
|
||
Actor.ActorSet actors(); | ||
|
||
Collection<StatsKey> stats(); | ||
|
||
// | ||
|
||
Optional<Record> find(@NotNull StatsKey key); | ||
|
||
int read(@NotNull StatsKey key); | ||
|
||
void update(@NotNull StatsKey key, @NotNull IntFunction<Integer> updater); | ||
|
||
default void write(@NotNull StatsKey key, int value) { | ||
update(key, i -> value); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
api/src/main/java/com/guflimc/brick/stats/api/container/Record.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,14 @@ | ||
package com.guflimc.brick.stats.api.container; | ||
|
||
import com.guflimc.brick.stats.api.actor.Actor; | ||
import com.guflimc.brick.stats.api.key.StatsKey; | ||
|
||
public interface Record { | ||
|
||
Actor.ActorSet actors(); | ||
|
||
StatsKey key(); | ||
|
||
int value(); | ||
|
||
} |
16 changes: 0 additions & 16 deletions
16
api/src/main/java/com/guflimc/brick/stats/api/container/StatsContainer.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
api/src/main/java/com/guflimc/brick/stats/api/container/StatsRecord.java
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
api/src/main/java/com/guflimc/brick/stats/api/event/Event.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.guflimc.brick.stats.api.event; | ||
|
||
import com.guflimc.brick.stats.api.container.StatsRecord; | ||
import com.guflimc.brick.stats.api.container.Record; | ||
import com.guflimc.brick.stats.api.key.StatsKey; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record Event(@NotNull StatsKey key, @NotNull StatsRecord record, int previousValue) { | ||
public record Event(@NotNull Record record, int previousValue) { | ||
} |
8 changes: 4 additions & 4 deletions
8
api/src/main/java/com/guflimc/brick/stats/api/relation/RelationProvider.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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package com.guflimc.brick.stats.api.relation; | ||
|
||
import com.guflimc.brick.stats.api.actor.Actor; | ||
import com.guflimc.brick.stats.api.key.StatsKey; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@FunctionalInterface | ||
public interface RelationProvider { | ||
|
||
Optional<UUID> relation(@NotNull UUID entityId, @NotNull StatsKey key); | ||
@Nullable | ||
Actor provide(@NotNull Actor actor, @NotNull StatsKey key); | ||
|
||
} |
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.