/
PacketLinkProxy.java
78 lines (72 loc) · 2.79 KB
/
PacketLinkProxy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package net.ME1312.SubServers.Sync.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.Protocol.Initial.InitialPacket;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Sync.ExProxy;
import net.ME1312.SubServers.Sync.SubAPI;
/**
* Link Proxy Packet
*/
public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private ExProxy plugin;
private int channel;
/**
* New PacketLinkProxy (In)
*
* @param plugin SubServers.Client
*/
public PacketLinkProxy(ExProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
this.plugin = plugin;
}
/**
* New PacketLinkProxy (Out)
*
* @param plugin SubServers.Client
* @param channel Channel ID
*/
public PacketLinkProxy(ExProxy plugin, int channel) {
if (Util.isNull(plugin)) throw new NullPointerException();
this.plugin = plugin;
this.channel = channel;
}
@Override
public ObjectMap<Integer> send(SubDataSender client) {
ObjectMap<Integer> json = new ObjectMap<Integer>();
json.set(0x0000, plugin.api.getName());
json.set(0x0001, channel);
return json;
}
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (data.getInt(0x0001) == 0) {
try {
if (data.contains(0x0000)) Util.reflect(SubAPI.class.getDeclaredField("name"), plugin.api, data.getRawString(0x0000));
setReady(client.getConnection());
} catch (Throwable e) {
e.printStackTrace();
}
} else {
Logger.get("SubData").info("Could not link name with proxy" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
try {
if (data.getInt(0x0001) == 2) {
if (!plugin.config.get().getMap("Settings").getMap("SubData").contains("Name")) {
plugin.config.get().getMap("Settings").getMap("SubData").set("Name", "");
plugin.config.save();
}
if (plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Name").length() <= 0)
Logger.get("SubData").info("Use the proxy \"Name\" option to override auto-linking");
}
} catch (Exception e) {}
new IllegalStateException().printStackTrace();
}
}
@Override
public int version() {
return 0x0001;
}
}