Skip to content

Commit db3983b

Browse files
committed
feat: update chat messages and add kick message when on version below 1.21.11
1 parent cb8e3a6 commit db3983b

6 files changed

Lines changed: 43 additions & 24 deletions

File tree

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
java
3-
id("com.gradleup.shadow") version "9.0.0-beta15"
3+
id("com.gradleup.shadow") version "9.3.1"
44
jacoco
55
}
66

@@ -22,7 +22,7 @@ dependencies {
2222
// Metrics
2323
implementation("io.pyroscope:agent:0.12.0")
2424

25-
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
25+
compileOnly("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
2626
compileOnly("com.velocitypowered:velocity-proxy:3.2.0-SNAPSHOT")
2727
compileOnly("com.viaversion:viaversion-api:4.9.2")
2828
annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/dev/emortal/velocity/lang/ChatMessages.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ public interface ChatMessages {
4040
4141
Please consider using a more capable client, such as Fabric""");
4242

43-
Args0 SENDING_TO_LOBBY = () -> green("Sending you to the lobby...");
4443
Args0 ERROR_SENDING_TO_LOBBY = () -> red("Something went wrong while sending you to the lobby!");
4544
Args0 ERROR_CONNECTING_TO_LOBBY = () -> red("Failed to connect to lobby");
4645
Args0 ERROR_CONNECTING_TO_FALLBACK_LOBBY = () -> red("Failed to connect to fallback lobby");
4746

48-
Args1<String> SENDING_TO_SERVER = serverName -> Component.text()
49-
.append(green("Sending you to "))
50-
.append(Component.text(serverName, NamedTextColor.GOLD).clickEvent(ClickEvent.copyToClipboard(serverName)))
51-
.append(green("..."))
52-
.build();
47+
Args1<String> SENDING_TO_SERVER = serverName -> Component.text("Joining " + serverName, NamedTextColor.GRAY)
48+
.clickEvent(ClickEvent.copyToClipboard(serverName));
5349

5450
// Command responses
5551
Args0 YOU_CLOSED_PARTY = () -> green("The party is now closed");
@@ -405,12 +401,25 @@ public interface ChatMessages {
405401
.append(green("Revoked your friend request to "))
406402
.append(MessageColors.purpleName(target))
407403
.build();
408-
Args2<Integer, Integer> FRIEND_LIST_HEADER = (currentPage, maxPage) -> Component.text()
409-
.append(Component.text(" ", NamedTextColor.LIGHT_PURPLE, TextDecoration.STRIKETHROUGH))
410-
.append(Component.text(" ꜰʀɪᴇɴᴅѕ ", NamedTextColor.LIGHT_PURPLE, TextDecoration.BOLD))
411-
.append(Component.text("(" + currentPage + "/" + maxPage + ") "))
412-
.append(Component.text(" ", NamedTextColor.LIGHT_PURPLE, TextDecoration.STRIKETHROUGH))
413-
.build();
404+
Args3<Integer, Integer, Component> FRIEND_LIST = (page, totalPages, members) -> {
405+
Component beforeAndAfterHeader = Component.text(" ", NamedTextColor.LIGHT_PURPLE, TextDecoration.STRIKETHROUGH);
406+
Component header = Component.text()
407+
.append(beforeAndAfterHeader)
408+
.append(Component.text(" ꜰʀɪᴇɴᴅѕ ", NamedTextColor.LIGHT_PURPLE, TextDecoration.BOLD))
409+
.append(Component.text("(" + page + "/" + totalPages + ") ", NamedTextColor.LIGHT_PURPLE))
410+
.append(beforeAndAfterHeader)
411+
.build();
412+
Component footer = Component.text(" ", NamedTextColor.LIGHT_PURPLE, TextDecoration.STRIKETHROUGH);
413+
return Component.text()
414+
.append(header)
415+
.appendNewline()
416+
.appendNewline()
417+
.append(members)
418+
.appendNewline()
419+
.appendNewline()
420+
.append(footer)
421+
.build();
422+
};
414423
Args2<String, String> FRIEND_LIST_ONLINE_LINE = (friend, activity) ->
415424
Component.text(friend + " - " + activity, NamedTextColor.GREEN).clickEvent(ClickEvent.suggestCommand("/message " + friend + " "));
416425
Args2<String, String> FRIEND_LIST_OFFLINE_LINE = (friend, lastOnline) -> red(friend + " - Last online " + lastOnline);

src/main/java/dev/emortal/velocity/matchmaking/commands/LobbyCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public void execute(@NotNull CommandSource source, @NotNull ArgumentProvider arg
3131

3232
try {
3333
this.matchmaker.sendPlayerToLobby(sender.getUniqueId(), false);
34-
ChatMessages.SENDING_TO_LOBBY.send(sender);
3534
} catch (StatusRuntimeException exception) {
3635
LOGGER.error("Failed to send '{}' to lobby", sender.getUsername(), exception);
3736
ChatMessages.ERROR_SENDING_TO_LOBBY.send(sender);

src/main/java/dev/emortal/velocity/player/listener/PlayerJoinQuitListener.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package dev.emortal.velocity.player.listener;
22

3+
import com.velocitypowered.api.event.ResultedEvent;
34
import com.velocitypowered.api.event.Subscribe;
45
import com.velocitypowered.api.event.connection.DisconnectEvent;
6+
import com.velocitypowered.api.event.connection.LoginEvent;
57
import com.velocitypowered.api.event.connection.PostLoginEvent;
8+
import com.velocitypowered.api.network.ProtocolVersion;
69
import dev.emortal.velocity.lang.ChatMessages;
710
import net.kyori.adventure.audience.Audience;
811
import net.kyori.adventure.key.Key;
912
import net.kyori.adventure.sound.Sound;
13+
import net.kyori.adventure.text.Component;
1014
import org.jetbrains.annotations.NotNull;
1115

1216
public final class PlayerJoinQuitListener {
@@ -18,6 +22,16 @@ public PlayerJoinQuitListener(@NotNull Audience audience) {
1822
this.audience = audience;
1923
}
2024

25+
@Subscribe
26+
public void onLogin(LoginEvent event) {
27+
if (event.getPlayer().getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_21_11)) {
28+
event.setResult(ResultedEvent.ComponentResult.denied(
29+
Component.text("EmortalMC requires Minecraft version 1.21.11")
30+
));
31+
}
32+
33+
}
34+
2135
@Subscribe
2236
public void onJoin(@NotNull PostLoginEvent event) {
2337
ChatMessages.JOIN.send(this.audience, event.getPlayer().getUsername());

src/main/java/dev/emortal/velocity/relationships/commands/friend/FriendListSub.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@ public void execute(@NotNull CommandSource source, @NotNull ArgumentProvider arg
6868
.skip((page - 1) * 8L)
6969
.limit(8)
7070
.toList();
71-
player.sendMessage(this.createMessage(pageFriends, page, maxPage));
71+
ChatMessages.FRIEND_LIST.send(player, page, maxPage, this.createMessageContent(pageFriends));
7272
}
7373

74-
private @NotNull Component createMessage(@NotNull List<FriendStatus> statuses, int page, int maxPage) {
75-
TextComponent.Builder message = Component.text()
76-
.append(ChatMessages.FRIEND_LIST_HEADER.get(page, maxPage))
77-
.appendNewline();
74+
private @NotNull Component createMessageContent(@NotNull List<FriendStatus> statuses) {
75+
TextComponent.Builder result = Component.text();
7876

7977
for (FriendStatus status : statuses) {
8078
ChatMessages.Args2<String, String> line = status.online() ? ChatMessages.FRIEND_LIST_ONLINE_LINE : ChatMessages.FRIEND_LIST_OFFLINE_LINE;
@@ -86,11 +84,10 @@ public void execute(@NotNull CommandSource source, @NotNull ArgumentProvider arg
8684
secondArgument = DurationFormatter.formatShortFromInstant(status.lastSeen());
8785
}
8886

89-
message.append(line.get(status.username(), secondArgument)).appendNewline();
87+
result.append(line.get(status.username(), secondArgument)).appendNewline();
9088
}
9189

92-
message.append(MESSAGE_FOOTER);
93-
return message.build();
90+
return result.build();
9491
}
9592

9693
private @NotNull List<FriendStatus> retrieveStatuses(@NotNull List<FriendCache.CachedFriend> friends) {

0 commit comments

Comments
 (0)