This commit is contained in:
kento2 2026-06-01 12:44:30 +02:00
parent cc402a71e7
commit f9ceea47d6
7 changed files with 17 additions and 18 deletions

View file

@ -22,7 +22,6 @@ public class OrderedUUIDPair {
} }
public UUID getOther(UUID self) { public UUID getOther(UUID self) {
final var ids = getFirst();
return getFirst().equals(self) ? getSecond() : getFirst(); return getFirst().equals(self) ? getSecond() : getFirst();
} }
} }

View file

@ -32,8 +32,6 @@ public class FriendListLiteral {
}) })
.doOnNext(line -> ctx.getSender().sendMessage(line)) .doOnNext(line -> ctx.getSender().sendMessage(line))
.doOnComplete(() -> ctx.getSender().sendMessage("EOF")) .doOnComplete(() -> ctx.getSender().sendMessage("EOF"))
.subscribeOn(Schedulers.boundedElastic())
.subscribe(); .subscribe();
} }

View file

@ -27,10 +27,9 @@ public class FriendRemoveLiteral {
var friend = ctx.getArg(playerArg); var friend = ctx.getArg(playerArg);
ScrowAPI.getFriendshipService().deleteFriendship(friend.getUniqueId(), ctx.getPlayerSender().getUniqueId()) ScrowAPI.getFriendshipService().deleteFriendship(friend.getUniqueId(), ctx.getPlayerSender().getUniqueId())
.doOnNext(wasDeleted -> { .subscribe(wasDeleted -> {
if (wasDeleted) throw new CommandException("You were not friends with " + friend.getName() + " in the first place"); if (wasDeleted) throw new CommandException("You were not friends with " + friend.getName() + " in the first place");
ctx.getSender().sendMessage("You are no longer friends with " + friend.getName()); ctx.getSender().sendMessage("You are no longer friends with " + friend.getName());
}) });
.subscribe();
} }
} }

View file

@ -3,11 +3,9 @@ package de.kentoj.scrow.bukkit.friends.command;
import de.kentoj.kencommandapi.BukkitCommandContext; import de.kentoj.kencommandapi.BukkitCommandContext;
import de.kentoj.kencommandapi.api.structure.node.CommandNode; import de.kentoj.kencommandapi.api.structure.node.CommandNode;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
import de.kentoj.scrow.bukkit.friends.FriendRequestService;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import reactor.core.scheduler.Schedulers;
public class FriendRequestsLiteral { public class FriendRequestsLiteral {
@ -29,8 +27,6 @@ public class FriendRequestsLiteral {
return "- " + fromName; return "- " + fromName;
}).doOnNext(line -> ctx.getPlayerSender().sendMessage(line)) }).doOnNext(line -> ctx.getPlayerSender().sendMessage(line))
.doOnComplete(() -> ctx.getPlayerSender().sendMessage("EOF")) .doOnComplete(() -> ctx.getPlayerSender().sendMessage("EOF"))
.subscribeOn(Schedulers.boundedElastic())
.subscribe(); .subscribe();
} }
} }

View file

@ -9,7 +9,6 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import java.time.Instant; import java.time.Instant;
@ -26,7 +25,6 @@ public class FriendAddHandler {
ScrowAPI.getCommandManager().sendErrorMessage(self, e); ScrowAPI.getCommandManager().sendErrorMessage(self, e);
}) })
.onErrorComplete(CommandException.class) .onErrorComplete(CommandException.class)
.subscribeOn(Schedulers.boundedElastic())
.subscribe(); .subscribe();
} }
@ -43,13 +41,22 @@ public class FriendAddHandler {
private Mono<?> sendRequest() { private Mono<?> sendRequest() {
return ScrowAPI.getFriendRequestService().saveFriendRequest(new FriendRequestImpl(self.getUniqueId(), other.getUniqueId(), Instant.now())) return ScrowAPI.getFriendRequestService().saveFriendRequest(new FriendRequestImpl(self.getUniqueId(), other.getUniqueId(), Instant.now()))
.then(sendMessage(self.getPlayer(), "Successfully sent " + other.getName() + " a friend request.")) .flatMap(success -> {
.then(Mono.fromRunnable(() -> { if (success) {
sendMessage(self.getPlayer(), "Successfully sent " + other.getName() + " a friend request.");
return Mono.just(true);
} else {
sendMessage(self.getPlayer(), "You already sent " + other.getName() + " a friend request");
return Mono.just(Mono.empty());
}
})
.doOnNext(success -> {
var otherPlayer = other.getPlayer(); var otherPlayer = other.getPlayer();
if (otherPlayer != null) if (otherPlayer != null)
sendMessage(otherPlayer, 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);
} }
private Mono<?> acceptRequest() { private Mono<?> acceptRequest() {

View file

@ -8,7 +8,7 @@ plugins {
} }
group = "de.kentoj.scrow" group = "de.kentoj.scrow"
version = "0.1" version = "0.2"
repositories { repositories {
mavenCentral() mavenCentral()

View file

@ -28,12 +28,12 @@ public class ServerRegisterWatchdog {
public void listen() { public void listen() {
natsRepo.subscribe("crown.set-state") natsRepo.subscribe("crown.set-state")
.map(DocumentRepository::fromMessage) .map(DocumentRepository::fromMessage)
.flatMap(doc -> { .concatMap(doc -> {
var state = doc.getString("state"); var state = doc.getString("state");
var handle = doc.getString("handle"); var handle = doc.getString("handle");
return handleStateChange(state, handle); return handleStateChange(state, handle);
}) })
.subscribe(); .subscribe(null, e -> log.throwing(getClass().getName(), "listen", e));
} }
private @NotNull Mono<@NotNull Void> handleStateChange(String state, String handle) { private @NotNull Mono<@NotNull Void> handleStateChange(String state, String handle) {