Skip to content

Commit

Permalink
fix(channel): channel name 'Unknown' after reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Feb 25, 2022
1 parent b6ca58f commit d69546f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
22 changes: 0 additions & 22 deletions bukkit/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,6 @@ channels:
# You can use the full power of MiniMessage (see above) and PlaceholderAPI placeholders.
#
message_format: "<yellow><hover:show_text:'<gray>Click to send <yellow><source.diplay_name></yellow> a message.\n<gray>Since: <aqua>%player_first_played_formatted%'><click:run_command:'/tell <source.name>'><source.display_name></click></yellow><gray>: <text>"

#
# The 'self_message_format' is applied to messages sent by the viewer.
# You can reference translations with the <lang:...> MiniMessage tag.
#
self_message_format: "<dark_gray><lang:schat.chat.message.you></dark_gray><gray>: <text>"

#
# The 'active_tab_format' is applied to the name of the channel tab when it is active.
#
# Currently, PlaceholderAPI placeholders cannot be used here.
# Send a feature request on discord if your need that feature.
#
active_tab_format: "<green><underlined><channel.name></underlined></green>"

#
# The 'inactive_tab_format' is applied to the name of the channel tab when it is inactive.
#
# Currently, PlaceholderAPI placeholders cannot be used here.
# Send a feature request on discord if your need that feature.
#
inactive_tab_format: "<gray><hover:show_text:'<lang:schat.hover.join-channel:<channel.name>'><click:run_command:'/channel join <channel.key>'><channel.name></click></hover></gray>"
team:
name: Team
settings:
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/net/silthus/schat/channel/ChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ private ChannelImpl(Builder builder) {
this.policies = Map.copyOf(builder.policies);
}

@Override
public @NotNull ChannelImpl settings(@NonNull Settings settings) {
this.settings = settings.toBuilder()
.withStatic(KEY, key())
.withStatic(DISPLAY_NAME, displayName())
.create();
return this;
}

public @NotNull @Unmodifiable Messages messages() {
return Messages.unmodifiable(messages);
}
Expand Down
17 changes: 15 additions & 2 deletions core/src/test/java/net/silthus/schat/channel/ChannelTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.silthus.schat.commands.SendMessageResult;
import net.silthus.schat.message.Message;
import net.silthus.schat.message.MessageTarget;
import net.silthus.schat.pointer.Settings;
import net.silthus.schat.policies.JoinChannelPolicy;
import net.silthus.schat.policies.SendChannelMessagePolicy;
import org.jetbrains.annotations.NotNull;
Expand All @@ -39,6 +40,7 @@

import static net.kyori.adventure.text.Component.text;
import static net.silthus.schat.channel.Channel.DISPLAY_NAME;
import static net.silthus.schat.channel.Channel.KEY;
import static net.silthus.schat.channel.Channel.createChannel;
import static net.silthus.schat.channel.ChannelHelper.channelWith;
import static net.silthus.schat.channel.ChannelHelper.randomChannel;
Expand Down Expand Up @@ -108,14 +110,25 @@ void same_message_is_only_processed_once() {
verify(target).sendMessage(message);
}

@Nested class given_no_display_name {
@Nested
class given_no_display_name {
@Test
void uses_key_as_display_name() {
assertThat(channel.displayName()).isEqualTo(text(channel.key()));
}
}

@Nested class given_display_name {
@Test
void when_settings_are_overwritten_key_and_name_is_kept() {
final Channel channel = channelWith("test");
channel.settings(Settings.createSettings());

assertThat(channel.get(KEY)).isPresent().get().isEqualTo("test");
assertThat(channel.get(DISPLAY_NAME)).isEqualTo(text("test"));
}

@Nested
class given_display_name {
private final TextComponent name = text("Test Channel");

@BeforeEach
Expand Down

0 comments on commit d69546f

Please sign in to comment.