Skip to content

Commit

Permalink
Add a post-connect subdata event
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Jun 18, 2019
1 parent 03ece29 commit 3af2087
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.ME1312.SubServers.Bungee.Event;

import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.DataClient;
import net.ME1312.SubData.Server.DataServer;
import net.ME1312.SubServers.Bungee.Library.SubEvent;
import net.md_5.bungee.api.plugin.Cancellable;
import net.md_5.bungee.api.plugin.Event;

/**
* SubData Network Login Event
*/
public class SubNetworkLoginEvent extends Event implements SubEvent {
private DataServer network;
private DataClient client;

/**
* SubData Network Login Event
*/
public SubNetworkLoginEvent(DataServer network, DataClient client) {
if (Util.isNull(network, client)) throw new NullPointerException();
this.network = network;
this.client = client;
}

/**
* Get the network the client is connected to
*
* @return SubData Network
*/
public DataServer getNetwork() {
return network;
}

/**
* Get the connecting client
*
* @return Client
*/
public DataClient getClient() {
return client;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Host;

import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubServers.Bungee.Event.SubEditServerEvent;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.SubServers.Bungee.SubAPI;
Expand Down Expand Up @@ -63,6 +64,7 @@ public boolean isAvailable() {

@Override
public void setTemplate(SubCreator.ServerTemplate template) {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("template", (template != null)?template.getName():null), false));
this.template = (template != null)?template.getName():null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.ME1312.SubData.Server.SubDataServer;
import net.ME1312.SubServers.Bungee.Event.SubNetworkConnectEvent;
import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
import net.ME1312.SubServers.Bungee.Event.SubNetworkLoginEvent;
import net.ME1312.SubServers.Bungee.Network.Packet.*;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.ME1312.SubServers.Bungee.SubPlugin;
Expand All @@ -31,7 +32,7 @@ public static SubProtocol get() {
instance.setVersion(new Version("2.14a+"));


// 00-09: Object Link Packets
// 00-0F: Object Link Packets
instance.registerPacket(0x0000, PacketLinkProxy.class);
instance.registerPacket(0x0001, PacketLinkExHost.class);
instance.registerPacket(0x0002, PacketLinkServer.class);
Expand All @@ -41,7 +42,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0002, new PacketLinkServer(plugin));


// 10-29: Download Packets
// 10-2F: Download Packets
instance.registerPacket(0x0010, PacketDownloadLang.class);
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
Expand All @@ -61,7 +62,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0017, new PacketCheckPermission());


// 30-49: Control Packets
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
Expand All @@ -85,7 +86,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0039, new PacketDeleteServer(plugin));


// 50-69: External Host Packets
// 50-6F: External Host Packets
instance.registerPacket(0x0050, PacketExConfigureHost.class);
instance.registerPacket(0x0051, PacketExDownloadTemplates.class);
//instance.registerPacket(0x0052, PacketInExRequestQueue.class);
Expand All @@ -107,7 +108,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0058, new PacketExRemoveServer());


