Search in sources :

Example 1 with ChannelRegistrationException

use of org.spongepowered.api.network.ChannelRegistrationException in project LanternServer by LanternPowered.

the class LanternChannelRegistrar method create.

private LanternChannelBinding create(Object plugin, String channel, boolean rawChannel) throws ChannelRegistrationException {
    final PluginContainer container = checkPlugin(plugin, "plugin");
    checkNotNullOrEmpty(channel, "channel");
    checkArgument(channel.length() <= MAX_NAME_LENGTH, "channel length may not be longer then 20");
    if (!isChannelAvailable(channel)) {
        throw new ChannelRegistrationException("Channel with name \"" + channel + "\" is already registered!");
    }
    final LanternChannelBinding binding;
    if (rawChannel) {
        binding = new LanternRawDataChannel(this, channel, container);
    } else {
        binding = new LanternIndexedMessageChannel(this, channel, container);
    }
    binding.bound = true;
    final MessagePlayInOutRegisterChannels message = new MessagePlayInOutRegisterChannels(Sets.newHashSet(channel));
    for (Player player : this.server.getOnlinePlayers()) {
        ((NetworkSession) player.getConnection()).send(message);
    }
    return binding;
}
Also used : MessagePlayInOutRegisterChannels(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Player(org.spongepowered.api.entity.living.player.Player) PluginContainer(org.spongepowered.api.plugin.PluginContainer) NetworkSession(org.lanternpowered.server.network.NetworkSession) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException)

Example 2 with ChannelRegistrationException

use of org.spongepowered.api.network.ChannelRegistrationException in project SpongeForge by SpongePowered.

the class SpongeModNetworkManager method createRawChannel.

@Override
public RawDataChannel createRawChannel(Object plugin, String channelName) throws ChannelRegistrationException {
    SpongeRawChannel channel;
    PluginContainer pluginContainer = checkCreateChannelArgs(plugin, channelName);
    try {
        channel = new SpongeRawChannel(this, channelName, pluginContainer);
    } catch (Exception e) {
        throw new ChannelRegistrationException("Error registering channel \"" + channelName + "\" to " + pluginContainer, e);
    }
    return this.registerChannel(channel);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException)

Example 3 with ChannelRegistrationException

use of org.spongepowered.api.network.ChannelRegistrationException in project SpongeForge by SpongePowered.

the class SpongeModNetworkManager method createChannel.

@Override
public IndexedMessageChannel createChannel(Object plugin, String channelName) throws ChannelRegistrationException {
    SpongeIndexedMessageChannel channel;
    PluginContainer pluginContainer = checkCreateChannelArgs(plugin, channelName);
    try {
        channel = new SpongeIndexedMessageChannel(this, channelName, pluginContainer);
    } catch (Exception e) {
        throw new ChannelRegistrationException("Error registering channel \"" + channelName + "\" to " + pluginContainer, e);
    }
    return this.registerChannel(channel);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException)

Aggregations

ChannelRegistrationException (org.spongepowered.api.network.ChannelRegistrationException)3 PluginContainer (org.spongepowered.api.plugin.PluginContainer)3 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)1 NetworkSession (org.lanternpowered.server.network.NetworkSession)1 MessagePlayInOutRegisterChannels (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels)1 Player (org.spongepowered.api.entity.living.player.Player)1