use of com.velocitypowered.proxy.connection.backend.VelocityServerConnection in project LimboAPI by Elytrium.
the class PlayerListItemHook method handle.
@Override
public boolean handle(MinecraftSessionHandler handler) {
if (handler instanceof BackendPlaySessionHandler) {
try {
List<Item> items = this.getItems();
for (int i = 0; i < items.size(); ++i) {
Item item = items.get(i);
ConnectedPlayer player = ((VelocityServerConnection) serverConnField.get(handler)).getPlayer();
UUID initialID = this.plugin.getInitialID(player);
if (player.getUniqueId().equals(item.getUuid())) {
items.set(i, new Item(initialID).setDisplayName(item.getDisplayName()).setGameMode(item.getGameMode()).setLatency(item.getLatency()).setName(item.getName()).setProperties(item.getProperties()));
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return super.handle(handler);
}
use of com.velocitypowered.proxy.connection.backend.VelocityServerConnection in project InteractiveChat by LOOHP.
the class InteractiveChatVelocity method onServerConnected.
@Subscribe
public void onServerConnected(ServerPostConnectEvent event) {
Player player = event.getPlayer();
RegisteredServer to = player.getCurrentServer().get().getServer();
UUID uuid = player.getUniqueId();
if (!placeholderList.containsKey(to.getServerInfo().getName())) {
try {
PluginMessageSendingVelocity.requestPlaceholderList(to);
} catch (IOException e) {
e.printStackTrace();
}
}
try {
PluginMessageSendingVelocity.sendPlayerListData();
} catch (IOException e1) {
e1.printStackTrace();
}
long universalTime = playerCooldownManager.getPlayerUniversalLastTimestamp(uuid);
if (universalTime >= 0) {
try {
PluginMessageSendingVelocity.sendPlayerUniversalCooldown(to, uuid, universalTime);
} catch (IOException e) {
e.printStackTrace();
}
}
List<ICPlaceholder> placeholders = placeholderList.get(to.getServerInfo().getName());
if (placeholders != null) {
for (ICPlaceholder placeholder : placeholders) {
long placeholderTime = playerCooldownManager.getPlayerPlaceholderLastTimestamp(uuid, placeholder.getInternalId());
if (placeholderTime >= 0) {
try {
PluginMessageSendingVelocity.sendPlayerPlaceholderCooldown(to, uuid, placeholder, placeholderTime);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
proxyServer.getScheduler().buildTask(plugin, () -> {
try {
PluginMessageSendingVelocity.sendDelayAndScheme();
} catch (IOException e) {
e.printStackTrace();
}
}).schedule();
proxyServer.getScheduler().buildTask(plugin, () -> {
if (event.getPlayer().getUsername().equals("LOOHP") || event.getPlayer().getUsername().equals("AppLEskakE")) {
sendMessage(event.getPlayer(), Component.text(TextColor.GOLD + "InteractiveChat (Velocity) " + getDescription().getVersion() + " is running!"));
}
}).delay(100, TimeUnit.MILLISECONDS).schedule();
VelocityServerConnection serverConnection = ((ConnectedPlayer) event.getPlayer()).getConnectedServer();
ChannelPipeline pipeline = serverConnection.ensureConnected().getChannel().pipeline();
pipeline.addBefore(Connections.HANDLER, "interactivechat_interceptor", new ChannelDuplexHandler() {
@Override
public void write(ChannelHandlerContext channelHandlerContext, Object obj, ChannelPromise channelPromise) throws Exception {
try {
if (obj instanceof Chat) {
Chat packet = (Chat) obj;
UUID uuid = player.getUniqueId();
String message = packet.getMessage();
byte position = packet.getType();
if ((position == 0 || position == 1) && uuid != null && message != null) {
Map<String, Long> list = forwardedMessages.get(uuid);
if (list != null) {
list.put(message, System.currentTimeMillis());
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
super.write(channelHandlerContext, obj, channelPromise);
}
});
}
use of com.velocitypowered.proxy.connection.backend.VelocityServerConnection in project LimboAPI by Elytrium.
the class LimboImpl method spawnPlayer.
@Override
public void spawnPlayer(Player apiPlayer, LimboSessionHandler handler) {
ConnectedPlayer player = (ConnectedPlayer) apiPlayer;
MinecraftConnection connection = player.getConnection();
Class<? extends LimboSessionHandler> handlerClass = handler.getClass();
if (this.limboName == null) {
this.limboName = handlerClass.getSimpleName();
}
connection.eventLoop().execute(() -> {
ChannelPipeline pipeline = connection.getChannel().pipeline();
if (Settings.IMP.MAIN.LOGGING_ENABLED) {
this.plugin.getLogger().info(player.getUsername() + " (" + player.getRemoteAddress() + ") has connected to the " + this.limboName + " Limbo");
}
if (!pipeline.names().contains("prepared-encoder")) {
// and an error occurs that "minecraft-encoder" doesn't exist.
if (!pipeline.names().contains(Connections.MINECRAFT_ENCODER)) {
connection.close();
return;
}
pipeline.addAfter(Connections.MINECRAFT_ENCODER, "prepared-encoder", new PreparedPacketEncoder(connection.getProtocolVersion()));
}
RegisteredServer previousServer = null;
if (connection.getState() != LimboProtocol.getLimboRegistry()) {
connection.setState(LimboProtocol.getLimboRegistry());
VelocityServerConnection server = player.getConnectedServer();
if (server != null) {
server.disconnect();
player.setConnectedServer(null);
previousServer = server.getServer();
this.plugin.setLimboJoined(player);
}
}
if (this.plugin.isLimboJoined(player)) {
if (connection.getType() == ConnectionTypes.LEGACY_FORGE) {
connection.delayedWrite(this.safeRejoinPackets);
} else {
connection.delayedWrite(this.fastRejoinPackets);
}
} else {
connection.delayedWrite(this.joinPackets);
}
connection.delayedWrite(this.postJoinPackets);
connection.delayedWrite(this.getBrandMessage(handlerClass));
this.plugin.setLimboJoined(player);
LimboSessionHandlerImpl sessionHandler = new LimboSessionHandlerImpl(this.plugin, player, handler, connection.getSessionHandler(), previousServer, () -> this.limboName);
connection.setSessionHandler(sessionHandler);
connection.flush();
if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_18_2) >= 0) {
this.plugin.getServer().getScheduler().buildTask(this.plugin, () -> connection.eventLoop().execute(() -> this.proceed(player, sessionHandler))).delay(Settings.IMP.MAIN.RECEIVER_LEVEL_1_18_2_FIXER_DELAY, TimeUnit.MILLISECONDS).schedule();
} else {
this.proceed(player, sessionHandler);
}
});
}
Aggregations