.
This commit is contained in:
parent
ce56c6e105
commit
35a0784e40
46 changed files with 597 additions and 673 deletions
|
|
@ -9,11 +9,11 @@ java_library(
|
|||
deps = [
|
||||
"//core/common",
|
||||
artifact("io.papermc.paper:paper-api"),
|
||||
artifact("de.kentoj.scrow:kencommandapi-bukkit"),
|
||||
artifact("site.lab0x13.scrow:commands-bukkit"),
|
||||
],
|
||||
exports = [
|
||||
"//core/common",
|
||||
artifact("de.kentoj.scrow:kencommandapi-bukkit"),
|
||||
artifact("site.lab0x13.scrow:commands-bukkit"),
|
||||
artifact("org.mongodb:bson"),
|
||||
],
|
||||
neverlink = True,
|
||||
|
|
@ -27,7 +27,7 @@ java_binary(
|
|||
resource_strip_prefix = "core/bukkit/plugin/main/resources",
|
||||
deps = [
|
||||
"//core/common",
|
||||
artifact("de.kentoj.scrow:kencommandapi-bukkit"),
|
||||
artifact("site.lab0x13.scrow:commands-bukkit"),
|
||||
artifact("net.luckperms:api"),
|
||||
artifact("io.papermc.paper:paper-api"),
|
||||
artifact("io.nats:jnats"),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package de.kentoj.scrow.bukkit;
|
||||
|
||||
import de.kentoj.kencommandapi.CommandAPI;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import de.kentoj.scrow.bukkit.minigame.MinigameManager;
|
||||
import de.kentoj.scrow.bukkit.region.RegionManager;
|
||||
import de.kentoj.scrowlib.economy.EconomyService;
|
||||
|
|
@ -12,12 +12,11 @@ import de.kentoj.scrowlib.player.NetworkPlayer;
|
|||
import de.kentoj.scrowlib.player.NetworkPlayerFactory;
|
||||
import de.kentoj.scrowlib.player.PlayerPrefixProvider;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import site.lab0x13.scrow.commands.bukkit.ScrowCommands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -38,8 +37,7 @@ public class ScrowAPI {
|
|||
private static MessageBroker messageBroker;
|
||||
private static InstanceManager instanceManager;
|
||||
private static RegionManager regionManager;
|
||||
private static CommandAPI<Player> playerCommands;
|
||||
private static CommandAPI<CommandSender> commands;
|
||||
private static ScrowCommands<ScrowBukkitCC> commands;
|
||||
private static PlayerPrefixProvider playerPrefixProvider;
|
||||
private static final MinigameManager minigameManager = new MinigameManager();
|
||||
private static NetworkPlayerFactory playerFactory;
|
||||
|
|
@ -103,13 +101,8 @@ public class ScrowAPI {
|
|||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setPlayerCommands(CommandAPI<Player> playerCommands) {
|
||||
ScrowAPI.playerCommands = playerCommands;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setCommands(CommandAPI<CommandSender> commands) {
|
||||
ScrowAPI.commands = commands;
|
||||
public static void setCommands(ScrowCommands<ScrowBukkitCC> commandsManager) {
|
||||
ScrowAPI.commands = commandsManager;
|
||||
}
|
||||
|
||||
public static @Nullable Jdbi jdbi() {
|
||||
|
|
@ -143,17 +136,15 @@ public class ScrowAPI {
|
|||
/**
|
||||
* Regions are not a reliable enough to detect fast movements.
|
||||
* The way regions work is that every few ticks, all regions are checked for players.
|
||||
*
|
||||
* @see org.bukkit.event.player.PlayerMoveEvent
|
||||
*/
|
||||
public static RegionManager regionManager() {
|
||||
return regionManager;
|
||||
}
|
||||
|
||||
public static CommandAPI<Player> playerCommands() {
|
||||
return playerCommands;
|
||||
}
|
||||
|
||||
public static CommandAPI<CommandSender> commands() {
|
||||
@ApiStatus.Internal
|
||||
public static ScrowCommands<ScrowBukkitCC> commands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package de.kentoj.scrow.bukkit.command;
|
||||
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import site.lab0x13.scrow.commands.bukkit.BukkitCommandContext;
|
||||
|
||||
public final class ScrowBukkitCC extends BukkitCommandContext<ScrowBukkitCC> {
|
||||
private final ScrowMessageStyle style;
|
||||
|
||||
public ScrowBukkitCC(CommandSender sender, ScrowMessageStyle style) {
|
||||
super(sender);
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public ScrowMessageStyle style() {
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package de.kentoj.scrow.bukkit.minigame.phaseflow;
|
||||
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.scrow.bukkit.minigame.Minigame;
|
||||
import de.kentoj.scrow.bukkit.minigame.PlayerManager;
|
||||
import de.kentoj.scrow.bukkit.minigame.phase.PhaseFlow;
|
||||
import de.kentoj.scrow.bukkit.minigame.phase.event.PhaseListeners;
|
||||
import de.kentoj.scrow.bukkit.minigame.phase.event.PhaseListenersImpl;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
|
||||
public class PhaseContext<T extends Minigame> {
|
||||
private final T game;
|
||||
|
|
@ -29,7 +29,7 @@ public class PhaseContext<T extends Minigame> {
|
|||
return game.playerManager();
|
||||
}
|
||||
|
||||
public MessageStyle style() {
|
||||
public ScrowMessageStyle style() {
|
||||
return game.messageStyle();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ public final class CoreImplPlugin extends JavaPlugin {
|
|||
ScrowAPISurface.initScrowAPI(this, cachedPrefixProvider);
|
||||
log.info("Initialized ScrowAPI");
|
||||
|
||||
ScrowAPI.playerCommands().register(new CoinsCommand().rootLiteral());
|
||||
ScrowAPI.playerCommands().register(new FriendCommand().rootLiteral());
|
||||
ScrowAPI.commands().register(new CoinsCommand().rootLiteral());
|
||||
ScrowAPI.commands().register(new FriendCommand().rootLiteral());
|
||||
|
||||
var luckperms = LuckPermsProvider.get();
|
||||
new LuckPermsPrefixSetter(luckperms, cachedPrefixProvider).init(this);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package de.kentoj.scrow.bukkit;
|
||||
|
||||
import de.kentoj.kencommandapi.CommandAPI;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import de.kentoj.scrow.bukkit.internal.player.NetworkPlayerWatchdog;
|
||||
import de.kentoj.scrow.bukkit.internal.region.RegionManagerImpl;
|
||||
import de.kentoj.scrow.bukkit.internal.region.RegionPlayerTracker;
|
||||
import de.kentoj.scrow.bukkit.internal.region.RegionTask;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import de.kentoj.scrowlib.economy.InMemoryEconomyService;
|
||||
import de.kentoj.scrowlib.economy.PostgresEconomyService;
|
||||
import de.kentoj.scrowlib.friends.friendship.InMemoryFriendshipService;
|
||||
|
|
@ -18,12 +19,11 @@ import de.kentoj.scrowlib.player.NetworkPlayerImpl;
|
|||
import de.kentoj.scrowlib.player.PlayerPrefixProvider;
|
||||
import io.nats.client.Nats;
|
||||
import io.nats.client.Options;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import site.lab0x13.scrow.commands.bukkit.ScrowCommands;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
|
@ -70,8 +70,7 @@ public class ScrowAPISurface {
|
|||
|
||||
ScrowAPI.setPlayerFactory(playerId -> new NetworkPlayerImpl(ScrowAPI.messageBroker(), playerId));
|
||||
ScrowAPI.setRegionManager(new RegionManagerImpl());
|
||||
ScrowAPI.setCommands(new CommandAPI<>(plugin, CommandSender.class));
|
||||
ScrowAPI.setPlayerCommands(new CommandAPI<>(plugin, Player.class));
|
||||
ScrowAPI.setCommands(new ScrowCommands<>(plugin, (literal, sender) -> new ScrowBukkitCC(sender, (ScrowMessageStyle) literal.style())));
|
||||
ScrowAPI.setInstanceManager(new InstanceManagerImpl(ScrowAPI.messageBroker()));
|
||||
ScrowAPI.setEconomyService(ScrowAPI.jdbi() != null ?
|
||||
new PostgresEconomyService(ScrowAPI.jdbi()) : new InMemoryEconomyService());
|
||||
|
|
|
|||
|
|
@ -1,31 +1,29 @@
|
|||
package de.kentoj.scrow.bukkit.command.economy;
|
||||
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
import site.lab0x13.scrow.commands.model.literal.RootLiteral;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class CoinsCommand {
|
||||
|
||||
private final RootLiteral<Player> rootLiteral;
|
||||
private final RootLiteral<ScrowBukkitCC> rootLiteral;
|
||||
|
||||
public CoinsCommand() {
|
||||
rootLiteral = Literal.<Player>builder("coins", "bal", "balance")
|
||||
rootLiteral = Literal.<ScrowBukkitCC>builder("coins", "bal", "balance")
|
||||
.withPermission("command.coins.get.self")
|
||||
.withExecutor(this::execute)
|
||||
.withLiteral(new CoinsSetLiteral().literal())
|
||||
.withLiteral(new CoinsGetLiteral().literal())
|
||||
.withSubLiteral(new CoinsSetLiteral().literal())
|
||||
.withSubLiteral(new CoinsGetLiteral().literal())
|
||||
.asRootLiteral(ScrowMessageStyle.GENERIC);
|
||||
}
|
||||
|
||||
public CompletableFuture<?> execute(CommandContext<Player> ctx) {
|
||||
var player = ctx.sender();
|
||||
public CompletableFuture<?> execute(ScrowBukkitCC ctx) {
|
||||
var player = ctx.player();
|
||||
return Tasks.supplyAsync(() ->
|
||||
ScrowAPI.economyService().getCoins(player.getUniqueId()))
|
||||
.thenSync(amount ->
|
||||
|
|
@ -33,7 +31,7 @@ public final class CoinsCommand {
|
|||
.toFuture();
|
||||
}
|
||||
|
||||
public RootLiteral<Player> rootLiteral() {
|
||||
public RootLiteral<ScrowBukkitCC> rootLiteral() {
|
||||
return rootLiteral;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,32 @@
|
|||
package de.kentoj.scrow.bukkit.command.economy;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.lab0x13.scrow.commands.bukkit.type.OfflinePlayerArgumentType;
|
||||
import site.lab0x13.scrow.commands.model.argument.Argument;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class CoinsGetLiteral {
|
||||
|
||||
private final Literal<Player> literal;
|
||||
private final CommandArgumentSpec<Player, OfflinePlayer> playerArg;
|
||||
private final Literal<ScrowBukkitCC> literal;
|
||||
private final Argument<ScrowBukkitCC, OfflinePlayer> playerArg;
|
||||
|
||||
public CoinsGetLiteral() {
|
||||
playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>())
|
||||
.withDefaultValue(CommandContext::sender)
|
||||
playerArg = Argument.builder("player", new OfflinePlayerArgumentType<ScrowBukkitCC>())
|
||||
.withDefaultValue(ScrowBukkitCC::player)
|
||||
.build();
|
||||
literal = Literal.<Player>builder("get")
|
||||
literal = Literal.<ScrowBukkitCC>builder("get")
|
||||
.withPermission("command.coins.get.others")
|
||||
.withArgument(playerArg)
|
||||
.withExecutor(this::execute)
|
||||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<?> execute(CommandContext<Player> ctx) {
|
||||
private CompletableFuture<?> execute(ScrowBukkitCC ctx) {
|
||||
var player = ctx.getArg(playerArg);
|
||||
return Tasks.supplyAsync(() ->
|
||||
ScrowAPI.economyService().getCoins(player.getUniqueId()))
|
||||
|
|
@ -37,7 +35,7 @@ public final class CoinsGetLiteral {
|
|||
.toFuture();
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
public Literal<ScrowBukkitCC> literal() {
|
||||
return literal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package de.kentoj.scrow.bukkit.command.economy;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.argument.types.IntegerArgumentType;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import site.lab0x13.scrow.commands.model.argument.Argument;
|
||||
import site.lab0x13.scrow.commands.model.argument.types.IntegerArgumentType;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
import site.lab0x13.scrow.commands.bukkit.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
|
@ -15,17 +14,17 @@ import java.util.concurrent.CompletableFuture;
|
|||
|
||||
public final class CoinsSetLiteral {
|
||||
|
||||
private final Literal<Player> literal;
|
||||
private final CommandArgumentSpec<Player, OfflinePlayer> playerArg;
|
||||
private final CommandArgumentSpec<Player, Integer> amountArg;
|
||||
private final Literal<ScrowBukkitCC> literal;
|
||||
private final Argument<ScrowBukkitCC, OfflinePlayer> playerArg;
|
||||
private final Argument<ScrowBukkitCC, Integer> amountArg;
|
||||
|
||||
CoinsSetLiteral() {
|
||||
playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>())
|
||||
.withDefaultValue(CommandContext::sender)
|
||||
playerArg = Argument.builder("player", new OfflinePlayerArgumentType<ScrowBukkitCC>())
|
||||
.withDefaultValue(ScrowBukkitCC::player)
|
||||
.build();
|
||||
amountArg = CommandArgumentSpec.builder("amount", new IntegerArgumentType<Player>())
|
||||
amountArg = Argument.builder("amount", new IntegerArgumentType<ScrowBukkitCC>())
|
||||
.build();
|
||||
literal = Literal.<Player>builder("set")
|
||||
literal = Literal.<ScrowBukkitCC>builder("set")
|
||||
.withPermission("command.coins.set")
|
||||
.withArgument(playerArg)
|
||||
.withArgument(amountArg)
|
||||
|
|
@ -33,7 +32,7 @@ public final class CoinsSetLiteral {
|
|||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<?> execute(CommandContext<Player> ctx) {
|
||||
private CompletableFuture<?> execute(ScrowBukkitCC ctx) {
|
||||
var player = ctx.getArg(playerArg);
|
||||
var amount = ctx.getArg(amountArg);
|
||||
return Tasks.runAsync(() ->
|
||||
|
|
@ -43,7 +42,7 @@ public final class CoinsSetLiteral {
|
|||
.toFuture();
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
public Literal<ScrowBukkitCC> literal() {
|
||||
return literal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,13 @@ package de.kentoj.scrow.bukkit.command.friends;
|
|||
|
||||
import com.leakyabstractions.result.api.Result;
|
||||
import com.leakyabstractions.result.core.Results;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||
import site.lab0x13.scrow.commands.model.argument.Argument;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
import site.lab0x13.scrow.commands.bukkit.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Task;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import de.kentoj.scrowlib.friends.FriendRequestService;
|
||||
import de.kentoj.scrowlib.friends.FriendshipService;
|
||||
import de.kentoj.scrowlib.friends.friendship.FriendshipImpl;
|
||||
|
|
@ -18,6 +16,7 @@ import de.kentoj.scrowlib.friends.request.FriendRequestImpl;
|
|||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.lab0x13.scrow.commands.model.literal.MessageStyle;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
|
@ -26,22 +25,22 @@ import java.util.concurrent.CompletableFuture;
|
|||
|
||||
public final class FriendAddLiteral {
|
||||
|
||||
private final Literal<Player> literal;
|
||||
private final CommandArgumentSpec<Player, OfflinePlayer> playerArg;
|
||||
private final Literal<ScrowBukkitCC> literal;
|
||||
private final Argument<ScrowBukkitCC, OfflinePlayer> playerArg;
|
||||
private final FriendRequestService requestService = ScrowAPI.friendRequestService();
|
||||
private final FriendshipService friendsService = ScrowAPI.friendshipService();
|
||||
|
||||
FriendAddLiteral() {
|
||||
playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>())
|
||||
playerArg = Argument.builder("player", new OfflinePlayerArgumentType<ScrowBukkitCC>())
|
||||
.build();
|
||||
literal = Literal.<Player>builder("add")
|
||||
literal = Literal.<ScrowBukkitCC>builder("add")
|
||||
.withArgument(playerArg)
|
||||
.withExecutor(this::execute)
|
||||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<?> execute(CommandContext<Player> ctx) {
|
||||
var self = ctx.sender();
|
||||
private CompletableFuture<?> execute(ScrowBukkitCC ctx) {
|
||||
var self = ctx.player();
|
||||
var other = ctx.getArg(playerArg);
|
||||
return Tasks.supplyAsync(() -> findAction(self, other)
|
||||
.mapSuccess(action -> {
|
||||
|
|
@ -53,6 +52,10 @@ public final class FriendAddLiteral {
|
|||
}
|
||||
|
||||
private void sendRequest(MessageStyle style, Player self, OfflinePlayer other) {
|
||||
if (other.equals(self)) {
|
||||
self.sendMessage(style.ok("You can't send yourself a friend request."));
|
||||
return;
|
||||
}
|
||||
Tasks.runAsync(() ->
|
||||
requestService.saveFriendRequest(new FriendRequestImpl(self.getUniqueId(), other.getUniqueId())))
|
||||
.runSync(() -> {
|
||||
|
|
@ -110,7 +113,7 @@ public final class FriendAddLiteral {
|
|||
.mapSync(Objects::nonNull);
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
public Literal<ScrowBukkitCC> literal() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
package de.kentoj.scrow.bukkit.command.friends;
|
||||
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
import site.lab0x13.scrow.commands.model.literal.RootLiteral;
|
||||
|
||||
public final class FriendCommand {
|
||||
|
||||
private final RootLiteral<Player> rootLiteral;
|
||||
private final RootLiteral<ScrowBukkitCC> rootLiteral;
|
||||
|
||||
public FriendCommand() {
|
||||
rootLiteral = Literal.<Player>builder("f", "friend")
|
||||
.withLiteral(new FriendListLiteral().literal())
|
||||
.withLiteral(new FriendAddLiteral().literal())
|
||||
.withLiteral(new FriendRemoveLiteral().literal())
|
||||
.withLiteral(new FriendRequestDeclineLiteral().literal())
|
||||
.withLiteral(new FriendRequestsLiteral().literal())
|
||||
rootLiteral = Literal.<ScrowBukkitCC>builder("f", "friend")
|
||||
.withSubLiteral(new FriendListLiteral().literal())
|
||||
.withSubLiteral(new FriendAddLiteral().literal())
|
||||
.withSubLiteral(new FriendRemoveLiteral().literal())
|
||||
.withSubLiteral(new FriendRequestDeclineLiteral().literal())
|
||||
.withSubLiteral(new FriendRequestsLiteral().literal())
|
||||
.asRootLiteral(new ScrowMessageStyle("Friends", NamedTextColor.AQUA));
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ public final class FriendCommand {
|
|||
.color(NamedTextColor.RED));
|
||||
}
|
||||
|
||||
public RootLiteral<Player> rootLiteral() {
|
||||
public RootLiteral<ScrowBukkitCC> rootLiteral() {
|
||||
return rootLiteral;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.command.friends;
|
||||
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
|
|
@ -11,7 +10,6 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
|
@ -20,16 +18,16 @@ import static java.util.Objects.requireNonNull;
|
|||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public final class FriendListLiteral {
|
||||
private final Literal<Player> literal;
|
||||
private final Literal<ScrowBukkitCC> literal;
|
||||
|
||||
FriendListLiteral() {
|
||||
literal = Literal.<Player>builder("list")
|
||||
literal = Literal.<ScrowBukkitCC>builder("list")
|
||||
.withExecutor(this::displayFriendList)
|
||||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<?> displayFriendList(CommandContext<Player> ctx) {
|
||||
var sender = ctx.sender();
|
||||
private CompletableFuture<?> displayFriendList(ScrowBukkitCC ctx) {
|
||||
var sender = ctx.player();
|
||||
return Tasks.supplyAsync(() ->
|
||||
ScrowAPI.friendshipService().getFriendships(sender.getUniqueId()))
|
||||
.thenSync(friendships -> {
|
||||
|
|
@ -67,7 +65,7 @@ public final class FriendListLiteral {
|
|||
return message;
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
public Literal<ScrowBukkitCC> literal() {
|
||||
return literal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +1,33 @@
|
|||
package de.kentoj.scrow.bukkit.command.friends;
|
||||
|
||||
import com.leakyabstractions.result.api.Result;
|
||||
import com.leakyabstractions.result.core.Results;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.lab0x13.scrow.commands.bukkit.type.OfflinePlayerArgumentType;
|
||||
import site.lab0x13.scrow.commands.model.argument.Argument;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class FriendRemoveLiteral {
|
||||
|
||||
private final Literal<Player> literal;
|
||||
private final CommandArgumentSpec<Player, OfflinePlayer> playerArg;
|
||||
private final Literal<ScrowBukkitCC> literal;
|
||||
private final Argument<ScrowBukkitCC, OfflinePlayer> playerArg;
|
||||
|
||||
FriendRemoveLiteral() {
|
||||
playerArg = CommandArgumentSpec.<Player, OfflinePlayer>builder("player", new OfflinePlayerArgumentType<>())
|
||||
playerArg = Argument.<ScrowBukkitCC, OfflinePlayer>builder("player", new OfflinePlayerArgumentType<>())
|
||||
.build();
|
||||
literal = Literal.<Player>builder("remove")
|
||||
literal = Literal.<ScrowBukkitCC>builder("remove")
|
||||
.withArgument(playerArg)
|
||||
.withExecutor(this::removeFriend)
|
||||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<?> removeFriend(CommandContext<Player> ctx) {
|
||||
private CompletableFuture<?> removeFriend(ScrowBukkitCC ctx) {
|
||||
var friend = ctx.getArg(playerArg);
|
||||
return Tasks.supplyAsync(() ->
|
||||
ScrowAPI.friendshipService().deleteFriendship(friend.getUniqueId(), ctx.sender().getUniqueId()))
|
||||
ScrowAPI.friendshipService().deleteFriendship(friend.getUniqueId(), ctx.player().getUniqueId()))
|
||||
.thenSync(deleted -> {
|
||||
if (!deleted) {
|
||||
ctx.sender().sendMessage(ctx.style().err("You are not friends with " + friend.getName() + "."));
|
||||
|
|
@ -40,7 +37,7 @@ public final class FriendRemoveLiteral {
|
|||
}).toFuture();
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
public Literal<ScrowBukkitCC> literal() {
|
||||
return literal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,50 +1,46 @@
|
|||
package de.kentoj.scrow.bukkit.command.friends;
|
||||
|
||||
import com.leakyabstractions.result.api.Result;
|
||||
import com.leakyabstractions.result.core.Results;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import de.kentoj.scrowlib.friends.FriendRequestService;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.lab0x13.scrow.commands.bukkit.type.OfflinePlayerArgumentType;
|
||||
import site.lab0x13.scrow.commands.model.argument.Argument;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class FriendRequestDeclineLiteral {
|
||||
|
||||
private final Literal<Player> literal;
|
||||
private final CommandArgumentSpec<Player, OfflinePlayer> playerArg;
|
||||
private final Literal<ScrowBukkitCC> literal;
|
||||
private final Argument<ScrowBukkitCC, OfflinePlayer> playerArg;
|
||||
private final FriendRequestService requestService = ScrowAPI.friendRequestService();
|
||||
|
||||
FriendRequestDeclineLiteral() {
|
||||
playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>())
|
||||
playerArg = Argument.builder("player", new OfflinePlayerArgumentType<ScrowBukkitCC>())
|
||||
.build();
|
||||
literal = Literal.<Player>builder("reject", "decline")
|
||||
literal = Literal.<ScrowBukkitCC>builder("reject", "decline")
|
||||
.withArgument(playerArg)
|
||||
.withExecutor(this::declineFriendRequest)
|
||||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<?> declineFriendRequest(CommandContext<Player> ctx) {
|
||||
private CompletableFuture<?> declineFriendRequest(ScrowBukkitCC ctx) {
|
||||
var other = ctx.getArg(playerArg);
|
||||
return Tasks.supplyAsync(() ->
|
||||
requestService.deleteFriendRequest(other.getUniqueId(), ctx.sender().getUniqueId()))
|
||||
requestService.deleteFriendRequest(other.getUniqueId(), ctx.player().getUniqueId()))
|
||||
.thenSync(deleted -> {
|
||||
if (!deleted) {
|
||||
ctx.sender().sendMessage(ctx.style().err("There's no incoming friend request from " + other.getName() + "."));
|
||||
ctx.player().sendMessage(ctx.style().err("There's no incoming friend request from " + other.getName() + "."));
|
||||
return;
|
||||
}
|
||||
ctx.sender().sendMessage(ctx.style().ok("Friend request declined."));
|
||||
ScrowAPI.getPlayer(other).sendMessage(ctx.style().ok(ctx.sender().getName() + " has declined your friend request."));
|
||||
ctx.player().sendMessage(ctx.style().ok("Friend request declined."));
|
||||
ScrowAPI.getPlayer(other).sendMessage(ctx.style().ok(ctx.player().getName() + " has declined your friend request."));
|
||||
}).toFuture();
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
public Literal<ScrowBukkitCC> literal() {
|
||||
return literal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.command.friends;
|
||||
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.scrow.bukkit.command.ScrowBukkitCC;
|
||||
import site.lab0x13.scrow.commands.model.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
|
|
@ -11,7 +10,6 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
|
@ -20,26 +18,26 @@ import static net.kyori.adventure.text.Component.text;
|
|||
|
||||
public final class FriendRequestsLiteral {
|
||||
|
||||
private final Literal<Player> literal;
|
||||
private final Literal<ScrowBukkitCC> literal;
|
||||
|
||||
FriendRequestsLiteral() {
|
||||
literal = Literal.<Player>builder("requests")
|
||||
literal = Literal.<ScrowBukkitCC>builder("requests")
|
||||
.withExecutor(this::displayFriendRequests)
|
||||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<?> displayFriendRequests(CommandContext<Player> ctx) {
|
||||
private CompletableFuture<?> displayFriendRequests(ScrowBukkitCC ctx) {
|
||||
return Tasks.supplyAsync(() ->
|
||||
ScrowAPI.friendRequestService().getFriendRequestsTo(ctx.sender().getUniqueId()))
|
||||
ScrowAPI.friendRequestService().getFriendRequestsTo(ctx.player().getUniqueId()))
|
||||
.thenSync(list -> {
|
||||
if (list.isEmpty()) {
|
||||
ctx.sender().sendMessage(ctx.style().err("You have no friend requests."));
|
||||
ctx.player().sendMessage(ctx.style().err("You have no friend requests."));
|
||||
return;
|
||||
}
|
||||
var requesters = list.stream()
|
||||
.sorted(this::compareByAge)
|
||||
.map(fr -> Bukkit.getOfflinePlayer(fr.from()).getName());
|
||||
ctx.sender().sendMessage(formatList(ctx.style(), requesters.toList()));
|
||||
ctx.player().sendMessage(formatList(ctx.style(), requesters.toList()));
|
||||
}).toFuture();
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +57,7 @@ public final class FriendRequestsLiteral {
|
|||
return message;
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
public Literal<ScrowBukkitCC> literal() {
|
||||
return literal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue