mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Go to default channel when entering already-selected channel (#486)
* Go to default channel when entering already-selected channel * Manually index config versions again
This commit is contained in:
1 parent
fe6a79434d
commit
efab5f9c73
2 files changed
+23
-16
No files matched your search
@@ -379,7 +379,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
final Command<Commander> command = builder.senderType(Commander.class)
|
||||
.handler(handler -> {
|
||||
final Commander commander = handler.sender();
|
||||
final @Nullable ChatChannel chatChannel = this.channel(channelKey);
|
||||
@Nullable ChatChannel chatChannel = this.channel(channelKey);
|
||||
|
||||
if (!(commander instanceof PlayerCommander playerCommander)) {
|
||||
if (chatChannel != null && handler.contains("message")) {
|
||||
@@ -408,11 +408,15 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
// TODO: trigger platform events related to chat
|
||||
this.sendMessageInChannel(player, chatChannel, message);
|
||||
} else {
|
||||
if (this.config.primaryConfig().returnToDefaultChannel() && player.selectedChannel().key().equals(channelKey)) {
|
||||
chatChannel = this.defaultChannel();
|
||||
}
|
||||
|
||||
final ChannelSwitchEvent switchEvent = new ChannelSwitchEventImpl(player, chatChannel);
|
||||
this.eventHandler.emit(switchEvent);
|
||||
|
||||
player.selectedChannel(switchEvent.channel());
|
||||
this.carbonMessages.changedChannels(player, channelKey.value());
|
||||
this.carbonMessages.changedChannels(player, chatChannel.key().value());
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
@@ -47,6 +47,9 @@ public class PrimaryConfig {
|
||||
If the channel is not found or the player cannot use the channel, they will speak in basic non-channel chat.""")
|
||||
private Key defaultChannel = Key.key("carbon", "global");
|
||||
|
||||
@Comment("Returns you to the default channel when you use a channel's command while you have that channel active.")
|
||||
private boolean returnToDefaultChannel = false;
|
||||
|
||||
@Comment("""
|
||||
The service that will be used to store and load player information.
|
||||
One of: JSON, H2, MYSQL, PSQL
|
||||
@@ -114,6 +117,10 @@ public class PrimaryConfig {
|
||||
return this.defaultChannel;
|
||||
}
|
||||
|
||||
public boolean returnToDefaultChannel() {
|
||||
return this.returnToDefaultChannel;
|
||||
}
|
||||
|
||||
public StorageType storageType() {
|
||||
return this.storageType;
|
||||
}
|
||||
@@ -187,20 +194,10 @@ public class PrimaryConfig {
|
||||
final ConfigurationTransformation.VersionedBuilder builder = ConfigurationTransformation.versionedBuilder()
|
||||
.versionKey(ConfigManager.CONFIG_VERSION_KEY);
|
||||
|
||||
final ConfigurationTransformation initial = ConfigurationTransformation.builder()
|
||||
.addAction(NodePath.path("use-carbon-nicknames"), (path, value) -> new Object[]{"nickname-settings", "use-carbon-nicknames"})
|
||||
.build();
|
||||
builder.addVersion(0, initial);
|
||||
|
||||
final ConfigurationTransformation one = ConfigurationTransformation.builder()
|
||||
.addAction(NodePath.path("party-chat"), (path, value) -> new Object[]{"party-chat", "enabled"})
|
||||
.build();
|
||||
builder.addVersion(1, one);
|
||||
|
||||
final ConfigurationTransformation two = ConfigurationTransformation.builder()
|
||||
.addAction(NodePath.path("nickname-settings"), (path, value) -> new Object[]{"filter", ".*"})
|
||||
.build();
|
||||
builder.addVersion(2, two);
|
||||
builder.addVersion(0, insertAddition("use-carbon-nicknames", "nickname-settings", "use-carbon-nicknames"));
|
||||
builder.addVersion(1, insertAddition("party-chat", "party-chat", "enabled"));
|
||||
builder.addVersion(2, insertAddition("nickname-settings", "filter", ".*"));
|
||||
builder.addVersion(3, insertAddition("return-to-default-channel", "return-to-default-channel", false));
|
||||
|
||||
final ConfigurationTransformation.Versioned upgrader = builder.build();
|
||||
final int from = upgrader.version(node);
|
||||
@@ -213,6 +210,12 @@ public class PrimaryConfig {
|
||||
ConfigManager.configVersionComment(node, upgrader);
|
||||
}
|
||||
|
||||
private static ConfigurationTransformation insertAddition(final String path, final Object key, final Object value) {
|
||||
return ConfigurationTransformation.builder()
|
||||
.addAction(NodePath.path(path), ($, $$) -> new Object[]{key, value})
|
||||
.build();
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public static final class NicknameSettings {
|
||||
|
||||
|
||||
Reference in new issue
Block a user