use of com.velocitypowered.proxy.connection.client.ConnectedPlayer in project LimboAPI by Elytrium.
the class LimboImpl method respawnPlayer.
@Override
public void respawnPlayer(Player player) {
MinecraftConnection connection = ((ConnectedPlayer) player).getConnection();
connection.write(this.spawnPosition);
if (this.chunks != null) {
connection.write(this.chunks);
}
}
use of com.velocitypowered.proxy.connection.client.ConnectedPlayer 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.client.ConnectedPlayer in project LimboAPI by Elytrium.
the class LoginListener method hookPlaySession.
@Subscribe
public void hookPlaySession(ServerConnectedEvent event) {
ConnectedPlayer player = (ConnectedPlayer) event.getPlayer();
MinecraftConnection connection = player.getConnection();
connection.eventLoop().execute(() -> {
if (!(connection.getSessionHandler() instanceof ClientPlaySessionHandler)) {
ClientPlaySessionHandler playHandler = new ClientPlaySessionHandler(this.server, player);
try {
spawned.set(playHandler, this.plugin.isLimboJoined(player));
} catch (IllegalAccessException ex) {
this.plugin.getLogger().error("Exception while hooking into ClientPlaySessionHandler of {}", player, ex);
}
connection.setSessionHandler(playHandler);
}
});
}
use of com.velocitypowered.proxy.connection.client.ConnectedPlayer in project LimboAPI by Elytrium.
the class LoginListener method hookLoginSession.
public void hookLoginSession(GameProfileRequestEvent event) throws IllegalAccessException {
// Changing mcConnection to the closed one. For what? To break the "initializePlayer"
// method (which checks mcConnection.isActive()) and to override it. :)
InitialInboundConnection inbound = (InitialInboundConnection) delegate.get(event.getConnection());
MinecraftConnection connection = inbound.getConnection();
LoginSessionHandler handler = (LoginSessionHandler) connection.getSessionHandler();
loginConnectionField.set(handler, closed);
if (connection.isClosed()) {
return;
}
connection.eventLoop().execute(() -> {
try {
// Initiate a regular connection and move over to it.
ConnectedPlayer player = ctor.newInstance(this.server, event.getGameProfile(), connection, event.getConnection().getVirtualHost().orElse(null), this.onlineMode.contains(event.getUsername()));
if (!this.server.canRegisterConnection(player)) {
player.disconnect0(Component.translatable("velocity.error.already-connected-proxy", NamedTextColor.RED), true);
return;
}
if (connection.isClosed()) {
return;
}
// Completing the Login process
int threshold = this.server.getConfiguration().getCompressionThreshold();
if (threshold >= 0 && connection.getProtocolVersion().compareTo(MINECRAFT_1_8) >= 0) {
connection.write(new SetCompression(threshold));
if (connection.isClosed()) {
return;
}
connection.setCompressionThreshold(threshold);
}
VelocityConfiguration configuration = this.server.getConfiguration();
UUID playerUniqueId = player.getUniqueId();
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
}
ServerLoginSuccess success = new ServerLoginSuccess();
success.setUsername(player.getUsername());
success.setUuid(playerUniqueId);
connection.write(success);
this.plugin.setInitialID(player, playerUniqueId);
connection.setState(StateRegistry.PLAY);
this.server.getEventManager().fire(new LoginLimboRegisterEvent(player)).thenAcceptAsync(limboEvent -> {
LoginTasksQueue queue = new LoginTasksQueue(this.plugin, handler, this.server, player, inbound, limboEvent.getCallbacks());
this.plugin.addLoginQueue(player, queue);
queue.next();
}, connection.eventLoop());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
});
}
use of com.velocitypowered.proxy.connection.client.ConnectedPlayer 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);
}
});
}
Aggregations