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

Allow Local Default Channel #164

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public abstract class LocalConfig {
// SERVER SETTINGS
private String serverName;

private String defaultChannel;

// GLOBAL CHAT SETTINGS
private boolean overrideGlobalFormat;
private String overrideGlobalFormatFormat;
Expand Down Expand Up @@ -118,6 +120,8 @@ private void setMemberAttributes() {
// Server
serverName = getString("server_name","SPIGOT_SERVER");

defaultChannel = getString("default_channel","global");

// Global Chat
overrideGlobalFormat = getBoolean("override_global_format", false);
overrideGlobalFormatFormat = getString("override_global_format_format", "&5[&dG&5] &f%DISPLAYNAME%&f: ");
Expand Down Expand Up @@ -182,6 +186,13 @@ public String getServerName() {
return serverName;
}

/**
* @return the serverName
*/
public String getDefaultChannel() {
return defaultChannel;
}

/**
* @return the overrideGlobalFormat
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@

import xyz.olivermartin.multichat.local.common.MultiChatLocal;
import xyz.olivermartin.multichat.local.common.MultiChatLocalPlayer;
import xyz.olivermartin.multichat.local.common.config.LocalConfig;

public abstract class LocalLoginLogoutListener {

protected String defaultChannel = "global";
Draesia marked this conversation as resolved.
Show resolved Hide resolved

protected abstract boolean isPlayerStillOnline(MultiChatLocalPlayer player);

LocalConfig config = MultiChatLocal.getInstance().getConfigManager().getLocalConfig();

protected void handleLoginEvent(MultiChatLocalPlayer player) {

MultiChatLocal.getInstance().getNameManager().registerPlayer(player.getUniqueId(), player.getName());

Map<UUID, String> playerChannels = MultiChatLocal.getInstance().getDataStore().getPlayerChannels();
synchronized (playerChannels) {
if (!playerChannels.containsKey(player.getUniqueId())) {
playerChannels.put(player.getUniqueId(), "global");
playerChannels.put(player.getUniqueId(), this.defaultChannel);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import xyz.olivermartin.multichat.local.common.MultiChatLocal;
import xyz.olivermartin.multichat.local.common.MultiChatLocalPlayer;
import xyz.olivermartin.multichat.local.common.config.LocalConfig;
import xyz.olivermartin.multichat.local.common.listeners.LocalLoginLogoutListener;
import xyz.olivermartin.multichat.local.spigot.MultiChatLocalSpigotPlayer;

public class LocalSpigotLoginLogoutListener extends LocalLoginLogoutListener implements Listener {

public LocalSpigotLoginLogoutListener() {
LocalConfig config = MultiChatLocal.getInstance().getConfigManager().getLocalConfig();
this.defaultChannel = config.getDefaultChannel();
}

@EventHandler
public void onLogin(final PlayerJoinEvent event) {
MultiChatLocalPlayer mclp = new MultiChatLocalSpigotPlayer(event.getPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.network.ClientConnectionEvent;

import xyz.olivermartin.multichat.local.common.MultiChatLocal;
import xyz.olivermartin.multichat.local.common.MultiChatLocalPlayer;
import xyz.olivermartin.multichat.local.common.config.LocalConfig;
import xyz.olivermartin.multichat.local.common.listeners.LocalLoginLogoutListener;
import xyz.olivermartin.multichat.local.sponge.MultiChatLocalSpongePlayer;

public class LocalSpongeLoginLogoutListener extends LocalLoginLogoutListener {

public LocalSpongeLoginLogoutListener() {
LocalConfig config = MultiChatLocal.getInstance().getConfigManager().getLocalConfig();
this.defaultChannel = config.getDefaultChannel();
}

@Listener(order=Order.POST)
public void onJoin(ClientConnectionEvent.Join event, @Root Player player) {
MultiChatLocalPlayer mclp = new MultiChatLocalSpongePlayer(player);
Expand Down
3 changes: 3 additions & 0 deletions multichat/src/main/resources/localconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ version: "1.9.6" #
# Specify the name of this server here for the %SERVER% placeholder
server_name: "UNNAMED_SERVER"

# Specify the channel the user should connect to when first joining (local / global)
default_channel: "global"

############################################################
# +------------------------------------------------------+ #
# | Global | #
Expand Down