use of com.velocitypowered.api.proxy.ServerConnection in project ResourcepacksPlugins by Phoenix616.
the class PluginMessageListener method pluginMessageReceived.
@Subscribe
public void pluginMessageReceived(PluginMessageEvent event) {
if (!plugin.isEnabled() || !event.getIdentifier().getId().equals("rp:plugin") || !(event.getSource() instanceof ServerConnection))
return;
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
String subchannel = in.readUTF();
if ("authMeLogin".equals(subchannel)) {
String playerName = in.readUTF();
UUID playerId = UUID.fromString(in.readUTF());
plugin.setAuthenticated(playerId, true);
if (!plugin.hasBackend(playerId) && plugin.getConfig().getBoolean("use-auth-plugin", plugin.getConfig().getBoolean("useauth", false))) {
Optional<Player> player = plugin.getProxy().getPlayer(playerId);
if (player.isPresent()) {
String serverName = "";
Optional<ServerConnection> server = player.get().getCurrentServer();
if (server.isPresent()) {
serverName = server.get().getServerInfo().getName();
}
long sendDelay = plugin.getPackManager().getAssignment(serverName).getSendDelay();
if (sendDelay < 0) {
sendDelay = plugin.getPackManager().getGlobalAssignment().getSendDelay();
}
if (sendDelay > 0) {
String finalServerName = serverName;
plugin.getProxy().getScheduler().buildTask(plugin, () -> plugin.getPackManager().applyPack(playerId, finalServerName)).delay(sendDelay * 20, TimeUnit.MILLISECONDS);
} else {
plugin.getPackManager().applyPack(playerId, serverName);
}
}
}
}
}
use of com.velocitypowered.api.proxy.ServerConnection in project 2FA by LielAmar.
the class OnPluginMessage method sendResponse.
public void sendResponse(UUID messageUUID, Player player, AuthCommunicationHandler.MessageType messageType) {
AuthHandler.AuthState authState = this.plugin.getAuthHandler().getAuthState(player.getUniqueId());
ByteArrayDataOutput response = ByteStreams.newDataOutput();
response.writeUTF(Constants.PROXY_SUB_CHANNEL_NAME);
response.writeUTF(messageUUID.toString());
response.writeUTF(player.getUniqueId().toString());
ByteArrayOutputStream msgBody = new ByteArrayOutputStream();
DataOutputStream msgBodyData = new DataOutputStream(msgBody);
try {
msgBodyData.writeUTF(messageType.name());
msgBodyData.writeUTF(authState.name());
} catch (IOException exception) {
exception.printStackTrace();
}
response.writeShort(msgBody.toByteArray().length);
response.write(msgBody.toByteArray());
Optional<ServerConnection> optionalServer = player.getCurrentServer();
optionalServer.ifPresent(serverConnection -> serverConnection.sendPluginMessage(this.plugin.getOUTGOING(), response.toByteArray()));
}
use of com.velocitypowered.api.proxy.ServerConnection 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());
}
}
use of com.velocitypowered.api.proxy.ServerConnection in project XConomy by YiC200333.
the class Vsync method on.
@SuppressWarnings(value = { "UnstableApiUsage", "unused" })
@Subscribe
public void on(PluginMessageEvent event) {
if (event.getSource() instanceof Player) {
return;
}
if (!event.getIdentifier().getId().equals(XConomyVelocity.acb.getId())) {
return;
}
ByteArrayDataInput input = ByteStreams.newDataInput(event.getData());
ServerConnection senderServer = (ServerConnection) event.getSource();
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeUTF(input.readUTF());
String sv = input.readUTF();
output.writeUTF(sv);
String svv = sv;
if (svv.contains(".")) {
svv = "versions §f" + svv;
} else {
svv = "§fold versions";
}
if (!sv.equals(XConomyVelocity.syncversion)) {
XConomyVelocity.getInstance().logger.warn("§cReceived data from " + svv + ", §cunable to synchronize, Current plugin version §f" + XConomyVelocity.syncversion);
return;
}
String type = input.readUTF();
if (type.equalsIgnoreCase("updateplayer")) {
output.writeUTF("updateplayer");
output.writeUTF(input.readUTF());
} else if (type.equalsIgnoreCase("message") || type.equalsIgnoreCase("message#semi")) {
output.writeUTF("message");
String uid = input.readUTF();
Optional<Player> p = XConomyVelocity.getInstance().server.getPlayer(UUID.fromString(uid));
if (type.equalsIgnoreCase("message") && !p.isPresent()) {
return;
}
output.writeUTF(uid);
output.writeUTF(input.readUTF());
} else if (type.equalsIgnoreCase("balanceall")) {
output.writeUTF("balanceall");
output.writeUTF(input.readUTF());
output.writeUTF(input.readUTF());
output.writeUTF(input.readUTF());
} else if (type.equalsIgnoreCase("broadcast")) {
output.writeUTF("broadcast");
output.writeUTF(input.readUTF());
} else if (type.equalsIgnoreCase("syncOnlineUUID")) {
output.writeUTF("syncOnlineUUID");
output.writeUTF(input.readUTF());
output.writeUTF(input.readUTF());
output.writeUTF(input.readUTF());
}
for (RegisteredServer s : XConomyVelocity.getInstance().server.getAllServers()) {
if (!s.equals(senderServer.getServer()) && s.getPlayersConnected().size() > 0) {
XConomyVelocity.getInstance().server.getScheduler().buildTask(XConomyVelocity.getInstance(), () -> SendMessTaskB(s, output)).schedule();
}
}
}
use of com.velocitypowered.api.proxy.ServerConnection in project ProxyQueues by JLyne.
the class ProxyQueueImpl method shouldAddPlayer.
private CompletableFuture<Boolean> shouldAddPlayer(Player player) {
PlayerQueueEvent event = new PlayerQueueEvent(player, server);
return proxyQueues.getProxyServer().getEventManager().fire(event).thenApply((PlayerQueueEvent result) -> {
// Don't add to queue if event cancelled, show player the reason
if (result.isCancelled()) {
String reason = result.getReason() != null ? result.getReason() : "An unexpected error occurred. Please try again later";
ServerConnection currentServer = player.getCurrentServer().orElse(null);
RegisteredServer waitingServer = proxyQueues.getWaitingServer().orElse(null);
proxyQueues.getLogger().info(player.getUsername() + "'s PlayerQueueEvent cancelled");
if (currentServer == null || currentServer.getServer().equals(waitingServer)) {
player.disconnect(Messages.getComponent("errors.queue-cannot-join", Collections.singletonMap("reason", reason), Collections.emptyMap()));
} else {
proxyQueues.sendMessage(player, MessageType.ERROR, "errors.queue-cannot-join", Collections.singletonMap("reason", reason));
}
}
return !result.isCancelled();
});
}
Aggregations