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 1 commit
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
15 changes: 6 additions & 9 deletions demo/src/main/java/net/minestom/demo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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.Configuration;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandManager;
import net.minestom.server.event.player.PlayerChatEvent;
Expand All @@ -31,7 +31,11 @@
public class Main {

public static void main(String[] args) {
MinecraftServer minecraftServer = MinecraftServer.init();
MinecraftServer minecraftServer = MinecraftServer.init(Configuration.builder()
.setSystemChatType(ChatTypeBuilder.builder(ChatType.SYSTEM.key())
.chat(ChatDecoration.content("SYSTEM: %s", Style.style(NamedTextColor.AQUA)
.font(Key.key("minecraft:uniform")))))
.build());

BlockManager blockManager = MinecraftServer.getBlockManager();

Expand Down Expand Up @@ -110,13 +114,6 @@ public static void main(String[] args) {
));
});

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
53 changes: 53 additions & 0 deletions src/main/java/net/minestom/server/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.minestom.server;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.registry.dynamic.chat.ChatDecoration;
import net.minestom.server.registry.dynamic.chat.ChatType;
import net.minestom.server.registry.dynamic.chat.ChatTypeBuilder;

public record Configuration(boolean requireValidPlayerPublicKey, Component missingPlayerPublicKeyMessage,
Component invalidPlayerPublicKeyMessage, ChatTypeBuilder playerChatType,
ChatTypeBuilder systemChatType) {

public static Builder builder() {
return new Builder();
}

public static class Builder {
private boolean requireValidPlayerPublicKey = false;
private Component missingPlayerPublicKeyMessage = Component.text("Missing public key!", NamedTextColor.RED);
private Component invalidPlayerPublicKeyMessage = Component.text("Invalid public key!", NamedTextColor.RED);
private ChatTypeBuilder playerChatType = ChatTypeBuilder.builder(ChatType.CHAT.key()).chat(ChatDecoration.contentWithSender("chat.type.text"));
private ChatTypeBuilder systemChatType = ChatTypeBuilder.builder(ChatType.SYSTEM.key()).chat();

public Builder setRequireValidPlayerPublicKey(boolean requireValidPlayerPublicKey) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't most of the other builders in Minestom omit the set prefix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change that, and this config change will be made in master first

this.requireValidPlayerPublicKey = requireValidPlayerPublicKey;
return this;
}

public Builder setMissingPlayerPublicKeyMessage(Component missingPlayerPublicKeyMessage) {
this.missingPlayerPublicKeyMessage = missingPlayerPublicKeyMessage;
return this;
}

public Builder setInvalidPlayerPublicKeyMessage(Component invalidPlayerPublicKeyMessage) {
this.invalidPlayerPublicKeyMessage = invalidPlayerPublicKeyMessage;
return this;
}

public Builder setPlayerChatType(ChatTypeBuilder playerChatType) {
this.playerChatType = playerChatType;
return this;
}

public Builder setSystemChatType(ChatTypeBuilder systemChatType) {
this.systemChatType = systemChatType;
return this;
}

public Configuration build() {
return new Configuration(requireValidPlayerPublicKey, missingPlayerPublicKeyMessage, invalidPlayerPublicKeyMessage, playerChatType, systemChatType);
}
}
}
30 changes: 0 additions & 30 deletions src/main/java/net/minestom/server/ConfigurationManager.java

This file was deleted.

