Search in sources :

Example 16 with EventHandler

use of net.md_5.bungee.event.EventHandler in project ChangeSkin by games647.

the class ServerSwitchListener method onServerConnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void onServerConnect(ServerConnectEvent connectEvent) {
    ServerInfo targetServer = connectEvent.getTarget();
    Server fromServer = connectEvent.getPlayer().getServer();
    if (fromServer != null && Objects.equals(targetServer, fromServer.getInfo())) {
        // check if we are switching to the same server
        return;
    }
    if (!isBlacklistEnabled()) {
        return;
    }
    ProxiedPlayer player = connectEvent.getPlayer();
    UserPreference session = plugin.getLoginSession(player.getPendingConnection());
    List<String> blacklist = core.getConfig().getStringList("server-blacklist");
    if (blacklist.contains(targetServer.getName())) {
        // clear the skin
        plugin.getApi().applySkin(player, null);
    } else if (session == null) {
        // lazy load
        ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> onLazyLoad(player));
    } else {
        // player switched to an enabled server
        Optional<SkinModel> optSkin = session.getTargetSkin();
        optSkin.ifPresent(skin -> plugin.getApi().applySkin(player, skin));
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) ServerInfo(net.md_5.bungee.api.config.ServerInfo) ProxyServer(net.md_5.bungee.api.ProxyServer) Objects(java.util.Objects) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) List(java.util.List) EventPriority(net.md_5.bungee.event.EventPriority) ChangeSkinBungee(com.github.games647.changeskin.bungee.ChangeSkinBungee) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel) Server(net.md_5.bungee.api.connection.Server) Optional(java.util.Optional) EventHandler(net.md_5.bungee.event.EventHandler) ServerConnectEvent(net.md_5.bungee.api.event.ServerConnectEvent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ProxyServer(net.md_5.bungee.api.ProxyServer) Server(net.md_5.bungee.api.connection.Server) Optional(java.util.Optional) ServerInfo(net.md_5.bungee.api.config.ServerInfo) UserPreference(com.github.games647.changeskin.core.model.UserPreference) EventHandler(net.md_5.bungee.event.EventHandler)

Example 17 with EventHandler

use of net.md_5.bungee.event.EventHandler in project ChangeSkin by games647.

the class ConnectListener method onPostLogin.

@EventHandler(priority = EventPriority.HIGH)
public void onPostLogin(LoginEvent loginEvent) {
    if (loginEvent.isCancelled() || isBlacklistEnabled()) {
        return;
    }
    PendingConnection connection = loginEvent.getConnection();
    String playerName = connection.getName().toLowerCase();
    loginEvent.registerIntent(plugin);
    Runnable task = () -> loadProfile(loginEvent, connection, playerName);
    ProxyServer.getInstance().getScheduler().runAsync(plugin, task);
}
Also used : PendingConnection(net.md_5.bungee.api.connection.PendingConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Example 18 with EventHandler

use of net.md_5.bungee.event.EventHandler in project ChangeSkin by games647.

the class ConnectListener method onPlayerLogin.

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerLogin(PostLoginEvent postLoginEvent) {
    ProxiedPlayer player = postLoginEvent.getPlayer();
    UserPreference preferences = plugin.getLoginSession(player.getPendingConnection());
    if (preferences == null || isBlacklistEnabled()) {
        return;
    }
    if (!preferences.getTargetSkin().isPresent()) {
        getRandomSkin().ifPresent(preferences::setTargetSkin);
    }
    preferences.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin));
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) UserPreference(com.github.games647.changeskin.core.model.UserPreference) EventHandler(net.md_5.bungee.event.EventHandler)

Example 19 with EventHandler

use of net.md_5.bungee.event.EventHandler in project ChangeSkin by games647.

the class ConnectListener method onDisconnect.

@EventHandler
public void onDisconnect(PlayerDisconnectEvent disconnectEvent) {
    PendingConnection pendingConnection = disconnectEvent.getPlayer().getPendingConnection();
    UserPreference preference = plugin.endSession(pendingConnection);
    if (preference != null) {
        save(preference);
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) PendingConnection(net.md_5.bungee.api.connection.PendingConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Example 20 with EventHandler

use of net.md_5.bungee.event.EventHandler in project ViaCheckConnection by x9nico.

the class Bungee method join.

@SuppressWarnings({ "unchecked" })
@EventHandler
public void join(ServerConnectedEvent e) throws IOException {
    ProxiedPlayer p = e.getPlayer();
    Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
    if (Bungee.isProtocolSupport()) {
        if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_8.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_8").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_2.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_2").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_3.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_3").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_10.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_10").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_11").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_11_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.unknown.getId()) {
            p.sendMessage(new TextComponent(config.getString("unknown_version").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_7_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_7_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_7_6.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_7_6").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_2.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12_2").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_13.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_13").replace("&", "§")));
        }
    } else {
        if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_8.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_8").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_2.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_2").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_3.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_3").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_10.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_10").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_11").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_11_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.unknown.getId()) {
            p.sendMessage(new TextComponent(config.getString("unknown_version").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_2.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12_2").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_13.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_13").replace("&", "§")));
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) File(java.io.File) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

EventHandler (net.md_5.bungee.event.EventHandler)37 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)20 TextComponent (net.md_5.bungee.api.chat.TextComponent)7 IOException (java.io.IOException)5 User (me.lucko.luckperms.common.model.User)4 EventHandler (org.bukkit.event.EventHandler)4 UserPreference (com.github.games647.changeskin.core.model.UserPreference)3 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)3 PacketSpyAction (fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction)3 Message (io.github.lxgaming.discordbot.entries.Message)3 Tristate (me.lucko.luckperms.api.Tristate)3 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)3 PendingConnection (net.md_5.bungee.api.connection.PendingConnection)3 Entity (org.bukkit.entity.Entity)3 Player (org.bukkit.entity.Player)3 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2