.
This commit is contained in:
parent
08129e7474
commit
1292a519f8
8 changed files with 46 additions and 94 deletions
|
|
@ -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 <T> Future<T> io(Callable<T> task) {
|
|
||||||
return executor.submit(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shutdown() {
|
|
||||||
executor.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull List<Runnable> 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 <T> Future<T> submit(@NotNull Callable<T> callable) {
|
|
||||||
return executor.submit(callable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull <T> Future<T> 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 <T> List<Future<T>> invokeAll(@NotNull Collection<? extends Callable<T>> collection) throws InterruptedException {
|
|
||||||
return executor.invokeAll(collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull <T> List<Future<T>> invokeAll(@NotNull Collection<? extends Callable<T>> collection, long l, @NotNull TimeUnit timeUnit) throws InterruptedException {
|
|
||||||
return executor.invokeAll(collection, l, timeUnit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull <T> T invokeAny(@NotNull Collection<? extends Callable<T>> collection) throws InterruptedException, ExecutionException {
|
|
||||||
return (T) executor.invokeAll(collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T invokeAny(@NotNull Collection<? extends Callable<T>> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,7 @@ import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
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.friendship.FriendshipDAO;
|
||||||
import de.kentoj.scrow.bukkit.friends.request.FriendRequestDAO;
|
import de.kentoj.scrow.bukkit.friends.request.FriendRequestDAO;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ public class FriendCommand {
|
||||||
this.rootNode = ScrowAPI.getCommandManager().createNode("friends", "f", "friend");
|
this.rootNode = ScrowAPI.getCommandManager().createNode("friends", "f", "friend");
|
||||||
rootNode.addLiteral(new FriendListLiteral(friendshipDAO).getNode());
|
rootNode.addLiteral(new FriendListLiteral(friendshipDAO).getNode());
|
||||||
rootNode.addLiteral(new FriendAddLiteral(friendshipDAO, friendRequestDAO).getNode());
|
rootNode.addLiteral(new FriendAddLiteral(friendshipDAO, friendRequestDAO).getNode());
|
||||||
|
rootNode.addLiteral(new FriendRemoveLiteral(friendshipDAO).getNode());
|
||||||
rootNode.addLiteral(new FriendRequestsLiteral(friendRequestDAO).getNode());
|
rootNode.addLiteral(new FriendRequestsLiteral(friendRequestDAO).getNode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,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"))
|
||||||
|
|
||||||
.publishOn(ScrowAPI.getMinecraftScheduler())
|
|
||||||
.subscribeOn(Schedulers.boundedElastic())
|
.subscribeOn(Schedulers.boundedElastic())
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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<CommandSender, BukkitCommandContext> node;
|
||||||
|
private final CommandArgument<CommandSender, BukkitCommandContext, OfflinePlayer> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,14 +25,14 @@ public class FriendRequestsLiteral {
|
||||||
var ownUid = ctx.getPlayerSender().getUniqueId();
|
var ownUid = ctx.getPlayerSender().getUniqueId();
|
||||||
ctx.getPlayerSender().sendMessage("incoming friends requests:");
|
ctx.getPlayerSender().sendMessage("incoming friends requests:");
|
||||||
friendRequestDAO.getFriendRequestsTo(ownUid)
|
friendRequestDAO.getFriendRequestsTo(ownUid)
|
||||||
.publishOn(ScrowAPI.getMinecraftScheduler())
|
|
||||||
.subscribeOn(Schedulers.boundedElastic())
|
|
||||||
.map(friendRequest -> {
|
.map(friendRequest -> {
|
||||||
var fromUid = friendRequest.getFrom();
|
var fromUid = friendRequest.getFrom();
|
||||||
var fromName = Bukkit.getOfflinePlayer(fromUid).getName();
|
var fromName = Bukkit.getOfflinePlayer(fromUid).getName();
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ public class MongoFriendshipDAO implements FriendshipDAO {
|
||||||
public Mono<@NotNull Friendship> getFriendship(UUID uuid1, UUID uuid2) {
|
public Mono<@NotNull Friendship> getFriendship(UUID uuid1, UUID uuid2) {
|
||||||
var uuids = new OrderedUUIDPair(uuid1, uuid2);
|
var uuids = new OrderedUUIDPair(uuid1, uuid2);
|
||||||
return Mono.from(collection()
|
return Mono.from(collection()
|
||||||
.find(Filters.or(
|
.find(Filters.and(
|
||||||
Filters.eq("first", uuids.getFirst()),
|
Filters.eq("first", uuids.getFirst()),
|
||||||
Filters.eq("second", uuids.getSecond())
|
Filters.eq("second", uuids.getSecond())
|
||||||
)))
|
)))
|
||||||
|
|
@ -95,8 +95,8 @@ public class MongoFriendshipDAO implements FriendshipDAO {
|
||||||
|
|
||||||
private Document toDocument(Friendship friendship) {
|
private Document toDocument(Friendship friendship) {
|
||||||
return new Document()
|
return new Document()
|
||||||
.append("first", friendship.getUuids().getFirst().toString())
|
.append("first", friendship.getUuids().getFirst())
|
||||||
.append("second", friendship.getUuids().getSecond().toString())
|
.append("second", friendship.getUuids().getSecond())
|
||||||
.append("createdAt", Date.from(friendship.getCreatedAt()));
|
.append("createdAt", Date.from(friendship.getCreatedAt()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.ScrowAPI;
|
||||||
import de.kentoj.scrow.bukkit.friends.friendship.FriendshipDAO;
|
import de.kentoj.scrow.bukkit.friends.friendship.FriendshipDAO;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue