This commit is contained in:
kento2 2026-02-23 20:14:08 +01:00
parent f1e9ac5ea9
commit 179f94085f
15 changed files with 167 additions and 67 deletions

View file

@ -3,14 +3,13 @@ package de.kentoj.scrow.bukkit;
import com.mongodb.reactivestreams.client.MongoDatabase;
import de.kentoj.scrow.bukkit.services.EconomyService;
import de.kentoj.scrow.bukkit.services.command.CommandManager;
import de.kentoj.scrow.bukkit.services.friends.FriendsService;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ScrowAPI {
@ -18,11 +17,13 @@ public class ScrowAPI {
@Getter
private static @Nullable MongoDatabase database;
@Getter
private static EconomyService economyService;
@Getter
private static CommandManager commandManager;
@Getter
private static Scheduler minecraftScheduler;
@Getter
private static EconomyService economyService;
@Getter
private static FriendsService friendsService;
@ApiStatus.Internal
public static void setDatabase(@Nullable MongoDatabase database) {
@ -43,5 +44,10 @@ public class ScrowAPI {
public static void setMinecraftScheduler(Scheduler minecraftScheduler) {
ScrowAPI.minecraftScheduler = minecraftScheduler;
}
@ApiStatus.Internal
public static void setFriendsService(FriendsService friendsService) {
ScrowAPI.friendsService = friendsService;
}
}

View file

@ -1,6 +1,8 @@
package de.kentoj.scrow.bukkit.services.command.execution;
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
public interface CommandExecutor {
void execute(CommandContext ctx);
void execute(CommandContext ctx) throws CommandInvocationException;
}

View file

@ -57,7 +57,7 @@ public class PlayerArgumentType {
try {
player = Bukkit.getOfflinePlayer(UUID.fromString(rawInput));
} catch (IllegalArgumentException ex) {
throw new CommandInvocationException("Not a UUID or name of an online player");
throw new CommandInvocationException("Not a UUID or name of an online player -- " + rawInput);
}
}
return player;
@ -75,6 +75,7 @@ public class PlayerArgumentType {
@Override
public void checkValue(CommandContext ctx, OfflinePlayer value, String rawInput) throws CommandInvocationException {
if (!value.hasPlayedBefore()) throw new CommandInvocationException("Player has never played before -- " + rawInput);
}
};

View file

@ -0,0 +1,12 @@
package de.kentoj.scrow.bukkit.services.friends;
public class FriendRequestUsageException extends RuntimeException {
public FriendRequestUsageException(String message) {
super(message);
}
public FriendRequestUsageException(String message, Throwable cause) {
super(message, cause);
}
}

View file

@ -0,0 +1,33 @@
package de.kentoj.scrow.bukkit.services.friends;
import org.jetbrains.annotations.NotNull;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.UUID;
public interface FriendsService {
Flux<@NotNull Friendship> getFriendships(UUID playerId);
/**
* @param initiator id of player who wished to end the friendship
* @param other id of the player the initiator wants to end the friendship with
* @throws FriendRequestUsageException
*/
Mono<@NotNull Boolean> removeFriend(UUID initiator, UUID other);
/**
* @param playerId
*/
Flux<@NotNull FriendRequest> getIncomingFriendRequests(UUID playerId);
Flux<@NotNull FriendRequest> getOutgoingFriendRequests(UUID playerId);
/**
* @param from id of player sending the friend request
* @param to id of the player the initiator wants to befriend
* @throws FriendRequestUsageException
*/
Mono<@NotNull Friendship> sendFriendRequest(UUID from, UUID to);
}

View file

@ -8,4 +8,9 @@ import java.util.UUID;
public interface Friendship {
Tuple2<UUID, UUID> getPlayerIds();
Instant getCreatedAt();
default UUID getOther(UUID self) {
final var ids = getPlayerIds();
return ids.getFirst() != self ? ids.getFirst() : ids.getSecond();
}
}