001package net.tnemc.plugincore.core.channel;
002/*
003 * The New Plugin Core
004 * Copyright (C) 2022 - 2024 Daniel "creatorfromhell" Vidmar
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 *
016 * You should have received a copy of the GNU Affero General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019
020
021import net.tnemc.plugincore.PluginCore;
022
023import java.util.ArrayList;
024import java.util.HashMap;
025import java.util.List;
026import java.util.Map;
027
028/**
029 * ChannelMessageManager
030 *
031 * @author creatorfromhell
032 * @since 0.1.2.0
033 */
034public class ChannelMessageManager {
035
036  private final Map<String, ChannelMessageHandler> handlers = new HashMap<>();
037
038  private final List<String> accountsMessage = new ArrayList<>();
039
040  public void register(final ChannelMessageHandler handler) {
041    handlers.put("tne:" + handler.tag, handler);
042  }
043
044  public void register() {
045    handlers.keySet().forEach(channel->{
046      PluginCore.server().proxy().registerChannel(channel);
047    });
048  }
049
050  public void handle(String channel, byte[] bytes) {
051    if(handlers.containsKey(channel)) {
052      handlers.get(channel).handle(bytes);
053    }
054  }
055
056  public boolean isAffected(final String account) {
057    return accountsMessage.contains(account);
058  }
059
060  public void removeAccount(final String account) {
061    accountsMessage.remove(account);
062  }
063
064  public void addAccount(final String account) {
065    accountsMessage.add(account);
066  }
067}