· 5 years ago · Jan 25, 2020, 01:34 PM
1//
2// Decompiled by Procyon v0.5.36
3//
4
5package com.jakubson.premium.listener;
6
7import net.md_5.bungee.connection.LoginResult;
8import java.lang.reflect.Field;
9import net.md_5.bungee.protocol.packet.Handshake;
10import net.md_5.bungee.api.connection.PendingConnection;
11import com.jakubson.premium.system.PasswordManager;
12import net.md_5.bungee.connection.InitialHandler;
13import net.md_5.bungee.event.EventHandler;
14import com.jakubson.premium.data.Connection;
15import com.jakubson.premium.system.MySQLManager;
16import java.util.UUID;
17import com.jakubson.premium.data.Cache;
18import com.jakubson.premium.data.User;
19import net.md_5.bungee.api.chat.TextComponent;
20import net.md_5.bungee.api.ChatColor;
21import com.jakubson.premium.data.util.UserUtils;
22import net.md_5.bungee.api.ProxyServer;
23import net.md_5.bungee.api.plugin.Plugin;
24import com.jakubson.premium.JPremium;
25import com.jakubson.premium.system.ConfigManager;
26import net.md_5.bungee.api.event.LoginEvent;
27import net.md_5.bungee.api.plugin.Listener;
28
29public class Login implements Listener
30{
31 @EventHandler(priority = -100)
32 public void onLoginFirst(final LoginEvent event) {
33 if (event.isCancelled()) {
34 return;
35 }
36 if (!ConfigManager.getInstance().getSettings().isFixedUniqueId()) {
37 return;
38 }
39 event.registerIntent((Plugin)JPremium.getInstance());
40 final String nickname;
41 final Connection connection;
42 String preServersNotResponding;
43 String serversNotResponding;
44 User user;
45 Cache cache;
46 UUID newIndex;
47 String language;
48 UUID newIndex2;
49 ProxyServer.getInstance().getScheduler().runAsync((Plugin)JPremium.getInstance(), () -> {
50 nickname = event.getConnection().getName();
51 connection = UserUtils.checkPremium(nickname);
52 if (!connection.isFeedback()) {
53 preServersNotResponding = ConfigManager.getInstance().getDefaultMessages().getServersNotResponding();
54 serversNotResponding = ChatColor.translateAlternateColorCodes('&', preServersNotResponding);
55 event.setCancelReason(TextComponent.fromLegacyText(serversNotResponding));
56 event.setCancelled(true);
57 event.completeIntent((Plugin)JPremium.getInstance());
58 }
59 else if (UserUtils.isUserExits(nickname)) {
60 user = User.get(nickname);
61 this.changeUniqueId(user.getIndex(), event);
62 this.changeSkin(user.getIndex(), connection, event);
63 event.completeIntent((Plugin)JPremium.getInstance());
64 }
65 else {
66 if (connection.isPremium()) {
67 if (UserUtils.isCacheExits(connection.getUniqueId())) {
68 cache = UserUtils.getCache().get(connection.getUniqueId());
69 this.changeUniqueId(cache.getIndex(), event);
70 this.changeSkin(cache.getIndex(), connection, event);
71 event.completeIntent((Plugin)JPremium.getInstance());
72 return;
73 }
74 else if (ConfigManager.getInstance().getSettings().isAutoLoginPremium()) {
75 newIndex = UUID.randomUUID();
76 language = ConfigManager.getInstance().getSettings().getDefaultLanguage();
77 UserUtils.addCache(connection.getUniqueId(), new Cache(newIndex, language));
78 MySQLManager.getInstance().createUser(connection.getUniqueId(), newIndex, language);
79 this.changeUniqueId(newIndex, event);
80 this.changeSkin(newIndex, connection, event);
81 event.completeIntent((Plugin)JPremium.getInstance());
82 return;
83 }
84 }
85 newIndex2 = UUID.randomUUID();
86 this.changeUniqueId(newIndex2, event);
87 this.changeSkin(newIndex2, connection, event);
88 event.completeIntent((Plugin)JPremium.getInstance());
89 }
90 });
91 }
92
93 @EventHandler(priority = Byte.MAX_VALUE)
94 public void onLoginSecond(final LoginEvent event) {
95 if (event.isCancelled()) {
96 return;
97 }
98 final PendingConnection pendingConnection = event.getConnection();
99 final Handshake handshake = ((InitialHandler)pendingConnection).getHandshake();
100 final String nickname = pendingConnection.getName();
101 final String secretKey = ConfigManager.getInstance().getSettings().getSecretKey();
102 final String hash = PasswordManager.getInstance().hash(nickname + secretKey);
103 handshake.setHost(hash);
104 handshake.setPort(1337);
105 }
106
107 private void changeUniqueId(final UUID index, final LoginEvent event) {
108 try {
109 final Class<?> initialHandlerClass = event.getConnection().getClass();
110 final Field uniqueIdField = initialHandlerClass.getDeclaredField("uniqueId");
111 uniqueIdField.setAccessible(true);
112 uniqueIdField.set(event.getConnection(), index);
113 }
114 catch (Exception exception) {
115 event.setCancelReason(TextComponent.fromLegacyText("Could not change your unique id!"));
116 event.setCancelled(true);
117 exception.printStackTrace();
118 }
119 }
120
121 private void changeSkin(final UUID index, final Connection connection, final LoginEvent event) {
122 if (!connection.hasTextures()) {
123 return;
124 }
125 try {
126 final Connection.Textures textures = connection.getTextures();
127 final LoginResult.Property property = new LoginResult.Property("textures", textures.getValue(), textures.getSignature());
128 final LoginResult loginResult = new LoginResult(index.toString(), connection.getNickName(), new LoginResult.Property[] { property });
129 final Class<?> initialHandlerClass = event.getConnection().getClass();
130 final Field loginProfile = initialHandlerClass.getDeclaredField("loginProfile");
131 loginProfile.setAccessible(true);
132 loginProfile.set(event.getConnection(), loginResult);
133 }
134 catch (Exception exception) {
135 event.setCancelReason(TextComponent.fromLegacyText("Could not change your skin"));
136 event.setCancelled(true);
137 exception.printStackTrace();
138 }
139 }
140}