Search in sources :

Example 1 with Result

use of org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Result in project Floodgate by GeyserMC.

the class BungeePluginMessageUtils method onPluginMessage.

@EventHandler(priority = EventPriority.LOW)
public void onPluginMessage(PluginMessageEvent event) {
    PluginMessageChannel channel = pluginMessageManager.getChannel(event.getTag());
    if (channel == null) {
        return;
    }
    UUID targetUuid = null;
    String targetUsername = null;
    Identity targetIdentity = Identity.UNKNOWN;
    Connection target = event.getReceiver();
    if (target instanceof ProxiedPlayer) {
        ProxiedPlayer player = (ProxiedPlayer) target;
        targetUuid = player.getUniqueId();
        targetUsername = player.getName();
        targetIdentity = Identity.PLAYER;
    } else if (target instanceof ServerConnection) {
        targetIdentity = Identity.SERVER;
    }
    UUID sourceUuid = null;
    String sourceUsername = null;
    Identity sourceIdentity = Identity.UNKNOWN;
    Connection source = event.getSender();
    if (source instanceof ProxiedPlayer) {
        ProxiedPlayer player = (ProxiedPlayer) source;
        sourceUuid = player.getUniqueId();
        sourceUsername = player.getName();
        sourceIdentity = Identity.PLAYER;
    } else if (source instanceof ServerConnection) {
        sourceIdentity = Identity.SERVER;
    }
    Result result = channel.handleProxyCall(event.getData(), targetUuid, targetUsername, targetIdentity, sourceUuid, sourceUsername, sourceIdentity);
    event.setCancelled(!result.isAllowed());
    if (!result.isAllowed() && result.getReason() != null) {
        logKick(source, result.getReason());
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Connection(net.md_5.bungee.api.connection.Connection) ServerConnection(net.md_5.bungee.ServerConnection) ServerConnection(net.md_5.bungee.ServerConnection) UUID(java.util.UUID) Identity(org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Identity) Result(org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Result) EventHandler(net.md_5.bungee.event.EventHandler)

Example 2 with Result

use of org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Result 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

UUID (java.util.UUID)2 Identity (org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Identity)2 Result (org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Result)2 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 ServerConnection (net.md_5.bungee.ServerConnection)1 Connection (net.md_5.bungee.api.connection.Connection)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 EventHandler (net.md_5.bungee.event.EventHandler)1