// 70-79: External Misc Packets
// 70-7F: External Misc Packets
instance.registerPacket(0x0070, PacketOutExRunEvent.class);
instance.registerPacket(0x0071, PacketOutExReset.class);
instance.registerPacket(0x0072, PacketOutExReload.class);
Expand All @@ -133,6 +134,7 @@ public SubDataServer open(Callback<Runnable> scheduler, Logger logger, InetAddre
subdata.on.closed(server -> plugin.subdata = null);
subdata.on.connect(client -> {
if (!plugin.getPluginManager().callEvent(new SubNetworkConnectEvent(client.getServer(), client)).isCancelled()) {
client.on.ready(c -> plugin.getPluginManager().callEvent(new SubNetworkLoginEvent(c.getServer(), c)));
client.on.closed(c -> plugin.getPluginManager().callEvent(new SubNetworkDisconnectEvent(c.get().getServer(), c.get(), c.name())));
return true;
} else return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void reload() throws IOException {


if (edits.getKeys().size() > 0) {
server.permaEdit(edits);
server.edit(edits);
server = api.getSubServer(name);
}
} else { // Server cannot edit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public static SubProtocol get() {
instance.addVersion(new Version("2.14a+"));


// 00-09: Object Link Packets
// 00-0F: Object Link Packets
instance.registerPacket(0x0002, PacketLinkServer.class);
instance.registerPacket(0x0002, new PacketLinkServer(plugin));


// 10-29: Download Packets
// 10-2F: Download Packets
instance.registerPacket(0x0010, PacketDownloadLang.class);
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
Expand All @@ -60,7 +60,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0017, new PacketCheckPermission());


// 30-49: Control Packets
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
Expand All @@ -84,7 +84,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0039, new PacketDeleteServer());


// 70-79: External Misc Packets
// 70-7F: External Misc Packets
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
//instance.registerPacket(0x0071, PacketInExReset.class);
//instance.registerPacket(0x0072, PacketInExReload.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public static SubProtocol get() {
instance.addVersion(new Version("2.14a+"));


// 00-09: Object Link Packets
// 00-0F: Object Link Packets
instance.registerPacket(0x0002, PacketLinkServer.class);
instance.registerPacket(0x0002, new PacketLinkServer(plugin));


// 10-29: Download Packets
// 10-2F: Download Packets
instance.registerPacket(0x0010, PacketDownloadLang.class);
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
Expand All @@ -67,7 +67,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0017, new PacketCheckPermission());


// 30-49: Control Packets
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
Expand All @@ -91,7 +91,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0039, new PacketDeleteServer());


// 70-79: External Misc Packets
// 70-7F: External Misc Packets
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
//instance.registerPacket(0x0071, PacketInExReset.class);
//instance.registerPacket(0x0072, PacketInExReload.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public static SubProtocol get() {
instance.addVersion(new Version("2.14a+"));


// 00-09: Object Link Packets
// 00-0F: Object Link Packets
instance.registerPacket(0x0001, PacketLinkExHost.class);

instance.registerPacket(0x0001, new PacketLinkExHost(host));


// 10-29: Download Packets
// 10-2F: Download Packets
instance.registerPacket(0x0010, PacketDownloadLang.class);
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
Expand All @@ -63,7 +63,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0017, new PacketCheckPermission());


// 30-49: Control Packets
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
Expand All @@ -87,7 +87,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0039, new PacketDeleteServer());


// 50-69: External Host Packets
// 50-6F: External Host Packets
instance.registerPacket(0x0050, PacketExConfigureHost.class);
instance.registerPacket(0x0051, PacketExDownloadTemplates.class);
instance.registerPacket(0x0052, PacketOutExRequestQueue.class);
Expand All @@ -109,7 +109,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0058, new PacketExRemoveServer(host));


// 70-79: External Misc Packets
// 70-7F: External Misc Packets
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
//instance.registerPacket(0x0071, PacketInExReset.class);
//instance.registerPacket(0x0072, PacketInExReload.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public static SubProtocol get() {
instance.addVersion(new Version("2.14a+"));


// 00-09: Object Link Packets
// 00-0F: Object Link Packets
instance.registerPacket(0x0000, PacketLinkProxy.class);
instance.registerPacket(0x0000, new PacketLinkProxy(plugin));


// 10-29: Download Packets
// 10-2F: Download Packets
instance.registerPacket(0x0010, PacketDownloadLang.class);
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
Expand All @@ -68,7 +68,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0017, new PacketCheckPermission());


// 30-49: Control Packets
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
Expand All @@ -92,7 +92,7 @@ public static SubProtocol get() {
instance.registerPacket(0x0039, new PacketDeleteServer());


// 70-79: External Misc Packets
// 70-7F: External Misc Packets
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
//instance.registerPacket(0x0071, PacketInExReset.class);
//instance.registerPacket(0x0073, PacketInExReload.class);
Expand Down

0 comments on commit 3af2087

Please sign in to comment.