50 lines
1.6 KiB
Java
50 lines
1.6 KiB
Java
package net.ME1312.SubServers.Sync.Network.Packet;
|
|
|
|
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
|
import net.ME1312.SubServers.Sync.Library.Util;
|
|
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
|
import net.ME1312.SubServers.Sync.Network.PacketIn;
|
|
import net.ME1312.SubServers.Sync.Network.PacketOut;
|
|
import net.ME1312.SubServers.Sync.Network.SubDataClient;
|
|
import net.ME1312.SubServers.Sync.SubPlugin;
|
|
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Method;
|
|
|
|
public final class PacketAuthorization implements PacketIn, PacketOut {
|
|
private SubPlugin plugin;
|
|
private String password;
|
|
|
|
public PacketAuthorization(SubPlugin plugin, String password) {
|
|
if (Util.isNull(plugin)) throw new NullPointerException();
|
|
this.plugin = plugin;
|
|
this.password = password;
|
|
}
|
|
|
|
@Override
|
|
public YAMLSection generate() {
|
|
YAMLSection json = new YAMLSection();
|
|
json.set("password", password);
|
|
return json;
|
|
}
|
|
|
|
@Override
|
|
public void execute(YAMLSection data) {
|
|
try {
|
|
if (data.getInt("r") == 0) {
|
|
Util.isException(() -> Util.reflect(SubDataClient.class.getDeclaredMethod("init"), plugin.subdata));
|
|
} else {
|
|
System.out.println("SubServers > Could not authorize SubData connection: " + data.getRawString("m"));
|
|
plugin.subdata.destroy(0);
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Version getVersion() {
|
|
return new Version("2.11.0a");
|
|
}
|
|
}
|