Search in sources :

Example 1 with ChannelMessageSink

use of com.velocitypowered.api.proxy.messages.ChannelMessageSink in project Floodgate by GeyserMC.

the class VelocityPluginMessageUtils method onPluginMessage.

@Subscribe
public void onPluginMessage(PluginMessageEvent event) {
    String channelId = event.getIdentifier().getId();
    PluginMessageChannel channel = pluginMessageManager.getChannel(channelId);
    if (channel == null) {
        return;
    }
    UUID targetUuid = null;
    String targetUsername = null;
    Identity targetIdentity = Identity.UNKNOWN;
    ChannelMessageSink target = event.getTarget();
    if (target instanceof Player) {
        Player player = (Player) target;
        targetUuid = player.getUniqueId();
        targetUsername = player.getUsername();
        targetIdentity = Identity.PLAYER;
    } else if (target instanceof ServerConnection) {
        targetIdentity = Identity.SERVER;
    }
    UUID sourceUuid = null;
    String sourceUsername = null;
    Identity sourceIdentity = Identity.UNKNOWN;
    ChannelMessageSource source = event.getSource();
    if (source instanceof Player) {
        Player player = (Player) source;
        sourceUuid = player.getUniqueId();
        sourceUsername = player.getUsername();
        sourceIdentity = Identity.PLAYER;
    } else if (source instanceof ServerConnection) {
        sourceIdentity = Identity.SERVER;
    }
    Result result = channel.handleProxyCall(event.getData(), targetUuid, targetUsername, targetIdentity, sourceUuid, sourceUsername, sourceIdentity);
    event.setResult(result.isAllowed() ? ForwardResult.forward() : ForwardResult.handled());
    if (!result.isAllowed() && result.getReason() != null) {
        logKick(source, result.getReason());
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) ServerConnection(com.velocitypowered.api.proxy.ServerConnection) UUID(java.util.UUID) Identity(org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Identity) ChannelMessageSink(com.velocitypowered.api.proxy.messages.ChannelMessageSink) ChannelMessageSource(com.velocitypowered.api.proxy.messages.ChannelMessageSource) Result(org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Result) ForwardResult(com.velocitypowered.api.event.connection.PluginMessageEvent.ForwardResult) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

Subscribe (com.velocitypowered.api.event.Subscribe)1 ForwardResult (com.velocitypowered.api.event.connection.PluginMessageEvent.ForwardResult)1 Player (com.velocitypowered.api.proxy.Player)1 ServerConnection (com.velocitypowered.api.proxy.ServerConnection)1 ChannelMessageSink (com.velocitypowered.api.proxy.messages.ChannelMessageSink)1 ChannelMessageSource (com.velocitypowered.api.proxy.messages.ChannelMessageSource)1 UUID (java.util.UUID)1 Identity (org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Identity)1 Result (org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Result)1