use of net.md_5.bungee.event.EventHandler in project LuckPerms by lucko.
the class BungeePermissionCheckListener method onPlayerPermissionCheck.
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
if (!(e.getSender() instanceof ProxiedPlayer)) {
return;
}
Objects.requireNonNull(e.getPermission(), "permission");
Objects.requireNonNull(e.getSender(), "sender");
ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
if (user == null) {
e.setHasPermission(false);
return;
}
Contexts contexts = this.plugin.getContextManager().getApplicableContexts(player);
Tristate result = user.getCachedData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
// just use the result provided by the proxy when the event was created
return;
}
e.setHasPermission(result.asBoolean());
}
use of net.md_5.bungee.event.EventHandler in project LuckPerms by lucko.
the class BungeeMessenger method onPluginMessage.
@EventHandler
public void onPluginMessage(PluginMessageEvent e) {
if (!e.getTag().equals(CHANNEL)) {
return;
}
e.setCancelled(true);
if (e.getSender() instanceof ProxiedPlayer) {
return;
}
byte[] data = e.getData();
ByteArrayDataInput in = ByteStreams.newDataInput(data);
String msg = in.readUTF();
if (this.consumer.consumeIncomingMessageAsString(msg)) {
// Forward to other servers
this.plugin.getBootstrap().getScheduler().doAsync(() -> {
for (ServerInfo server : this.plugin.getBootstrap().getProxy().getServers().values()) {
server.sendData(CHANNEL, data, true);
}
});
}
}
use of net.md_5.bungee.event.EventHandler in project CloudNet by Dytanic.
the class ProxiedListener method handleDisconnect.
@EventHandler(priority = EventPriority.HIGHEST)
public void handleDisconnect(PlayerDisconnectEvent e) {
CloudPlayer cloudPlayer = CloudProxy.getInstance().getCloudPlayers().get(e.getPlayer().getUniqueId());
if (cloudPlayer != null) {
CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutLogoutPlayer(cloudPlayer, e.getPlayer().getUniqueId()));
} else {
CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutLogoutPlayer(null, e.getPlayer().getUniqueId()));
}
CloudProxy.getInstance().getCloudPlayers().remove(e.getPlayer().getUniqueId());
ProxyServer.getInstance().getScheduler().schedule(CloudProxy.getInstance().getPlugin(), new Runnable() {
@Override
public void run() {
CloudProxy.getInstance().update();
}
}, 250, TimeUnit.MILLISECONDS);
}
use of net.md_5.bungee.event.EventHandler in project CloudNet by Dytanic.
the class ProxiedListener method handleServerConnect.
@EventHandler(priority = EventPriority.HIGHEST)
public void handleServerConnect(ServerConnectEvent event) {
if (event.getPlayer().getServer() == null) {
String fallback = CloudProxy.getInstance().fallback(event.getPlayer());
ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent(event.getPlayer(), CloudAPI.getInstance().getOnlinePlayer(event.getPlayer().getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.SERVER_KICK, fallback);
ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
fallback = proxiedPlayerFallbackEvent.getFallback();
if (fallback != null) {
event.setTarget(ProxyServer.getInstance().getServerInfo(fallback));
CloudAPI.getInstance().getNetworkConnection().getChannel().writeAndFlush(new PacketOutCustomSubChannelMessage(DefaultType.BUKKIT, event.getTarget().getName(), "cloudnet_internal", "server_connect_request", new Document("uniqueId", event.getPlayer().getUniqueId())));
NetworkUtils.sleepUninterruptedly(6);
} else
event.setCancelled(true);
} else {
CloudAPI.getInstance().getNetworkConnection().getChannel().writeAndFlush(new PacketOutCustomSubChannelMessage(DefaultType.BUKKIT, event.getTarget().getName(), "cloudnet_internal", "server_connect_request", new Document("uniqueId", event.getPlayer().getUniqueId())));
NetworkUtils.sleepUninterruptedly(6);
}
}
use of net.md_5.bungee.event.EventHandler in project CloudNet by Dytanic.
the class ProxiedListener method handleChannel.
@EventHandler
public void handleChannel(PluginMessageEvent pluginMessageEvent) {
if (!(pluginMessageEvent.getReceiver() instanceof ProxiedPlayer))
return;
if (pluginMessageEvent.getTag().equalsIgnoreCase("CloudNet")) {
ByteArrayDataInput byteArrayDataInput = ByteStreams.newDataInput(pluginMessageEvent.getData());
switch(byteArrayDataInput.readUTF().toLowerCase()) {
case "connect":
List<String> servers = CloudProxy.getInstance().getServers(byteArrayDataInput.readUTF());
if (servers.size() == 0)
return;
((ProxiedPlayer) pluginMessageEvent.getReceiver()).connect(ProxyServer.getInstance().getServerInfo(servers.get(NetworkUtils.RANDOM.nextInt(servers.size()))));
break;
case "fallback":
((ProxiedPlayer) pluginMessageEvent.getReceiver()).connect(ProxyServer.getInstance().getServerInfo(CloudProxy.getInstance().fallback(((ProxiedPlayer) pluginMessageEvent.getReceiver()))));
break;
case "command":
ProxyServer.getInstance().getPluginManager().dispatchCommand(((ProxiedPlayer) pluginMessageEvent.getReceiver()), byteArrayDataInput.readUTF());
break;
}
}
}
Aggregations