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 042 handlers.put("tne:" + handler.tag, handler); 043 } 044 045 public void register() { 046 047 handlers.keySet().forEach(channel->{ 048 PluginCore.server().proxy().registerChannel(channel); 049 }); 050 } 051 052 public void handle(String channel, byte[] bytes) { 053 054 if(handlers.containsKey(channel)) { 055 handlers.get(channel).handle(bytes); 056 } 057 } 058 059 public boolean isAffected(final String account) { 060 061 return accountsMessage.contains(account); 062 } 063 064 public void removeAccount(final String account) { 065 066 accountsMessage.remove(account); 067 } 068 069 public void addAccount(final String account) { 070 071 accountsMessage.add(account); 072 } 073}