.
This commit is contained in:
parent
a9b7f47494
commit
a088d27485
15 changed files with 65 additions and 74 deletions
|
|
@ -1,7 +1,5 @@
|
|||
package de.kentoj.scrow.bukkit.command.economy;
|
||||
|
||||
import com.leakyabstractions.result.api.Result;
|
||||
import com.leakyabstractions.result.core.Results;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
|
|
@ -16,26 +14,23 @@ import java.util.concurrent.CompletableFuture;
|
|||
public final class CoinsCommand {
|
||||
|
||||
private final RootLiteral<Player> rootLiteral;
|
||||
private final MessageStyle style;
|
||||
|
||||
public CoinsCommand() {
|
||||
style = ScrowMessageStyle.GENERIC;
|
||||
rootLiteral = Literal.<Player>builder("coins", "bal", "balance")
|
||||
.withPermission("command.coins.get.self")
|
||||
.withExecutor(this::execute)
|
||||
.withLiteral(new CoinsSetLiteral(style).literal())
|
||||
.withLiteral(new CoinsGetLiteral(style).literal())
|
||||
.asRootLiteral(style);
|
||||
.withLiteral(new CoinsSetLiteral().literal())
|
||||
.withLiteral(new CoinsGetLiteral().literal())
|
||||
.asRootLiteral(ScrowMessageStyle.GENERIC);
|
||||
}
|
||||
|
||||
public CompletableFuture<Result<Object, String>> execute(CommandContext<Player> ctx) {
|
||||
public CompletableFuture<?> execute(MessageStyle style, CommandContext<Player> ctx) {
|
||||
var player = ctx.sender();
|
||||
return Tasks.supplyAsync(() ->
|
||||
ScrowAPI.economyService().getCoins(player.getUniqueId()))
|
||||
.<Result<Object, String>>mapSync(amount -> {
|
||||
player.sendMessage(style.ok("You have " + amount + "$"));
|
||||
return Results.success(new Object());
|
||||
}).toFuture();
|
||||
.thenSync(amount ->
|
||||
player.sendMessage(style.ok("You have " + amount + "$")))
|
||||
.toFuture();
|
||||
}
|
||||
|
||||
public RootLiteral<Player> rootLiteral() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package de.kentoj.scrow.bukkit.command.economy;
|
||||
|
||||
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;
|
||||
|
|
@ -17,12 +15,9 @@ import java.util.concurrent.CompletableFuture;
|
|||
public final class CoinsGetLiteral {
|
||||
|
||||
private final Literal<Player> literal;
|
||||
private final MessageStyle style;
|
||||
private final CommandArgumentSpec<Player, OfflinePlayer> playerArg;
|
||||
|
||||
public CoinsGetLiteral(MessageStyle style) {
|
||||
this.style = style;
|
||||
|
||||
public CoinsGetLiteral() {
|
||||
playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>())
|
||||
.withDefaultValue(CommandContext::sender)
|
||||
.build();
|
||||
|
|
@ -33,14 +28,13 @@ public final class CoinsGetLiteral {
|
|||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<Result<Object, String>> execute(CommandContext<Player> ctx) {
|
||||
private CompletableFuture<?> execute(MessageStyle style, CommandContext<Player> ctx) {
|
||||
var player = ctx.getArg(playerArg);
|
||||
return Tasks.supplyAsync(() ->
|
||||
ScrowAPI.economyService().getCoins(player.getUniqueId()))
|
||||
.<Result<Object, String>>mapSync(amount -> {
|
||||
ctx.sender().sendMessage(style.ok(player.getName() + " has " + amount + "$"));
|
||||
return Results.success(new Object());
|
||||
}).toFuture();
|
||||
.thenSync(amount ->
|
||||
ctx.sender().sendMessage(style.ok(player.getName() + " has " + amount + "$")))
|
||||
.toFuture();
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package de.kentoj.scrow.bukkit.command.economy;
|
||||
|
||||
import com.leakyabstractions.result.api.Result;
|
||||
import com.leakyabstractions.result.core.Results;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.argument.types.IntegerArgumentType;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
|
|
@ -18,12 +16,10 @@ import java.util.concurrent.CompletableFuture;
|
|||
public final class CoinsSetLiteral {
|
||||
|
||||
private final Literal<Player> literal;
|
||||
private final MessageStyle style;
|
||||
private final CommandArgumentSpec<Player, OfflinePlayer> playerArg;
|
||||
private final CommandArgumentSpec<Player, Integer> amountArg;
|
||||
|
||||
CoinsSetLiteral(MessageStyle style) {
|
||||
this.style = style;
|
||||
CoinsSetLiteral() {
|
||||
playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>())
|
||||
.withDefaultValue(CommandContext::sender)
|
||||
.build();
|
||||
|
|
@ -37,15 +33,14 @@ public final class CoinsSetLiteral {
|
|||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<Result<Object, String>> execute(CommandContext<Player> ctx) {
|
||||
private CompletableFuture<?> execute(MessageStyle style, CommandContext<Player> ctx) {
|
||||
var player = ctx.getArg(playerArg);
|
||||
var amount = ctx.getArg(amountArg);
|
||||
return Tasks.runAsync(() ->
|
||||
ScrowAPI.economyService().setCoins(player.getUniqueId(), amount))
|
||||
.<Result<Object, String>>supplySync(() -> {
|
||||
ctx.sender().sendMessage(style.ok(player.getName() + " now has " + amount + "$"));
|
||||
return Results.success(new Object());
|
||||
}).toFuture();
|
||||
.runSync(() ->
|
||||
ctx.sender().sendMessage(style.ok(player.getName() + " now has " + amount + "$")))
|
||||
.toFuture();
|
||||
}
|
||||
|
||||
public Literal<Player> literal() {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,13 @@ public final class FriendCommand {
|
|||
private final RootLiteral<Player> rootLiteral;
|
||||
|
||||
public FriendCommand() {
|
||||
var style = new ScrowMessageStyle("Friends", NamedTextColor.AQUA);
|
||||
rootLiteral = Literal.<Player>builder("f", "friend")
|
||||
.withLiteral(new FriendListLiteral(style).literal())
|
||||
.withLiteral(new FriendAddLiteral(style).literal())
|
||||
.withLiteral(new FriendRemoveLiteral(style).literal())
|
||||
.withLiteral(new FriendRequestDeclineLiteral(style).literal())
|
||||
.withLiteral(new FriendRequestsLiteral(style).literal())
|
||||
.asRootLiteral(style);
|
||||
.withLiteral(new FriendListLiteral().literal())
|
||||
.withLiteral(new FriendAddLiteral().literal())
|
||||
.withLiteral(new FriendRemoveLiteral().literal())
|
||||
.withLiteral(new FriendRequestDeclineLiteral().literal())
|
||||
.withLiteral(new FriendRequestsLiteral().literal())
|
||||
.asRootLiteral(new ScrowMessageStyle("Friends", NamedTextColor.AQUA));
|
||||
}
|
||||
|
||||
public static Component friendRequestOptions(String requestSenderName, boolean runInstantly) {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import com.leakyabstractions.result.api.Result;
|
|||
import com.leakyabstractions.result.core.Results;
|
||||
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.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
|
@ -22,28 +22,28 @@ import static net.kyori.adventure.text.Component.text;
|
|||
|
||||
public final class FriendListLiteral {
|
||||
private final Literal<Player> literal;
|
||||
private final ScrowMessageStyle style;
|
||||
|
||||
FriendListLiteral(ScrowMessageStyle style) {
|
||||
this.style = style;
|
||||
FriendListLiteral() {
|
||||
literal = Literal.<Player>builder("list")
|
||||
.withExecutor(this::displayFriendList)
|
||||
.build();
|
||||
.withExecutor(this::displayFriendList)
|
||||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<Result<Object, String>> displayFriendList(CommandContext<Player> ctx) {
|
||||
private CompletableFuture<?> displayFriendList(MessageStyle style, CommandContext<Player> ctx) {
|
||||
var sender = ctx.sender();
|
||||
return Tasks.supplyAsync(() ->
|
||||
ScrowAPI.friendshipService().getFriendships(sender.getUniqueId()))
|
||||
.<Result<Object, String>>mapSync(friendships -> {
|
||||
.thenSync(friendships -> {
|
||||
var friends = friendships.stream()
|
||||
.map(friendship -> Bukkit.getOfflinePlayer(friendship.uuids().getOther(sender.getUniqueId())))
|
||||
.sorted(this::compareByOnlineStatus)
|
||||
.toList();
|
||||
if (friends.isEmpty()) return Results.failure("You have no friends. Use /friend add <player>");
|
||||
if (friends.isEmpty()) {
|
||||
ctx.sender().sendMessage(style.err("You have no friends. Use /friend add <player>"));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(formatList(friends));
|
||||
return Results.success(new Object());
|
||||
sender.sendMessage(formatList(style, friends));
|
||||
}).toFuture();
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ public final class FriendListLiteral {
|
|||
return 0;
|
||||
}
|
||||
|
||||
private Component formatList(List<OfflinePlayer> friends) {
|
||||
private Component formatList(MessageStyle style, List<OfflinePlayer> friends) {
|
||||
var message = style.ok(MiniMessage.miniMessage().deserialize("Your friends:"));
|
||||
for (var friend : friends) {
|
||||
var status = MiniMessage.miniMessage().deserialize(friend.isOnline()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue