Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement chat changes #1172

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
4550b47
1.19
TheMode Mar 16, 2022
2617257
Fix system message
TheMode Jun 9, 2022
19871ec
Copy chat registry from vanilla
TheMode Jun 9, 2022
3bef4f8
Listener for ClientCommandChatPacket
TheMode Jun 9, 2022
ede16bd
Add ClientChatPreviewPacket
TheMode Jun 9, 2022
9ebcfe6
Add ServerDataPacket
TheMode Jun 9, 2022
bf602b5
Fix ClientChatPreviewPacket
TheMode Jun 9, 2022
d919fac
Register temporary metadata for 1.19 entities
TheMode Jun 9, 2022
4440f39
Fix PlayerChatMessagePacket
Kebab11noel Jun 10, 2022
cb679b5
use raw type id instead of ChatPosition
TheMode Jun 10, 2022
2d38bef
Fix test compile
TheMode Jun 10, 2022
a282c9f
Implement PlayerPublicKey parsing and verification
Kebab11noel Jun 10, 2022
d626eb0
Inline expiration check
Kebab11noel Jun 10, 2022
cb5b9d4
Simplify validator names
Kebab11noel Jun 10, 2022
8424679
Distribute public keys
Kebab11noel Jun 10, 2022
c4b5a20
Add convenience methods
Kebab11noel Jun 10, 2022
6b489b5
Signature forwarding works
Kebab11noel Jun 10, 2022
960d5c8
Update convenience methods
Kebab11noel Jun 10, 2022
11ba78a
Implement chat preview toggling and event
Kebab11noel Jun 10, 2022
4ee6985
Add signature to chat event
Kebab11noel Jun 10, 2022
ab84bd6
Implement Component signature verification
Kebab11noel Jun 10, 2022
d0a7f45
Move preview listener into ChatMessageListener
Kebab11noel Jun 10, 2022
533bb49
Chat handling done
Kebab11noel Jun 10, 2022
192b6de
Cleanup
Kebab11noel Jun 10, 2022
b0e0da0
New line
Kebab11noel Jun 11, 2022
24c3fbf
Document SignatureValidator
Kebab11noel Jun 11, 2022
74ceb81
Add chat preview command
Kebab11noel Jun 12, 2022
29c5d1d
Correct name
Kebab11noel Jun 12, 2022
fa9ab30
Move uuid into MessageSignature from MessageSender
Kebab11noel Jun 12, 2022
f81b310
Rename constructor param
Kebab11noel Jun 12, 2022
0a68dac
Add util methods
Kebab11noel Jun 12, 2022
e770509
Move signatures to different record to be used in command context
Kebab11noel Jun 12, 2022
4a04d16
Command argument signing, TODO: Check where is it necessary to pass t…
Kebab11noel Jun 12, 2022
c3960e6
Better debug commands
Kebab11noel Jun 17, 2022
7c33dd9
Initial chat registry
Kebab11noel Jun 18, 2022
77b5df0
Finish chat registry descriptor objects
Kebab11noel Jun 18, 2022
d2ccf82
Add translation key matching
Kebab11noel Jun 18, 2022
c9b2c01
Create ObjectCache
Kebab11noel Jun 18, 2022
9b6c277
Add name based lookup and register defaults
Kebab11noel Jun 18, 2022
4c5731e
Deprecate ChatPosition, extend Messenger, add CommonChatType, rename …
Kebab11noel Jun 18, 2022
cd23975
Use nullable methods
Kebab11noel Jun 18, 2022
e2b2401
Fix annotations
Kebab11noel Jun 18, 2022
f9eb273
Cleanup CommandSignTest
Kebab11noel Jun 18, 2022
5d1e3e8
Deprecate Player#chat
Kebab11noel Jun 19, 2022
3923277
Update getter name
Kebab11noel Jun 19, 2022
2a48916
Use else get
Kebab11noel Jun 19, 2022
4c90af5
Use else get
Kebab11noel Jun 19, 2022
6145a9f
Use nullable writer
Kebab11noel Jun 19, 2022
45d1d19
Fix type
Kebab11noel Jun 19, 2022
5175384
Fix preview
Kebab11noel Jun 19, 2022
418edc0
Fix ArgumentMessage
Kebab11noel Jun 19, 2022
7fe4334
Use interface for ChatType, and register using nbt
Kebab11noel Jun 19, 2022
47f28a3
Clear preview on command
Kebab11noel Jun 19, 2022
ecff687
Cleanup command changes, fix caching issue
Kebab11noel Jun 19, 2022
0cfdde0
Cleanup, minor changes
Kebab11noel Jun 19, 2022
87dda18
Improve isSet logic, add utils
Kebab11noel Jun 19, 2022
61cd9d1
Implement config manager
Kebab11noel Jun 19, 2022
1127a98
Fix tests
Kebab11noel Jun 19, 2022
908d39e
Move chat types to config
Kebab11noel Jun 19, 2022
aa8b798
Remove CommonChatType.java
Kebab11noel Jun 20, 2022
4050265
Rework registry
Kebab11noel Jun 20, 2022
8fd6644
Improve registry design
Kebab11noel Jun 20, 2022
6f36d24
Address styling issues
Kebab11noel Jun 20, 2022
ea3936b
Rework config
Kebab11noel Jun 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions demo/src/main/java/net/minestom/demo/Main.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package net.minestom.demo;

