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());
}
}
Aggregations