001package net.tnemc.plugincore.paper.impl; 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 020import net.tnemc.plugincore.core.compatibility.ProxyProvider; 021import net.tnemc.plugincore.paper.PaperPluginCore; 022import net.tnemc.plugincore.paper.listener.server.MessageChannelListener; 023import org.bukkit.Bukkit; 024 025/** 026 * BukkitProxyProvider 027 * 028 * @author creatorfromhell 029 * @since 0.1.2.0 030 */ 031public class PaperProxyProvider implements ProxyProvider { 032 033 private final MessageChannelListener listener = new MessageChannelListener(); 034 035 /** 036 * Used to register a plugin message channel. 037 * 038 * @param channel The channel to register. 039 */ 040 @Override 041 public void registerChannel(String channel) { 042 Bukkit.getMessenger().registerIncomingPluginChannel(PaperPluginCore.instance().getPlugin(), channel, listener); 043 Bukkit.getMessenger().registerOutgoingPluginChannel(PaperPluginCore.instance().getPlugin(), channel); 044 } 045 046 /** 047 * Used to send a message through a specific plugin message channel. 048 * 049 * @param channel The channel to send the message through. 050 * @param bytes The byte data to send. 051 */ 052 @Override 053 public void send(String channel, byte[] bytes) { 054 if(Bukkit.getServer().getOnlinePlayers().isEmpty()) { 055 return; 056 } 057 058 Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(PaperPluginCore.instance().getPlugin(), channel, bytes); 059 } 060}