Don't fire edit events for temporary modifications

This commit is contained in:
ME1312 2021-06-06 01:28:22 -04:00
parent e1de6636f0
commit 4d081f6e4f
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
22 changed files with 175 additions and 160 deletions

View File

@ -21,7 +21,6 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
private UUID player;
private Server server;
private Pair<String, ObjectMapValue> edit;
private boolean perm;
/**
* Server Edit Event
@ -29,16 +28,14 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
* @param player Player Adding Server
* @param server Server to be Edited
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, Server server, Pair<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, Server server, Pair<String, ?> edit) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new ContainedPair<String, ObjectMapValue>(edit.key(), section.get("."));
this.perm = permanent;
}
/**
@ -64,15 +61,6 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
return edit;
}
/**
* Gets if the edit is permanent
*
* @return Permanent Status
*/
public boolean isPermanent() {
return perm;
}
/**
* Gets the Cancelled Status
*

View File

@ -108,7 +108,7 @@ public class ExternalHost extends Host implements ClientHandler {
clean = true;
}
for (SubServer server : servers.values()) {
client.sendPacket(new PacketExAddServer(server.getName(), server.isEnabled(), server.getAddress().getPort(), server.isLogging(), server.getPath(), ((ExternalSubServer) server).exec, server.getStopCommand(), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
client.sendPacket(new PacketExAddServer((ExternalSubServer) server, (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
if (data.contains(0x0002)) ((ExternalSubServer) server).started(data.getUUID(0x0002));
}));
}
@ -166,19 +166,24 @@ public class ExternalHost extends Host implements ClientHandler {
}
@Override
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
ExternalSubServer server = ExternalSubServer.construct(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
public SubServer constructSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
return ExternalSubServer.construct(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
}
@Override
public boolean addSubServer(UUID player, SubServer server) throws InvalidServerException {
if (server.getHost() != this) throw new IllegalArgumentException("That Server does not belong to this Host!");
if (plugin.api.getServers().keySet().contains(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
queue(new PacketExAddServer(name, enabled, port, log, directory, executable, stopcmd, (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
if (data.contains(0x0002)) server.started(data.getUUID(0x0002));
queue(new PacketExAddServer(((ExternalSubServer) server), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
if (data.contains(0x0002)) ((ExternalSubServer) server).started(data.getUUID(0x0002));
}));
servers.put(name.toLowerCase(), server);
return server;
servers.put(server.getName().toLowerCase(), server);
return true;
} else {
return null;
return false;
}
}

View File

@ -203,7 +203,7 @@ public class ExternalSubCreator extends SubCreator {
server.setAll(config);
if (update != null) Util.isException(() -> update.getHost().forceRemoveSubServer(name));
subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"),
subserver = host.constructSubServer(name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"),
server.getRawString("Directory"), server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
@ -220,6 +220,7 @@ public class ExternalSubCreator extends SubCreator {
host.plugin.servers.save();
}
host.addSubServer(subserver);
if (update == null && template.getBuildOptions().getBoolean("Run-On-Finish", true))
subserver.start();
}

View File

@ -227,14 +227,18 @@ public class ExternalSubServer extends SubServerImpl {
for (String key : edit.getKeys()) {
pending.remove(key);
ObjectMapValue value = edit.get(key);
SubEditServerEvent event = new SubEditServerEvent(player, this, new ContainedPair<String, ObjectMapValue>(key, value), perma);
host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
boolean allowed = true;
if (perma) {
SubEditServerEvent event = new SubEditServerEvent(player, this, new ContainedPair<String, ObjectMapValue>(key, value));
host.plugin.getPluginManager().callEvent(event);
allowed = !event.isCancelled();
}
if (allowed) {
try {
switch (key.toLowerCase()) {
case "name":
if (value.isString() && host.removeSubServer(player, getName())) {
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
SubServer server = host.constructSubServer(value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
if (server != null) {
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
ObjectMap<String> config = this.host.plugin.servers.get().getMap("Servers").getMap(getName());
@ -293,7 +297,7 @@ public class ExternalSubServer extends SubServerImpl {
case "host":
if (value.isString() && host.removeSubServer(player, getName())) {
waitFor(() -> host.getSubServer(getName()), null);
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
SubServer server = this.host.plugin.api.getHost(value.asRawString()).constructSubServer(getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
if (server != null) {
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
@ -306,7 +310,7 @@ public class ExternalSubServer extends SubServerImpl {
break;
case "template":
if (value.isString()) {
Util.reflect(SubServerImpl.class.getDeclaredField("template"), this, value.asString());
setTemplate(value.asRawString());
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Template", value.asString());
this.host.plugin.servers.save();
@ -317,7 +321,7 @@ public class ExternalSubServer extends SubServerImpl {
case "port":
if (value.isNumber() && host.removeSubServer(player, getName())) {
waitFor(() -> host.getSubServer(getName()), null);
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
SubServer server = host.constructSubServer(getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
if (server != null) {
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
@ -330,7 +334,7 @@ public class ExternalSubServer extends SubServerImpl {
break;
case "motd":
if (value.isString()) {
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
setMotd(ChatColor.translateAlternateColorCodes('&', value.asString()));
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
this.host.plugin.servers.save();
@ -353,7 +357,7 @@ public class ExternalSubServer extends SubServerImpl {
case "directory":
if (value.isString() && host.removeSubServer(player, getName())) {
waitFor(() -> host.getSubServer(getName()), null);
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), value.asRawString(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
SubServer server = host.constructSubServer(getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), value.asRawString(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
if (server != null) {
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Directory", server.getPath());
@ -368,7 +372,7 @@ public class ExternalSubServer extends SubServerImpl {
case "executable":
if (value.isString() && host.removeSubServer(player, getName())) {
waitFor(() -> host.getSubServer(getName()), null);
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), value.asRawString(), getStopCommand(), isHidden(), isRestricted());
SubServer server = host.constructSubServer(getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), value.asRawString(), getStopCommand(), isHidden(), isRestricted());
if (server != null) {
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
@ -435,7 +439,7 @@ public class ExternalSubServer extends SubServerImpl {
break;
case "restricted":
if (value.isBoolean()) {
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
setRestricted(value.asBoolean());
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
this.host.plugin.servers.save();
@ -445,7 +449,7 @@ public class ExternalSubServer extends SubServerImpl {
break;
case "hidden":
if (value.isBoolean()) {
Util.reflect(ServerImpl.class.getDeclaredField("hidden"), this, value.asBoolean());
setHidden(value.asBoolean());
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
this.host.plugin.servers.save();
@ -464,7 +468,7 @@ public class ExternalSubServer extends SubServerImpl {
forward.setStopAction(getStopAction());
if (!getName().equals(getDisplayName())) forward.setDisplayName(getDisplayName());
List<String> groups = new ArrayList<String>();
Util.reflect(SubServerImpl.class.getDeclaredField("template"), forward, Util.reflect(SubServerImpl.class.getDeclaredField("template"), this));
forward.setTemplate(getTemplate());
groups.addAll(getGroups());
for (String group : groups) {
removeGroup(group);
@ -510,7 +514,6 @@ public class ExternalSubServer extends SubServerImpl {
public void setDisplayName(String value) {
super.setDisplayName(value);
logger.name = getDisplayName();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("display", value), false));
}
@Override
@ -526,7 +529,6 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setEnabled(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("enabled", value), false));
if (enabled != value) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_ENABLED, (Boolean) value));
enabled = value;
}
@ -539,7 +541,6 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("log", value), false));
if (log.value() != value) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_LOGGING, (Boolean) value));
log.value(value);
}
@ -572,7 +573,6 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setStopCommand(String value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("stop-cmd", value), false));
if (!stopcmd.equals(value)) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_STOP_COMMAND, value));
stopcmd = value;
}
@ -585,7 +585,6 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setStopAction(StopAction action) {
if (Util.isNull(action)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("stop-action", action), false));
stopaction = action;
}
}

View File

@ -262,9 +262,8 @@ public abstract class Host implements ExtraDataHandler {
public abstract SubServer getSubServer(String name);
/**
* Adds a SubServer
* Constructs a SubServer (but doesn't add it to the server manager)
*
* @param player Player who Added
* @param name Name of Server
* @param enabled Enabled Status
* @param port Port Number
@ -278,7 +277,7 @@ public abstract class Host implements ExtraDataHandler {
* @return The SubServer
* @throws InvalidServerException
*/
public abstract SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException;
public abstract SubServer constructSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException;
/**
* Adds a SubServer
@ -300,6 +299,47 @@ public abstract class Host implements ExtraDataHandler {
return addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
}
/**
* Adds a SubServer
*
* @param player Player who Added
* @param name Name of Server
* @param enabled Enabled Status
* @param port Port Number
* @param motd Motd of the Server
* @param log Logging Status
* @param directory Directory
* @param executable Executable String
* @param stopcmd Command to Stop the Server
* @param hidden if the server should be hidden from players
* @param restricted Players will need a permission to join if true
* @return The SubServer
* @throws InvalidServerException
*/
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
SubServer server = constructSubServer(name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
return (addSubServer(player, server))?server:null;
}
/**
* Adds a SubServer
*
* @param server SubServer to add
* @return Success status
*/
public boolean addSubServer(SubServer server) throws InvalidServerException {
return addSubServer(null, server);
}
/**
* Adds a SubServer
*
* @param player Player who added
* @param server SubServer to add
* @return Success status
*/
public abstract boolean addSubServer(UUID player, SubServer server) throws InvalidServerException;
/**
* Removes a SubServer
*

View File

@ -99,17 +99,22 @@ public class InternalHost extends Host {
}
@Override
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
SubServer server = InternalSubServer.construct(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
public SubServer constructSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
return InternalSubServer.construct(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
}
@Override
public boolean addSubServer(UUID player, SubServer server) throws InvalidServerException {
if (server.getHost() != this) throw new IllegalArgumentException("That Server does not belong to this Host!");
if (plugin.api.getServers().keySet().contains(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
servers.put(name.toLowerCase(), server);
if (UPnP.isUPnPAvailable() && plugin.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(port);
return server;
servers.put(server.getName().toLowerCase(), server);
if (UPnP.isUPnPAvailable() && plugin.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getAddress().getPort());
return true;
} else {
return null;
return false;
}
}

View File

@ -302,7 +302,7 @@ public class InternalSubCreator extends SubCreator {
server.setAll(config);
if (update != null) Util.isException(() -> update.getHost().forceRemoveSubServer(name));
subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"),
subserver = host.constructSubServer(name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"),
server.getRawString("Directory"), server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
@ -319,6 +319,7 @@ public class InternalSubCreator extends SubCreator {
host.plugin.servers.save();
}
host.addSubServer(subserver);
if (update == null && template.getBuildOptions().getBoolean("Run-On-Finish", true))
subserver.start();
}

View File

@ -297,14 +297,18 @@ public class InternalSubServer extends SubServerImpl {
for (String key : edit.getKeys()) {
pending.remove(key);
ObjectMapValue value = edit.get(key);
SubEditServerEvent event = new SubEditServerEvent(player, this, new ContainedPair<String, ObjectMapValue>(key, value), perma);
host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
boolean allowed = true;
if (perma) {
SubEditServerEvent event = new SubEditServerEvent(player, this, new ContainedPair<String, ObjectMapValue>(key, value));
host.plugin.getPluginManager().callEvent(event);
allowed = !event.isCancelled();
}
if (allowed) {
try {
switch (key.toLowerCase()) {
case "name":
if (value.isString() && host.removeSubServer(player, getName())) {
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
SubServer server = host.constructSubServer(value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
if (server != null) {
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
ObjectMap<String> config = this.host.plugin.servers.get().getMap("Servers").getMap(getName());
@ -361,7 +365,7 @@ public class InternalSubServer extends SubServerImpl {
break;
case "host":
if (value.isString() && host.removeSubServer(player, getName())) {
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
SubServer server = this.host.plugin.api.getHost(value.asRawString()).constructSubServer(getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
if (server != null) {
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
@ -374,7 +378,7 @@ public class InternalSubServer extends SubServerImpl {
break;
case "template":
if (value.isString()) {
Util.reflect(SubServerImpl.class.getDeclaredField("template"), this, value.asRawString());
setTemplate(value.asRawString());
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Template", value.asRawString());
this.host.plugin.servers.save();
@ -384,7 +388,7 @@ public class InternalSubServer extends SubServerImpl {
break;
case "port":
if (value.isNumber() && host.removeSubServer(player, getName())) {
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
SubServer server = host.constructSubServer(getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
if (server != null) {
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
@ -397,7 +401,7 @@ public class InternalSubServer extends SubServerImpl {
break;
case "motd":
if (value.isString()) {
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
setMotd(ChatColor.translateAlternateColorCodes('&', value.asString()));
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
this.host.plugin.servers.save();
@ -501,7 +505,7 @@ public class InternalSubServer extends SubServerImpl {
break;
case "restricted":
if (value.isBoolean()) {
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
setRestricted(value.asBoolean());
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
this.host.plugin.servers.save();
@ -511,7 +515,7 @@ public class InternalSubServer extends SubServerImpl {
break;
case "hidden":
if (value.isBoolean()) {
Util.reflect(ServerImpl.class.getDeclaredField("hidden"), this, value.asBoolean());
setHidden(value.asBoolean());
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
this.host.plugin.servers.save();
@ -529,7 +533,7 @@ public class InternalSubServer extends SubServerImpl {
if (forward != null) {
forward.setStopAction(getStopAction());
if (!getName().equals(getDisplayName())) forward.setDisplayName(getDisplayName());
Util.reflect(SubServerImpl.class.getDeclaredField("template"), forward, Util.reflect(SubServerImpl.class.getDeclaredField("template"), this));
forward.setTemplate(getTemplate());
List<String> groups = new ArrayList<String>();
groups.addAll(getGroups());
for (String group : groups) {
@ -541,6 +545,7 @@ public class InternalSubServer extends SubServerImpl {
forward.toggleCompatibility(server);
}
for (String extra : getExtra().getKeys()) forward.addExtra(extra, getExtra(extra));
forward.getHost().addSubServer(player, forward);
if (state) pending.set("state", true);
c += (perma)?forward.permaEdit(player, pending):forward.edit(player, pending);
@ -587,7 +592,6 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setEnabled(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("enabled", value), false));
enabled = value;
}
@ -599,7 +603,6 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("log", value), false));
log.value(value);
}
@ -631,7 +634,6 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setStopCommand(String value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("stop-cmd", value), false));
stopcmd = value;
}
@ -643,7 +645,6 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setStopAction(StopAction action) {
if (Util.isNull(action)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("stop-action", action), false));
stopaction = action;
}
}

View File

@ -126,10 +126,8 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@SuppressWarnings("deprecation")
public void setDisplayName(String value) {
if (value == null || value.length() == 0 || getName().equals(value)) {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("display", getName()), false));
this.nick = null;
} else {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("display", value), false));
this.nick = value;
}
}
@ -168,17 +166,13 @@ public class ServerImpl extends BungeeServerInfo implements Server {
}
@Override
@SuppressWarnings("deprecation")
public void setHidden(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("hidden", value), false));
this.hidden = value;
}
@SuppressWarnings("deprecation")
public void setMotd(String value) {
if (Util.isNull(value)) throw new NullPointerException();
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("motd", value), false));
try {
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, value);
} catch (Exception e) {
@ -186,10 +180,8 @@ public class ServerImpl extends BungeeServerInfo implements Server {
}
}
@SuppressWarnings("deprecation")
public void setRestricted(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("restricted", value), false));
try {
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value);
} catch (Exception e) {

View File

@ -3,7 +3,6 @@ package net.ME1312.SubServers.Bungee.Host;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Pair;
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.SubServers.Bungee.SubAPI;
@ -21,6 +20,7 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
private List<Pair<String, String>> incompatibilities = new ArrayList<Pair<String, String>>();
private SubCreator.ServerTemplate templateV = null;
private String templateS = null;
protected boolean registered;
protected boolean started;
private boolean updating;
@ -110,14 +110,12 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
@Override
public void setTemplate(String template) {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("template", template), false));
this.templateV = null;
this.templateS = template;
}
@Override
public void setTemplate(SubCreator.ServerTemplate template) {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("template", (template != null)?template.getName():null), false));
this.templateV = template;
this.templateS = (template != null)?template.getName():null;
}

View File

@ -6,6 +6,7 @@ import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.External.ExternalSubServer;
import java.util.HashMap;
import java.util.UUID;
@ -32,23 +33,17 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
/**
* New PacketExAddServer (Out)
*
* @param name Name of Server
* @param enabled Enabled Status
* @param log Logging Status
* @param directory Directory
* @param executable Executable
*/
@SafeVarargs
public PacketExAddServer(String name, boolean enabled, int port, boolean log, String directory, String executable, String stopcmd, UUID running, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(name, enabled, log, directory, executable, callback)) throw new NullPointerException();
this.name = name;
this.enabled = enabled;
this.port = port;
this.log = log;
this.directory = directory;
this.executable = executable;
this.stopcmd = stopcmd;
public PacketExAddServer(ExternalSubServer server, UUID running, Callback<ObjectMap<Integer>>... callback) {
if (callback == null) throw new NullPointerException();
this.name = server.getName();
this.enabled = server.isEnabled();
this.port = server.getAddress().getPort();
this.log = server.isLogging();
this.directory = server.getPath();
this.executable = server.getExecutable();
this.stopcmd = server.getStopCommand();
this.running = running;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
callbacks.put(tracker, callback);

View File

@ -151,7 +151,6 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
args.set("server", event.getServer().getName());
args.set("edit", event.getEdit().key());
args.set("value", event.getEdit().value().asObject());
args.set("perm", event.isPermanent());
broadcast(new PacketOutExRunEvent(event.getClass(), args));
}
}

View File

@ -213,7 +213,7 @@ public final class SubAPI implements BungeeAPI {
*/
public Host addHost(UUID player, Class<? extends Host> driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
if (Util.isNull(driver, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
Host host = driver.getConstructor(SubProxy.class, String.class, boolean.class, Range.class, boolean.class, InetAddress.class, String.class, String.class).newInstance(plugin, name, enabled, ports, log, address, directory, gitBash);
Host host = plugin.constructHost(driver, name, enabled, ports, log, address, directory, gitBash);
return addHost(player, host)?host:null;
}
@ -410,15 +410,37 @@ public final class SubAPI implements BungeeAPI {
* @return The Server
*/
public Server addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
if (getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
Server server = ServerImpl.construct(name, new InetSocketAddress(ip, port), motd, hidden, restricted);
return (addServer(player, server))?server:null;
}
/**
* Adds a Server to the Network
*
* @param server Server to add
* @return Success status
*/
public boolean addServer(Server server) {
return addServer(null, server);
}
/**
* Adds a Server to the Network
*
* @param player Player who added
* @param server Server to add
* @return Success status
*/
public boolean addServer(UUID player, Server server) {
if (getServers().keySet().contains(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
SubAddServerEvent event = new SubAddServerEvent(player, null, server);
plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
plugin.exServers.put(name.toLowerCase(), server);
return server;
plugin.exServers.put(server.getName().toLowerCase(), server);
return true;
} else {
return null;
return false;
}
}

View File

@ -370,8 +370,10 @@ public final class SubProxy extends BungeeCommon implements Listener {
Logger.get("SubServers").info(((status)?"Rel":"L")+"oading Hosts...");
for (String name : config.get().getMap("Hosts").getKeys()) {
if (!ukeys.contains(name.toLowerCase())) try {
if (!hostDrivers.keySet().contains(config.get().getMap("Hosts").getMap(name).getRawString("Driver").toUpperCase().replace('-', '_').replace(' ', '_'))) throw new InvalidHostException("Invalid Driver for host: " + name);
boolean add = false;
Host host = this.hosts.get(name.toLowerCase());
Class<? extends Host> driver = hostDrivers.get(config.get().getMap("Hosts").getMap(name).getRawString("Driver").toUpperCase().replace('-', '_').replace(' ', '_'));
if (driver == null) throw new InvalidHostException("Invalid Driver for host: " + name);
if (host == null || // Host must be reset
!hostDrivers.get(config.get().getMap("Hosts").getMap(name).getRawString("Driver").toUpperCase().replace('-', '_').replace(' ', '_')).equals(host.getClass()) ||
!config.get().getMap("Hosts").getMap(name).getRawString("Address").equals(host.getAddress().getHostAddress()) ||
@ -379,7 +381,8 @@ public final class SubProxy extends BungeeCommon implements Listener {
!config.get().getMap("Hosts").getMap(name).getRawString("Git-Bash").equals(host.getCreator().getBashDirectory())
) {
if (host != null) api.forceRemoveHost(name);
host = api.addHost(config.get().getMap("Hosts").getMap(name).getRawString("Driver").toLowerCase(), name, config.get().getMap("Hosts").getMap(name).getBoolean("Enabled"),
add = true;
host = constructHost(driver, name, config.get().getMap("Hosts").getMap(name).getBoolean("Enabled"),
Range.closed(Integer.parseInt(config.get().getMap("Hosts").getMap(name).getRawString("Port-Range", "25500-25559").split("-")[0]), Integer.parseInt(config.get().getMap("Hosts").getMap(name).getRawString("Port-Range", "25500-25559").split("-")[1])),
config.get().getMap("Hosts").getMap(name).getBoolean("Log-Creator", true), InetAddress.getByName(config.get().getMap("Hosts").getMap(name).getRawString("Address")),
config.get().getMap("Hosts").getMap(name).getRawString("Directory"), config.get().getMap("Hosts").getMap(name).getRawString("Git-Bash"));
@ -396,6 +399,8 @@ public final class SubProxy extends BungeeCommon implements Listener {
host.setDisplayName(config.get().getMap("Hosts").getMap(name).getString("Display"));
if (config.get().getMap("Hosts").getMap(name).getKeys().contains("Extra"))
for (String extra : config.get().getMap("Hosts").getMap(name).getMap("Extra").getKeys()) host.addExtra(extra, config.get().getMap("Hosts").getMap(name).getMap("Extra").getObject(extra));
if (add)
api.addHost(host);
ukeys.add(name.toLowerCase());
hosts++;
} catch (Exception e) {
@ -409,14 +414,16 @@ public final class SubProxy extends BungeeCommon implements Listener {
bungee.reload();
for (String name : bungee.get().getMap("servers").getKeys()) {
if (!ukeys.contains(name.toLowerCase())) try {
boolean add = false;
Server server = api.getServer(name);
if (server == null || !(server instanceof SubServer)) {
if (server == null || // Server must be reset
bungee.get().getMap("servers").getMap(name).getRawString("address").equals(server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort())
) {
if (server != null) api.forceRemoveServer(name);
server = api.addServer(name, InetAddress.getByName(bungee.get().getMap("servers").getMap(name).getRawString("address").split(":")[0]),
Integer.parseInt(bungee.get().getMap("servers").getMap(name).getRawString("address").split(":")[1]), ChatColor.translateAlternateColorCodes('&', bungee.get().getMap("servers").getMap(name).getString("motd")),
add = true;
server = ServerImpl.construct(name, new InetSocketAddress(InetAddress.getByName(bungee.get().getMap("servers").getMap(name).getRawString("address").split(":")[0]),
Integer.parseInt(bungee.get().getMap("servers").getMap(name).getRawString("address").split(":")[1])), ChatColor.translateAlternateColorCodes('&', bungee.get().getMap("servers").getMap(name).getString("motd")),
bungee.get().getMap("servers").getMap(name).getBoolean("hidden", false), bungee.get().getMap("servers").getMap(name).getBoolean("restricted"));
} else { // Server wasn't reset, so check for these changes
if (!ChatColor.translateAlternateColorCodes('&', bungee.get().getMap("servers").getMap(name).getString("motd")).equals(server.getMotd()))
@ -436,6 +443,8 @@ public final class SubProxy extends BungeeCommon implements Listener {
for (String extra : config.get().getMap("servers").getMap(name).getMap("extra").getKeys()) server.addExtra(extra, config.get().getMap("servers").getMap(name).getMap("extra").getObject(extra));
if (server.getSubData()[0] != null)
((SubDataClient) server.getSubData()[0]).sendPacket(new PacketOutExReload(null));
if (add)
api.addServer(server);
ukeys.add(name.toLowerCase());
servers++;
}
@ -455,6 +464,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
exServers.remove(name.toLowerCase());
servers--;
}
boolean add = false;
SubServer server = api.getSubServer(name);
if (server != null && server.isEditable()) { // Server can edit() (May be reset depending on change severity)
ObjectMap<String> edits = new ObjectMap<String>();
@ -501,7 +511,8 @@ public final class SubProxy extends BungeeCommon implements Listener {
!this.servers.get().getMap("Servers").getMap(name).getRawString("Executable").equals(server.getExecutable())
) {
if (server != null) server.getHost().forceRemoveSubServer(name);
server = this.hosts.get(this.servers.get().getMap("Servers").getMap(name).getString("Host").toLowerCase()).addSubServer(name, this.servers.get().getMap("Servers").getMap(name).getBoolean("Enabled"),
add = true;
server = this.hosts.get(this.servers.get().getMap("Servers").getMap(name).getString("Host").toLowerCase()).constructSubServer(name, this.servers.get().getMap("Servers").getMap(name).getBoolean("Enabled"),
this.servers.get().getMap("Servers").getMap(name).getInt("Port"), ChatColor.translateAlternateColorCodes('&', this.servers.get().getMap("Servers").getMap(name).getString("Motd")), this.servers.get().getMap("Servers").getMap(name).getBoolean("Log"),
this.servers.get().getMap("Servers").getMap(name).getRawString("Directory"), this.servers.get().getMap("Servers").getMap(name).getRawString("Executable"), this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Command"),
this.servers.get().getMap("Servers").getMap(name).getBoolean("Hidden"), this.servers.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
@ -534,6 +545,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
}
} // Apply these changes regardless of edit/reset
if (this.servers.get().getMap("Servers").getMap(name).getKeys().contains("Extra")) for (String extra : this.servers.get().getMap("Servers").getMap(name).getMap("Extra").getKeys()) server.addExtra(extra, this.servers.get().getMap("Servers").getMap(name).getMap("Extra").getObject(extra));
if (add) server.getHost().addSubServer(server);
ukeys.add(name.toLowerCase());
subservers++;
} catch (Exception e) {
@ -849,6 +861,11 @@ public final class SubProxy extends BungeeCommon implements Listener {
return (result.length() == 0) ? DIGITS.substring(0, 1) : result.toString();
}
Host constructHost(Class<? extends Host> driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
if (Util.isNull(driver, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
return driver.getConstructor(SubProxy.class, String.class, boolean.class, Range.class, boolean.class, InetAddress.class, String.class, String.class).newInstance(this, name, enabled, ports, log, address, directory, gitBash);
}
/**
* Further override BungeeCord's signature when patched into the same jar
*

View File

@ -19,7 +19,6 @@ public class SubEditServerEvent extends Event implements SubEvent {
private UUID player;
private String server;
private Pair<String, ObjectMapValue<String>> edit;
private boolean perm;
/**
* Server Edit Event
@ -27,16 +26,14 @@ public class SubEditServerEvent extends Event implements SubEvent {
* @param player Player Adding Server
* @param server Server to be Edited
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new ContainedPair<String, ObjectMapValue<String>>(edit.key(), section.contains(".")?section.get("."):null);
this.perm = permanent;
}
/**
@ -62,15 +59,6 @@ public class SubEditServerEvent extends Event implements SubEvent {
return edit;
}
/**
* Gets if the edit is permanent
*
* @return Permanent Status
*/
public boolean isPermanent() {
return perm;
}
@Override
public HandlerList getHandlers() {
return handlers;

View File

@ -86,7 +86,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@Override
public void run(ObjectMap<String> data) {
if (plugin.isEnabled()) {
Bukkit.getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new ContainedPair<String, Object>(data.getString("edit"), data.get("value")), data.getBoolean("perm")));
Bukkit.getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new ContainedPair<String, Object>(data.getString("edit"), data.get("value"))));
callback("SubEditServerEvent", this);
}
}

View File

@ -19,7 +19,6 @@ public class SubEditServerEvent extends AbstractEvent implements SubEvent {
private UUID player;
private String server;
private Pair<String, ObjectMapValue<String>> edit;
private boolean perm;
/**
* Server Edit Event
@ -27,16 +26,14 @@ public class SubEditServerEvent extends AbstractEvent implements SubEvent {
* @param player Player Adding Server
* @param server Server to be Edited
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new ContainedPair<String, ObjectMapValue<String>>(edit.key(), section.contains(".")?section.get("."):null);
this.perm = permanent;
}
/**
@ -62,15 +59,6 @@ public class SubEditServerEvent extends AbstractEvent implements SubEvent {
return edit;
}
/**
* Gets if the edit is permanent
*
* @return Permanent Status
*/
public boolean isPermanent() {
return perm;
}
/**
* Gets the cause of this Event
*

View File

@ -73,7 +73,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> data) {
Sponge.getEventManager().post(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new ContainedPair<String, Object>(data.getString("edit"), data.get("value")), data.getBoolean("perm")));
Sponge.getEventManager().post(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new ContainedPair<String, Object>(data.getString("edit"), data.get("value"))));
callback("SubEditServerEvent", this);
}
});

View File

@ -16,7 +16,6 @@ public class SubEditServerEvent extends Event {
private UUID player;
private String server;
private Pair<String, ObjectMapValue<String>> edit;
private boolean perm;
/**
* Server Edit Event
@ -24,16 +23,14 @@ public class SubEditServerEvent extends Event {
* @param player Player Adding Server
* @param server Server to be Edited
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new ContainedPair<String, ObjectMapValue<String>>(edit.key(), section.get("."));
this.perm = permanent;
}
/**
@ -58,13 +55,4 @@ public class SubEditServerEvent extends Event {
public Pair<String, ObjectMapValue<String>> getEdit() {
return edit;
}
/**
* Gets if the edit is permanent
*
* @return Permanent Status
*/
public boolean isPermanent() {
return perm;
}
}

View File

@ -70,7 +70,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> data) {
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new ContainedPair<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new ContainedPair<String, Object>(data.getRawString("edit"), data.get("value"))));
callback("SubEditServerEvent", this);
}
});

View File

@ -18,7 +18,6 @@ public class SubEditServerEvent extends Event implements SubEvent {
private UUID player;
private String server;
private Pair<String, ObjectMapValue<String>> edit;
private boolean perm;
/**
* Server Edit Event
@ -26,16 +25,14 @@ public class SubEditServerEvent extends Event implements SubEvent {
* @param player Player Adding Server
* @param server Server to be Edited
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new ContainedPair<String, ObjectMapValue<String>>(edit.key(), section.get("."));
this.perm = permanent;
}
/**
@ -60,13 +57,4 @@ public class SubEditServerEvent extends Event implements SubEvent {
public Pair<String, ObjectMapValue<String>> getEdit() {
return edit;
}
/**
* Gets if the edit is permanent
*
* @return Permanent Status
*/
public boolean isPermanent() {
return perm;
}
}

View File

@ -72,7 +72,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> data) {
ProxyServer.getInstance().getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new ContainedPair<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
ProxyServer.getInstance().getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new ContainedPair<String, Object>(data.getRawString("edit"), data.get("value"))));
callback("SubEditServerEvent", this);
}
});