Skip to content

Commit 6dfa18c

Browse files
authored
Implement chat message signing for 1.19.1+ (#5030)
**Known issue: this inadvertently reformats `/minecraft:tell`. There's not much we can do about this in 2.19.x.** This commit refactors EssentialsX Chat in order to support chat previews and signed chat messages in 1.19.1+.
1 parent a394760 commit 6dfa18c

12 files changed

Lines changed: 629 additions & 372 deletions

Essentials/src/main/java/net/ess3/api/events/LocalChatSpyEvent.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public void setMessage(final String message) {
5252
}
5353

5454
/**
55-
* Gets the format to use to display this chat message. When this event finishes execution, the first format
56-
* parameter is the {@link Player#getDisplayName()} and the second parameter is {@link #getMessage()}
55+
* Gets the format to use to display this chat message to spy recipients. When this event finishes execution, the
56+
* first format parameter is the {@link Player#getDisplayName()} and the second parameter is {@link #getMessage()}
5757
*
5858
* @return {@link String#format(String, Object...)} compatible format string
5959
*/
@@ -62,8 +62,8 @@ public String getFormat() {
6262
}
6363

6464
/**
65-
* Sets the format to use to display this chat message. When this event finishes execution, the first format
66-
* parameter is the {@link Player#getDisplayName()} and the second parameter is {@link #getMessage()}
65+
* Sets the format to use to display this chat message to spy recipients. When this event finishes execution, the
66+
* first format parameter is the {@link Player#getDisplayName()} and the second parameter is {@link #getMessage()}
6767
*
6868
* @param format {@link String#format(String, Object...)} compatible format string
6969
* @throws IllegalFormatException if the underlying API throws the exception

Essentials/src/main/resources/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ enderchestCommandUsage2=/<command> <player>
314314
enderchestCommandUsage2Description=Opens the ender chest of the target player
315315
errorCallingCommand=Error calling the command /{0}
316316
errorWithMessage=\u00a7cError\:\u00a74 {0}
317+
essChatNoSecureMsg=EssentialsX Chat version {0} does not support secure chat on this server software. Update EssentialsX, and if this issue persists, inform the developers.
317318
essentialsCommandDescription=Reloads essentials.
318319
essentialsCommandUsage=/<command>
319320
essentialsCommandUsage1=/<command> reload

EssentialsChat/src/main/java/com/earth2me/essentials/chat/ChatStore.java

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

EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package com.earth2me.essentials.chat;
22

3+
import com.earth2me.essentials.Essentials;
34
import com.earth2me.essentials.EssentialsLogger;
5+
import com.earth2me.essentials.chat.processing.LegacyChatHandler;
6+
import com.earth2me.essentials.chat.processing.SignedChatHandler;
47
import com.earth2me.essentials.metrics.MetricsWrapper;
58
import net.ess3.api.IEssentials;
69
import org.bukkit.command.Command;
710
import org.bukkit.command.CommandSender;
8-
import org.bukkit.event.player.AsyncPlayerChatEvent;
911
import org.bukkit.plugin.PluginManager;
1012
import org.bukkit.plugin.java.JavaPlugin;
1113

12-
import java.util.Collections;
13-
import java.util.HashMap;
14-
import java.util.Map;
1514
import java.util.logging.Level;
1615

1716
import static com.earth2me.essentials.I18n.tl;
@@ -33,14 +32,13 @@ public void onEnable() {
3332
return;
3433
}
3534

36-
final Map<AsyncPlayerChatEvent, ChatStore> chatStore = Collections.synchronizedMap(new HashMap<>());
37-
38-
final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, this, chatStore);
39-
final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, this, chatStore);
40-
final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, this, chatStore);
41-
pluginManager.registerEvents(playerListenerLowest, this);
42-
pluginManager.registerEvents(playerListenerNormal, this);
43-
pluginManager.registerEvents(playerListenerHighest, this);
35+
final SignedChatHandler signedHandler = new SignedChatHandler((Essentials) ess, this);
36+
if (signedHandler.tryRegisterListeners()) {
37+
getLogger().info("Secure signed chat and previews are enabled.");
38+
} else {
39+
final LegacyChatHandler legacyHandler = new LegacyChatHandler((Essentials) ess, this);
40+
legacyHandler.registerListeners();
41+
}
4442

4543
if (metrics == null) {
4644
metrics = new MetricsWrapper(this, 3814, false);

EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java

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

EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java

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

EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java

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

0 commit comments

Comments
 (0)