16 changes: 10 additions & 6 deletions src/main/java/net/minestom/server/MinecraftServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ public final class MinecraftServer {
private static Difficulty difficulty = Difficulty.NORMAL;

public static MinecraftServer init() {
updateProcess();
return init(Configuration.builder().build());
}

public static MinecraftServer init(Configuration configuration) {
updateProcess(configuration);
return new MinecraftServer();
}

@ApiStatus.Internal
public static ServerProcess updateProcess() {
public static ServerProcess updateProcess(Configuration configuration) {
ServerProcess process;
try {
process = new ServerProcessImpl();
process = new ServerProcessImpl(configuration);
serverProcess = process;
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -191,7 +195,7 @@ public static DynamicRegistryManager getDynamicRegistryManager() {
return serverProcess.dynamicRegistry();
}

public static ConfigurationManager getConfigurationManager() {
public static Configuration getConfiguration() {
return serverProcess.configuration();
}

Expand Down Expand Up @@ -328,12 +332,12 @@ public static Server getServer() {
* @param address the server address
* @throws IllegalStateException if called before {@link #init()} or if the server is already running
*/
public void start(@NotNull SocketAddress address) {
public static void start(@NotNull SocketAddress address) {
serverProcess.start(address);
new TickSchedulerThread(serverProcess).start();
}

public void start(@NotNull String address, int port) {
public static void start(@NotNull String address, int port) {
start(new InetSocketAddress(address, port));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/minestom/server/ServerProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public interface ServerProcess extends Snapshotable {

@NotNull DynamicRegistryManager dynamicRegistry();

@NotNull ConfigurationManager configuration();
@NotNull Configuration configuration();

void start(@NotNull SocketAddress socketAddress);

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/net/minestom/server/ServerProcessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ final class ServerProcessImpl implements ServerProcess {
private final ThreadDispatcher<Chunk> dispatcher;
private final Ticker ticker;
private final DynamicRegistryManager dynamicRegistry;
private final ConfigurationManager configurationManager;
private final Configuration configuration;

private final AtomicBoolean started = new AtomicBoolean();
private final AtomicBoolean stopped = new AtomicBoolean();

public ServerProcessImpl() throws IOException {
public ServerProcessImpl(Configuration configuration) throws IOException {
this.configuration = configuration;
this.exception = new ExceptionManager();
this.extension = new ExtensionManager(this);
this.connection = new ConnectionManager();
Expand All @@ -99,7 +100,6 @@ public ServerProcessImpl() throws IOException {
this.dispatcher = ThreadDispatcher.singleThread();
this.ticker = new TickerImpl();
this.dynamicRegistry = new DynamicRegistryManager();
this.configurationManager = new ConfigurationManager();
}

@Override
Expand Down Expand Up @@ -213,8 +213,8 @@ public ServerProcessImpl() throws IOException {
}

@Override
public @NotNull ConfigurationManager configuration() {
return configurationManager;
public @NotNull Configuration configuration() {
return configuration;
}

@Override
Expand All @@ -223,8 +223,6 @@ public void start(@NotNull SocketAddress socketAddress) {
throw new IllegalStateException("Server already started");
}

configurationManager.initDefaults();

extension.start();
extension.gotoPreInit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.ConfigurationManager;
import net.minestom.server.Configuration;
import net.minestom.server.MinecraftServer;
import net.minestom.server.crypto.PlayerPublicKey;
import net.minestom.server.entity.Player;
Expand Down Expand Up @@ -35,16 +35,16 @@ public LoginStartPacket(BinaryReader reader) {
@Override
public void process(@NotNull PlayerConnection connection) {
connection.setPlayerPublicKey(publicKey);
final ConfigurationManager config = MinecraftServer.getConfigurationManager();
final Configuration config = MinecraftServer.getConfiguration();

if (config.REQUIRE_VALID_PLAYER_PUBLIC_KEY.get()) {
if (config.requireValidPlayerPublicKey()) {
if (publicKey != null) {
if (!publicKey.isValid()) {
connection.sendPacket(new LoginDisconnectPacket(config.INVALID_PLAYER_PUBLIC_KEY.get()));
connection.sendPacket(new LoginDisconnectPacket(config.invalidPlayerPublicKeyMessage()));
connection.disconnect();
}
} else {
connection.sendPacket(new LoginDisconnectPacket(config.MISSING_PLAYER_PUBLIC_KEY.get()));
connection.sendPacket(new LoginDisconnectPacket(config.missingPlayerPublicKeyMessage()));
connection.disconnect();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.minestom.server.registry.dynamic;

import net.kyori.adventure.key.Key;
import net.minestom.server.ConfigurationManager;
import net.minestom.server.Configuration;
import net.minestom.server.MinecraftServer;
import net.minestom.server.registry.NBTRepresentable;
import net.minestom.server.registry.dynamic.chat.ChatType;
Expand Down Expand Up @@ -79,8 +79,8 @@ public NBTCompound toNBT() {

@ApiStatus.Internal
public void initDefaults() {
final ConfigurationManager config = MinecraftServer.getConfigurationManager();
((DynamicChatTypeImpl) ChatType.CHAT).setBackingType(register(config.PLAYER_CHAT_TYPE.get()));
((DynamicChatTypeImpl) ChatType.SYSTEM).setBackingType(register(config.SYSTEM_CHAT_TYPE.get()));
final Configuration config = MinecraftServer.getConfiguration();
((DynamicChatTypeImpl) ChatType.CHAT).setBackingType(register(config.playerChatType()));
((DynamicChatTypeImpl) ChatType.SYSTEM).setBackingType(register(config.systemChatType()));
}
}
4 changes: 2 additions & 2 deletions src/test/java/net/minestom/server/ServerProcessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class ServerProcessTest {
@Test
public void init() {
AtomicReference<ServerProcess> process = new AtomicReference<>();
assertDoesNotThrow(() -> process.set(MinecraftServer.updateProcess()));
assertDoesNotThrow(() -> process.set(MinecraftServer.updateProcess(Configuration.builder().build())));
assertDoesNotThrow(() -> process.get().start(new InetSocketAddress("localhost", 25565)));
assertThrows(Exception.class, () -> process.get().start(new InetSocketAddress("localhost", 25566)));
assertDoesNotThrow(() -> process.get().stop());
}

@Test
public void tick() {
var process = MinecraftServer.updateProcess();
var process = MinecraftServer.updateProcess(Configuration.builder().build());
process.start(new InetSocketAddress("localhost", 25565));
var ticker = process.ticker();
assertDoesNotThrow(() -> ticker.tick(System.currentTimeMillis()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.minestom.server.api;

import net.minestom.server.Configuration;
import net.minestom.server.MinecraftServer;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
Expand All @@ -10,6 +11,6 @@ final class EnvParameterResolver extends TypeBasedParameterResolver<Env> {
@Override
public Env resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
return new EnvImpl(MinecraftServer.updateProcess());
return new EnvImpl(MinecraftServer.updateProcess(Configuration.builder().build()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.minestom.server.event;

import net.minestom.server.Configuration;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void map() {

@Test
public void entityLocal() {
var process = MinecraftServer.updateProcess();
var process = MinecraftServer.updateProcess(Configuration.builder().build());
var node = process.eventHandler();
var entity = new Entity(EntityType.ZOMBIE);

Expand Down