From 9beb9f839772ac19c20497e21a664d26cf025ad8 Mon Sep 17 00:00:00 2001 From: Draycia Date: Tue, 8 Sep 2020 23:57:38 -0700 Subject: [PATCH] Allow setting channel on join --- .../carbon/listeners/PlayerJoinListener.java | 18 ++++++++++++++++++ src/main/resources/config.yml | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/net/draycia/carbon/listeners/PlayerJoinListener.java b/src/main/java/net/draycia/carbon/listeners/PlayerJoinListener.java index 8e43d2d5..f7467a24 100644 --- a/src/main/java/net/draycia/carbon/listeners/PlayerJoinListener.java +++ b/src/main/java/net/draycia/carbon/listeners/PlayerJoinListener.java @@ -1,6 +1,7 @@ package net.draycia.carbon.listeners; import net.draycia.carbon.CarbonChat; +import net.draycia.carbon.channels.ChatChannel; import net.draycia.carbon.storage.ChatUser; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -24,6 +25,23 @@ public class PlayerJoinListener implements Listener { if (user.getNickname() != null) { user.setNickname(user.getNickname()); } + + String channel = carbonChat.getConfig().getString("channel-on-join"); + + if (channel == null || channel.isEmpty()) { + return; + } + + if (channel.equals("DEFAULT")) { + user.setSelectedChannel(carbonChat.getChannelManager().getDefaultChannel()); + return; + } + + ChatChannel chatChannel = carbonChat.getChannelManager().getRegistry().get(channel); + + if (chatChannel != null) { + user.setSelectedChannel(chatChannel); + } } @EventHandler diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 98a76ef6..8ad54373 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -99,6 +99,13 @@ placeholders: prefix: "[]" group: "%vault_group%" +# Sets the player's channel to the specified channel when they join +# Set to "" or remove to disable +# Set to DEFAULT to set the player's channel to the default channel on join +# Otherwise, set to a channel to set the player's channel to it on join +# For example, channel-on-join: "global" sets their channel to global on join +channel-on-join: "" + # Global context options contexts: Towny: