mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 02:08:27 +01:00
Add SubCreatedEvent
This commit is contained in:
parent
73c402fc53
commit
51d3c31220
@ -44,6 +44,13 @@ public class SubCreateEvent extends Event implements SubEvent, Cancellable {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Server Create Event (as an Update)
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @param server Server to be Updated
|
||||
* @param version Server Version
|
||||
*/
|
||||
public SubCreateEvent(UUID player, SubServer server, Version version) {
|
||||
if (Util.isNull(server)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
@ -78,7 +85,7 @@ public class SubCreateEvent extends Event implements SubEvent, Cancellable {
|
||||
*
|
||||
* @return Updating Server
|
||||
*/
|
||||
public SubServer getUpdating() {
|
||||
public SubServer getUpdatingServer() {
|
||||
return update;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,131 @@
|
||||
package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*/
|
||||
public class SubCreatedEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private SubServer server;
|
||||
private boolean success;
|
||||
private boolean update;
|
||||
private Host host;
|
||||
private String name;
|
||||
private SubCreator.ServerTemplate template;
|
||||
private Version version;
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param host Potential Host
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param server Server Object
|
||||
* @param update Update Mode Status
|
||||
* @param success Success Status
|
||||
*/
|
||||
public SubCreatedEvent(UUID player, Host host, String name, SubCreator.ServerTemplate template, Version version, int port, SubServer server, boolean update, boolean success) {
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.server = server;
|
||||
this.update = update;
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Host the SubServer runs on
|
||||
*
|
||||
* @return Host
|
||||
*/
|
||||
public Host getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator was being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean wasUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the operation was a success
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean wasSuccessful() {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that was created/updated
|
||||
*
|
||||
* @return Finished Server
|
||||
*/
|
||||
public SubServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer used
|
||||
*
|
||||
* @return SubServer Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Template that was used
|
||||
*
|
||||
* @return Server Template
|
||||
*/
|
||||
public SubCreator.ServerTemplate getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server used
|
||||
*
|
||||
* @return Server Version
|
||||
*/
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server used
|
||||
*
|
||||
* @return Port Number
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
*
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
}
|
@ -6,6 +6,7 @@ import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Callback.ReturnCallback;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubCreatedEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
@ -146,9 +147,11 @@ public class ExternalSubCreator extends SubCreator {
|
||||
if (template.getBuildOptions().getBoolean("Run-On-Finish", true))
|
||||
subserver.start();
|
||||
|
||||
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, fport, subserver, false, true));
|
||||
callback(origin, callback, subserver);
|
||||
} else {
|
||||
Logger.get(prefix).info(data.getString(0x0004));
|
||||
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, fport, null, false, false));
|
||||
callback(origin, callback, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -220,6 +223,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
Logger.get(prefix).info(data.getString(0x0004));
|
||||
}
|
||||
|
||||
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, server.getTemplate(), version, server.getAddress().getPort(), server, true, data.getInt(0x0001) == 0));
|
||||
if (callback != null) try {
|
||||
callback.run(data.getInt(0x0001) == 0);
|
||||
} catch (Throwable e) {
|
||||
|
@ -7,6 +7,7 @@ import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Callback.ReturnCallback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubCreatedEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
@ -263,13 +264,17 @@ public class InternalSubCreator extends SubCreator {
|
||||
}
|
||||
|
||||
InternalSubCreator.this.thread.remove(name.toLowerCase());
|
||||
|
||||
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, port, subserver, update != null, true));
|
||||
callback.run(subserver);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, port, update, update != null, false));
|
||||
callback.run(null);
|
||||
}
|
||||
} else {
|
||||
Logger.get(prefix).info("Couldn't build the server jar. Check the SubCreator logs for more detail.");
|
||||
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, port, update, update != null, false));
|
||||
callback.run(null);
|
||||
}
|
||||
InternalSubCreator.this.thread.remove(name.toLowerCase());
|
||||
|
@ -117,6 +117,20 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubCreatedEvent event) {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("success", event.wasSuccessful());
|
||||
args.set("update", event.wasUpdate());
|
||||
args.set("name", event.getName());
|
||||
args.set("host", event.getHost().getName());
|
||||
args.set("template", event.getTemplate().getName());
|
||||
if (event.getVersion() != null) args.set("version", event.getVersion());
|
||||
args.set("port", event.getPort());
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubSendCommandEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
|
@ -68,7 +68,7 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getUpdating(Callback<SubServer> callback) {
|
||||
public void getUpdatingServer(Callback<SubServer> callback) {
|
||||
if (!update) {
|
||||
try {
|
||||
callback.run(null);
|
||||
@ -99,15 +99,6 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Template to Use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void getTemplate(String value) {
|
||||
this.template = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server will use
|
||||
*
|
||||
@ -117,15 +108,6 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Version the Server will use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setVersion(Version value) {
|
||||
this.version = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server will use
|
||||
*
|
||||
|
@ -0,0 +1,146 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*/
|
||||
public class SubCreatedEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private boolean success;
|
||||
private boolean update;
|
||||
private String host;
|
||||
private String name;
|
||||
private String template;
|
||||
private Version version;
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param host Potential Host
|
||||
* @param name Server Name
|
||||
* @param template Server Type
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreatedEvent(UUID player, String host, String name, String template, Version version, int port, boolean update, boolean success) {
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.success = success;
|
||||
this.update = update;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Host the SubServer runs on
|
||||
*
|
||||
* @return Host
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator was being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean wasUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the operation was a success
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean wasSuccessful() {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getServer(Callback<SubServer> callback) {
|
||||
if (!update && !success) {
|
||||
try {
|
||||
callback.run(null);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
SubAPI.getInstance().getSubServer(name, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer used
|
||||
*
|
||||
* @return SubServer Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Template that was used
|
||||
*
|
||||
* @return Server Template
|
||||
*/
|
||||
public String getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server used
|
||||
*
|
||||
* @return Server Version
|
||||
*/
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server used
|
||||
*
|
||||
* @return Port Number
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
*
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -51,15 +51,6 @@ public class SubSendCommandEvent extends Event implements SubEvent {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Command to be Sent
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setCommand(String value) {
|
||||
command = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
|
@ -62,6 +62,16 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
}
|
||||
}
|
||||
});
|
||||
callback("SubCreatedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
if (plugin.isEnabled()) {
|
||||
Bukkit.getPluginManager().callEvent(new SubCreatedEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host"), data.getString("name"),
|
||||
data.getString("template"), (data.contains("version"))?new Version(data.getString("version")):null, data.getInt("port"), data.getBoolean("update"), data.getBoolean("success")));
|
||||
callback("SubCreatedEvent", this);
|
||||
}
|
||||
}
|
||||
});
|
||||
callback("SubSendCommandEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
|
@ -68,7 +68,7 @@ public class SubCreateEvent extends AbstractEvent implements SubEvent {
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getUpdating(Callback<SubServer> callback) {
|
||||
public void getUpdatingServer(Callback<SubServer> callback) {
|
||||
if (!update) {
|
||||
try {
|
||||
callback.run(null);
|
||||
@ -99,15 +99,6 @@ public class SubCreateEvent extends AbstractEvent implements SubEvent {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Template to Use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void getTemplate(String value) {
|
||||
this.template = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server will use
|
||||
*
|
||||
@ -117,15 +108,6 @@ public class SubCreateEvent extends AbstractEvent implements SubEvent {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Version the Server will use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setVersion(Version value) {
|
||||
this.version = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server will use
|
||||
*
|
||||
|
@ -0,0 +1,149 @@
|
||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*/
|
||||
public class SubCreatedEvent extends AbstractEvent implements SubEvent {
|
||||
private UUID player;
|
||||
private boolean success;
|
||||
private boolean update;
|
||||
private String host;
|
||||
private String name;
|
||||
private String template;
|
||||
private Version version;
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param host Potential Host
|
||||
* @param name Server Name
|
||||
* @param template Server Type
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreatedEvent(UUID player, String host, String name, String template, Version version, int port, boolean update, boolean success) {
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.success = success;
|
||||
this.update = update;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Host the SubServer runs on
|
||||
*
|
||||
* @return Host
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator was being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean wasUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the operation was a success
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean wasSuccessful() {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getServer(Callback<SubServer> callback) {
|
||||
if (!update && !success) {
|
||||
try {
|
||||
callback.run(null);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
SubAPI.getInstance().getSubServer(name, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer used
|
||||
*
|
||||
* @return SubServer Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Template that was used
|
||||
*
|
||||
* @return Server Template
|
||||
*/
|
||||
public String getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server used
|
||||
*
|
||||
* @return Server Version
|
||||
*/
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server used
|
||||
*
|
||||
* @return Port Number
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
*
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
/**
|
||||
* Gets the cause of this Event
|
||||
*
|
||||
* @deprecated Use simplified methods where available
|
||||
* @return The player UUID who triggered this event
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Cause getCause() {
|
||||
return Cause.builder().append(player).build(getContext());
|
||||
}
|
||||
}
|
@ -51,15 +51,6 @@ public class SubSendCommandEvent extends AbstractEvent implements SubEvent {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Command to be Sent
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setCommand(String value) {
|
||||
command = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cause of this Event
|
||||
*
|
||||
|
@ -54,6 +54,14 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubCreatedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
Sponge.getEventManager().post(new SubCreatedEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host"), data.getString("name"),
|
||||
data.getString("template"), new Version(data.getString("version")), data.getInt("port"), data.getBoolean("update"), data.getBoolean("success")));
|
||||
callback("SubCreatedEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubSendCommandEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
|
@ -66,7 +66,7 @@ public class SubCreateEvent extends Event {
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getUpdating(Callback<SubServer> callback) {
|
||||
public void getUpdatingServer(Callback<SubServer> callback) {
|
||||
if (!update) {
|
||||
try {
|
||||
callback.run(null);
|
||||
@ -97,15 +97,6 @@ public class SubCreateEvent extends Event {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Template to Use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void getTemplate(String value) {
|
||||
this.template = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server will use
|
||||
*
|
||||
@ -115,15 +106,6 @@ public class SubCreateEvent extends Event {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Version the Server will use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setVersion(Version value) {
|
||||
this.version = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server will use
|
||||
*
|
||||
|
@ -0,0 +1,135 @@
|
||||
package net.ME1312.SubServers.Host.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Event.Event;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*/
|
||||
public class SubCreatedEvent extends Event {
|
||||
private UUID player;
|
||||
private boolean success;
|
||||
private boolean update;
|
||||
private String host;
|
||||
private String name;
|
||||
private String template;
|
||||
private Version version;
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param host Potential Host
|
||||
* @param name Server Name
|
||||
* @param template Server Type
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreatedEvent(UUID player, String host, String name, String template, Version version, int port, boolean update, boolean success) {
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.success = success;
|
||||
this.update = update;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Host the SubServer runs on
|
||||
*
|
||||
* @return Host
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator was being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean wasUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the operation was a success
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean wasSuccessful() {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getServer(Callback<SubServer> callback) {
|
||||
if (!update && !success) {
|
||||
try {
|
||||
callback.run(null);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
SubAPI.getInstance().getSubServer(name, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer used
|
||||
*
|
||||
* @return SubServer Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Template that was used
|
||||
*
|
||||
* @return Server Template
|
||||
*/
|
||||
public String getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server used
|
||||
*
|
||||
* @return Server Version
|
||||
*/
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server used
|
||||
*
|
||||
* @return Port Number
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
*
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
}
|
@ -48,13 +48,4 @@ public class SubSendCommandEvent extends Event {
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Command to be Sent
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setCommand(String value) {
|
||||
command = value;
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,14 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubCreatedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubCreatedEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host"), data.getRawString("name"),
|
||||
data.getRawString("template"), data.getVersion("version"), data.getInt("port"), data.getBoolean("update"), data.getBoolean("success")));
|
||||
callback("SubCreatedEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubSendCommandEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
|
@ -67,7 +67,7 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getUpdating(Callback<SubServer> callback) {
|
||||
public void getUpdatingServer(Callback<SubServer> callback) {
|
||||
if (!update) {
|
||||
try {
|
||||
callback.run(null);
|
||||
@ -98,15 +98,6 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Template to Use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void getTemplate(String value) {
|
||||
this.template = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server will use
|
||||
*
|
||||
@ -116,15 +107,6 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Version the Server will use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setVersion(Version value) {
|
||||
this.version = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server will use
|
||||
*
|
||||
|
@ -0,0 +1,136 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*/
|
||||
public class SubCreatedEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private boolean success;
|
||||
private boolean update;
|
||||
private String host;
|
||||
private String name;
|
||||
private String template;
|
||||
private Version version;
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* Server Created Event
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param host Potential Host
|
||||
* @param name Server Name
|
||||
* @param template Server Type
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreatedEvent(UUID player, String host, String name, String template, Version version, int port, boolean update, boolean success) {
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.success = success;
|
||||
this.update = update;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Host the SubServer runs on
|
||||
*
|
||||
* @return Host
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator was being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean wasUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the operation was a success
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean wasSuccessful() {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getServer(Callback<SubServer> callback) {
|
||||
if (!update && !success) {
|
||||
try {
|
||||
callback.run(null);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
SubAPI.getInstance().getSubServer(name, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer used
|
||||
*
|
||||
* @return SubServer Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Template that was used
|
||||
*
|
||||
* @return Server Template
|
||||
*/
|
||||
public String getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server used
|
||||
*
|
||||
* @return Server Version
|
||||
*/
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server used
|
||||
*
|
||||
* @return Port Number
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
*
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
}
|
@ -49,13 +49,4 @@ public class SubSendCommandEvent extends Event implements SubEvent {
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Command to be Sent
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setCommand(String value) {
|
||||
command = value;
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,14 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubCreatedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubCreatedEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host"), data.getRawString("name"),
|
||||
data.getRawString("template"), data.getVersion("version"), data.getInt("port"), data.getBoolean("update"), data.getBoolean("success")));
|
||||
callback("SubCreatedEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubSendCommandEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
|
Loading…
Reference in New Issue
Block a user