import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.minestom.demo.commands.*;
import net.minestom.server.ConfigurationManager;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandManager;
import net.minestom.server.event.player.PlayerChatEvent;
import net.minestom.server.event.server.ServerListPingEvent;
import net.minestom.server.extras.lan.OpenToLAN;
import net.minestom.server.extras.lan.OpenToLANConfig;
import net.minestom.server.extras.optifine.OptifineSupport;
import net.minestom.server.instance.block.BlockManager;
import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule;
import net.minestom.server.message.MessageSender;
import net.minestom.server.ping.ResponseData;
import net.minestom.server.registry.dynamic.chat.ChatDecoration;
import net.minestom.server.registry.dynamic.chat.ChatType;
import net.minestom.server.registry.dynamic.chat.ChatTypeBuilder;
import net.minestom.server.utils.identity.NamedAndIdentified;
import net.minestom.server.utils.time.TimeUnit;

Expand Down Expand Up @@ -52,6 +60,8 @@ public static void main(String[] args) {
commandManager.register(new AutoViewCommand());
commandManager.register(new SaveCommand());
commandManager.register(new GamemodeCommand());
commandManager.register(new CommandSignTest());
commandManager.register(new ChatPreviewCommand());


commandManager.setUnknownCommandCallback((sender, command) -> sender.sendMessage(Component.text("Unknown command", NamedTextColor.RED)));
Expand Down Expand Up @@ -92,8 +102,21 @@ public static void main(String[] args) {
// on legacy versions, colors will be converted to the section format so it'll work there too
responseData.setDescription(Component.text("This is a Minestom Server", TextColor.color(0x66b3ff)));
//responseData.setPlayersHidden(true);
}).addListener(PlayerChatEvent.class, e -> {
final MessageSender s = e.getSender();
e.setSender(new MessageSender(
s.displayName().clickEvent(ClickEvent.suggestCommand("/msg "+e.getPlayer().getUsername())).color(NamedTextColor.DARK_GREEN),
Component.text("Team Name").color(NamedTextColor.GOLD)
));
});

final ConfigurationManager conf = MinecraftServer.getConfigurationManager();
// conf.PLAYER_CHAT_TYPE.set(ChatTypeBuilder.builder(ChatType.CHAT.key())
// .chat(ChatDecoration.full("%s | %s> %s", Style.style(NamedTextColor.DARK_RED))));
conf.SYSTEM_CHAT_TYPE.set(ChatTypeBuilder.builder(ChatType.SYSTEM.key())
.chat(ChatDecoration.content("SYSTEM: %s", Style.style(NamedTextColor.AQUA)
.font(Key.key("minecraft:uniform")))));

PlayerInit.init();

OptifineSupport.enable();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package net.minestom.demo.commands;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.arguments.ArgumentBoolean;
import net.minestom.server.command.builder.arguments.ArgumentEnum;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerChatPreviewEvent;

import java.util.function.Consumer;

public class ChatPreviewCommand extends Command {
private static final ArgumentBoolean on = ArgumentType.Boolean("on");
private static final ArgumentEnum<PreviewHandler> handlerArg = ArgumentType.Enum("handler", PreviewHandler.class);
private static PreviewHandler handler = PreviewHandler.NULL;

private enum PreviewHandler {
BLACK(e -> e.setResult(Component.text(e.getQuery(), NamedTextColor.BLACK))),
//TODO Better name?
ENCLOSE(e -> e.setResult(Component.empty()
.append(Component.text("PREPEND>", TextColor.color(255,0,255)))
.append(Component.text(e.getQuery()))
.append(Component.text("<APPEND", TextColor.color(255,0,255))))),
NULL(e -> e.setResult(null));

private final Consumer<PlayerChatPreviewEvent> eventConsumer;

PreviewHandler(Consumer<PlayerChatPreviewEvent> eventConsumer) {
this.eventConsumer = eventConsumer;
}
}

public ChatPreviewCommand() {
super("preview");

MinecraftServer.getGlobalEventHandler().addListener(PlayerChatPreviewEvent.class, e -> handler.eventConsumer.accept(e));

addSyntax(((sender, context) -> {
if (sender instanceof Player player) {
final Boolean enable = context.get(on);
player.enableChatPreview(enable);
player.sendMessage("Chat preview: " + (enable ? "enabled" : "disabled"));
}
}), ArgumentType.Literal("enable"), on);

addSyntax(((sender, context) -> {
handler = context.getOrDefault(handlerArg, PreviewHandler.NULL);
sender.sendMessage("Preview handler set to: " + handler.name());
}), ArgumentType.Literal("handler"), handlerArg);


addSyntax(((sender, context) -> {
if (sender instanceof Player player) {
final Boolean enable = context.get(on);
player.toggleChatPreview(enable);
player.sendMessage("Chat preview: " + (enable ? "on" : "off"));
}
}), ArgumentType.Literal("toggle"), on);
}
}
55 changes: 55 additions & 0 deletions demo/src/main/java/net/minestom/demo/commands/CommandSignTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package net.minestom.demo.commands;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.command.ArgumentsSignature;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentMessage;
import net.minestom.server.crypto.MessageSignature;
import net.minestom.server.crypto.SignatureValidator;
import net.minestom.server.entity.Player;
import net.minestom.server.message.Messenger;

