This commit is contained in:
kento2 2026-04-18 12:57:34 +02:00
parent d4370de78c
commit c234c600fe
6 changed files with 30 additions and 40 deletions

View file

@ -17,6 +17,15 @@ subprojects {
apply(plugin = "java")
apply(plugin = "io.freefair.lombok")
java {
withSourcesJar()
withJavadocJar()
}
tasks.withType<Javadoc>().configureEach {
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:all,-missing", "-quiet")
}
repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") {

View file

@ -36,9 +36,9 @@ dependencies {
api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
api("net.kyori:adventure-platform-bukkit:4.4.1")
api("de.kentoj:kencommandapi-core:2.0.2")
implementation("de.kentoj:kencommandapi-bukkit:2.0.2")
api("de.kentoj:kencommandapi-bukkit:2.0.2")
api("de.kentoj.scrow:kencommandapi-core:0.2")
implementation("de.kentoj.scrow:kencommandapi-bukkit:0.2")
api("de.kentoj.scrow:kencommandapi-bukkit:0.2")
}
publishing {

View file

@ -8,26 +8,26 @@ import java.util.UUID;
public interface EconomyService {
/**
* @throws IllegalArgumentException if amount < 0
* @throws IllegalArgumentException if amount is less than 0
*/
Mono<@NotNull Integer> getCoins(UUID playerId);
/**
* @param playerId uuid of player
* @throws IllegalArgumentException if amount < 0
* @throws IllegalArgumentException if amount is less than 0
*/
Mono<@NotNull Void> depositCoins(UUID playerId, int amount);
/**
* @param playerId uuid of player
* @return true on success, false on insufficient funds
* @throws IllegalArgumentException if amount < 0
* @throws IllegalArgumentException if amount is less than 0
*/
Mono<@NotNull Boolean> tryWithdrawCoins(UUID playerId, int amount);
/**
* @param playerId uuid of player
* @throws IllegalArgumentException if amount < 0
* @throws IllegalArgumentException if amount is less than 0
*/
Mono<@NotNull Void> setCoins(UUID playerId, int amount);
}

View file

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

View file

@ -10,22 +10,9 @@ 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(Friendship friendship);
/**
* @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
*/
}

View file

@ -1,5 +1,6 @@
package de.kentoj.scrow.bukkit.friends.handler;
import de.kentoj.kencommandapi.api.processing.CommandException;
import de.kentoj.scrow.bukkit.ScrowAPI;
import de.kentoj.scrow.bukkit.friends.friendship.FriendshipDAO;
import de.kentoj.scrow.bukkit.friends.friendship.FriendshipImpl;
@ -25,15 +26,18 @@ public class FriendAddHandler {
public void handle() {
findAction()
.flatMap(this::executeAction)
.doOnError(CommandException.class, e -> {
ScrowAPI.getCommandManager().sendErrorMessage(self, e);
})
.subscribeOn(Schedulers.boundedElastic())
.subscribe();
}
private Mono<?> executeAction(AddAction action) {
return switch (action) {
case ERR_ALREADY_FRIENDS -> sendMessage(self, "[friends] You are already friends with " + other.getName());
case ERR_ALREADY_REQUESTED ->
sendMessage(self, "[friends] You already requested " + other.getName() + " to be friends with you");
case ERR_CAN_NOT_ADD_SELF -> throw new CommandException("You can not add yourself");
case ERR_ALREADY_FRIENDS -> throw new CommandException("You are already friends with " + other.getName());
case ERR_ALREADY_REQUESTED -> throw new CommandException("You already requested " + other.getName() + " to be friends with you");
case SEND_REQUEST -> sendRequest();
case ACCEPT_REQUEST -> acceptRequest();
};
@ -41,11 +45,11 @@ public class FriendAddHandler {
private Mono<?> sendRequest() {
return friendRequestDAO.saveFriendRequest(new FriendRequestImpl(self.getUniqueId(), other.getUniqueId(), Instant.now()))
.then(sendMessage(self.getPlayer(), "[friends] Successfully sent " + other.getName() + " a friend request."))
.then(sendMessage(self.getPlayer(), "Successfully sent " + other.getName() + " a friend request."))
.then(Mono.fromRunnable(() -> {
var otherPlayer = other.getPlayer();
if (otherPlayer != null)
sendMessage(otherPlayer, "[friends] " + self.getName() + " wants to be friends with you. Use '/f add " + self.getName() + "' to accept.").subscribe();
sendMessage(otherPlayer, self.getName() + " wants to be friends with you. Use '/f add " + self.getName() + "' to accept.").subscribe();
}))
.doOnError(this::handleError);
}
@ -56,16 +60,17 @@ public class FriendAddHandler {
friendRequestDAO.deleteFriendRequest(other.getUniqueId(), self.getUniqueId()),
friendshipDAO.saveFriendship(new FriendshipImpl(self.getUniqueId(), other.getUniqueId(), Instant.now()))
)
.then(sendMessage(self, "[friends] You are now friends with " + other.getName()))
.then(sendMessage(self, "You are now friends with " + other.getName()))
.then(Mono.fromRunnable(() -> {
var otherPlayer = other.getPlayer();
if (otherPlayer != null)
sendMessage(otherPlayer, "[friends] You are now friends with " + self.getName()).subscribe();
sendMessage(otherPlayer, "You are now friends with " + self.getName()).subscribe();
}))
.doOnError(this::handleError);
}
private Mono<@NotNull AddAction> findAction() {
if (self.getUniqueId() == other.getUniqueId()) return Mono.just(AddAction.ERR_CAN_NOT_ADD_SELF);
return friendshipDAO.getFriendship(self.getUniqueId(), other.getUniqueId())
.map(f -> AddAction.ERR_ALREADY_FRIENDS)
.switchIfEmpty(
@ -91,6 +96,7 @@ public class FriendAddHandler {
private enum AddAction {
ERR_ALREADY_FRIENDS,
ERR_ALREADY_REQUESTED,
ERR_CAN_NOT_ADD_SELF,
SEND_REQUEST,
ACCEPT_REQUEST
}