    001package co.aikar.commands;
    002
    003import java.util.concurrent.TimeUnit;
    004
    005import com.velocitypowered.api.event.Subscribe;
    006import com.velocitypowered.api.event.connection.DisconnectEvent;
    007import com.velocitypowered.api.event.connection.PostLoginEvent;
    008import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
    009import com.velocitypowered.api.plugin.PluginContainer;
    010import com.velocitypowered.api.proxy.Player;
    011import com.velocitypowered.api.proxy.ProxyServer;
    012
    013public class ACFVelocityListener {
    014
    015    private final VelocityCommandManager manager;
    016    private final PluginContainer plugin;
    017    private final ProxyServer proxy;
    018
    019    public ACFVelocityListener(VelocityCommandManager manager, PluginContainer plugin, ProxyServer proxy) {
    020        this.manager = manager;
    021        this.plugin = plugin;
    022        this.proxy = proxy;
    023    }
    024
    025    @Subscribe
    026    public void onPlayerJoin(PostLoginEvent loginEvent) {
    027        Player player = loginEvent.getPlayer();
    028
    029        // the client settings are sent after a successful login
    030        Runnable task = () -> manager.readLocale(player);
    031        proxy.getScheduler().buildTask(plugin, task).delay(1, TimeUnit.SECONDS).schedule();
    032    }
    033
    034    @Subscribe
    035    public void onDisconnect(DisconnectEvent disconnectEvent) {
    036        // cleanup
    037        Player player = disconnectEvent.getPlayer();
    038        manager.issuersLocale.remove(player.getUniqueId());
    039    }
    040
    041    @Subscribe
    042    public void onSettingsChange(PlayerSettingsChangedEvent settingsEvent) {
    043        manager.setIssuerLocale(settingsEvent.getPlayer(), settingsEvent.getPlayer().getPlayerSettings().getLocale());
    044    }
    045}