import java.util.List;

public class CommandSignTest extends Command {
private static final ArgumentMessage message = ArgumentType.Message("message");

public CommandSignTest() {
super("sign");

addSyntax(((sender, context) -> {
if (sender instanceof Player player) {
final ArgumentsSignature argumentsSignature = context.getSignature();
if (argumentsSignature == null) {
Messenger.sendSystemMessage(List.of(player), Component.text("You didn't sign the arguments!", NamedTextColor.RED));
return;
}
final MessageSignature signature = argumentsSignature.signatureOf(message, player.getUuid());
final SignatureValidator validator = SignatureValidator.from(player);
if (validator == null) {
Messenger.sendSystemMessage(List.of(player), Component.text("There is no public key associated with your profile!", NamedTextColor.RED));
return;
}
Messenger.sendSystemMessage(List.of(player),
Component.text("Signature details: preview: ")
.append(formatBoolean(argumentsSignature.signedPreview()))
.append(Component.text(", argument_signature: "))
.append(format(SignatureValidator.validate(validator, signature, Component.text(context.get(message)))))
.append(Component.text(", preview_signature: "))
.append(format(SignatureValidator.validate(validator, signature, player.getLastPreviewedMessage()))));
} else {
sender.sendMessage("Consoles luckily doesn't sign commands...");
}
}), message);
}

private static Component format(boolean valid) {
return valid ? Component.text("valid", NamedTextColor.GREEN) : Component.text("invalid", NamedTextColor.RED);
}

private static Component formatBoolean(boolean value) {
return value ? Component.text("true", NamedTextColor.GREEN) : Component.text("false", NamedTextColor.RED);
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ adventure = "4.10.1"
kotlin = "1.6.20"
hydrazine = "1.7.2"
dependencyGetter = "v1.0.1"
minestomData = "3e211f3953"
minestomData = "adbb835d9c"
hephaistos = "2.4.4"
jetbrainsAnnotations = "23.0.0"

Expand Down
10 changes: 10 additions & 0 deletions src/autogenerated/java/net/minestom/server/entity/EntityTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
@SuppressWarnings("unused")
interface EntityTypes {
EntityType ALLAY = EntityTypeImpl.get("minecraft:allay");

EntityType AREA_EFFECT_CLOUD = EntityTypeImpl.get("minecraft:area_effect_cloud");

EntityType ARMOR_STAND = EntityTypeImpl.get("minecraft:armor_stand");
Expand All @@ -21,6 +23,8 @@ interface EntityTypes {

EntityType BOAT = EntityTypeImpl.get("minecraft:boat");

EntityType CHEST_BOAT = EntityTypeImpl.get("minecraft:chest_boat");

EntityType CAT = EntityTypeImpl.get("minecraft:cat");

EntityType CAVE_SPIDER = EntityTypeImpl.get("minecraft:cave_spider");
Expand Down Expand Up @@ -65,6 +69,8 @@ interface EntityTypes {

EntityType FOX = EntityTypeImpl.get("minecraft:fox");

EntityType FROG = EntityTypeImpl.get("minecraft:frog");

EntityType GHAST = EntityTypeImpl.get("minecraft:ghast");

EntityType GIANT = EntityTypeImpl.get("minecraft:giant");
Expand Down Expand Up @@ -183,6 +189,8 @@ interface EntityTypes {

EntityType STRIDER = EntityTypeImpl.get("minecraft:strider");

EntityType TADPOLE = EntityTypeImpl.get("minecraft:tadpole");

EntityType EGG = EntityTypeImpl.get("minecraft:egg");

EntityType ENDER_PEARL = EntityTypeImpl.get("minecraft:ender_pearl");
Expand All @@ -207,6 +215,8 @@ interface EntityTypes {

EntityType WANDERING_TRADER = EntityTypeImpl.get("minecraft:wandering_trader");

EntityType WARDEN = EntityTypeImpl.get("minecraft:warden");

EntityType WITCH = EntityTypeImpl.get("minecraft:witch");

EntityType WITHER = EntityTypeImpl.get("minecraft:wither");
Expand Down