Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.eternalcode.core.feature.spawn.SpawnService;
import com.eternalcode.core.feature.teleport.TeleportService;
import com.eternalcode.core.feature.warp.WarpService;
import com.eternalcode.core.user.UserManager;

public interface EternalCoreApi {

Expand All @@ -32,4 +33,6 @@ public interface EternalCoreApi {
TeleportService getTeleportService();

WarpService getWarpService();

UserManager getUserManager();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.eternalcode.core.user;

import java.time.Instant;
import java.util.UUID;

/**
* Immutable snapshot of a player's EternalCore account data.
*/
public interface User {

UUID getUniqueId();

String getName();

Instant getLastSeen();

Instant getAccountCreated();
Comment thread
P1otrulla marked this conversation as resolved.
Resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.eternalcode.core.user;

import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public interface UserManager {

/**
* Returns the cached user with the given unique id.
*/
Optional<User> getUser(UUID uniqueId);

/**
* Returns the cached user with the given name.
*/
Optional<User> getUser(String name);

/**
* Loads the user from cache or database, creating a new one if it does not exist.
* Refreshes the user's name and last seen time.
*/
CompletableFuture<User> findOrCreate(UUID uniqueId, String name);

/**
* Returns an immutable snapshot of all cached users.
*/
Collection<User> getUsers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.eternalcode.core.feature.teleport.TeleportService;
import com.eternalcode.core.feature.warp.WarpService;
import com.eternalcode.core.injector.DependencyProvider;
import com.eternalcode.core.user.UserManager;

class EternalCoreApiImpl implements EternalCoreApi {

Expand Down Expand Up @@ -69,4 +70,9 @@ public TeleportService getTeleportService() {
public WarpService getWarpService() {
return this.dependencyProvider.getDependency(WarpService.class);
}

@Override
public UserManager getUserManager() {
return this.dependencyProvider.getDependency(UserManager.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ void ignore(@Context User sender, @Arg User target) {
UUID targetUuid = target.getUniqueId();

if (sender.equals(target)) {
this.noticeService.viewer(sender, translation -> translation.ignore().cannotIgnoreSelf());
this.noticeService.create()
.user(sender)
.notice(translation -> translation.ignore().cannotIgnoreSelf())
.send();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ void unignore(@Context User sender, @Arg("ignored_player") User target) {
UUID targetUuid = target.getUniqueId();

if (sender.equals(target)) {
this.noticeService.viewer(sender, translation -> translation.ignore().cannotUnignoreSelf());
this.noticeService.create()
.user(sender)
.notice(translation -> translation.ignore().cannotUnignoreSelf())
.send();
return;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.eternalcode.core.user;

import java.time.Instant;
import java.util.Objects;
import java.util.UUID;

public final class UserImpl implements User {

private final UUID uniqueId;
private final String name;
private final Instant lastSeen;
private final Instant accountCreated;

public UserImpl(UUID uniqueId, String name, Instant lastSeen, Instant accountCreated) {
this.uniqueId = uniqueId;
this.name = name;
this.lastSeen = lastSeen;
this.accountCreated = accountCreated;
}

static UserImpl create(UUID uniqueId, String name, Instant lastSeen, Instant accountCreated) {
return new UserImpl(uniqueId, name, lastSeen, accountCreated);
}

@Override
public UUID getUniqueId() {
return this.uniqueId;
}

@Override
public String getName() {
return this.name;
}

@Override
public Instant getLastSeen() {
return this.lastSeen;
}

@Override
public Instant getAccountCreated() {
return this.accountCreated;
}

UserImpl withName(String name) {
return new UserImpl(this.uniqueId, name, this.lastSeen, this.accountCreated);
}

UserImpl withLastSeen(Instant lastSeen) {
return new UserImpl(this.uniqueId, this.name, lastSeen, this.accountCreated);
}

@Override
public boolean equals(Object o) {
if (o == null || this.getClass() != o.getClass()) {
return false;
}
UserImpl user = (UserImpl) o;

return Objects.equals(this.uniqueId, user.uniqueId)
&& Objects.equals(this.name, user.name)
&& Objects.equals(this.lastSeen, user.lastSeen)
&& Objects.equals(this.accountCreated, user.accountCreated);
}

@Override
public int hashCode() {
return Objects.hash(this.uniqueId, this.name, this.lastSeen, this.accountCreated);
}
}

This file was deleted.

Loading
Loading