.
This commit is contained in:
parent
d4370de78c
commit
c234c600fe
6 changed files with 30 additions and 40 deletions
|
|
@ -17,6 +17,15 @@ subprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
apply(plugin = "io.freefair.lombok")
|
apply(plugin = "io.freefair.lombok")
|
||||||
|
|
||||||
|
java {
|
||||||
|
withSourcesJar()
|
||||||
|
withJavadocJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<Javadoc>().configureEach {
|
||||||
|
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:all,-missing", "-quiet")
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") {
|
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") {
|
||||||
|
|
@ -41,7 +50,7 @@ subprojects {
|
||||||
implementation("org.jetbrains:annotations:26.0.2-1")
|
implementation("org.jetbrains:annotations:26.0.2-1")
|
||||||
|
|
||||||
// https://projectreactor.io/docs/core/release/reference/gettingStarted.html
|
// https://projectreactor.io/docs/core/release/reference/gettingStarted.html
|
||||||
implementation(platform("io.projectreactor:reactor-bom:2025.0.3"))
|
implementation(platform("io.projectreactor:reactor-bom:2025.0.3"))
|
||||||
implementation("io.projectreactor:reactor-core")
|
implementation("io.projectreactor:reactor-core")
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/com.google.guava/guava
|
// https://mvnrepository.com/artifact/com.google.guava/guava
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@ dependencies {
|
||||||
api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||||
api("net.kyori:adventure-platform-bukkit:4.4.1")
|
api("net.kyori:adventure-platform-bukkit:4.4.1")
|
||||||
|
|
||||||
api("de.kentoj:kencommandapi-core:2.0.2")
|
api("de.kentoj.scrow:kencommandapi-core:0.2")
|
||||||
implementation("de.kentoj:kencommandapi-bukkit:2.0.2")
|
implementation("de.kentoj.scrow:kencommandapi-bukkit:0.2")
|
||||||
api("de.kentoj:kencommandapi-bukkit:2.0.2")
|
api("de.kentoj.scrow:kencommandapi-bukkit:0.2")
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|
|
||||||
|
|
@ -8,26 +8,26 @@ import java.util.UUID;
|
||||||
public interface EconomyService {
|
public interface EconomyService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws IllegalArgumentException if amount < 0
|
* @throws IllegalArgumentException if amount is less than 0
|
||||||
*/
|
*/
|
||||||
Mono<@NotNull Integer> getCoins(UUID playerId);
|
Mono<@NotNull Integer> getCoins(UUID playerId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param playerId uuid of player
|
* @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);
|
Mono<@NotNull Void> depositCoins(UUID playerId, int amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param playerId uuid of player
|
* @param playerId uuid of player
|
||||||
* @return true on success, false on insufficient funds
|
* @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);
|
Mono<@NotNull Boolean> tryWithdrawCoins(UUID playerId, int amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param playerId uuid of player
|
* @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);
|
Mono<@NotNull Void> setCoins(UUID playerId, int amount);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -10,22 +10,9 @@ public interface FriendsService {
|
||||||
|
|
||||||
Flux<@NotNull Friendship> getFriendships(UUID playerId);
|
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);
|
Mono<@NotNull Boolean> removeFriend(Friendship friendship);
|
||||||
|
|
||||||
/**
|
|
||||||
* @param playerId
|
|
||||||
*/
|
|
||||||
Flux<@NotNull FriendRequest> getIncomingFriendRequests(UUID playerId);
|
Flux<@NotNull FriendRequest> getIncomingFriendRequests(UUID playerId);
|
||||||
|
|
||||||
Flux<@NotNull FriendRequest> getOutgoingFriendRequests(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
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package de.kentoj.scrow.bukkit.friends.handler;
|
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.ScrowAPI;
|
||||||
import de.kentoj.scrow.bukkit.friends.friendship.FriendshipDAO;
|
import de.kentoj.scrow.bukkit.friends.friendship.FriendshipDAO;
|
||||||
import de.kentoj.scrow.bukkit.friends.friendship.FriendshipImpl;
|
import de.kentoj.scrow.bukkit.friends.friendship.FriendshipImpl;
|
||||||
|
|
@ -25,15 +26,18 @@ public class FriendAddHandler {
|
||||||
public void handle() {
|
public void handle() {
|
||||||
findAction()
|
findAction()
|
||||||
.flatMap(this::executeAction)
|
.flatMap(this::executeAction)
|
||||||
|
.doOnError(CommandException.class, e -> {
|
||||||
|
ScrowAPI.getCommandManager().sendErrorMessage(self, e);
|
||||||
|
})
|
||||||
.subscribeOn(Schedulers.boundedElastic())
|
.subscribeOn(Schedulers.boundedElastic())
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<?> executeAction(AddAction action) {
|
private Mono<?> executeAction(AddAction action) {
|
||||||
return switch (action) {
|
return switch (action) {
|
||||||
case ERR_ALREADY_FRIENDS -> sendMessage(self, "[friends] You are already friends with " + other.getName());
|
case ERR_CAN_NOT_ADD_SELF -> throw new CommandException("You can not add yourself");
|
||||||
case ERR_ALREADY_REQUESTED ->
|
case ERR_ALREADY_FRIENDS -> throw new CommandException("You are already friends with " + other.getName());
|
||||||
sendMessage(self, "[friends] You already requested " + other.getName() + " to be friends with you");
|
case ERR_ALREADY_REQUESTED -> throw new CommandException("You already requested " + other.getName() + " to be friends with you");
|
||||||
case SEND_REQUEST -> sendRequest();
|
case SEND_REQUEST -> sendRequest();
|
||||||
case ACCEPT_REQUEST -> acceptRequest();
|
case ACCEPT_REQUEST -> acceptRequest();
|
||||||
};
|
};
|
||||||
|
|
@ -41,11 +45,11 @@ public class FriendAddHandler {
|
||||||
|
|
||||||
private Mono<?> sendRequest() {
|
private Mono<?> sendRequest() {
|
||||||
return friendRequestDAO.saveFriendRequest(new FriendRequestImpl(self.getUniqueId(), other.getUniqueId(), Instant.now()))
|
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(() -> {
|
.then(Mono.fromRunnable(() -> {
|
||||||
var otherPlayer = other.getPlayer();
|
var otherPlayer = other.getPlayer();
|
||||||
if (otherPlayer != null)
|
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);
|
.doOnError(this::handleError);
|
||||||
}
|
}
|
||||||
|
|
@ -56,16 +60,17 @@ public class FriendAddHandler {
|
||||||
friendRequestDAO.deleteFriendRequest(other.getUniqueId(), self.getUniqueId()),
|
friendRequestDAO.deleteFriendRequest(other.getUniqueId(), self.getUniqueId()),
|
||||||
friendshipDAO.saveFriendship(new FriendshipImpl(self.getUniqueId(), other.getUniqueId(), Instant.now()))
|
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(() -> {
|
.then(Mono.fromRunnable(() -> {
|
||||||
var otherPlayer = other.getPlayer();
|
var otherPlayer = other.getPlayer();
|
||||||
if (otherPlayer != null)
|
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);
|
.doOnError(this::handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<@NotNull AddAction> findAction() {
|
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())
|
return friendshipDAO.getFriendship(self.getUniqueId(), other.getUniqueId())
|
||||||
.map(f -> AddAction.ERR_ALREADY_FRIENDS)
|
.map(f -> AddAction.ERR_ALREADY_FRIENDS)
|
||||||
.switchIfEmpty(
|
.switchIfEmpty(
|
||||||
|
|
@ -91,6 +96,7 @@ public class FriendAddHandler {
|
||||||
private enum AddAction {
|
private enum AddAction {
|
||||||
ERR_ALREADY_FRIENDS,
|
ERR_ALREADY_FRIENDS,
|
||||||
ERR_ALREADY_REQUESTED,
|
ERR_ALREADY_REQUESTED,
|
||||||
|
ERR_CAN_NOT_ADD_SELF,
|
||||||
SEND_REQUEST,
|
SEND_REQUEST,
|
||||||
ACCEPT_REQUEST
|
ACCEPT_REQUEST
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue