mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
SubServers.Bungee Beta 2
This commit is contained in:
parent
e177acc722
commit
82b9d9b2d0
Binary file not shown.
BIN
SubServers.Bungee/Vanilla-Patch.jar
Normal file
BIN
SubServers.Bungee/Vanilla-Patch.jar
Normal file
Binary file not shown.
@ -2,11 +2,13 @@ package net.ME1312.SubServers.Proxy.Event;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.Host;
|
||||
import net.ME1312.SubServers.Proxy.Host.Server;
|
||||
import net.ME1312.SubServers.Proxy.Library.SubEvent;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubAddServerEvent extends Event {
|
||||
public class SubAddServerEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private Host host;
|
||||
|
@ -2,12 +2,14 @@ package net.ME1312.SubServers.Proxy.Event;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.Host;
|
||||
import net.ME1312.SubServers.Proxy.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Proxy.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubCreateEvent extends Event {
|
||||
public class SubCreateEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private Host host;
|
||||
|
@ -1,10 +1,11 @@
|
||||
package net.ME1312.SubServers.Proxy.Event;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class SubDataRecieveGenericInfoEvent extends Event {
|
||||
public class SubDataRecieveGenericInfoEvent extends Event implements SubEvent{
|
||||
private String handle;
|
||||
private Version version;
|
||||
private JSONObject content;
|
||||
|
@ -1,11 +1,13 @@
|
||||
package net.ME1312.SubServers.Proxy.Event;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.SubEvent;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubSendCommandEvent extends Event {
|
||||
public class SubSendCommandEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private SubServer server;
|
||||
|
@ -1,11 +1,13 @@
|
||||
package net.ME1312.SubServers.Proxy.Event;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.SubEvent;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubStartEvent extends Event {
|
||||
public class SubStartEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private SubServer server;
|
||||
|
@ -1,11 +1,13 @@
|
||||
package net.ME1312.SubServers.Proxy.Event;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.SubEvent;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubStopEvent extends Event {
|
||||
public class SubStopEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private SubServer server;
|
||||
|
@ -1,9 +1,10 @@
|
||||
package net.ME1312.SubServers.Proxy.Event;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.SubEvent;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
public class SubStoppedEvent extends Event {
|
||||
public class SubStoppedEvent extends Event implements SubEvent {
|
||||
private SubServer server;
|
||||
|
||||
/**
|
||||
|
@ -77,8 +77,8 @@ public abstract class Host {
|
||||
*
|
||||
* @param servers Servers
|
||||
*/
|
||||
public void start(String... servers) {
|
||||
start(null, servers);
|
||||
public int start(String... servers) {
|
||||
return start(null, servers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,15 +87,15 @@ public abstract class Host {
|
||||
* @param player Player who started
|
||||
* @param servers Servers
|
||||
*/
|
||||
public abstract void start(UUID player, String... servers);
|
||||
public abstract int start(UUID player, String... servers);
|
||||
|
||||
/**
|
||||
* Stops the Servers Specified
|
||||
*
|
||||
* @param servers Servers
|
||||
*/
|
||||
public void stop(String... servers) {
|
||||
stop(null, servers);
|
||||
public int stop(String... servers) {
|
||||
return stop(null, servers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,15 +104,15 @@ public abstract class Host {
|
||||
* @param player Player who started
|
||||
* @param servers Servers
|
||||
*/
|
||||
public abstract void stop(UUID player, String... servers);
|
||||
public abstract int stop(UUID player, String... servers);
|
||||
|
||||
/**
|
||||
* Terminates the Servers Specified
|
||||
*
|
||||
* @param servers Servers
|
||||
*/
|
||||
public void terminate(String... servers) {
|
||||
terminate(null, servers);
|
||||
public int terminate(String... servers) {
|
||||
return terminate(null, servers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +121,7 @@ public abstract class Host {
|
||||
* @param player Player who started
|
||||
* @param servers Servers
|
||||
*/
|
||||
public abstract void terminate(UUID player, String... servers);
|
||||
public abstract int terminate(UUID player, String... servers);
|
||||
|
||||
/**
|
||||
* Commands the Servers Specified
|
||||
@ -129,8 +129,8 @@ public abstract class Host {
|
||||
* @param command Command to send
|
||||
* @param servers Servers
|
||||
*/
|
||||
public void command(String command, String... servers) {
|
||||
command(null, command, servers);
|
||||
public int command(String command, String... servers) {
|
||||
return command(null, command, servers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,14 +140,14 @@ public abstract class Host {
|
||||
* @param command Command to send
|
||||
* @param servers Servers
|
||||
*/
|
||||
public abstract void command(UUID player, String command, String... servers);
|
||||
public abstract int command(UUID player, String command, String... servers);
|
||||
|
||||
/**
|
||||
* Applies edits to the Host
|
||||
*
|
||||
* @param change Change(s) to be applied
|
||||
*/
|
||||
public abstract void edit(NamedContainer<String, ?>... change);
|
||||
public abstract boolean edit(NamedContainer<String, ?>... change);
|
||||
|
||||
/**
|
||||
* Gets the SubCreator Instance for this Host
|
||||
@ -184,12 +184,13 @@ public abstract class Host {
|
||||
* @param executable Executable
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param restart Auto Restart Status
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param temporary Temporary Status
|
||||
* @return The SubServer
|
||||
* @throws InvalidServerException
|
||||
*/
|
||||
public abstract SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean start, boolean restart, boolean restricted, boolean temporary) throws InvalidServerException;
|
||||
public abstract SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean start, boolean restart, boolean hidden, boolean restricted, boolean temporary) throws InvalidServerException;
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
@ -203,13 +204,14 @@ public abstract class Host {
|
||||
* @param executable Executable
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param restart Auto Restart Status
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param temporary Temporary Status
|
||||
* @return The SubServer
|
||||
* @throws InvalidServerException
|
||||
*/
|
||||
public SubServer addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean start, boolean restart, boolean restricted, boolean temporary) throws InvalidServerException {
|
||||
return addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, start, restart, restricted, temporary);
|
||||
public SubServer addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean start, boolean restart, boolean hidden, boolean restricted, boolean temporary) throws InvalidServerException {
|
||||
return addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, start, restart, hidden, restricted, temporary);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,40 +66,49 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(UUID player, String... servers) {
|
||||
public int start(UUID player, String... servers) {
|
||||
int i = 0;
|
||||
for (String server : servers) {
|
||||
this.servers.get(server.toLowerCase()).start(player);
|
||||
if (this.servers.get(server.toLowerCase()).start(player)) i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(UUID player, String... servers) {
|
||||
public int stop(UUID player, String... servers) {
|
||||
int i = 0;
|
||||
for (String server : servers) {
|
||||
this.servers.get(server.toLowerCase()).stop(player);
|
||||
if (this.servers.get(server.toLowerCase()).stop(player)) i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void terminate(UUID player, String... servers) {
|
||||
public int terminate(UUID player, String... servers) {
|
||||
int i = 0;
|
||||
for (String server : servers) {
|
||||
this.servers.get(server.toLowerCase()).terminate(player);
|
||||
if (this.servers.get(server.toLowerCase()).terminate(player)) i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(UUID player, String command, String... servers) {
|
||||
public int command(UUID player, String command, String... servers) {
|
||||
int i = 0;
|
||||
for (String server : servers) {
|
||||
this.servers.get(server.toLowerCase()).command(player, command);
|
||||
if (this.servers.get(server.toLowerCase()).command(player, command)) i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(NamedContainer<String, ?>... changes) {
|
||||
public boolean edit(NamedContainer<String, ?>... changes) {
|
||||
for (NamedContainer<String, ?> change : changes) {
|
||||
switch (change.name().toLowerCase()) {
|
||||
// TODO SubEditor
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,9 +127,9 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean start, boolean restart, boolean restricted, boolean temporary) throws InvalidServerException {
|
||||
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean start, boolean restart, boolean hidden, boolean restricted, boolean temporary) throws InvalidServerException {
|
||||
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
|
||||
SubServer server = new InternalSubServer(this, name, enabled, port, motd, log, directory, executable, stopcmd, start, restart, restricted, temporary);
|
||||
SubServer server = new InternalSubServer(this, name, enabled, port, motd, log, directory, executable, stopcmd, start, restart, hidden, restricted, temporary);
|
||||
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
|
@ -46,7 +46,6 @@ public class InternalSubCreator extends SubCreator {
|
||||
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private void GenerateProperties(File dir, int port) throws FileNotFoundException, UnsupportedEncodingException {
|
||||
PrintWriter writer = new PrintWriter(new File(dir, "server.properties"), "UTF-8");
|
||||
|
||||
@ -363,7 +362,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
|
||||
}
|
||||
|
||||
private void run(String name, ServerType type, Version version, int memory, int port) {
|
||||
private void run(UUID player, String name, ServerType type, Version version, int memory, int port) {
|
||||
Executable exec = null;
|
||||
UniversalFile dir = new UniversalFile(new File(host.getDirectory()), name);
|
||||
dir.mkdirs();
|
||||
@ -474,7 +473,8 @@ public class InternalSubCreator extends SubCreator {
|
||||
}
|
||||
|
||||
if (process2.exitValue() == 0) {
|
||||
host.addSubServer(name, true, port, "&aThis is a SubServer", true, dir.getPath(), exec, "stop", true, false, false, false);
|
||||
if (host.plugin.exServers.keySet().contains(name.toLowerCase())) host.plugin.exServers.remove(name.toLowerCase());
|
||||
host.addSubServer(player, name, true, port, "&aThis is a SubServer", true, dir.getPath(), exec, "stop", true, false, false, false, false);
|
||||
|
||||
YAMLSection server = new YAMLSection();
|
||||
server.set("Enabled", true);
|
||||
@ -487,7 +487,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
server.set("Stop-Command", "stop");
|
||||
server.set("Run-On-Launch", false);
|
||||
server.set("Auto-Restart", false);
|
||||
server.set("Auto-Restart", false);
|
||||
server.set("Hidden", false);
|
||||
server.set("Restricted", false);
|
||||
host.plugin.config.get().getSection("Servers").set(name, server);
|
||||
host.plugin.config.save();
|
||||
@ -502,16 +502,17 @@ public class InternalSubCreator extends SubCreator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(UUID player, String name, ServerType type, Version version, int memory, int port) {
|
||||
public boolean create(UUID player, String name, ServerType type, Version version, int memory, int port) {
|
||||
if (!isBusy()) {
|
||||
final SubCreateEvent event = new SubCreateEvent(player, host, name, type, version, memory, port);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
(thread = new Thread(() -> {
|
||||
InternalSubCreator.this.run(name, event.getType(), event.getVersion(), event.getMemory(), port);
|
||||
InternalSubCreator.this.run(player, name, event.getType(), event.getVersion(), event.getMemory(), port);
|
||||
})).start();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,41 +34,38 @@ public class InternalSubLogger extends Thread {
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
String line = null;
|
||||
while ((line = br.readLine()) != null) {
|
||||
if (log.get() && !line.startsWith(">")) {
|
||||
String msg = line;
|
||||
// REGEX Formatting
|
||||
String type = "INFO";
|
||||
Matcher matcher = Pattern.compile("^((?:\\s*\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}]?)?\\s*(?:\\[|\\[.*\\/)?(INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]:?\\s*)").matcher(msg);
|
||||
while (matcher.find()) {
|
||||
type = matcher.group(2);
|
||||
if (!line.startsWith(">")) {
|
||||
if (log.get()) {
|
||||
String msg = line;
|
||||
// REGEX Formatting
|
||||
String type = "INFO";
|
||||
Matcher matcher = Pattern.compile("^((?:\\s*\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}]?)?\\s*(?:\\[|\\[.*\\/)?(INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]:?\\s*)").matcher(msg);
|
||||
while (matcher.find()) {
|
||||
type = matcher.group(2);
|
||||
}
|
||||
|
||||
msg = msg.replaceAll("^((?:\\s*\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}]?)?\\s*(?:\\[|\\[.*\\/)?(INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]:?\\s*)", "");
|
||||
|
||||
switch (type) {
|
||||
case "INFO":
|
||||
ProxyServer.getInstance().getLogger().info(name + " > " + msg);
|
||||
break;
|
||||
case "WARNING":
|
||||
case "WARN":
|
||||
ProxyServer.getInstance().getLogger().warning(name + " > " + msg);
|
||||
break;
|
||||
case "SEVERE":
|
||||
case "ERROR":
|
||||
case "ERR":
|
||||
ProxyServer.getInstance().getLogger().severe(name + " > " + msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replaceAll("^((?:\\s*\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}]?)?\\s*(?:\\[|\\[.*\\/)?(INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]:?\\s*)", "");
|
||||
|
||||
switch (type) {
|
||||
case "INFO":
|
||||
ProxyServer.getInstance().getLogger().info(name + " > " + msg);
|
||||
break;
|
||||
case "WARNING":
|
||||
case "WARN":
|
||||
ProxyServer.getInstance().getLogger().warning(name + " > " + msg);
|
||||
break;
|
||||
case "SEVERE":
|
||||
case "ERROR":
|
||||
case "ERR":
|
||||
ProxyServer.getInstance().getLogger().severe(name + " > " + msg);
|
||||
break;
|
||||
}
|
||||
|
||||
if (writer != null) {
|
||||
writer.println(line);
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
if (writer != null) {
|
||||
writer.println(line);
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {} finally {
|
||||
if (writer != null) {
|
||||
|
@ -29,10 +29,9 @@ public class InternalSubServer extends SubServer {
|
||||
private boolean restart;
|
||||
private boolean allowrestart;
|
||||
private boolean temporary;
|
||||
private InternalSubServer instance;
|
||||
|
||||
public InternalSubServer(Host host, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean start, boolean restart, boolean restricted, boolean temporary) throws InvalidServerException {
|
||||
super(host, name, port, motd, restricted);
|
||||
public InternalSubServer(Host host, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean start, boolean restart, boolean hidden, boolean restricted, boolean temporary) throws InvalidServerException {
|
||||
super(host, name, port, motd, hidden, restricted);
|
||||
this.host = (InternalHost) host;
|
||||
this.enabled = enabled;
|
||||
this.log = new Container<Boolean>(log);
|
||||
@ -43,7 +42,6 @@ public class InternalSubServer extends SubServer {
|
||||
this.command = null;
|
||||
this.restart = restart;
|
||||
this.temporary = temporary;
|
||||
this.instance = this;
|
||||
|
||||
if (start || temporary) start();
|
||||
}
|
||||
@ -53,8 +51,8 @@ public class InternalSubServer extends SubServer {
|
||||
allowrestart = true;
|
||||
try {
|
||||
process = Runtime.getRuntime().exec(executable.toString(), null, directory);
|
||||
System.out.println("SubServers > Now starting " + instance.getName());
|
||||
final InternalSubLogger read = new InternalSubLogger(process.getInputStream(), instance.getName(), log, null);
|
||||
System.out.println("SubServers > Now starting " + getName());
|
||||
final InternalSubLogger read = new InternalSubLogger(process.getInputStream(), getName(), log, null);
|
||||
read.start();
|
||||
command = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
|
||||
|
||||
@ -68,15 +66,15 @@ public class InternalSubServer extends SubServer {
|
||||
allowrestart = false;
|
||||
}
|
||||
|
||||
SubStoppedEvent event = new SubStoppedEvent(instance);
|
||||
SubStoppedEvent event = new SubStoppedEvent(this);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
System.out.println("SubServers > " + instance.getName() + " has stopped");
|
||||
System.out.println("SubServers > " + getName() + " has stopped");
|
||||
process = null;
|
||||
command = null;
|
||||
|
||||
if (temporary) {
|
||||
try {
|
||||
host.removeSubServer(instance.getName());
|
||||
host.removeSubServer(getName());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -94,69 +92,78 @@ public class InternalSubServer extends SubServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(UUID player) {
|
||||
public boolean start(UUID player) {
|
||||
if (enabled && !isRunning()) {
|
||||
SubStartEvent event = new SubStartEvent(player, this);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
run();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(UUID player) {
|
||||
public boolean stop(UUID player) {
|
||||
if (isRunning()) {
|
||||
SubStopEvent event = new SubStopEvent(player, this, false);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
try {
|
||||
allowrestart = false;
|
||||
command.write(stopcmd);
|
||||
command.newLine();
|
||||
command.flush();
|
||||
allowrestart = false;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void terminate(UUID player) {
|
||||
public boolean terminate(UUID player) {
|
||||
if (isRunning()) {
|
||||
SubStopEvent event = new SubStopEvent(player, this, true);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
allowrestart = false;
|
||||
process.destroyForcibly();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(UUID player, String command) {
|
||||
public boolean command(UUID player, String command) {
|
||||
if (isRunning()) {
|
||||
SubSendCommandEvent event = new SubSendCommandEvent(player, this, command);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
try {
|
||||
if (event.getCommand().equalsIgnoreCase(stopcmd)) allowrestart = false;
|
||||
this.command.write(event.getCommand());
|
||||
this.command.newLine();
|
||||
this.command.flush();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(NamedContainer<String, ?>... changes) {
|
||||
public boolean edit(NamedContainer<String, ?>... changes) {
|
||||
for (NamedContainer<String, ?> change : changes) {
|
||||
switch (change.name().toLowerCase()) {
|
||||
// TODO SubEditor
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@ import java.net.InetSocketAddress;
|
||||
public class Server extends BungeeServerInfo implements ClientHandler {
|
||||
private Client client = null;
|
||||
|
||||
public Server(String name, InetSocketAddress address, String motd, boolean restricted) throws InvalidServerException {
|
||||
public Server(String name, InetSocketAddress address, String motd, boolean hidden, boolean restricted) throws InvalidServerException {
|
||||
super(name, address, ChatColor.translateAlternateColorCodes('&', motd), restricted);
|
||||
if (name.contains(" ")) throw new InvalidServerException("Server names cannot have spaces: " + name);
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ public abstract class SubCreator {
|
||||
SPONGE,
|
||||
}
|
||||
|
||||
public abstract void create(UUID player, String name, ServerType type, Version version, int memory, int port);
|
||||
public void create(String name, ServerType type, Version version, int memory, int port) {
|
||||
create(null, name, type, version, memory, port);
|
||||
public abstract boolean create(UUID player, String name, ServerType type, Version version, int memory, int port);
|
||||
public boolean create(String name, ServerType type, Version version, int memory, int port) {
|
||||
return create(null, name, type, version, memory, port);
|
||||
}
|
||||
|
||||
public abstract void waitFor() throws InterruptedException;
|
||||
|
@ -23,50 +23,59 @@ public abstract class SubServer extends Server {
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @throws InvalidServerException
|
||||
*/
|
||||
public SubServer(Host host, String name, int port, String motd, boolean restricted) throws InvalidServerException {
|
||||
super(name, InetSocketAddress.createUnresolved(host.getAddress().getHostAddress(), port), motd, restricted);
|
||||
public SubServer(Host host, String name, int port, String motd, boolean hidden, boolean restricted) throws InvalidServerException {
|
||||
super(name, InetSocketAddress.createUnresolved(host.getAddress().getHostAddress(), port), motd, hidden, restricted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Server
|
||||
*
|
||||
* @param player Player who Started
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract void start(UUID player);
|
||||
public abstract boolean start(UUID player);
|
||||
|
||||
/**
|
||||
* Starts the Server
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public void start() {
|
||||
start(null);
|
||||
public boolean start() {
|
||||
return start(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the Server
|
||||
*
|
||||
* @param player Player who Stopped
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract void stop(UUID player);
|
||||
public abstract boolean stop(UUID player);
|
||||
|
||||
/**
|
||||
* Stops the Server
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public void stop() {
|
||||
stop(null);
|
||||
public boolean stop() {
|
||||
return stop(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminates the Server
|
||||
*
|
||||
* @param player Player who Terminated
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract void terminate(UUID player);
|
||||
public abstract boolean terminate(UUID player);
|
||||
|
||||
/**
|
||||
* Terminates the Server
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public void terminate() {
|
||||
terminate(null);
|
||||
public boolean terminate() {
|
||||
return terminate(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,24 +83,27 @@ public abstract class SubServer extends Server {
|
||||
*
|
||||
* @param player Player who Commanded
|
||||
* @param command Command to Send
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract void command(UUID player, String command);
|
||||
public abstract boolean command(UUID player, String command);
|
||||
|
||||
/**
|
||||
* Commands the Server
|
||||
*
|
||||
* @param command Command to Send
|
||||
* @return Success Status
|
||||
*/
|
||||
public void command(String command) {
|
||||
command(null, command);
|
||||
public boolean command(String command) {
|
||||
return command(null, command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies edits to the SubServer
|
||||
*
|
||||
* @param change Change(s) to be applied
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract void edit(NamedContainer<String, ?>... change);
|
||||
public abstract boolean edit(NamedContainer<String, ?>... change);
|
||||
|
||||
/**
|
||||
* Waits for the Server to Stop
|
||||
|
@ -3,20 +3,72 @@ Lang:
|
||||
'Interface.Generic.Back': '&cBack'
|
||||
'Interface.Generic.Back-Arrow': '&e&l<--'
|
||||
'Interface.Generic.Next-Arrow': '&e&l-->'
|
||||
'Interface.Generic.Undo': '&6Undo'
|
||||
'Interface.Generic.Downloading': '&bSubServers \u00BB Downloading - $str$'
|
||||
'Interface.Generic.Downloading.Title': 'Downloading...'
|
||||
'Interface.Generic.Downloading.Title-Color': '&b'
|
||||
'Interface.Generic.Downloading.Title-Color-Alt': '&3'
|
||||
'Interface.Generic.Downloading.Response': '&eWaiting for response'
|
||||
'Interface.Host-Menu.Title': 'Host Menu'
|
||||
'Interface.Host-Menu.Host-Disabled': '&4Disabled'
|
||||
'Interface.Host-Menu.Host-Server-Count': '&9$int$ Servers'
|
||||
'Interface.Host-Menu.No-Hosts': '&4&oThere are No Hosts'
|
||||
'Interface.Host-Menu.No-Hosts': '&c&oThere are No Hosts'
|
||||
'Interface.Host-Menu.SubServer-Menu': '&a&lSubServer Menu'
|
||||
'Interface.Host-Admin.Title': 'Host/$str$'
|
||||
'Interface.Host-Admin.Creator': '&eCreate a SubServer'
|
||||
'Interface.Host-Admin.Creator-Busy': '&4SubCreator is already running'
|
||||
'Interface.Host-Admin.SubServers': '&aView SubServers'
|
||||
'Interface.Host-Admin.Editor': '&eEdit Host'
|
||||
'Interface.Host-Admin.Editor-Unavailable': '&4This Host cannot be edited'
|
||||
'Interface.Host-Creator.Title': 'Host/$str$/Create'
|
||||
'Interface.Host-Creator.Edit-Name': 'Change Name'
|
||||
'Interface.Host-Creator.Edit-Name.Title': '&eSubCreator\n&6Enter a Name for this Server'
|
||||
'Interface.Host-Creator.Edit-Name.Message': '&eSubCreator \u00BB Enter a Name for this Server via Chat'
|
||||
'Interface.Host-Creator.Edit-Name.Exists': '&cSubCreator \u00BB There is already a SubServer with that name'
|
||||
'Interface.Host-Creator.Edit-Name.Exists-Title': '&eSubCreator\n&cThere is already a SubServer with that name'
|
||||
'Interface.Host-Creator.Edit-Name.Invalid': '&cSubCreator \u00BB Invalid Server Name'
|
||||
'Interface.Host-Creator.Edit-Name.Invalid-Title': '&eSubCreator\n&cInvalid Server Name'
|
||||
'Interface.Host-Creator.Edit-Type': 'Change Server Type'
|
||||
'Interface.Host-Creator.Edit-Type.Title': '&eSubCreator\n&6Enter a Type of Server'
|
||||
'Interface.Host-Creator.Edit-Type.Message': '&eSubCreator \u00BB Enter a Type of Server via Chat'
|
||||
'Interface.Host-Creator.Edit-Type.Invalid': '&cSubCreator \u00BB There is no server type with that name'
|
||||
'Interface.Host-Creator.Edit-Type.Invalid-Title': '&eSubCreator\n&cThere is no server type with that name'
|
||||
'Interface.Host-Creator.Edit-Version': 'Change Server Version'
|
||||
'Interface.Host-Creator.Edit-Version.Title': '&eSubCreator\n&6Enter a Server Version'
|
||||
'Interface.Host-Creator.Edit-Version.Message': '&eSubCreator \u00BB Enter a Server Version via Chat'
|
||||
'Interface.Host-Creator.Edit-Version.Unavailable': '&cSubCreator \u00BB SubCreator cannot create servers before Minecraft 1.8'
|
||||
'Interface.Host-Creator.Edit-Version.Unavailable-Title': '&eSubCreator\n&cCannot create servers before MC 1.8'
|
||||
'Interface.Host-Creator.Edit-Port': 'Change Server Port'
|
||||
'Interface.Host-Creator.Edit-Port.Title': '&eSubCreator\n&6Enter a Port Number'
|
||||
'Interface.Host-Creator.Edit-Port.Message': '&eSubCreator \u00BB Enter a Port Number via Chat'
|
||||
'Interface.Host-Creator.Edit-Port.Invalid': '&cSubCreator \u00BB Invalid Port Number'
|
||||
'Interface.Host-Creator.Edit-Port.Invalid-Title': '&eSubCreator\n&cInvalid Port Number'
|
||||
'Interface.Host-Creator.Edit-RAM': 'Change Server Memory Amount'
|
||||
'Interface.Host-Creator.Edit-RAM.Title': '&eSubCreator\n&6Enter a RAM Amount'
|
||||
'Interface.Host-Creator.Edit-RAM.Message': '&eSubCreator \u00BB Enter a RAM Amount via Chat'
|
||||
'Interface.Host-Creator.Edit-RAM.Invalid': '&cSubCreator \u00BB Invalid Ram Amount'
|
||||
'Interface.Host-Creator.Edit-RAM.Invalid-Title': '&eSubCreator\n&cInvalid Ram Amount'
|
||||
'Interface.Host-Creator.Submit': '&eCreate SubServer'
|
||||
'Interface.Host-Creator.Form-Incomplete': '&4Buttons above must be green'
|
||||
'Interface.Host-Editor.Title': 'Host/$str$/Edit'
|
||||
'Interface.Host-SubServer.Title': 'Host/$str$/SubServers'
|
||||
'Interface.SubServer-Menu.Title': 'SubServer Menu'
|
||||
'Interface.SubServer-Menu.SubServer-Player-Count': '&e$int$ Players Online'
|
||||
'Interface.SubServer-Menu.SubServer-Online': '&2Online'
|
||||
'Interface.SubServer-Menu.SubServer-Player-Count': '&2$int$ Players Online'
|
||||
'Interface.SubServer-Menu.SubServer-Temporary': '&9Temporary'
|
||||
'Interface.SubServer-Menu.SubServer-Offline': '&6Offline'
|
||||
'Interface.SubServer-Menu.SubServer-Disabled': '&4Disabled'
|
||||
'Interface.SubServer-Menu.No-SubServers': '&4&oThere are No SubServers'
|
||||
'Interface.SubServer-Menu.No-SubServers': '&c&oThere are No SubServers'
|
||||
'Interface.SubServer-Menu.Host-Menu': '&b&lHost Menu'
|
||||
'Interface.SubServer-Admin.Title': 'SubServer/$str$'
|
||||
'Interface.SubServer-Admin.Start': '&aStart SubServer'
|
||||
'Interface.SubServer-Admin.Start.Title': '&aStarting SubServer'
|
||||
'Interface.SubServer-Admin.Stop': '&cStop SubServer'
|
||||
'Interface.SubServer-Admin.Stop.Title': '&cStopping $str$'
|
||||
'Interface.SubServer-Admin.Terminate': '&4Terminate SubServer'
|
||||
'Interface.SubServer-Admin.Terminate.Title': '&cTerminating $str$'
|
||||
'Interface.SubServer-Admin.Command': '&eSend a Command to the SubServer'
|
||||
'Interface.SubServer-Admin.Command.Title': '&eSubServers\n&6Enter a Command to send via Chat'
|
||||
'Interface.SubServer-Admin.Command.Message': '&eSubServers \u00BB Enter a Command to send via Chat'
|
||||
'Interface.SubServer-Admin.Teleport': '&bTeleport to Server'
|
||||
'Interface.SubServer-Admin.Editor': '&eEdit SubServer'
|
||||
'Interface.SubServer-Admin.Editor-Unavailable': '&4This SubServer cannot be edited'
|
@ -0,0 +1,7 @@
|
||||
package net.ME1312.SubServers.Proxy.Library;
|
||||
|
||||
public interface SubEvent {
|
||||
/*
|
||||
This Class is used to define a SubEvent
|
||||
*/
|
||||
}
|
@ -9,14 +9,14 @@ import org.json.JSONObject;
|
||||
|
||||
public class PacketAuthorization implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private boolean response;
|
||||
private int response;
|
||||
private String message;
|
||||
|
||||
public PacketAuthorization(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public PacketAuthorization(boolean response, String message) {
|
||||
public PacketAuthorization(int response, String message) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
}
|
||||
@ -34,12 +34,12 @@ public class PacketAuthorization implements PacketIn, PacketOut {
|
||||
try {
|
||||
if (data.getString("password").equals(plugin.config.get().getSection("Settings").getSection("SubData").getString("Password"))) {
|
||||
client.authorize();
|
||||
client.sendPacket(new PacketAuthorization(true, "Successfully Logged in"));
|
||||
client.sendPacket(new PacketAuthorization(0, "Successfully Logged in"));
|
||||
} else {
|
||||
client.sendPacket(new PacketAuthorization(false, "Invalid Password"));
|
||||
client.sendPacket(new PacketAuthorization(2, "Invalid Password"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
client.sendPacket(new PacketAuthorization(false, e.getClass().getCanonicalName() + ": " + e.getMessage()));
|
||||
client.sendPacket(new PacketAuthorization(1, e.getClass().getCanonicalName() + ": " + e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,66 @@
|
||||
package net.ME1312.SubServers.Proxy.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.Server;
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Proxy.Network.Client;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Proxy.SubPlugin;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketCommandServer implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
|
||||
public PacketCommandServer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public PacketCommandServer(int response, String message, String id) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("r", response);
|
||||
json.put("m", message);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, JSONObject data) {
|
||||
try {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(data.getString("server").toLowerCase())) {
|
||||
client.sendPacket(new PacketCommandServer(3, "There is no server with that name", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (!(servers.get(data.getString("server").toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketCommandServer(4, "That Server is not a SubServer", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (!((SubServer) servers.get(data.getString("server").toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketCommandServer(5, "That SubServer is not running", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else {
|
||||
if (((SubServer) servers.get(data.getString("server").toLowerCase())).command((data.keySet().contains("player"))?UUID.fromString(data.getString("player")):null, data.getString("command"))) {
|
||||
client.sendPacket(new PacketCommandServer(0, "Sending Command", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else {
|
||||
client.sendPacket(new PacketCommandServer(1, "Couldn't send command", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketCommandServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package net.ME1312.SubServers.Proxy.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Proxy.Library.Util;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Proxy.Network.Client;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Proxy.SubPlugin;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
|
||||
public PacketCreateServer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public PacketCreateServer(int response, String message, String id) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("r", response);
|
||||
json.put("m", message);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, JSONObject data) {
|
||||
try {
|
||||
if (data.getJSONObject("creator").getString("name").contains(" ")) {
|
||||
client.sendPacket(new PacketCreateServer(3, "server names cannot have spaces", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (plugin.api.getSubServers().keySet().contains(data.getJSONObject("creator").getString("name").toLowerCase())) {
|
||||
client.sendPacket(new PacketCreateServer(3, "There is already a subserver with that name", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (!plugin.hosts.keySet().contains(data.getJSONObject("creator").getString("host").toLowerCase())) {
|
||||
client.sendPacket(new PacketCreateServer(4, "There is no Host with that name", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (plugin.hosts.get(data.getJSONObject("creator").getString("host").toLowerCase()).getCreator().isBusy()) {
|
||||
client.sendPacket(new PacketCreateServer(5, "The SubCreator instance on that host is already running", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (Util.isException(() -> SubCreator.ServerType.valueOf(data.getJSONObject("creator").getString("type").toUpperCase()))) {
|
||||
client.sendPacket(new PacketCreateServer(6, "There is no server type with that name", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (new Version("1.8").compareTo(new Version(data.getJSONObject("creator").getString("version"))) > 0) {
|
||||
client.sendPacket(new PacketCreateServer(7, "SubCreator cannot create servers before Minecraft 1.8", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (data.getJSONObject("creator").getInt("port") <= 0 || data.getJSONObject("creator").getInt("port") > 65535) {
|
||||
client.sendPacket(new PacketCreateServer(8, "Invalid Port Number", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else if (data.getJSONObject("creator").getInt("ram") < 256) {
|
||||
client.sendPacket(new PacketCreateServer(9, "Invalid Ram Amount", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else {
|
||||
if (plugin.hosts.get(data.getJSONObject("creator").getString("host").toLowerCase()).getCreator().create((data.keySet().contains("player"))?UUID.fromString(data.getString("player")):null, data.getJSONObject("creator").getString("name"), SubCreator.ServerType.valueOf(data.getJSONObject("creator").getString("type").toUpperCase()), new Version(data.getJSONObject("creator").getString("version")), data.getJSONObject("creator").getInt("ram"), data.getJSONObject("creator").getInt("port"))) {
|
||||
client.sendPacket(new PacketCreateServer(0, "Creaing SubServer", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
} else {
|
||||
client.sendPacket(new PacketCreateServer(1, "Couldn't create SubServer", (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketCreateServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.keySet().contains("id")) ? data.getString("id") : null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("Lang", plugin.lang.get().getSection("Lang").toJSON());
|
||||
json.put("Lang", plugin.api.getLang());
|
||||
return json;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
|
||||
if (server != null && server instanceof SubServer) {
|
||||
info.put("host", ((SubServer) server).getHost().getName());
|
||||
info.put("enabled", ((SubServer) server).isEnabled());
|
||||
info.put("enabled", ((SubServer) server).isEnabled() && ((SubServer) server).getHost().isEnabled());
|
||||
info.put("editable", ((SubServer) server).isEditable());
|
||||
info.put("log", ((SubServer) server).isLogging());
|
||||
info.put("dir", plugin.config.get().getSection("Servers").getSection(server.getName()).getString("Directory"));
|
||||
|
@ -60,7 +60,7 @@ public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
JSONObject servers = new JSONObject();
|
||||
for (SubServer server : host.getSubServers().values()) {
|
||||
JSONObject sinfo = new JSONObject();
|
||||
sinfo.put("enabled", server.isEnabled());
|
||||
sinfo.put("enabled", server.isEnabled() && host.isEnabled());
|
||||
sinfo.put("running", server.isRunning());
|
||||
sinfo.put("temp", server.isTemporary());
|
||||
JSONObject players = new JSONObject();
|
||||
|
@ -13,14 +13,14 @@ import java.util.Map;
|
||||
|
||||
public class PacketLinkServer implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private boolean response;
|
||||
private int response;
|
||||
private String message;
|
||||
|
||||
public PacketLinkServer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public PacketLinkServer(boolean response, String message) {
|
||||
public PacketLinkServer(int response, String message) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
}
|
||||
@ -43,15 +43,16 @@ public class PacketLinkServer implements PacketIn, PacketOut {
|
||||
if (server.getSubDataClient() == null) {
|
||||
server.linkSubDataClient(client);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as " + ((server instanceof SubServer) ? "SubServer" : "Server") + ": " + server.getName());
|
||||
client.sendPacket(new PacketLinkServer(true, "Definition Successful"));
|
||||
client.sendPacket(new PacketLinkServer(0, "Definition Successful"));
|
||||
if (server instanceof SubServer && !((SubServer) server).isRunning()) client.sendPacket(new PacketOutShutdown("Rogue SubServer Detected"));
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkServer(false, "Server already linked"));
|
||||
client.sendPacket(new PacketLinkServer(3, "Server already linked"));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkServer(false, "There is no server with that name"));
|
||||
client.sendPacket(new PacketLinkServer(2, "There is no server with that name"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
client.sendPacket(new PacketLinkServer(false, e.getClass().getCanonicalName() + ": " + e.getMessage()));
|
||||
client.sendPacket(new PacketLinkServer(1, e.getClass().getCanonicalName() + ": " + e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,128 @@
|
||||
package net.ME1312.SubServers.Proxy.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Event.*;
|
||||
import net.ME1312.SubServers.Proxy.Host.Server;
|
||||
import net.ME1312.SubServers.Proxy.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Proxy.SubPlugin;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PacketOutRunEvent implements Listener, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private Map<String, ?> args;
|
||||
private String type;
|
||||
|
||||
public PacketOutRunEvent(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public PacketOutRunEvent(Class<? extends SubEvent> event, Map<String, ?> args) {
|
||||
this.type = event.getSimpleName();
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("type", type);
|
||||
json.put("args", args);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void event(SubAddServerEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
List<Server> list = new ArrayList<Server>();
|
||||
list.addAll(plugin.api.getServers().values());
|
||||
for (Server server : list) {
|
||||
HashMap<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("player", ((event.getPlayer() == null)?null:event.getPlayer().toString()));
|
||||
args.put("host", event.getHost().getName());
|
||||
args.put("server", event.getServer().getName());
|
||||
if (server.getSubDataClient() != null) server.getSubDataClient().sendPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void event(SubCreateEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
List<Server> list = new ArrayList<Server>();
|
||||
list.addAll(plugin.api.getServers().values());
|
||||
for (Server server : list) {
|
||||
HashMap<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("player", ((event.getPlayer() == null)?null:event.getPlayer().toString()));
|
||||
args.put("host", event.getHost().getName());
|
||||
args.put("name", event.getName());
|
||||
args.put("type", event.getType().toString());
|
||||
args.put("version", event.getVersion().toString());
|
||||
args.put("port", event.getPort());
|
||||
args.put("memory", event.getMemory());
|
||||
if (server.getSubDataClient() != null) server.getSubDataClient().sendPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void event(SubSendCommandEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
List<Server> list = new ArrayList<Server>();
|
||||
list.addAll(plugin.api.getServers().values());
|
||||
for (Server server : list) {
|
||||
HashMap<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("player", ((event.getPlayer() == null)?null:event.getPlayer().toString()));
|
||||
args.put("server", event.getServer().getName());
|
||||
args.put("command", event.getCommand());
|
||||
if (server.getSubDataClient() != null) server.getSubDataClient().sendPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void event(SubStartEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
List<Server> list = new ArrayList<Server>();
|
||||
list.addAll(plugin.api.getServers().values());
|
||||
for (Server server : list) {
|
||||
HashMap<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("player", ((event.getPlayer() == null)?null:event.getPlayer().toString()));
|
||||
args.put("server", event.getServer().getName());
|
||||
if (server.getSubDataClient() != null) server.getSubDataClient().sendPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void event(SubStopEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
List<Server> list = new ArrayList<Server>();
|
||||
list.addAll(plugin.api.getServers().values());
|
||||
for (Server server : list) {
|
||||
HashMap<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("player", ((event.getPlayer() == null)?null:event.getPlayer().toString()));
|
||||
args.put("server", event.getServer().getName());
|
||||
if (server.getSubDataClient() != null) server.getSubDataClient().sendPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void event(SubStoppedEvent event) {
|
||||
List<Server> list = new ArrayList<Server>();
|
||||
list.addAll(plugin.api.getServers().values());
|
||||
for (Server server : list) {
|
||||
HashMap<String, Object> args = new HashMap<String, Object>();
|
||||
args.put("server", event.getServer().getName());
|
||||
if (server.getSubDataClient() != null) server.getSubDataClient().sendPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package net.ME1312.SubServers.Proxy.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class PacketOutShutdown implements PacketOut {
|
||||
private String message;
|
||||
|
||||
public PacketOutShutdown(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
if (message == null) {
|
||||
return null;
|
||||
} else {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("m", message);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package net.ME1312.SubServers.Proxy.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.Server;
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Proxy.Network.Client;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Proxy.SubPlugin;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketStartServer implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
|
||||
public PacketStartServer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public PacketStartServer(int response, String message, String id) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("r", response);
|
||||
json.put("m", message);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, JSONObject data) {
|
||||
try {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(data.getString("server").toLowerCase())) {
|
||||
client.sendPacket(new PacketStartServer(3, "There is no server with that name", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else if (!(servers.get(data.getString("server").toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketStartServer(4, "That Server is not a SubServer", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else if (!((SubServer) servers.get(data.getString("server").toLowerCase())).getHost().isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(5, "That SubServer's Host is not enabled", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else if (!((SubServer) servers.get(data.getString("server").toLowerCase())).isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(5, "That SubServer is not enabled", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else if (((SubServer) servers.get(data.getString("server").toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketStartServer(6, "That SubServer is already running", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else {
|
||||
if (((SubServer) servers.get(data.getString("server").toLowerCase())).start((data.keySet().contains("player"))?UUID.fromString(data.getString("player")):null)) {
|
||||
client.sendPacket(new PacketStartServer(0, "Starting SubServer", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else {
|
||||
client.sendPacket(new PacketStartServer(1, "Couldn't start SubServer", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketStartServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package net.ME1312.SubServers.Proxy.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.Server;
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Proxy.Network.Client;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Proxy.SubPlugin;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketStopServer implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
|
||||
public PacketStopServer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public PacketStopServer(int response, String message, String id) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("r", response);
|
||||
json.put("m", message);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, JSONObject data) {
|
||||
try {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(data.getString("server").toLowerCase())) {
|
||||
client.sendPacket(new PacketStopServer(3, "There is no server with that name", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else if (!(servers.get(data.getString("server").toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketStopServer(4, "That Server is not a SubServer", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else if (!((SubServer) servers.get(data.getString("server").toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketStopServer(5, "That SubServer is not running", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else if (data.keySet().contains("force") && data.getBoolean("force")) {
|
||||
if (((SubServer) servers.get(data.getString("server").toLowerCase())).terminate((data.keySet().contains("player"))?UUID.fromString(data.getString("player")):null)) {
|
||||
client.sendPacket(new PacketStopServer(0, "Terminating SubServer", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else {
|
||||
client.sendPacket(new PacketStopServer(1, "Couldn't terminate SubServer", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
}
|
||||
} else {
|
||||
if (((SubServer) servers.get(data.getString("server").toLowerCase())).stop((data.keySet().contains("player"))?UUID.fromString(data.getString("player")):null)) {
|
||||
client.sendPacket(new PacketStopServer(0, "Stopping SubServer", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else {
|
||||
client.sendPacket(new PacketStopServer(1, "Couldn't stop SubServer", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketStopServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package net.ME1312.SubServers.Proxy.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.Server;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Proxy.Network.Client;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Proxy.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Proxy.SubPlugin;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketTeleportPlayer implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
|
||||
public PacketTeleportPlayer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public PacketTeleportPlayer(int response, String message, String id) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("r", response);
|
||||
json.put("m", message);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, JSONObject data) {
|
||||
try {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(data.getString("server").toLowerCase())) {
|
||||
client.sendPacket(new PacketTeleportPlayer(2, "There is no server with that name", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else if (plugin.getPlayer(UUID.fromString(data.getString("player"))) == null) {
|
||||
client.sendPacket(new PacketTeleportPlayer(3, "There is no player with that id", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
} else {
|
||||
plugin.getPlayer(UUID.fromString(data.getString("player"))).connect(servers.get(data.getString("server").toLowerCase()));
|
||||
client.sendPacket(new PacketTeleportPlayer(0, "Teleporting Player", (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketTeleportPlayer(1, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.keySet().contains("id"))?data.getString("id"):null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -54,25 +54,39 @@ public final class SubDataServer {
|
||||
}
|
||||
}
|
||||
|
||||
plugin.getPluginManager().registerListener(null, new PacketOutRunEvent(plugin));
|
||||
|
||||
registerPacket(new PacketAuthorization(plugin), "Authorization");
|
||||
registerPacket(new PacketDownloadBuildScript(plugin), "DownloadBuildScript");
|
||||
registerPacket(new PacketDownloadHostInfo(plugin), "DownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(plugin), "DownloadLang");
|
||||
registerPacket(new PacketDownloadPlayerList(plugin), "DownloadPlayerList");
|
||||
registerPacket(new PacketDownloadServerInfo(plugin), "DownloadServerInfo");
|
||||
registerPacket(new PacketDownloadServerList(plugin), "DownloadServerList");
|
||||
registerPacket(new PacketInfoPassthrough(plugin), "InfoPassthrough");
|
||||
registerPacket(new PacketLinkServer(plugin), "LinkServer");
|
||||
registerPacket(new PacketCommandServer(plugin), "SubCommandServer");
|
||||
registerPacket(new PacketCreateServer(plugin), "SubCreateServer");
|
||||
registerPacket(new PacketDownloadBuildScript(plugin), "SubDownloadBuildScript");
|
||||
registerPacket(new PacketDownloadHostInfo(plugin), "SubDownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(plugin), "SubDownloadLang");
|
||||
registerPacket(new PacketDownloadPlayerList(plugin), "SubDownloadPlayerList");
|
||||
registerPacket(new PacketDownloadServerInfo(plugin), "SubDownloadServerInfo");
|
||||
registerPacket(new PacketDownloadServerList(plugin), "SubDownloadServerList");
|
||||
registerPacket(new PacketInfoPassthrough(plugin), "SubInfoPassthrough");
|
||||
registerPacket(new PacketLinkServer(plugin), "SubLinkServer");
|
||||
registerPacket(new PacketStartServer(plugin), "SubStartServer");
|
||||
registerPacket(new PacketStopServer(plugin), "SubStopServer");
|
||||
registerPacket(new PacketTeleportPlayer(plugin), "SubTeleportPlayer");
|
||||
|
||||
registerPacket(PacketAuthorization.class, "Authorization");
|
||||
registerPacket(PacketDownloadBuildScript.class, "DownloadBuildScript");
|
||||
registerPacket(PacketDownloadHostInfo.class, "DownloadHostInfo");
|
||||
registerPacket(PacketDownloadLang.class, "DownloadLang");
|
||||
registerPacket(PacketDownloadPlayerList.class, "DownloadPlayerList");
|
||||
registerPacket(PacketDownloadServerInfo.class, "DownloadServerInfo");
|
||||
registerPacket(PacketDownloadServerList.class, "DownloadServerList");
|
||||
registerPacket(PacketInfoPassthrough.class, "InfoPassthrough");
|
||||
registerPacket(PacketLinkServer.class, "LinkServer");
|
||||
registerPacket(PacketCommandServer.class, "SubCommandServer");
|
||||
registerPacket(PacketCreateServer.class, "SubCreateServer");
|
||||
registerPacket(PacketDownloadBuildScript.class, "SubDownloadBuildScript");
|
||||
registerPacket(PacketDownloadHostInfo.class, "SubDownloadHostInfo");
|
||||
registerPacket(PacketDownloadLang.class, "SubDownloadLang");
|
||||
registerPacket(PacketDownloadPlayerList.class, "SubDownloadPlayerList");
|
||||
registerPacket(PacketDownloadServerInfo.class, "SubDownloadServerInfo");
|
||||
registerPacket(PacketDownloadServerList.class, "SubDownloadServerList");
|
||||
registerPacket(PacketInfoPassthrough.class, "SubInfoPassthrough");
|
||||
registerPacket(PacketLinkServer.class, "SubLinkServer");
|
||||
registerPacket(PacketOutRunEvent.class, "SubRunEvent");
|
||||
registerPacket(PacketOutShutdown.class, "SubShutdown");
|
||||
registerPacket(PacketStartServer.class, "SubStartServer");
|
||||
registerPacket(PacketStopServer.class, "SubStopServer");
|
||||
registerPacket(PacketTeleportPlayer.class, "SubTeleportPlayer");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,12 +4,14 @@ import net.ME1312.SubServers.Proxy.Event.SubAddServerEvent;
|
||||
import net.ME1312.SubServers.Proxy.Host.Server;
|
||||
import net.ME1312.SubServers.Proxy.Host.Host;
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Proxy.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Proxy.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Proxy.Network.SubDataServer;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
@ -108,11 +110,12 @@ public final class SubAPI {
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of 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 Server
|
||||
*/
|
||||
public Server addServer(String name, InetAddress ip, int port, String motd, boolean restricted) {
|
||||
return addServer(null, name, ip, port, motd, restricted);
|
||||
public Server addServer(String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
||||
return addServer(null, name, ip, port, motd, hidden, restricted);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,11 +126,12 @@ public final class SubAPI {
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of 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 Server
|
||||
*/
|
||||
public Server addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean restricted) {
|
||||
Server server = new Server(name, new InetSocketAddress(ip, port), motd, restricted);
|
||||
public Server addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
||||
Server server = new Server(name, new InetSocketAddress(ip, port), motd, hidden, restricted);
|
||||
SubAddServerEvent event = new SubAddServerEvent(player, null, server);
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
@ -171,6 +175,30 @@ public final class SubAPI {
|
||||
return getSubServers().get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubServers Lang
|
||||
*
|
||||
* @return SubServers Lang
|
||||
*/
|
||||
public Map<String, String> getLang() {
|
||||
HashMap<String, String> lang = new HashMap<String, String>();
|
||||
for (String key : plugin.lang.get().getSection("Lang").getKeys()) {
|
||||
if (plugin.lang.get().getSection("Lang").isString(key)) lang.put(key, plugin.lang.get().getSection("Lang").getString(key));
|
||||
}
|
||||
lang.putAll(plugin.exLang);
|
||||
return lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the Language Map
|
||||
*
|
||||
* @param key Key
|
||||
* @param value Lang Value
|
||||
*/
|
||||
public void addLang(String key, String value) {
|
||||
plugin.exLang.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Runtime Directory
|
||||
*
|
||||
|
@ -120,8 +120,8 @@ public final class SubCommand extends Command {
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("create")) {
|
||||
if (args.length > 5) {
|
||||
if (plugin.api.getServers().keySet().contains(args[1].toLowerCase())) {
|
||||
sender.sendMessage("SubServers > There is already a server with that name");
|
||||
if (plugin.api.getSubServers().keySet().contains(args[1].toLowerCase())) {
|
||||
sender.sendMessage("SubServers > There is already a SubServer with that name");
|
||||
} else if (!plugin.hosts.keySet().contains(args[2].toLowerCase())) {
|
||||
sender.sendMessage("SubServers > There is no host with that name");
|
||||
} else if (plugin.hosts.get(args[2].toLowerCase()).getCreator().isBusy()) {
|
||||
|
@ -33,9 +33,10 @@ public final class SubPlugin extends BungeeCord {
|
||||
public final UniversalFile dir = new UniversalFile(new File(System.getProperty("user.dir")));
|
||||
public YAMLConfig config;
|
||||
public YAMLConfig lang;
|
||||
public HashMap<String, String> exLang = new HashMap<String, String>();
|
||||
public SubDataServer subdata = null;
|
||||
public final Version version = new Version("2.11.0a");
|
||||
protected Version bversion = new Version(1);
|
||||
protected Version bversion = new Version(2);
|
||||
|
||||
protected boolean running = false;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
@ -51,7 +52,7 @@ public final class SubPlugin extends BungeeCord {
|
||||
*/
|
||||
protected void enable() throws IOException {
|
||||
if (running) throw new IllegalStateException("SubServers has already been loaded");
|
||||
System.out.println("SubServers > Loading SubServers v" + version.toString() + " Library... ");
|
||||
System.out.println("SubServers > Loading SubServers v" + version.toString() + " Libraries... ");
|
||||
running = true;
|
||||
UniversalFile dir = new UniversalFile(this.dir, "SubServers");
|
||||
dir.mkdir();
|
||||
@ -94,7 +95,7 @@ public final class SubPlugin extends BungeeCord {
|
||||
|
||||
hostDrivers.put("built-in", net.ME1312.SubServers.Proxy.Host.Internal.InternalHost.class);
|
||||
|
||||
System.out.println("SubServers > Loading BungeeCord Library...");
|
||||
System.out.println("SubServers > Loading BungeeCord Libraries...");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +135,7 @@ public final class SubPlugin extends BungeeCord {
|
||||
try {
|
||||
Server server = new Server(name, new InetSocketAddress(bungee.get().getSection("servers").getSection(name).getRawString("address").split(":")[0],
|
||||
Integer.parseInt(bungee.get().getSection("servers").getSection(name).getRawString("address").split(":")[1])), bungee.get().getSection("servers").getSection(name).getColoredString("motd", '&'),
|
||||
bungee.get().getSection("servers").getSection(name).getBoolean("restricted"));
|
||||
bungee.get().getSection("servers").getSection(name).getBoolean("hidden", false), bungee.get().getSection("servers").getSection(name).getBoolean("restricted"));
|
||||
exServers.put(name.toLowerCase(), server);
|
||||
SubDataServer.allowConnection(server.getAddress().getAddress());
|
||||
servers++;
|
||||
@ -155,7 +156,7 @@ public final class SubPlugin extends BungeeCord {
|
||||
SubServer server = this.hosts.get(config.get().getSection("Servers").getSection(name).getString("Host").toLowerCase()).addSubServer(name, config.get().getSection("Servers").getSection(name).getBoolean("Enabled"),
|
||||
config.get().getSection("Servers").getSection(name).getInt("Port"), config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&'), config.get().getSection("Servers").getSection(name).getBoolean("Log"),
|
||||
config.get().getSection("Servers").getSection(name).getRawString("Directory"), new Executable(config.get().getSection("Servers").getSection(name).getRawString("Executable")), config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"),
|
||||
config.get().getSection("Servers").getSection(name).getBoolean("Run-On-Launch"), config.get().getSection("Servers").getSection(name).getBoolean("Auto-Restart"), config.get().getSection("Servers").getSection(name).getBoolean("Restricted"), false);
|
||||
config.get().getSection("Servers").getSection(name).getBoolean("Run-On-Launch"), config.get().getSection("Servers").getSection(name).getBoolean("Hidden", false), config.get().getSection("Servers").getSection(name).getBoolean("Auto-Restart"), config.get().getSection("Servers").getSection(name).getBoolean("Restricted"), false);
|
||||
subservers++;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user