diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/BukkitExecutorService.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/BukkitExecutorService.java deleted file mode 100644 index eeb47e8..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/BukkitExecutorService.java +++ /dev/null @@ -1,86 +0,0 @@ -package de.kentoj.scrow.bukkit.friends.command; - -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.List; -import java.util.concurrent.*; - -public class BukkitExecutorService implements ExecutorService { - - private final ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor(); - - public Future io(Callable task) { - return executor.submit(task); - } - - @Override - public void shutdown() { - executor.shutdown(); - } - - @Override - public @NotNull List shutdownNow() { - return executor.shutdownNow(); - } - - @Override - public boolean isShutdown() { - return executor.isShutdown(); - } - - @Override - public boolean isTerminated() { - return executor.isTerminated(); - } - - @Override - public boolean awaitTermination(long l, @NotNull TimeUnit timeUnit) throws InterruptedException { - return executor.awaitTermination(l, timeUnit); - } - - @Override - public @NotNull Future submit(@NotNull Callable callable) { - return executor.submit(callable); - } - - @Override - public @NotNull Future submit(@NotNull Runnable runnable, T t) { - return executor.submit(runnable, t); - } - - @Override - public @NotNull Future submit(@NotNull Runnable runnable) { - return executor.submit(runnable); - } - - @Override - public @NotNull List> invokeAll(@NotNull Collection> collection) throws InterruptedException { - return executor.invokeAll(collection); - } - - @Override - public @NotNull List> invokeAll(@NotNull Collection> collection, long l, @NotNull TimeUnit timeUnit) throws InterruptedException { - return executor.invokeAll(collection, l, timeUnit); - } - - @Override - public @NotNull T invokeAny(@NotNull Collection> collection) throws InterruptedException, ExecutionException { - return (T) executor.invokeAll(collection); - } - - @Override - public T invokeAny(@NotNull Collection> collection, long l, @NotNull TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { - return (T) executor.invokeAll(collection, l, timeUnit); - } - - @Override - public void close() { - executor.close(); - } - - @Override - public void execute(@NotNull Runnable runnable) { - executor.execute(runnable); - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java index 2d22e06..93d8f5d 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java @@ -4,7 +4,7 @@ import de.kentoj.kencommandapi.BukkitCommandContext; import de.kentoj.kencommandapi.api.structure.node.CommandNode; import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType; import de.kentoj.scrow.bukkit.ScrowAPI; -import de.kentoj.scrow.bukkit.friends.command.handler.FriendAddHandler; +import de.kentoj.scrow.bukkit.friends.handler.FriendAddHandler; import de.kentoj.scrow.bukkit.friends.friendship.FriendshipDAO; import de.kentoj.scrow.bukkit.friends.request.FriendRequestDAO; import lombok.Getter; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendCommand.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendCommand.java index ee47467..500e25b 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendCommand.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendCommand.java @@ -17,6 +17,7 @@ public class FriendCommand { this.rootNode = ScrowAPI.getCommandManager().createNode("friends", "f", "friend"); rootNode.addLiteral(new FriendListLiteral(friendshipDAO).getNode()); rootNode.addLiteral(new FriendAddLiteral(friendshipDAO, friendRequestDAO).getNode()); + rootNode.addLiteral(new FriendRemoveLiteral(friendshipDAO).getNode()); rootNode.addLiteral(new FriendRequestsLiteral(friendRequestDAO).getNode()); } } diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendListLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendListLiteral.java index 061ec5f..ab5593b 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendListLiteral.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendListLiteral.java @@ -33,7 +33,6 @@ public class FriendListLiteral { .doOnNext(line -> ctx.getSender().sendMessage(line)) .doOnComplete(() -> ctx.getSender().sendMessage("EOF")) - .publishOn(ScrowAPI.getMinecraftScheduler()) .subscribeOn(Schedulers.boundedElastic()) .subscribe(); } diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java new file mode 100644 index 0000000..4faab53 --- /dev/null +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java @@ -0,0 +1,38 @@ +package de.kentoj.scrow.bukkit.friends.command; + +import de.kentoj.kencommandapi.BukkitCommandContext; +import de.kentoj.kencommandapi.api.structure.argument.CommandArgument; +import de.kentoj.kencommandapi.api.structure.node.CommandNode; +import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType; +import de.kentoj.scrow.bukkit.ScrowAPI; +import de.kentoj.scrow.bukkit.friends.friendship.FriendshipDAO; +import lombok.Getter; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import reactor.core.publisher.Mono; + +public class FriendRemoveLiteral { + @Getter + private final CommandNode node; + private final CommandArgument playerArg; + private final FriendshipDAO friendshipDAO; + + public FriendRemoveLiteral(FriendshipDAO friendshipDAO) { + this.friendshipDAO = friendshipDAO; + this.node = ScrowAPI.getCommandManager().createNode("remove"); + this.playerArg = ScrowAPI.getCommandManager().createArgument("player", OfflinePlayerArgumentType.getInstance()); + this.node.addArgument(playerArg); + this.node.setExecutor(this::removeFriend); + } + + private void removeFriend(BukkitCommandContext ctx) { + var friend = ctx.getArg(playerArg); + + friendshipDAO.getFriendship(friend.getUniqueId(), ctx.getPlayerSender().getUniqueId()) + .map(wasDeleted -> { + ctx.getSender().sendMessage("[friend] You are no longer friends with " + friend.getName()); + return Mono.empty(); + }) + .subscribe(); + } +} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java index e5f985a..003977a 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java @@ -25,14 +25,14 @@ public class FriendRequestsLiteral { var ownUid = ctx.getPlayerSender().getUniqueId(); ctx.getPlayerSender().sendMessage("incoming friends requests:"); friendRequestDAO.getFriendRequestsTo(ownUid) - .publishOn(ScrowAPI.getMinecraftScheduler()) - .subscribeOn(Schedulers.boundedElastic()) .map(friendRequest -> { var fromUid = friendRequest.getFrom(); var fromName = Bukkit.getOfflinePlayer(fromUid).getName(); return "- " + fromName; }).doOnNext(line -> ctx.getPlayerSender().sendMessage(line)) .doOnComplete(() -> ctx.getPlayerSender().sendMessage("EOF")) + + .subscribeOn(Schedulers.boundedElastic()) .subscribe(); } } diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/MongoFriendshipDAO.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/MongoFriendshipDAO.java index 02e15ed..4e2ad48 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/MongoFriendshipDAO.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/MongoFriendshipDAO.java @@ -41,7 +41,7 @@ public class MongoFriendshipDAO implements FriendshipDAO { public Mono<@NotNull Friendship> getFriendship(UUID uuid1, UUID uuid2) { var uuids = new OrderedUUIDPair(uuid1, uuid2); return Mono.from(collection() - .find(Filters.or( + .find(Filters.and( Filters.eq("first", uuids.getFirst()), Filters.eq("second", uuids.getSecond()) ))) @@ -95,8 +95,8 @@ public class MongoFriendshipDAO implements FriendshipDAO { private Document toDocument(Friendship friendship) { return new Document() - .append("first", friendship.getUuids().getFirst().toString()) - .append("second", friendship.getUuids().getSecond().toString()) + .append("first", friendship.getUuids().getFirst()) + .append("second", friendship.getUuids().getSecond()) .append("createdAt", Date.from(friendship.getCreatedAt())); } } diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/handler/FriendAddHandler.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/handler/FriendAddHandler.java similarity index 98% rename from core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/handler/FriendAddHandler.java rename to core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/handler/FriendAddHandler.java index aab1362..7536f7f 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/handler/FriendAddHandler.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/handler/FriendAddHandler.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.friends.command.handler; +package de.kentoj.scrow.bukkit.friends.handler; import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.friends.friendship.FriendshipDAO;