SubServers-2/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadProxyInfo.java

80 lines
2.7 KiB
Java
Raw Normal View History

2017-04-10 05:39:22 +02:00
package net.ME1312.SubServers.Bungee.Network.Packet;
2019-04-18 16:02:09 +02:00
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
2020-11-16 21:34:59 +01:00
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.Proxy;
import net.ME1312.SubServers.Bungee.SubProxy;
2017-04-10 05:39:22 +02:00
import java.util.Arrays;
import java.util.List;
2019-04-18 16:02:09 +02:00
import java.util.UUID;
2017-04-10 05:39:22 +02:00
/**
* Download Proxy Info Packet
*/
2019-04-18 16:02:09 +02:00
public class PacketDownloadProxyInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private SubProxy plugin;
private String[] proxies;
2019-04-18 16:02:09 +02:00
private UUID tracker;
2017-04-10 05:39:22 +02:00
/**
* New PacketDownloadProxyInfo (In)
*
* @param plugin SubPlugin
*/
public PacketDownloadProxyInfo(SubProxy plugin) {
Util.nullpo(plugin);
2017-04-10 05:39:22 +02:00
this.plugin = plugin;
}
/**
* New PacketDownloadProxyInfo (Out)
*
* @param plugin SubPlugin
* @param proxies Proxies (or null for all)
2019-04-18 16:02:09 +02:00
* @param tracker Receiver ID
2017-04-10 05:39:22 +02:00
*/
public PacketDownloadProxyInfo(SubProxy plugin, List<String> proxies, UUID tracker) {
Util.nullpo(plugin);
2017-04-10 05:39:22 +02:00
this.plugin = plugin;
2019-04-18 16:02:09 +02:00
this.tracker = tracker;
if (proxies != null) {
this.proxies = new String[proxies.size()];
for (int i = 0; i < this.proxies.length; ++i) this.proxies[i] = proxies.get(i).toLowerCase();
Arrays.sort(this.proxies);
}
2017-04-10 05:39:22 +02:00
}
@Override
2019-04-18 16:02:09 +02:00
public ObjectMap<Integer> send(SubDataClient client) {
ObjectMap<Integer> data = new ObjectMap<Integer>();
if (tracker != null) data.set(0x0000, tracker);
2019-04-18 16:02:09 +02:00
ObjectMap<String> proxies = new ObjectMap<String>();
for (Proxy proxy : plugin.api.getProxies().values()) {
if (this.proxies == null || Arrays.binarySearch(this.proxies, proxy.getName().toLowerCase()) >= 0) {
2019-04-18 16:02:09 +02:00
proxies.set(proxy.getName(), proxy.forSubData());
}
}
2019-04-18 16:02:09 +02:00
data.set(0x0001, proxies);
2021-06-12 00:16:05 +02:00
if (this.proxies != null && plugin.api.getMasterProxy() != null && (this.proxies.length <= 0 || Arrays.binarySearch(this.proxies, plugin.api.getMasterProxy().getName().toLowerCase()) >= 0)) {
data.set(0x0002, plugin.api.getMasterProxy().forSubData());
}
return data;
2017-04-10 05:39:22 +02:00
}
@Override
2019-04-18 16:02:09 +02:00
public void receive(SubDataClient client, ObjectMap<Integer> data) {
client.sendPacket(new PacketDownloadProxyInfo(plugin, (data.contains(0x0001))?data.getStringList(0x0001):null, (data.contains(0x0000))?data.getUUID(0x0000):null));
2017-04-10 05:39:22 +02:00
}
@Override
2019-04-18 16:02:09 +02:00
public int version() {
return 0x0001;
2017-04-10 05:39:22 +02:00
}
}