Skip to content

Commit 722d06a

Browse files
committed
Begin improving party messages
1 parent 468e6af commit 722d06a

File tree

7 files changed

+134
-72
lines changed

7 files changed

+134
-72
lines changed

src/main/java/dev/emortal/velocity/party/commands/PartyCommand.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import dev.emortal.velocity.general.UsernameSuggestions;
1111
import dev.emortal.velocity.party.PartyCache;
1212
import dev.emortal.velocity.party.commands.subs.PartyDisbandSub;
13-
import dev.emortal.velocity.party.commands.subs.PartyInfoSub;
13+
import dev.emortal.velocity.party.commands.subs.PartyListSub;
1414
import dev.emortal.velocity.party.commands.subs.PartyInviteSub;
1515
import dev.emortal.velocity.party.commands.subs.PartyJoinSub;
1616
import dev.emortal.velocity.party.commands.subs.PartyKickSub;
@@ -25,12 +25,14 @@
2525
public class PartyCommand {
2626
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
2727

28+
public static final Component ERROR_MESSAGE = MINI_MESSAGE.deserialize("<red>An error occurred");
29+
2830
private static final Component HELP_MESSAGE = MINI_MESSAGE.deserialize("""
2931
<light_purple>------ Party Help ------
3032
/party invite <player>
3133
/party join <player>
3234
/party leave
33-
/party info
35+
/party list
3436
/party open
3537
3638
/party kick <player>
@@ -61,12 +63,12 @@ public class PartyCommand {
6163
private final PartyDisbandSub disbandSub = new PartyDisbandSub();
6264
private final PartyOpenSub openSub;
6365

64-
private final PartyInfoSub infoSub;
66+
private final PartyListSub listSub;
6567

6668
public PartyCommand(ProxyServer proxy, UsernameSuggestions usernameSuggestions, PartyCache partyCache) {
6769
this.usernameSuggestions = usernameSuggestions;
6870

69-
this.infoSub = new PartyInfoSub(partyCache);
71+
this.listSub = new PartyListSub(partyCache);
7072
this.openSub = new PartyOpenSub(partyCache);
7173

7274
proxy.getCommandManager().register(this.createCommand());
@@ -114,8 +116,7 @@ public BrigadierCommand createCommand() {
114116
)
115117
)
116118
.then(LiteralArgumentBuilder.<CommandSource>literal("open").executes(this.openSub::execute))
117-
.then(LiteralArgumentBuilder.<CommandSource>literal("list").executes(this.infoSub::execute))
118-
.then(LiteralArgumentBuilder.<CommandSource>literal("info").executes(this.infoSub::execute))
119+
.then(LiteralArgumentBuilder.<CommandSource>literal("list").executes(this.listSub::execute))
119120
.then(LiteralArgumentBuilder.<CommandSource>literal("disband").executes(this.disbandSub::execute))
120121
.then(LiteralArgumentBuilder.<CommandSource>literal("settings").executes(context -> {
121122
context.getSource().sendMessage(SETTINGS_HELP_MESSAGE);

src/main/java/dev/emortal/velocity/party/commands/subs/PartyDisbandSub.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,27 @@
1010
import dev.emortal.api.grpc.party.PartyServiceGrpc;
1111
import dev.emortal.api.utils.GrpcStubCollection;
1212
import dev.emortal.api.utils.callback.FunctionalFutureCallback;
13+
import dev.emortal.velocity.party.commands.PartyCommand;
1314
import io.grpc.protobuf.StatusProto;
15+
import net.kyori.adventure.text.Component;
1416
import net.kyori.adventure.text.minimessage.MiniMessage;
1517
import org.slf4j.Logger;
1618
import org.slf4j.LoggerFactory;
1719

1820
import java.util.concurrent.ForkJoinPool;
1921

2022
public class PartyDisbandSub {
21-
private static final Logger LOGGER = LoggerFactory.getLogger(PartyInfoSub.class);
23+
private static final Logger LOGGER = LoggerFactory.getLogger(PartyListSub.class);
2224
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
2325

26+
27+
private static final Component DISBANDED_MESSAGE = MINI_MESSAGE.deserialize("<green>Party disbanded</green>");
28+
private static final Component NOT_LEADER_MESSAGE = MINI_MESSAGE.deserialize("""
29+
<red>You are not the leader of the party
30+
<red>Use <underlined><click:run_command:'/party leave'>/party leave</click></underlined> to leave the party instead"""
31+
);
32+
33+
2434
private final PartyServiceGrpc.PartyServiceFutureStub partyService = GrpcStubCollection.getPartyService().orElse(null);
2535

2636
public int execute(CommandContext<CommandSource> context) {
@@ -33,31 +43,29 @@ public int execute(CommandContext<CommandSource> context) {
3343

3444
Futures.addCallback(disbandPartyFuture, FunctionalFutureCallback.create(
3545
response -> {
36-
executor.sendMessage(MINI_MESSAGE.deserialize("<hover:show_text:'<color:#9fff87>Note: disbanding a party only empties it</color>'><green>Party disbanded</green></hover>"));
46+
executor.sendMessage(DISBANDED_MESSAGE);
3747
},
3848
throwable -> {
3949
Status status = StatusProto.fromThrowable(throwable);
4050
if (status == null || status.getDetailsCount() == 0) {
4151
LOGGER.error("Failed to disband party", throwable);
42-
executor.sendMessage(MINI_MESSAGE.deserialize("<red>Failed to disband party"));
52+
executor.sendMessage(PartyCommand.ERROR_MESSAGE);
4353
return;
4454
}
4555

4656
try {
4757
PartyProto.EmptyPartyErrorResponse errorResponse = status.getDetails(0).unpack(PartyProto.EmptyPartyErrorResponse.class);
4858

4959
executor.sendMessage(switch (errorResponse.getErrorType()) {
50-
case NOT_LEADER -> MINI_MESSAGE.deserialize("""
51-
<red>You are not the leader of the party
52-
<red>Use /party leave to leave the party instead""");
60+
case NOT_LEADER -> NOT_LEADER_MESSAGE;
5361
default -> {
5462
LOGGER.error("Failed to disband party", throwable);
55-
yield MINI_MESSAGE.deserialize("<red>Failed to disband party");
63+
yield PartyCommand.ERROR_MESSAGE;
5664
}
5765
});
5866
} catch (InvalidProtocolBufferException e) {
5967
LOGGER.error("Failed to disband party", throwable);
60-
executor.sendMessage(MINI_MESSAGE.deserialize("<red>Failed to disband party"));
68+
executor.sendMessage(PartyCommand.ERROR_MESSAGE);
6169
}
6270
}
6371
), ForkJoinPool.commonPool());

src/main/java/dev/emortal/velocity/party/commands/subs/PartyInfoSub.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main/java/dev/emortal/velocity/party/commands/subs/PartyInviteSub.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import dev.emortal.api.utils.callback.FunctionalFutureCallback;
1212
import dev.emortal.api.utils.resolvers.PlayerResolver;
1313
import dev.emortal.velocity.lang.TempLang;
14+
import dev.emortal.velocity.party.commands.PartyCommand;
1415
import io.grpc.Status;
1516
import io.grpc.protobuf.StatusProto;
1617
import net.kyori.adventure.text.Component;
1718
import net.kyori.adventure.text.format.NamedTextColor;
19+
import net.kyori.adventure.text.minimessage.MiniMessage;
1820
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
1921
import org.slf4j.Logger;
2022
import org.slf4j.LoggerFactory;
@@ -23,6 +25,16 @@
2325

2426
public class PartyInviteSub {
2527
private static final Logger LOGGER = LoggerFactory.getLogger(PartyInviteSub.class);
28+
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
29+
30+
31+
private static final String INVITED_MESSAGE = "<green>Invited <username> to the party";
32+
private static final String NO_PERMISSION_MESSAGE = "<red>You must be the leader of the party to invite another player";
33+
private static final String ALREADY_INVITED_MESSAGE = "<red><username> has already been invited to your party";
34+
private static final String ALREADY_IN_PARTY_MESSAGE = "<red><username> is already in the party";
35+
private static final String ALREADY_IN_PARTY_OTHER_MESSAGE = "<red><username> is in another party";
36+
private static final String PARTY_IS_OPEN_MESSAGE = "<red>The party is open, anyone can join";
37+
2638

2739
private final PartyServiceGrpc.PartyServiceFutureStub partyService = GrpcStubCollection.getPartyService().orElse(null);
2840

@@ -46,36 +58,34 @@ public int execute(CommandContext<CommandSource> context) {
4658
);
4759

4860
Futures.addCallback(inviteResponseFuture, FunctionalFutureCallback.create(
49-
inviteResponse -> executor.sendMessage(Component.text("Invited " + target.username() + " to your party", NamedTextColor.GREEN)),
61+
inviteResponse -> executor.sendMessage(MINI_MESSAGE.deserialize(INVITED_MESSAGE, Placeholder.unparsed("username", target.username()))),
5062
throwable -> {
5163
com.google.rpc.Status status = StatusProto.fromThrowable(throwable);
5264
if (status == null || status.getDetailsCount() == 0) {
5365
LOGGER.error("An error occurred PartyInviteSub invitePlayerToParty: ", throwable);
54-
executor.sendMessage(Component.text("An error occurred inviting " + target.username(), NamedTextColor.RED));
66+
executor.sendMessage(PartyCommand.ERROR_MESSAGE);
5567
return;
5668
}
5769

5870
try {
5971
PartyProto.InvitePlayerErrorResponse errorResponse = status.getDetails(0).unpack(PartyProto.InvitePlayerErrorResponse.class);
6072

6173
executor.sendMessage(switch (errorResponse.getErrorType()) {
62-
case NO_PERMISSION ->
63-
Component.text("You must be the leader of the party to invite another player.", NamedTextColor.RED);
64-
case TARGET_ALREADY_INVITED ->
65-
Component.text(target.username() + " is already invited to your party.", NamedTextColor.RED);
66-
case TARGET_ALREADY_IN_SELF_PARTY ->
67-
Component.text(target.username() + " is already in your party.", NamedTextColor.RED);
68-
case TARGET_ALREADY_IN_ANOTHER_PARTY ->
69-
Component.text(target.username() + " is already in another party.", NamedTextColor.RED);
70-
case PARTY_IS_OPEN -> Component.text("Your party is open, anyone can join.", NamedTextColor.RED);
74+
case NO_PERMISSION -> MINI_MESSAGE.deserialize(NO_PERMISSION_MESSAGE);
75+
case TARGET_ALREADY_INVITED -> MINI_MESSAGE.deserialize(ALREADY_INVITED_MESSAGE, Placeholder.unparsed("username", target.username()));
76+
case TARGET_ALREADY_IN_SELF_PARTY -> MINI_MESSAGE.deserialize(ALREADY_IN_PARTY_MESSAGE, Placeholder.unparsed("username", target.username()));
77+
// TODO: Why is this an error?
78+
case TARGET_ALREADY_IN_ANOTHER_PARTY -> MINI_MESSAGE.deserialize(ALREADY_IN_PARTY_OTHER_MESSAGE, Placeholder.unparsed("username", target.username()));
79+
// TODO: This too.
80+
case PARTY_IS_OPEN -> MINI_MESSAGE.deserialize(PARTY_IS_OPEN_MESSAGE);
7181
default -> {
7282
LOGGER.error("An error occurred PartyInviteSub invitePlayerToParty: ", throwable);
73-
yield Component.text("An error occurred", NamedTextColor.RED);
83+
yield PartyCommand.ERROR_MESSAGE;
7484
}
7585
});
7686
} catch (InvalidProtocolBufferException e) {
7787
LOGGER.error("An error occurred PartyInviteSub invitePlayerToParty: ", throwable);
78-
executor.sendMessage(Component.text("An error occurred", NamedTextColor.RED));
88+
executor.sendMessage(PartyCommand.ERROR_MESSAGE);
7989
}
8090
}
8191
), ForkJoinPool.commonPool());
@@ -87,7 +97,7 @@ public int execute(CommandContext<CommandSource> context) {
8797
}
8898

8999
LOGGER.error("An error occurred PartyInviteSub getPlayerByUsername: ", status.asException());
90-
executor.sendMessage(Component.text("An error occurred", NamedTextColor.RED));
100+
executor.sendMessage(PartyCommand.ERROR_MESSAGE);
91101
}
92102
);
93103

src/main/java/dev/emortal/velocity/party/commands/subs/PartyJoinSub.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
import dev.emortal.api.utils.callback.FunctionalFutureCallback;
1313
import dev.emortal.api.utils.resolvers.PlayerResolver;
1414
import dev.emortal.velocity.lang.TempLang;
15+
import dev.emortal.velocity.party.commands.PartyCommand;
1516
import io.grpc.protobuf.StatusProto;
1617
import net.kyori.adventure.text.Component;
1718
import net.kyori.adventure.text.format.NamedTextColor;
19+
import net.kyori.adventure.text.minimessage.MiniMessage;
1820
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
1921
import org.slf4j.Logger;
2022
import org.slf4j.LoggerFactory;
@@ -23,6 +25,13 @@
2325

2426
public class PartyJoinSub {
2527
private static final Logger LOGGER = LoggerFactory.getLogger(PartyJoinSub.class);
28+
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
29+
30+
31+
private static final String PARTY_JOIN_MESSAGE = "<green>Joined <username>'s party";
32+
private static final Component NOT_INVITED_MESSAGE = MINI_MESSAGE.deserialize("<red>You were not invited to this party");
33+
private static final Component ALREADY_IN_PARTY_MESSAGE = MINI_MESSAGE.deserialize("<red>You are already in the party");
34+
2635

2736
private final PartyServiceGrpc.PartyServiceFutureStub partyService = GrpcStubCollection.getPartyService().orElse(null);
2837

@@ -45,31 +54,29 @@ public int execute(CommandContext<CommandSource> context) {
4554
);
4655

4756
Futures.addCallback(joinResponseFuture, FunctionalFutureCallback.create(
48-
joinResponse -> executor.sendMessage(Component.text("Joined " + target.username() + "'s party", NamedTextColor.GREEN)),
57+
joinResponse -> executor.sendMessage(MINI_MESSAGE.deserialize(PARTY_JOIN_MESSAGE, Placeholder.unparsed("username", target.username()))),
4958
throwable -> {
5059
Status status = StatusProto.fromThrowable(throwable);
5160
if (status == null || status.getDetailsCount() == 0) {
5261
LOGGER.error("An error occurred PartyJoinSub joinParty: ", throwable);
53-
executor.sendMessage(Component.text("An error occurred", NamedTextColor.RED));
62+
executor.sendMessage(PartyCommand.ERROR_MESSAGE);
5463
return;
5564
}
5665

5766
try {
5867
PartyProto.JoinPartyErrorResponse errorResponse = status.getDetails(0).unpack(PartyProto.JoinPartyErrorResponse.class);
5968

6069
executor.sendMessage(switch (errorResponse.getErrorType()) {
61-
case NOT_INVITED ->
62-
Component.text("You are not invited to this party", NamedTextColor.RED);
63-
case ALREADY_IN_PARTY ->
64-
Component.text("You are already in a party", NamedTextColor.RED);
70+
case NOT_INVITED -> NOT_INVITED_MESSAGE;
71+
case ALREADY_IN_PARTY -> ALREADY_IN_PARTY_MESSAGE;
6572
default -> {
6673
LOGGER.error("An error occurred PartyJoinSub joinParty: ", throwable);
67-
yield Component.text("An error occurred", NamedTextColor.RED);
74+
yield PartyCommand.ERROR_MESSAGE;
6875
}
6976
});
7077
} catch (InvalidProtocolBufferException e) {
7178
LOGGER.error("An error occurred PartyJoinSub joinParty: ", throwable);
72-
executor.sendMessage(Component.text("An error occurred", NamedTextColor.RED));
79+
executor.sendMessage(PartyCommand.ERROR_MESSAGE);
7380
}
7481
}
7582
), ForkJoinPool.commonPool());
@@ -81,7 +88,7 @@ public int execute(CommandContext<CommandSource> context) {
8188
}
8289

8390
LOGGER.error("An error occurred PartyJoinSub getPlayerByUsername: ", status.asException());
84-
executor.sendMessage(Component.text("An error occurred", NamedTextColor.RED));
91+
executor.sendMessage(PartyCommand.ERROR_MESSAGE);
8592
}
8693
);
8794
return 1;

0 commit comments

Comments
 (0)